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