1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2011 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.classic; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Color; |
27 |
import java.awt.Dialog; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.Frame; |
30 |
import java.awt.Rectangle; |
31 |
|
32 |
import java.awt.event.ActionEvent; |
33 |
import java.awt.event.ActionListener; |
34 |
import java.awt.event.KeyEvent; |
35 |
|
36 |
import java.io.BufferedReader; |
37 |
import java.io.File; |
38 |
import java.io.FileNotFoundException; |
39 |
import java.io.FileReader; |
40 |
|
41 |
import java.util.Vector; |
42 |
|
43 |
import javax.swing.Action; |
44 |
import javax.swing.ImageIcon; |
45 |
import javax.swing.JCheckBoxMenuItem; |
46 |
import javax.swing.JMenu; |
47 |
import javax.swing.JMenuBar; |
48 |
import javax.swing.JMenuItem; |
49 |
import javax.swing.JPanel; |
50 |
import javax.swing.JSplitPane; |
51 |
import javax.swing.JTabbedPane; |
52 |
import javax.swing.KeyStroke; |
53 |
|
54 |
import javax.swing.event.ChangeEvent; |
55 |
import javax.swing.event.ChangeListener; |
56 |
import javax.swing.event.ListSelectionEvent; |
57 |
import javax.swing.event.ListSelectionListener; |
58 |
|
59 |
import net.sf.juife.NavigationPage; |
60 |
|
61 |
import org.jsampler.CC; |
62 |
import org.jsampler.HF; |
63 |
import org.jsampler.JSUtils; |
64 |
import org.jsampler.LSConsoleModel; |
65 |
import org.jsampler.OrchestraModel; |
66 |
import org.jsampler.Server; |
67 |
|
68 |
import org.jsampler.task.Global; |
69 |
|
70 |
import org.jsampler.view.JSChannel; |
71 |
import org.jsampler.view.JSChannelsPane; |
72 |
|
73 |
import org.jsampler.view.std.JSBackendLogFrame; |
74 |
import org.jsampler.view.std.JSConnectDlg; |
75 |
import org.jsampler.view.std.JSConnectionFailurePane; |
76 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
77 |
import org.jsampler.view.std.JSQuitDlg; |
78 |
import org.jsampler.view.std.JSamplerHomeChooser; |
79 |
import org.jsampler.view.std.StdUtils; |
80 |
|
81 |
import static org.jsampler.view.classic.A4n.a4n; |
82 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
83 |
import static org.jsampler.view.classic.ClassicPrefs.preferences; |
84 |
import static org.jsampler.view.classic.LeftPane.getLeftPane; |
85 |
import static org.jsampler.view.std.StdPrefs.*; |
86 |
|
87 |
/** |
88 |
* |
89 |
* @author Grigor Iliev |
90 |
*/ |
91 |
public class |
92 |
MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener { |
93 |
public static ImageIcon applicationIcon = Res.appIcon; |
94 |
|
95 |
private final ChannelsBar channelsBar = new ChannelsBar(); |
96 |
private final Statusbar statusbar = new Statusbar(); |
97 |
private final JMenuBar menuBar = new JMenuBar(); |
98 |
private final JMenu recentScriptsMenu = |
99 |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
100 |
private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab")); |
101 |
|
102 |
private final JSplitPane vSplitPane; |
103 |
private final JSplitPane hSplitPane; |
104 |
|
105 |
private final JPanel mainPane = new JPanel(); |
106 |
private final StandardBar standardBar = new StandardBar(); |
107 |
private final JPanel channelsPane = new JPanel(new BorderLayout()); |
108 |
private final JPanel rightPane = new JPanel(); |
109 |
private final JPanel bottomPane = new JPanel(); |
110 |
private final LSConsolePane lsConsolePane = new LSConsolePane(this); |
111 |
private LSConsoleDlg lsConsoleDlg = null; |
112 |
private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame(); |
113 |
|
114 |
private final JTabbedPane tabbedPane = |
115 |
new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT); |
116 |
private final Vector<JMenuItem> miList = new Vector<JMenuItem>(); |
117 |
|
118 |
private final JCheckBoxMenuItem cbmiLeftPaneVisible = |
119 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane")); |
120 |
|
121 |
private final JCheckBoxMenuItem cbmiStandardBarVisible = |
122 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.standard")); |
123 |
|
124 |
private final JCheckBoxMenuItem cbmiLSConsoleShown = |
125 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.lsconsole")); |
126 |
|
127 |
private boolean lsConsolePopOut; |
128 |
|
129 |
private final Vector<String> recentScripts = new Vector<String>(); |
130 |
|
131 |
|
132 |
/** Creates a new instance of <code>MainFrame</code>. */ |
133 |
public |
134 |
MainFrame() { |
135 |
setTitle(i18n.getLabel("MainFrame.title")); |
136 |
|
137 |
CC.setMainFrame(this); // TODO: |
138 |
|
139 |
getContentPane().add(standardBar, BorderLayout.NORTH); |
140 |
getContentPane().add(mainPane); |
141 |
|
142 |
mainPane.setLayout(new BorderLayout()); |
143 |
mainPane.add(statusbar, BorderLayout.SOUTH); |
144 |
|
145 |
ChannelsPane p = new ChannelsPane("Untitled"); |
146 |
p.addListSelectionListener(this); |
147 |
getChannelsPaneList().add(p); |
148 |
miList.add(new JMenuItem(new A4n.MoveChannelsTo(p))); |
149 |
|
150 |
channelsPane.add(getChannelsPane(0)); |
151 |
|
152 |
bottomPane.setLayout(new BorderLayout()); |
153 |
|
154 |
rightPane.setLayout(new BorderLayout()); |
155 |
|
156 |
rightPane.add(channelsBar, BorderLayout.NORTH); |
157 |
rightPane.add(channelsPane); |
158 |
|
159 |
hSplitPane = new JSplitPane ( |
160 |
JSplitPane.HORIZONTAL_SPLIT, |
161 |
true, // continuousLayout |
162 |
getLeftPane(), |
163 |
rightPane |
164 |
); |
165 |
|
166 |
hSplitPane.setOneTouchExpandable(true); |
167 |
if(ClassicPrefs.getSaveWindowProperties()) { |
168 |
hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation()); |
169 |
} |
170 |
|
171 |
mainPane.add(hSplitPane); |
172 |
|
173 |
|
174 |
vSplitPane = new JSplitPane ( |
175 |
JSplitPane.VERTICAL_SPLIT, |
176 |
true, // continuousLayout |
177 |
channelsPane, |
178 |
bottomPane |
179 |
); |
180 |
|
181 |
vSplitPane.setDividerSize(3); |
182 |
vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation()); |
183 |
|
184 |
rightPane.add(vSplitPane); |
185 |
|
186 |
if(applicationIcon != null) setIconImage(applicationIcon.getImage()); |
187 |
|
188 |
initMainFrame(); |
189 |
|
190 |
pack(); |
191 |
|
192 |
if(ClassicPrefs.getSaveWindowProperties()) setSavedSize(); |
193 |
else setDefaultSize(); |
194 |
|
195 |
if(ClassicPrefs.getSaveLeftPaneState()) { |
196 |
NavigationPage page = |
197 |
getLeftPane().getPages()[ClassicPrefs.getLeftPanePageIndex()]; |
198 |
|
199 |
getLeftPane().getModel().addPage(page); |
200 |
getLeftPane().getModel().clearHistory(); |
201 |
|
202 |
int idx = ClassicPrefs.getCurrentOrchestraIndex(); |
203 |
if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) { |
204 |
OrchestraModel om = CC.getOrchestras().getOrchestra(idx); |
205 |
getLeftPane().getOrchestrasPage().setSelectedOrchestra(om); |
206 |
} |
207 |
} |
208 |
|
209 |
//CC.getInstrumentsDbTreeModel(); // used to initialize the db tree model |
210 |
} |
211 |
|
212 |
/** Invoked when this window is about to close. */ |
213 |
@Override |
214 |
public void |
215 |
onWindowClose() { |
216 |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
217 |
if(b && CC.getSamplerModel().isModified()) { |
218 |
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
219 |
dlg.setVisible(true); |
220 |
if(dlg.isCancelled()) return; |
221 |
} |
222 |
|
223 |
if(ClassicPrefs.getSaveWindowProperties()) { |
224 |
ClassicPrefs.setWindowMaximized ( |
225 |
"Mainframe", (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
226 |
); |
227 |
|
228 |
setVisible(false); |
229 |
if(ClassicPrefs.getWindowMaximized("MainFrame")) { |
230 |
//setExtendedState(getExtendedState() & ~MAXIMIZED_BOTH); |
231 |
CC.cleanExit(); |
232 |
return; |
233 |
} |
234 |
|
235 |
StdUtils.saveWindowBounds("MainFrame", getBounds()); |
236 |
|
237 |
ClassicPrefs.setHSplitDividerLocation(hSplitPane.getDividerLocation()); |
238 |
} |
239 |
|
240 |
if(ClassicPrefs.getSaveLeftPaneState()) { |
241 |
int idx = 0; |
242 |
for(int i = 0; i < getLeftPane().getPages().length; i++) { |
243 |
if(getLeftPane().getPages()[i] == getLeftPane().getCurrentPage()) { |
244 |
idx = i; |
245 |
break; |
246 |
} |
247 |
} |
248 |
|
249 |
ClassicPrefs.setLeftPanePageIndex(idx); |
250 |
|
251 |
idx = getLeftPane().getOrchestrasPage().getCurrentOrchestraIndex(); |
252 |
|
253 |
if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) |
254 |
ClassicPrefs.setCurrentOrchestraIndex(idx); |
255 |
} |
256 |
|
257 |
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
258 |
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
259 |
|
260 |
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
261 |
lsConsolePane.saveConsoleHistory(); |
262 |
} |
263 |
|
264 |
ClassicPrefs.setShowLSConsole(isLSConsoleShown()); |
265 |
ClassicPrefs.setLSConsolePopOut(isLSConsolePopOut()); |
266 |
|
267 |
ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation()); |
268 |
|
269 |
if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer(); |
270 |
if(lsConsolePane != null) lsConsolePane.disconnect(); |
271 |
super.onWindowClose(); |
272 |
} |
273 |
|
274 |
@Override |
275 |
public void |
276 |
setVisible(boolean b) { |
277 |
if(b == isVisible()) return; |
278 |
|
279 |
super.setVisible(b); |
280 |
|
281 |
if(ClassicPrefs.getWindowMaximized("MainFrame")) { |
282 |
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
283 |
} |
284 |
} |
285 |
|
286 |
private void |
287 |
initMainFrame() { |
288 |
addMenu(); |
289 |
handleEvents(); |
290 |
} |
291 |
|
292 |
private void |
293 |
setDefaultSize() { |
294 |
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
295 |
double width = dimension.getWidth(); |
296 |
double height = dimension.getHeight(); |
297 |
setBounds(50, 100, (int) width - 100, (int) height - 200); |
298 |
} |
299 |
|
300 |
private void |
301 |
setSavedSize() { |
302 |
Rectangle r = StdUtils.getWindowBounds("MainFrame"); |
303 |
if(r == null) { |
304 |
setDefaultSize(); |
305 |
return; |
306 |
} |
307 |
|
308 |
setBounds(r); |
309 |
} |
310 |
|
311 |
private void |
312 |
addMenu() { |
313 |
JMenu m; |
314 |
JMenuItem mi; |
315 |
|
316 |
setJMenuBar(menuBar); |
317 |
|
318 |
// Actions |
319 |
m = new JMenu(i18n.getMenuLabel("actions")); |
320 |
menuBar.add(m); |
321 |
|
322 |
mi = new JMenuItem(a4n.refresh); |
323 |
mi.setIcon(null); |
324 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
325 |
m.add(mi); |
326 |
|
327 |
mi = new JMenuItem(A4n.samplerInfo); |
328 |
mi.setIcon(null); |
329 |
m.add(mi); |
330 |
|
331 |
mi = new JMenuItem(a4n.resetSampler); |
332 |
mi.setIcon(null); |
333 |
m.add(mi); |
334 |
|
335 |
JMenu midiInstrMenu = new JMenu(i18n.getMenuLabel("actions.midiInstruments")); |
336 |
m.add(midiInstrMenu); |
337 |
|
338 |
mi = new JMenuItem(A4n.addMidiInstrumentMap); |
339 |
mi.setIcon(null); |
340 |
midiInstrMenu.add(mi); |
341 |
|
342 |
mi = new JMenuItem(A4n.removeMidiInstrumentMap); |
343 |
mi.setIcon(null); |
344 |
midiInstrMenu.add(mi); |
345 |
|
346 |
mi = new JMenuItem(A4n.addMidiInstrumentWizard); |
347 |
mi.setIcon(null); |
348 |
midiInstrMenu.add(mi); |
349 |
|
350 |
m.addSeparator(); |
351 |
|
352 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
353 |
m.add(exportMenu); |
354 |
|
355 |
int modKey = CC.getViewConfig().getDefaultModKey(); |
356 |
mi = new JMenuItem(a4n.exportSamplerConfig); |
357 |
mi.setIcon(null); |
358 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey)); |
359 |
exportMenu.add(mi); |
360 |
|
361 |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
362 |
mi.setIcon(null); |
363 |
exportMenu.add(mi); |
364 |
|
365 |
m.addSeparator(); |
366 |
|
367 |
mi = new JMenuItem(A4n.loadScript); |
368 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey)); |
369 |
mi.setIcon(null); |
370 |
m.add(mi); |
371 |
|
372 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
373 |
for(String s : list) recentScripts.add(s); |
374 |
|
375 |
updateRecentScriptsMenu(); |
376 |
|
377 |
m.add(recentScriptsMenu); |
378 |
|
379 |
m.addSeparator(); |
380 |
|
381 |
mi = new JMenuItem(a4n.changeBackend); |
382 |
mi.setIcon(null); |
383 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey)); |
384 |
m.add(mi); |
385 |
|
386 |
m.addSeparator(); |
387 |
|
388 |
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
389 |
m.add(mi); |
390 |
mi.addActionListener(new ActionListener() { |
391 |
public void |
392 |
actionPerformed(ActionEvent e) { onWindowClose(); } |
393 |
}); |
394 |
|
395 |
// Edit |
396 |
m = new JMenu(i18n.getMenuLabel("edit")); |
397 |
menuBar.add(m); |
398 |
|
399 |
mi = new JMenuItem(i18n.getMenuLabel("edit.audioDevices")); |
400 |
m.add(mi); |
401 |
mi.addActionListener(new ActionListener() { |
402 |
public void |
403 |
actionPerformed(ActionEvent e) { |
404 |
if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0); |
405 |
LeftPane.getLeftPane().showAudioDevicesPage(); |
406 |
} |
407 |
}); |
408 |
|
409 |
mi = new JMenuItem(i18n.getMenuLabel("edit.midiDevices")); |
410 |
m.add(mi); |
411 |
mi.addActionListener(new ActionListener() { |
412 |
public void |
413 |
actionPerformed(ActionEvent e) { |
414 |
if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0); |
415 |
LeftPane.getLeftPane().showMidiDevicesPage(); |
416 |
} |
417 |
}); |
418 |
|
419 |
mi = new JMenuItem(i18n.getMenuLabel("edit.orchestras")); |
420 |
m.add(mi); |
421 |
mi.addActionListener(new ActionListener() { |
422 |
public void |
423 |
actionPerformed(ActionEvent e) { |
424 |
if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0); |
425 |
LeftPane.getLeftPane().showManageOrchestrasPage(); |
426 |
} |
427 |
}); |
428 |
|
429 |
m.addSeparator(); |
430 |
|
431 |
mi = new JMenuItem(A4n.preferences); |
432 |
mi.setIcon(null); |
433 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
434 |
KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK |
435 |
)); |
436 |
m.add(mi); |
437 |
|
438 |
// View |
439 |
m = new JMenu(i18n.getMenuLabel("view")); |
440 |
menuBar.add(m); |
441 |
|
442 |
JMenu toolbarsMenu = new JMenu(i18n.getMenuLabel("view.toolbars")); |
443 |
m.add(toolbarsMenu); |
444 |
|
445 |
toolbarsMenu.add(cbmiStandardBarVisible); |
446 |
cbmiStandardBarVisible.addActionListener(new ActionListener() { |
447 |
public void |
448 |
actionPerformed(ActionEvent e) { |
449 |
showStandardBar(cbmiStandardBarVisible.getState()); |
450 |
} |
451 |
}); |
452 |
|
453 |
boolean b = ClassicPrefs.shouldShowStandardBar(); |
454 |
cbmiStandardBarVisible.setSelected(b); |
455 |
showStandardBar(b); |
456 |
|
457 |
final JCheckBoxMenuItem cbmi = |
458 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.channels")); |
459 |
|
460 |
toolbarsMenu.add(cbmi); |
461 |
cbmi.addActionListener(new ActionListener() { |
462 |
public void |
463 |
actionPerformed(ActionEvent e) { showChannelsBar(cbmi.getState()); } |
464 |
}); |
465 |
|
466 |
b = ClassicPrefs.shouldShowChannelsBar(); |
467 |
cbmi.setSelected(b); |
468 |
showChannelsBar(b); |
469 |
|
470 |
m.add(cbmiLeftPaneVisible); |
471 |
cbmiLeftPaneVisible.addActionListener(new ActionListener() { |
472 |
public void |
473 |
actionPerformed(ActionEvent e) { |
474 |
showLeftPane(cbmiLeftPaneVisible.getState()); |
475 |
} |
476 |
}); |
477 |
|
478 |
b = ClassicPrefs.shouldShowLeftPane(); |
479 |
cbmiLeftPaneVisible.setSelected(b); |
480 |
showLeftPane(b); |
481 |
|
482 |
final JCheckBoxMenuItem cbmi2 = |
483 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.statusbar")); |
484 |
|
485 |
m.add(cbmi2); |
486 |
cbmi2.addActionListener(new ActionListener() { |
487 |
public void |
488 |
actionPerformed(ActionEvent e) { showStatusbar(cbmi2.getState()); } |
489 |
}); |
490 |
b = ClassicPrefs.shouldShowStatusbar(); |
491 |
cbmi2.setSelected(b); |
492 |
showStatusbar(b); |
493 |
|
494 |
m.addSeparator(); |
495 |
|
496 |
setLSConsolePopOut(ClassicPrefs.isLSConsolePopOut()); |
497 |
cbmiLSConsoleShown.setSelected(ClassicPrefs.shouldShowLSConsole()); |
498 |
showLSConsole(ClassicPrefs.shouldShowLSConsole()); |
499 |
|
500 |
cbmiLSConsoleShown.addActionListener(new ActionListener() { |
501 |
public void |
502 |
actionPerformed(ActionEvent e) { |
503 |
showLSConsole(cbmiLSConsoleShown.isSelected()); |
504 |
} |
505 |
}); |
506 |
m.add(cbmiLSConsoleShown); |
507 |
|
508 |
lsConsolePane.updateLSConsoleViewMode(); |
509 |
|
510 |
// Channels |
511 |
m = new JMenu(i18n.getMenuLabel("channels")); |
512 |
menuBar.add(m); |
513 |
|
514 |
mi = new JMenuItem(A4n.newChannel); |
515 |
mi.setIcon(null); |
516 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, modKey)); |
517 |
m.add(mi); |
518 |
|
519 |
mi = new JMenuItem(A4n.newChannelWizard); |
520 |
mi.setIcon(null); |
521 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
522 |
KeyEvent.VK_N, modKey | KeyEvent.SHIFT_MASK) |
523 |
); |
524 |
m.add(mi); |
525 |
|
526 |
mi = new JMenuItem(a4n.duplicateChannels); |
527 |
mi.setIcon(null); |
528 |
m.add(mi); |
529 |
|
530 |
m.addSeparator(); |
531 |
|
532 |
mi = new JMenuItem(a4n.moveChannelsOnTop); |
533 |
mi.setIcon(null); |
534 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
535 |
KeyEvent.VK_UP, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK |
536 |
)); |
537 |
m.add(mi); |
538 |
|
539 |
mi = new JMenuItem(a4n.moveChannelsUp); |
540 |
mi.setIcon(null); |
541 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK)); |
542 |
m.add(mi); |
543 |
|
544 |
mi = new JMenuItem(a4n.moveChannelsDown); |
545 |
mi.setIcon(null); |
546 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_MASK)); |
547 |
m.add(mi); |
548 |
|
549 |
mi = new JMenuItem(a4n.moveChannelsAtBottom); |
550 |
mi.setIcon(null); |
551 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
552 |
KeyEvent.VK_DOWN, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK |
553 |
)); |
554 |
m.add(mi); |
555 |
|
556 |
tabsMenu.setEnabled(false); |
557 |
m.add(tabsMenu); |
558 |
|
559 |
m.addSeparator(); |
560 |
|
561 |
mi = new JMenuItem(a4n.selectAllChannels); |
562 |
mi.setIcon(null); |
563 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey)); |
564 |
m.add(mi); |
565 |
|
566 |
mi = new JMenuItem(a4n.deselectChannels); |
567 |
mi.setIcon(null); |
568 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
569 |
KeyEvent.VK_A, KeyEvent.SHIFT_MASK | modKey |
570 |
)); |
571 |
m.add(mi); |
572 |
|
573 |
m.addSeparator(); |
574 |
|
575 |
mi = new JMenuItem(a4n.removeChannels); |
576 |
mi.setIcon(null); |
577 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.SHIFT_MASK)); |
578 |
m.add(mi); |
579 |
|
580 |
|
581 |
// Tabs |
582 |
m = new JMenu(i18n.getMenuLabel("tabs")); |
583 |
menuBar.add(m); |
584 |
|
585 |
mi = new JMenuItem(A4n.newChannelsTab); |
586 |
mi.setIcon(null); |
587 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, modKey)); |
588 |
m.add(mi); |
589 |
|
590 |
mi = new JMenuItem(A4n.editTabTitle); |
591 |
mi.setIcon(null); |
592 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)); |
593 |
m.add(mi); |
594 |
|
595 |
m.addSeparator(); |
596 |
|
597 |
mi = new JMenuItem(A4n.moveTab2Beginning); |
598 |
mi.setIcon(null); |
599 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
600 |
KeyEvent.VK_LEFT, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK |
601 |
)); |
602 |
m.add(mi); |
603 |
|
604 |
mi = new JMenuItem(A4n.moveTab2Left); |
605 |
mi.setIcon(null); |
606 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK)); |
607 |
m.add(mi); |
608 |
|
609 |
mi = new JMenuItem(A4n.moveTab2Right); |
610 |
mi.setIcon(null); |
611 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK)); |
612 |
m.add(mi); |
613 |
|
614 |
mi = new JMenuItem(A4n.moveTab2End); |
615 |
mi.setIcon(null); |
616 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
617 |
KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK |
618 |
)); |
619 |
m.add(mi); |
620 |
|
621 |
m.addSeparator(); |
622 |
|
623 |
mi = new JMenuItem(A4n.closeChannelsTab); |
624 |
mi.setIcon(null); |
625 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, modKey)); |
626 |
m.add(mi); |
627 |
|
628 |
|
629 |
// Window |
630 |
m = new JMenu(i18n.getMenuLabel("window")); |
631 |
menuBar.add(m); |
632 |
|
633 |
mi = new JMenuItem(A4n.windowInstrumentsDb); |
634 |
mi.setIcon(null); |
635 |
m.add(mi); |
636 |
|
637 |
final JMenuItem mi2 = new JMenuItem(i18n.getMenuLabel("window.backendLog")); |
638 |
m.add(mi2); |
639 |
mi2.addActionListener(new ActionListener() { |
640 |
public void |
641 |
actionPerformed(ActionEvent e) { |
642 |
if(getBackendLogFrame().isVisible()) { |
643 |
getBackendLogFrame().setVisible(false); |
644 |
} |
645 |
|
646 |
getBackendLogFrame().setVisible(true); |
647 |
} |
648 |
}); |
649 |
|
650 |
mi2.setEnabled(CC.getBackendProcess() != null); |
651 |
|
652 |
CC.addBackendProcessListener(new ActionListener() { |
653 |
public void |
654 |
actionPerformed(ActionEvent e) { |
655 |
mi2.setEnabled(CC.getBackendProcess() != null); |
656 |
} |
657 |
}); |
658 |
|
659 |
|
660 |
// Help |
661 |
m = new JMenu(i18n.getMenuLabel("help")); |
662 |
|
663 |
mi = new JMenuItem(A4n.helpAbout); |
664 |
mi.setIcon(null); |
665 |
m.add(mi); |
666 |
|
667 |
m.addSeparator(); |
668 |
|
669 |
mi = new JMenuItem(a4n.browseOnlineTutorial); |
670 |
mi.setIcon(null); |
671 |
m.add(mi); |
672 |
|
673 |
menuBar.add(m); |
674 |
} |
675 |
|
676 |
private class RecentScriptHandler implements ActionListener { |
677 |
private String script; |
678 |
|
679 |
RecentScriptHandler(String script) { this.script = script; } |
680 |
|
681 |
@Override |
682 |
public void |
683 |
actionPerformed(ActionEvent e) { runScript(script); } |
684 |
} |
685 |
|
686 |
private void |
687 |
handleEvents() { |
688 |
tabbedPane.addChangeListener(this); |
689 |
} |
690 |
|
691 |
private void |
692 |
showChannelsBar(boolean b) { |
693 |
channelsBar.setVisible(b); |
694 |
ClassicPrefs.setShowChannelsBar(b); |
695 |
|
696 |
validate(); |
697 |
repaint(); |
698 |
} |
699 |
|
700 |
private void |
701 |
showStatusbar(boolean b) { |
702 |
ClassicPrefs.setShowStatusbar(b); |
703 |
statusbar.setVisible(b); |
704 |
} |
705 |
|
706 |
protected boolean |
707 |
isLeftPaneVisible() { return cbmiLeftPaneVisible.isSelected(); } |
708 |
|
709 |
protected void |
710 |
setLeftPaneVisible(boolean b) { |
711 |
if(b != cbmiLeftPaneVisible.isSelected()) cbmiLeftPaneVisible.doClick(0); |
712 |
} |
713 |
|
714 |
protected boolean |
715 |
isLSConsoleVisible() { return cbmiLSConsoleShown.isSelected(); } |
716 |
|
717 |
protected void |
718 |
setLSConsoleVisible(boolean b) { |
719 |
if(b != cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0); |
720 |
} |
721 |
|
722 |
private void |
723 |
showLeftPane(boolean b) { |
724 |
ClassicPrefs.setShowLeftPane(b); |
725 |
|
726 |
mainPane.remove(hSplitPane); |
727 |
mainPane.remove(rightPane); |
728 |
|
729 |
if(b) { |
730 |
hSplitPane.setRightComponent(rightPane); |
731 |
mainPane.add(hSplitPane); |
732 |
if(ClassicPrefs.getSaveWindowProperties()) { |
733 |
int i = ClassicPrefs.getHSplitDividerLocation(); |
734 |
hSplitPane.setDividerLocation(i); |
735 |
} |
736 |
} else { |
737 |
mainPane.add(rightPane); |
738 |
} |
739 |
|
740 |
validate(); |
741 |
repaint(); |
742 |
} |
743 |
|
744 |
private void |
745 |
showStandardBar(boolean b) { |
746 |
ClassicPrefs.setShowStandardBar(b); |
747 |
standardBar.setVisible(b); |
748 |
validate(); |
749 |
repaint(); |
750 |
} |
751 |
|
752 |
private void |
753 |
showBottomPane(boolean b) { |
754 |
if(!b) ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation()); |
755 |
|
756 |
rightPane.remove(vSplitPane); |
757 |
rightPane.remove(channelsPane); |
758 |
|
759 |
if(b) { |
760 |
vSplitPane.setTopComponent(channelsPane); |
761 |
rightPane.add(vSplitPane); |
762 |
vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation()); |
763 |
} else { |
764 |
rightPane.add(channelsPane); |
765 |
} |
766 |
|
767 |
validate(); |
768 |
repaint(); |
769 |
} |
770 |
|
771 |
protected void |
772 |
setLSConsolePopOut(boolean b) { |
773 |
if(b == lsConsolePopOut) return; |
774 |
|
775 |
lsConsolePopOut = b; |
776 |
|
777 |
if(isLSConsoleShown()) setLSConsolePopOut0(b); |
778 |
} |
779 |
|
780 |
/** |
781 |
* Changes the pop-out state of the LS Console. |
782 |
* Invoke this method only when LS Console is shown. |
783 |
*/ |
784 |
private void |
785 |
setLSConsolePopOut0(boolean b) { |
786 |
if(b) { |
787 |
bottomPane.remove(lsConsolePane); |
788 |
showBottomPane(false); |
789 |
|
790 |
lsConsoleDlg = new LSConsoleDlg(this, lsConsolePane); |
791 |
lsConsoleDlg.setVisible(true); |
792 |
} else { |
793 |
if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false); |
794 |
lsConsoleDlg = null; |
795 |
bottomPane.add(lsConsolePane); |
796 |
showBottomPane(true); |
797 |
} |
798 |
} |
799 |
|
800 |
protected boolean |
801 |
isLSConsolePopOut() { return lsConsolePopOut; } |
802 |
|
803 |
protected boolean |
804 |
isLSConsoleShown() { return cbmiLSConsoleShown.isSelected(); } |
805 |
|
806 |
protected void |
807 |
setLSConsoleShown(boolean b) { cbmiLSConsoleShown.setSelected(b); } |
808 |
|
809 |
@Override |
810 |
public LSConsoleModel |
811 |
getLSConsoleModel() { return lsConsolePane.getModel(); } |
812 |
|
813 |
protected JSBackendLogFrame |
814 |
getBackendLogFrame() { return backendLogFrame; } |
815 |
|
816 |
/** |
817 |
* Sets the text color of the LS Console. |
818 |
* @param c The text color of the LS Console. |
819 |
*/ |
820 |
protected void |
821 |
setLSConsoleTextColor(Color c) { lsConsolePane.setTextColor(c); } |
822 |
|
823 |
/** |
824 |
* Sets the background color of the LS Console. |
825 |
* @param c The background color of the LS Console. |
826 |
*/ |
827 |
protected void |
828 |
setLSConsoleBackgroundColor(Color c) { lsConsolePane.setBackgroundColor(c); } |
829 |
|
830 |
/** |
831 |
* Sets the notification messages' color of the LS Console. |
832 |
* @param c The notification messages' color of the LS Console. |
833 |
*/ |
834 |
protected void |
835 |
setLSConsoleNotifyColor(Color c) { lsConsolePane.setNotifyColor(c); } |
836 |
|
837 |
/** |
838 |
* Sets the warning messages' color of the LS Console. |
839 |
* @param c The warning messages' color of the LS Console. |
840 |
*/ |
841 |
protected void |
842 |
setLSConsoleWarningColor(Color c) { lsConsolePane.setWarningColor(c); } |
843 |
|
844 |
/** |
845 |
* Sets the error messages' color of the LS Console. |
846 |
* @param c The error messages' color of the LS Console. |
847 |
*/ |
848 |
protected void |
849 |
setLSConsoleErrorColor(Color c) { lsConsolePane.setErrorColor(c); } |
850 |
|
851 |
protected void |
852 |
showLSConsole(boolean b) { |
853 |
if(!b) { |
854 |
showBottomPane(false); |
855 |
if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false); |
856 |
lsConsolePane.hideAutoCompleteWindow(); |
857 |
return; |
858 |
} |
859 |
|
860 |
setLSConsolePopOut0(isLSConsolePopOut()); |
861 |
} |
862 |
|
863 |
/** |
864 |
* Adds the specified <code>JSChannelsPane</code> to the view. |
865 |
* @param chnPane The <code>JSChannelsPane</code> to be added. |
866 |
*/ |
867 |
@Override |
868 |
public void |
869 |
addChannelsPane(JSChannelsPane chnPane) { |
870 |
insertChannelsPane(chnPane, getChannelsPaneCount()); |
871 |
} |
872 |
|
873 |
@Override |
874 |
public void |
875 |
insertChannelsPane(JSChannelsPane chnPane, int idx) { |
876 |
chnPane.addListSelectionListener(this); |
877 |
|
878 |
if(getChannelsPaneCount() == 1) { |
879 |
channelsPane.remove(getChannelsPane(0)); |
880 |
channelsPane.add(tabbedPane); |
881 |
tabbedPane.addTab(getChannelsPane(0).getTitle(), getChannelsPane(0)); |
882 |
A4n.closeChannelsTab.setEnabled(true); |
883 |
A4n.editTabTitle.setEnabled(true); |
884 |
} |
885 |
|
886 |
getChannelsPaneList().insertElementAt(chnPane, idx); |
887 |
tabbedPane.insertTab(chnPane.getTitle(), null, chnPane, null, idx); |
888 |
tabbedPane.setSelectedComponent(chnPane); |
889 |
miList.insertElementAt(new JMenuItem(new A4n.MoveChannelsTo(chnPane)), idx); |
890 |
|
891 |
updateTabsMenu(); |
892 |
|
893 |
firePropertyChange("channelLaneInserted", null, chnPane); |
894 |
} |
895 |
|
896 |
/** |
897 |
* Gets the <code>JSChannelsPane</code> that is currently shown. |
898 |
* @return The currently shown <code>JSChannelsPane</code>. |
899 |
*/ |
900 |
@Override |
901 |
public JSChannelsPane |
902 |
getSelectedChannelsPane() { |
903 |
if(getChannelsPaneList().size() == 1) return getChannelsPane(0); |
904 |
return (JSChannelsPane)tabbedPane.getSelectedComponent(); |
905 |
} |
906 |
|
907 |
/** |
908 |
* Sets the <code>JSChannelsPane</code> to be selected. |
909 |
* @param pane The <code>JSChannelsPane</code> to be shown. |
910 |
*/ |
911 |
@Override |
912 |
public void |
913 |
setSelectedChannelsPane(JSChannelsPane pane) { |
914 |
if(getChannelsPaneList().size() == 1) return; |
915 |
tabbedPane.setSelectedComponent(pane); |
916 |
fireChannelsPaneSelectionChanged(); |
917 |
} |
918 |
|
919 |
/** |
920 |
* Removes the specified <code>JSChannelsPane</code> from the view. |
921 |
* @param chnPane The <code>JSChannelsPane</code> to be removed. |
922 |
* @return <code>true</code> if the specified code>JSChannelsPane</code> |
923 |
* is actually removed from the view, <code>false</code> otherwise. |
924 |
*/ |
925 |
@Override |
926 |
public boolean |
927 |
removeChannelsPane(JSChannelsPane chnPane) { |
928 |
chnPane.removeListSelectionListener(this); |
929 |
|
930 |
tabbedPane.remove(chnPane); |
931 |
boolean b = super.removeChannelsPane(chnPane); |
932 |
for(int i = 0; i < miList.size(); i++) { |
933 |
A4n.MoveChannelsTo a = (A4n.MoveChannelsTo)miList.get(i).getAction(); |
934 |
if(a.getChannelsPane().equals(chnPane)) { |
935 |
miList.remove(i); |
936 |
break; |
937 |
} |
938 |
} |
939 |
|
940 |
updateTabsMenu(); |
941 |
|
942 |
if(getChannelsPaneCount() == 1) { |
943 |
A4n.closeChannelsTab.setEnabled(false); |
944 |
A4n.editTabTitle.setEnabled(false); |
945 |
tabbedPane.remove(getChannelsPane(0)); |
946 |
channelsPane.remove(tabbedPane); |
947 |
channelsPane.add(getChannelsPane(0)); |
948 |
} |
949 |
|
950 |
return b; |
951 |
} |
952 |
|
953 |
private void |
954 |
updateTabsMenu() { |
955 |
tabsMenu.removeAll(); |
956 |
|
957 |
for(JMenuItem mi : miList) { |
958 |
A4n.MoveChannelsTo a = (A4n.MoveChannelsTo)mi.getAction(); |
959 |
if(!a.getChannelsPane().equals(getSelectedChannelsPane())) tabsMenu.add(mi); |
960 |
} |
961 |
|
962 |
} |
963 |
|
964 |
public void |
965 |
updateTabTitle(JSChannelsPane chnPane) { |
966 |
tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), chnPane.getTitle()); |
967 |
} |
968 |
|
969 |
private void |
970 |
checkChannelSelection(JSChannelsPane pane) { |
971 |
if(!pane.hasSelectedChannel()) { |
972 |
a4n.duplicateChannels.putValue ( |
973 |
Action.NAME, i18n.getMenuLabel("channels.duplicate") |
974 |
); |
975 |
a4n.duplicateChannels.setEnabled(false); |
976 |
|
977 |
a4n.removeChannels.putValue ( |
978 |
Action.NAME, i18n.getMenuLabel("channels.RemoveChannel") |
979 |
); |
980 |
a4n.removeChannels.setEnabled(false); |
981 |
|
982 |
tabsMenu.setEnabled(false); |
983 |
|
984 |
a4n.moveChannelsOnTop.setEnabled(false); |
985 |
a4n.moveChannelsUp.setEnabled(false); |
986 |
a4n.moveChannelsDown.setEnabled(false); |
987 |
a4n.moveChannelsAtBottom.setEnabled(false); |
988 |
|
989 |
return; |
990 |
} |
991 |
|
992 |
a4n.duplicateChannels.setEnabled(true); |
993 |
a4n.removeChannels.setEnabled(true); |
994 |
|
995 |
if(getChannelsPaneCount() > 1) tabsMenu.setEnabled(true); |
996 |
|
997 |
if(pane.getSelectedChannelCount() > 1) { |
998 |
a4n.duplicateChannels.putValue ( |
999 |
Action.NAME, i18n.getMenuLabel("channels.duplicateChannels") |
1000 |
); |
1001 |
a4n.removeChannels.putValue ( |
1002 |
Action.NAME, i18n.getMenuLabel("channels.RemoveChannels") |
1003 |
); |
1004 |
} else { |
1005 |
a4n.duplicateChannels.putValue ( |
1006 |
Action.NAME, i18n.getMenuLabel("channels.duplicate") |
1007 |
); |
1008 |
a4n.removeChannels.putValue ( |
1009 |
Action.NAME, i18n.getMenuLabel("channels.RemoveChannel") |
1010 |
); |
1011 |
} |
1012 |
|
1013 |
a4n.moveChannelsOnTop.setEnabled(false); |
1014 |
a4n.moveChannelsUp.setEnabled(true); |
1015 |
a4n.moveChannelsDown.setEnabled(true); |
1016 |
a4n.moveChannelsAtBottom.setEnabled(false); |
1017 |
|
1018 |
JSChannel[] chns = pane.getSelectedChannels(); |
1019 |
|
1020 |
for(int i = 0; i < chns.length; i++) { |
1021 |
if(pane.getChannel(i) != chns[i]) { |
1022 |
a4n.moveChannelsOnTop.setEnabled(true); |
1023 |
break; |
1024 |
} |
1025 |
} |
1026 |
|
1027 |
if(chns[0] == pane.getFirstChannel()) a4n.moveChannelsUp.setEnabled(false); |
1028 |
|
1029 |
if(chns[chns.length - 1] == pane.getLastChannel()) |
1030 |
a4n.moveChannelsDown.setEnabled(false); |
1031 |
|
1032 |
for(int i = chns.length - 1, j = pane.getChannelCount() - 1; i >= 0; i--, j--) { |
1033 |
if(pane.getChannel(j) != chns[i]) { |
1034 |
a4n.moveChannelsAtBottom.setEnabled(true); |
1035 |
break; |
1036 |
} |
1037 |
} |
1038 |
} |
1039 |
|
1040 |
private void |
1041 |
checkTabSelection() { |
1042 |
int si = tabbedPane.getSelectedIndex(); |
1043 |
|
1044 |
if(si > 0) { |
1045 |
A4n.moveTab2Beginning.setEnabled(true); |
1046 |
A4n.moveTab2Left.setEnabled(true); |
1047 |
} else { |
1048 |
A4n.moveTab2Beginning.setEnabled(false); |
1049 |
A4n.moveTab2Left.setEnabled(false); |
1050 |
} |
1051 |
|
1052 |
if(si != -1 && si < tabbedPane.getTabCount() - 1) { |
1053 |
A4n.moveTab2Right.setEnabled(true); |
1054 |
A4n.moveTab2End.setEnabled(true); |
1055 |
} else { |
1056 |
A4n.moveTab2Right.setEnabled(false); |
1057 |
A4n.moveTab2End.setEnabled(false); |
1058 |
} |
1059 |
} |
1060 |
|
1061 |
/*public JTabbedPane |
1062 |
getTabbedPane() { return tabbedPane; }*/ |
1063 |
|
1064 |
public JMenu |
1065 |
getTabsMenu() { return tabsMenu; } |
1066 |
|
1067 |
@Override |
1068 |
public void |
1069 |
stateChanged(ChangeEvent e) { |
1070 |
updateTabsMenu(); |
1071 |
checkChannelSelection(getSelectedChannelsPane()); |
1072 |
checkTabSelection(); |
1073 |
} |
1074 |
|
1075 |
@Override |
1076 |
public void |
1077 |
valueChanged(ListSelectionEvent e) { |
1078 |
if(e.getValueIsAdjusting()) return; |
1079 |
if(e.getSource() != getSelectedChannelsPane()) return; |
1080 |
|
1081 |
checkChannelSelection(getSelectedChannelsPane()); |
1082 |
} |
1083 |
|
1084 |
public void |
1085 |
moveTab2Beginning() { |
1086 |
int idx = tabbedPane.getSelectedIndex(); |
1087 |
if(idx < 1) { |
1088 |
CC.getLogger().info("Can't move tab to beginning"); |
1089 |
return; |
1090 |
} |
1091 |
|
1092 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1093 |
if(getChannelsPane(idx) != c) |
1094 |
CC.getLogger().warning("Channels pane indices don't match"); |
1095 |
removeChannelsPane(c); |
1096 |
insertChannelsPane(c, 0); |
1097 |
tabbedPane.setSelectedComponent(c); |
1098 |
} |
1099 |
|
1100 |
public void |
1101 |
moveTab2Left() { |
1102 |
int idx = tabbedPane.getSelectedIndex(); |
1103 |
if(idx < 1) { |
1104 |
CC.getLogger().info("Can't move tab to left"); |
1105 |
return; |
1106 |
} |
1107 |
|
1108 |
|
1109 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1110 |
if(getChannelsPane(idx) != c) |
1111 |
CC.getLogger().warning("Channels pane indices don't match"); |
1112 |
removeChannelsPane(c); |
1113 |
insertChannelsPane(c, idx - 1); |
1114 |
tabbedPane.setSelectedComponent(c); |
1115 |
} |
1116 |
|
1117 |
public void |
1118 |
moveTab2Right() { |
1119 |
int idx = tabbedPane.getSelectedIndex(); |
1120 |
if(idx == -1 && idx >= tabbedPane.getTabCount()) { |
1121 |
CC.getLogger().info("Can't move tab to right"); |
1122 |
return; |
1123 |
} |
1124 |
|
1125 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1126 |
if(getChannelsPane(idx) != c) |
1127 |
CC.getLogger().warning("Channels pane indices don't match"); |
1128 |
removeChannelsPane(c); |
1129 |
insertChannelsPane(c, idx + 1); |
1130 |
tabbedPane.setSelectedComponent(c); |
1131 |
} |
1132 |
|
1133 |
public void |
1134 |
moveTab2End() { |
1135 |
int idx = tabbedPane.getSelectedIndex(); |
1136 |
if(idx == -1 && idx >= tabbedPane.getTabCount()) { |
1137 |
CC.getLogger().info("Can't move tab to right"); |
1138 |
return; |
1139 |
} |
1140 |
|
1141 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1142 |
if(getChannelsPane(idx) != c) |
1143 |
CC.getLogger().warning("Channels pane indices don't match"); |
1144 |
removeChannelsPane(c); |
1145 |
addChannelsPane(c); |
1146 |
tabbedPane.setSelectedComponent(c); |
1147 |
} |
1148 |
|
1149 |
protected void |
1150 |
runScript() { |
1151 |
File f = StdUtils.showOpenLscpFileChooser(); |
1152 |
if(f == null) return; |
1153 |
runScript(f); |
1154 |
} |
1155 |
|
1156 |
@Override |
1157 |
public void |
1158 |
runScript(String script) { runScript(new File(script)); } |
1159 |
|
1160 |
private void |
1161 |
runScript(File script) { |
1162 |
FileReader fr; |
1163 |
try { fr = new FileReader(script); } |
1164 |
catch(FileNotFoundException e) { |
1165 |
HF.showErrorMessage(i18n.getError("fileNotFound!", script.getAbsolutePath())); |
1166 |
return; |
1167 |
} |
1168 |
|
1169 |
BufferedReader br = new BufferedReader(fr); |
1170 |
|
1171 |
try { |
1172 |
String s = br.readLine(); |
1173 |
while(s != null) { |
1174 |
getLSConsoleModel().setCommandLineText(s); |
1175 |
getLSConsoleModel().execCommand(); |
1176 |
s = br.readLine(); |
1177 |
} |
1178 |
} catch(Exception e) { |
1179 |
HF.showErrorMessage(e); |
1180 |
return; |
1181 |
} |
1182 |
|
1183 |
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
1184 |
if(!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0); |
1185 |
} |
1186 |
|
1187 |
String s = script.getAbsolutePath(); |
1188 |
recentScripts.remove(s); |
1189 |
recentScripts.insertElementAt(s, 0); |
1190 |
|
1191 |
updateRecentScriptsMenu(); |
1192 |
} |
1193 |
|
1194 |
protected void |
1195 |
clearRecentScripts() { |
1196 |
recentScripts.removeAllElements(); |
1197 |
updateRecentScriptsMenu(); |
1198 |
} |
1199 |
|
1200 |
protected void |
1201 |
updateRecentScriptsMenu() { |
1202 |
int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
1203 |
while(recentScripts.size() > size) { |
1204 |
recentScripts.removeElementAt(recentScripts.size() - 1); |
1205 |
} |
1206 |
|
1207 |
recentScriptsMenu.removeAll(); |
1208 |
|
1209 |
for(String script : recentScripts) { |
1210 |
JMenuItem mi = new JMenuItem(script); |
1211 |
recentScriptsMenu.add(mi); |
1212 |
mi.addActionListener(new RecentScriptHandler(script)); |
1213 |
} |
1214 |
|
1215 |
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
1216 |
} |
1217 |
|
1218 |
@Override |
1219 |
public void |
1220 |
installJSamplerHome() { |
1221 |
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
1222 |
chooser.setVisible(true); |
1223 |
if(chooser.isCancelled()) return; |
1224 |
|
1225 |
JSUtils.changeJSamplerHome(chooser.getJSamplerHome()); |
1226 |
} |
1227 |
|
1228 |
@Override |
1229 |
public void |
1230 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
1231 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
1232 |
owner, Res.iconWarning32, i18n.getError("error"), err, details |
1233 |
); |
1234 |
dlg.setVisible(true); |
1235 |
} |
1236 |
|
1237 |
@Override |
1238 |
public void |
1239 |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
1240 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
1241 |
owner, Res.iconWarning32, i18n.getError("error"), err, details |
1242 |
); |
1243 |
dlg.setVisible(true); |
1244 |
} |
1245 |
|
1246 |
/** |
1247 |
* Gets the server address to which to connect. If the server should be |
1248 |
* manually selected, a dialog asking the user to choose a server is displayed. |
1249 |
*/ |
1250 |
@Override |
1251 |
public Server |
1252 |
getServer() { |
1253 |
boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP); |
1254 |
return getServer(b); |
1255 |
} |
1256 |
|
1257 |
/** |
1258 |
* Gets the server address to which to connect. If the server should be |
1259 |
* manually selected, a dialog asking the user to choose a server is displayed. |
1260 |
* @param manualSelect Determines whether the server should be manually selected. |
1261 |
*/ |
1262 |
@Override |
1263 |
public Server |
1264 |
getServer(boolean manualSelect) { |
1265 |
if(manualSelect) { |
1266 |
JSConnectDlg dlg = new JSConnectDlg(); |
1267 |
dlg.setVisible(true); |
1268 |
return dlg.getSelectedServer(); |
1269 |
} |
1270 |
|
1271 |
int i = preferences().getIntProperty(SERVER_INDEX); |
1272 |
int size = CC.getServerList().getServerCount(); |
1273 |
if(size == 0) return null; |
1274 |
if(i >= size) return CC.getServerList().getServer(0); |
1275 |
|
1276 |
return CC.getServerList().getServer(i); |
1277 |
} |
1278 |
|
1279 |
private boolean processConnectionFailure = false; |
1280 |
|
1281 |
@Override |
1282 |
public void |
1283 |
handleConnectionFailure() { |
1284 |
if(processConnectionFailure) return; |
1285 |
processConnectionFailure = true; |
1286 |
CC.getTaskQueue().add(new Global.Disconnect()); |
1287 |
JSConnectionFailurePane p = new JSConnectionFailurePane(); |
1288 |
p.showDialog(); |
1289 |
processConnectionFailure = false; |
1290 |
} |
1291 |
} |