/[svn]/jsampler/trunk/src/org/jsampler/view/std/StdMainFrame.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/StdMainFrame.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1867 - (show annotations) (download)
Mon Mar 16 22:12:32 2009 UTC (15 years, 1 month ago) by iliev
File size: 4271 byte(s)
* proper handling of connection failures
* renamed Channels Panels to Channel Lanes
* code cleanup

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.std;
24
25 import javax.swing.Action;
26
27 import javax.swing.event.ListSelectionEvent;
28 import javax.swing.event.ListSelectionListener;
29
30 import org.jsampler.CC;
31 import org.jsampler.task.Global;
32 import org.jsampler.view.JSChannel;
33 import org.jsampler.view.JSChannelsPane;
34 import org.jsampler.view.JSMainFrame;
35
36 import static org.jsampler.view.std.StdI18n.i18n;
37
38 /**
39 *
40 * @author Grigor Iliev
41 */
42 public abstract class StdMainFrame extends JSMainFrame implements ListSelectionListener {
43 public
44 StdMainFrame() {
45 addChannelsPaneSelectionListener(this);
46 }
47
48 @Override
49 public void
50 addChannelsPane(JSChannelsPane chnPane) {
51 super.addChannelsPane(chnPane);
52 chnPane.addListSelectionListener(this);
53 }
54
55 @Override
56 public boolean
57 removeChannelsPane(JSChannelsPane chnPane) {
58 chnPane.removeListSelectionListener(this);
59 return super.removeChannelsPane(chnPane);
60 }
61
62 @Override
63 public void
64 valueChanged(ListSelectionEvent e) {
65 if(e.getValueIsAdjusting()) return;
66
67 checkChannelSelection(getSelectedChannelsPane());
68 }
69
70 public StdA4n
71 getA4n() { return StdA4n.a4n; }
72
73 private boolean processConnectionFailure = false;
74
75 @Override
76 public void
77 handleConnectionFailure() {
78 if(processConnectionFailure) return;
79 processConnectionFailure = true;
80 CC.getTaskQueue().add(new Global.Disconnect());
81 JSConnectionFailurePane p = new JSConnectionFailurePane();
82 p.showDialog();
83 processConnectionFailure = false;
84 }
85
86 private void
87 checkChannelSelection(JSChannelsPane pane) {
88 if(!pane.hasSelectedChannel()) {
89 getA4n().duplicateChannels.putValue (
90 Action.NAME, i18n.getMenuLabel("channels.duplicate")
91 );
92 getA4n().duplicateChannels.setEnabled(false);
93
94 getA4n().removeChannels.putValue (
95 Action.NAME, i18n.getMenuLabel("channels.removeChannel")
96 );
97 getA4n().removeChannels.setEnabled(false);
98
99 getA4n().moveChannelsOnTop.setEnabled(false);
100 getA4n().moveChannelsUp.setEnabled(false);
101 getA4n().moveChannelsDown.setEnabled(false);
102 getA4n().moveChannelsAtBottom.setEnabled(false);
103
104 return;
105 }
106
107 getA4n().duplicateChannels.setEnabled(true);
108 getA4n().removeChannels.setEnabled(true);
109
110 if(pane.getSelectedChannelCount() > 1) {
111 getA4n().duplicateChannels.putValue (
112 Action.NAME, i18n.getMenuLabel("channels.duplicateChannels")
113 );
114 getA4n().removeChannels.putValue (
115 Action.NAME, i18n.getMenuLabel("channels.removeChannels")
116 );
117 } else {
118 getA4n().duplicateChannels.putValue (
119 Action.NAME, i18n.getMenuLabel("channels.duplicate")
120 );
121 getA4n().removeChannels.putValue (
122 Action.NAME, i18n.getMenuLabel("channels.removeChannel")
123 );
124 }
125
126 getA4n().moveChannelsOnTop.setEnabled(false);
127 getA4n().moveChannelsUp.setEnabled(true);
128 getA4n().moveChannelsDown.setEnabled(true);
129 getA4n().moveChannelsAtBottom.setEnabled(false);
130
131 JSChannel[] chns = pane.getSelectedChannels();
132
133 for(int i = 0; i < chns.length; i++) {
134 if(pane.getChannel(i) != chns[i]) {
135 getA4n().moveChannelsOnTop.setEnabled(true);
136 break;
137 }
138 }
139
140 if(chns[0] == pane.getFirstChannel()) getA4n().moveChannelsUp.setEnabled(false);
141
142 if(chns[chns.length - 1] == pane.getLastChannel())
143 getA4n().moveChannelsDown.setEnabled(false);
144
145 for(int i = chns.length - 1, j = pane.getChannelCount() - 1; i >= 0; i--, j--) {
146 if(pane.getChannel(j) != chns[i]) {
147 getA4n().moveChannelsAtBottom.setEnabled(true);
148 break;
149 }
150 }
151 }
152 }

  ViewVC Help
Powered by ViewVC