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