1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2007 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 |
import java.io.StringReader; |
40 |
|
41 |
import java.util.logging.Level; |
42 |
import java.util.Vector; |
43 |
|
44 |
import javax.swing.Action; |
45 |
import javax.swing.ImageIcon; |
46 |
import javax.swing.JCheckBoxMenuItem; |
47 |
import javax.swing.JFileChooser; |
48 |
import javax.swing.JMenu; |
49 |
import javax.swing.JMenuBar; |
50 |
import javax.swing.JMenuItem; |
51 |
import javax.swing.JPanel; |
52 |
import javax.swing.JSplitPane; |
53 |
import javax.swing.JTabbedPane; |
54 |
import javax.swing.KeyStroke; |
55 |
|
56 |
import javax.swing.event.ChangeEvent; |
57 |
import javax.swing.event.ChangeListener; |
58 |
import javax.swing.event.ListSelectionEvent; |
59 |
import javax.swing.event.ListSelectionListener; |
60 |
|
61 |
import net.sf.juife.NavigationPage; |
62 |
import net.sf.juife.NavigationPane; |
63 |
|
64 |
import org.jsampler.CC; |
65 |
import org.jsampler.HF; |
66 |
import org.jsampler.LSConsoleModel; |
67 |
import org.jsampler.OrchestraModel; |
68 |
import org.jsampler.Prefs; |
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.JSDetailedErrorDlg; |
75 |
import org.jsampler.view.std.JSQuitDlg; |
76 |
import org.jsampler.view.std.JSamplerHomeChooser; |
77 |
|
78 |
import static org.jsampler.view.classic.A4n.a4n; |
79 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
80 |
import static org.jsampler.view.classic.ClassicPrefs.preferences; |
81 |
import static org.jsampler.view.classic.LeftPane.getLeftPane; |
82 |
import static org.jsampler.view.std.StdPrefs.*; |
83 |
|
84 |
/** |
85 |
* |
86 |
* @author Grigor Iliev |
87 |
*/ |
88 |
public class |
89 |
MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener { |
90 |
public static ImageIcon applicationIcon = Res.appIcon; |
91 |
|
92 |
private final ChannelsBar channelsBar = new ChannelsBar(); |
93 |
private final Statusbar statusbar = new Statusbar(); |
94 |
private final JMenuBar menuBar = new JMenuBar(); |
95 |
private final JMenu recentScriptsMenu = |
96 |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
97 |
private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab")); |
98 |
|
99 |
private final JSplitPane vSplitPane; |
100 |
private final JSplitPane hSplitPane; |
101 |
|
102 |
private final JPanel mainPane = new JPanel(); |
103 |
private final StandardBar standardBar = new StandardBar(); |
104 |
private final JPanel channelsPane = new JPanel(new BorderLayout()); |
105 |
private final JPanel rightPane = new JPanel(); |
106 |
private final JPanel bottomPane = new JPanel(); |
107 |
private final LSConsolePane lsConsolePane = new LSConsolePane(this); |
108 |
private LSConsoleDlg lsConsoleDlg = null; |
109 |
|
110 |
private final JTabbedPane tabbedPane = |
111 |
new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT); |
112 |
private final Vector<JMenuItem> miList = new Vector<JMenuItem>(); |
113 |
|
114 |
private final JCheckBoxMenuItem cbmiLeftPaneVisible = |
115 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane")); |
116 |
|
117 |
private final JCheckBoxMenuItem cbmiStandardBarVisible = |
118 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.standard")); |
119 |
|
120 |
private final JCheckBoxMenuItem cbmiLSConsoleShown = |
121 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.lsconsole")); |
122 |
|
123 |
private boolean lsConsolePopOut; |
124 |
|
125 |
private final Vector<String> recentScripts = new Vector<String>(); |
126 |
|
127 |
|
128 |
/** Creates a new instance of <code>MainFrame</code>. */ |
129 |
public |
130 |
MainFrame() { |
131 |
setTitle(i18n.getLabel("MainFrame.title")); |
132 |
|
133 |
getContentPane().add(standardBar, BorderLayout.NORTH); |
134 |
getContentPane().add(mainPane); |
135 |
|
136 |
mainPane.setLayout(new BorderLayout()); |
137 |
mainPane.add(statusbar, BorderLayout.SOUTH); |
138 |
|
139 |
ChannelsPane p = new ChannelsPane("Untitled"); |
140 |
p.addListSelectionListener(this); |
141 |
getChannelsPaneList().add(p); |
142 |
miList.add(new JMenuItem(new A4n.MoveChannelsTo(p))); |
143 |
|
144 |
channelsPane.add(getChannelsPane(0)); |
145 |
|
146 |
bottomPane.setLayout(new BorderLayout()); |
147 |
|
148 |
rightPane.setLayout(new BorderLayout()); |
149 |
|
150 |
rightPane.add(channelsBar, BorderLayout.NORTH); |
151 |
rightPane.add(channelsPane); |
152 |
|
153 |
hSplitPane = new JSplitPane ( |
154 |
JSplitPane.HORIZONTAL_SPLIT, |
155 |
true, // continuousLayout |
156 |
getLeftPane(), |
157 |
rightPane |
158 |
); |
159 |
|
160 |
hSplitPane.setOneTouchExpandable(true); |
161 |
if(ClassicPrefs.getSaveWindowProperties()) { |
162 |
hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation()); |
163 |
} |
164 |
|
165 |
mainPane.add(hSplitPane); |
166 |
|
167 |
|
168 |
vSplitPane = new JSplitPane ( |
169 |
JSplitPane.VERTICAL_SPLIT, |
170 |
true, // continuousLayout |
171 |
channelsPane, |
172 |
bottomPane |
173 |
); |
174 |
|
175 |
vSplitPane.setDividerSize(3); |
176 |
vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation()); |
177 |
|
178 |
rightPane.add(vSplitPane); |
179 |
|
180 |
if(applicationIcon != null) setIconImage(applicationIcon.getImage()); |
181 |
|
182 |
initMainFrame(); |
183 |
|
184 |
pack(); |
185 |
|
186 |
if(ClassicPrefs.getSaveWindowProperties()) setSavedSize(); |
187 |
else setDefaultSize(); |
188 |
|
189 |
if(ClassicPrefs.getSaveLeftPaneState()) { |
190 |
NavigationPage page = |
191 |
getLeftPane().getPages()[ClassicPrefs.getLeftPanePageIndex()]; |
192 |
|
193 |
getLeftPane().getModel().addPage(page); |
194 |
getLeftPane().getModel().clearHistory(); |
195 |
|
196 |
int idx = ClassicPrefs.getCurrentOrchestraIndex(); |
197 |
if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) { |
198 |
OrchestraModel om = CC.getOrchestras().getOrchestra(idx); |
199 |
getLeftPane().getOrchestrasPage().setSelectedOrchestra(om); |
200 |
} |
201 |
} |
202 |
|
203 |
//CC.getInstrumentsDbTreeModel(); // used to initialize the db tree model |
204 |
} |
205 |
|
206 |
/** Invoked when this window is about to close. */ |
207 |
protected void |
208 |
onWindowClose() { |
209 |
if(CC.getSamplerModel().isModified()) { |
210 |
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
211 |
dlg.setVisible(true); |
212 |
if(dlg.isCancelled()) return; |
213 |
} |
214 |
|
215 |
if(ClassicPrefs.getSaveWindowProperties()) { |
216 |
ClassicPrefs.setWindowMaximized ( |
217 |
"Mainframe", (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
218 |
); |
219 |
|
220 |
setVisible(false); |
221 |
if(ClassicPrefs.getWindowMaximized("Mainframe")) { |
222 |
//setExtendedState(getExtendedState() & ~MAXIMIZED_BOTH); |
223 |
CC.cleanExit(); |
224 |
return; |
225 |
} |
226 |
|
227 |
java.awt.Point p = getLocation(); |
228 |
Dimension d = getSize(); |
229 |
StringBuffer sb = new StringBuffer(); |
230 |
sb.append(p.x).append(',').append(p.y).append(','); |
231 |
sb.append(d.width).append(',').append(d.height); |
232 |
ClassicPrefs.setWindowSizeAndLocation("Mainframe", sb.toString()); |
233 |
|
234 |
ClassicPrefs.setHSplitDividerLocation(hSplitPane.getDividerLocation()); |
235 |
} |
236 |
|
237 |
if(ClassicPrefs.getSaveLeftPaneState()) { |
238 |
int idx = 0; |
239 |
for(int i = 0; i < getLeftPane().getPages().length; i++) { |
240 |
if(getLeftPane().getPages()[i] == getLeftPane().getCurrentPage()) { |
241 |
idx = i; |
242 |
break; |
243 |
} |
244 |
} |
245 |
|
246 |
ClassicPrefs.setLeftPanePageIndex(idx); |
247 |
|
248 |
idx = getLeftPane().getOrchestrasPage().getCurrentOrchestraIndex(); |
249 |
|
250 |
if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) |
251 |
ClassicPrefs.setCurrentOrchestraIndex(idx); |
252 |
} |
253 |
|
254 |
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
255 |
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
256 |
|
257 |
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
258 |
lsConsolePane.saveConsoleHistory(); |
259 |
} |
260 |
|
261 |
ClassicPrefs.setShowLSConsole(isLSConsoleShown()); |
262 |
ClassicPrefs.setLSConsolePopOut(isLSConsolePopOut()); |
263 |
|
264 |
ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation()); |
265 |
super.onWindowClose(); |
266 |
} |
267 |
|
268 |
private void |
269 |
initMainFrame() { |
270 |
addMenu(); |
271 |
handleEvents(); |
272 |
} |
273 |
|
274 |
private void |
275 |
setDefaultSize() { |
276 |
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
277 |
double width = dimension.getWidth(); |
278 |
double height = dimension.getHeight(); |
279 |
setBounds(50, 100, (int) width - 100, (int) height - 200); |
280 |
} |
281 |
|
282 |
private void |
283 |
setSavedSize() { |
284 |
String s = ClassicPrefs.getWindowSizeAndLocation("Mainframe"); |
285 |
if(s == null) { |
286 |
setDefaultSize(); |
287 |
return; |
288 |
} |
289 |
|
290 |
try { |
291 |
int i = s.indexOf(','); |
292 |
int x = Integer.parseInt(s.substring(0, i)); |
293 |
|
294 |
s = s.substring(i + 1); |
295 |
i = s.indexOf(','); |
296 |
int y = Integer.parseInt(s.substring(0, i)); |
297 |
|
298 |
s = s.substring(i + 1); |
299 |
i = s.indexOf(','); |
300 |
int width = Integer.parseInt(s.substring(0, i)); |
301 |
|
302 |
s = s.substring(i + 1); |
303 |
int height = Integer.parseInt(s); |
304 |
|
305 |
setBounds(x, y, width, height); |
306 |
} catch(Exception x) { |
307 |
String msg = "Parsing of window size and location string failed"; |
308 |
CC.getLogger().log(Level.INFO, msg, x); |
309 |
setDefaultSize(); |
310 |
} |
311 |
|
312 |
if(ClassicPrefs.getWindowMaximized("Mainframe")) |
313 |
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
314 |
} |
315 |
|
316 |
private void |
317 |
addMenu() { |
318 |
JMenu m; |
319 |
JMenuItem mi; |
320 |
|
321 |
setJMenuBar(menuBar); |
322 |
|
323 |
// Actions |
324 |
m = new JMenu(i18n.getMenuLabel("actions")); |
325 |
menuBar.add(m); |
326 |
|
327 |
mi = new JMenuItem(a4n.connect); |
328 |
mi.setIcon(null); |
329 |
//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); |
330 |
m.add(mi); |
331 |
|
332 |
mi = new JMenuItem(a4n.refresh); |
333 |
mi.setIcon(null); |
334 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
335 |
m.add(mi); |
336 |
|
337 |
mi = new JMenuItem(a4n.resetSampler); |
338 |
mi.setIcon(null); |
339 |
m.add(mi); |
340 |
|
341 |
mi = new JMenuItem(A4n.samplerInfo); |
342 |
mi.setIcon(null); |
343 |
m.add(mi); |
344 |
|
345 |
JMenu midiInstrMenu = new JMenu(i18n.getMenuLabel("actions.midiInstruments")); |
346 |
m.add(midiInstrMenu); |
347 |
|
348 |
mi = new JMenuItem(A4n.addMidiInstrumentMap); |
349 |
mi.setIcon(null); |
350 |
midiInstrMenu.add(mi); |
351 |
|
352 |
mi = new JMenuItem(A4n.removeMidiInstrumentMap); |
353 |
mi.setIcon(null); |
354 |
midiInstrMenu.add(mi); |
355 |
|
356 |
mi = new JMenuItem(A4n.addMidiInstrumentWizard); |
357 |
mi.setIcon(null); |
358 |
midiInstrMenu.add(mi); |
359 |
|
360 |
m.addSeparator(); |
361 |
|
362 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
363 |
m.add(exportMenu); |
364 |
|
365 |
mi = new JMenuItem(a4n.exportSamplerConfig); |
366 |
mi.setIcon(null); |
367 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
368 |
exportMenu.add(mi); |
369 |
|
370 |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
371 |
mi.setIcon(null); |
372 |
exportMenu.add(mi); |
373 |
|
374 |
m.addSeparator(); |
375 |
|
376 |
mi = new JMenuItem(A4n.loadScript); |
377 |
mi.setIcon(null); |
378 |
m.add(mi); |
379 |
|
380 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
381 |
for(String s : list) recentScripts.add(s); |
382 |
|
383 |
updateRecentScriptsMenu(); |
384 |
|
385 |
m.add(recentScriptsMenu); |
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, KeyEvent.CTRL_MASK | 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, KeyEvent.CTRL_MASK)); |
518 |
m.add(mi); |
519 |
|
520 |
mi = new JMenuItem(A4n.newChannelWizard); |
521 |
mi.setIcon(null); |
522 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
523 |
KeyEvent.VK_N, KeyEvent.CTRL_MASK | 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, KeyEvent.CTRL_MASK)); |
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.CTRL_MASK | KeyEvent.SHIFT_MASK |
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, KeyEvent.CTRL_MASK)); |
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, KeyEvent.CTRL_MASK)); |
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 |
|
639 |
// Help |
640 |
m = new JMenu(i18n.getMenuLabel("help")); |
641 |
|
642 |
mi = new JMenuItem(A4n.helpAbout); |
643 |
mi.setIcon(null); |
644 |
m.add(mi); |
645 |
|
646 |
m.addSeparator(); |
647 |
|
648 |
mi = new JMenuItem(a4n.browseOnlineTutorial); |
649 |
mi.setIcon(null); |
650 |
m.add(mi); |
651 |
|
652 |
menuBar.add(m); |
653 |
} |
654 |
|
655 |
private class RecentScriptHandler implements ActionListener { |
656 |
private String script; |
657 |
|
658 |
RecentScriptHandler(String script) { this.script = script; } |
659 |
|
660 |
public void |
661 |
actionPerformed(ActionEvent e) { runScript(script); } |
662 |
} |
663 |
|
664 |
private void |
665 |
handleEvents() { |
666 |
tabbedPane.addChangeListener(this); |
667 |
} |
668 |
|
669 |
private void |
670 |
showChannelsBar(boolean b) { |
671 |
channelsBar.setVisible(b); |
672 |
ClassicPrefs.setShowChannelsBar(b); |
673 |
|
674 |
validate(); |
675 |
repaint(); |
676 |
} |
677 |
|
678 |
private void |
679 |
showStatusbar(boolean b) { |
680 |
ClassicPrefs.setShowStatusbar(b); |
681 |
statusbar.setVisible(b); |
682 |
} |
683 |
|
684 |
protected boolean |
685 |
isLeftPaneVisible() { return cbmiLeftPaneVisible.isSelected(); } |
686 |
|
687 |
protected void |
688 |
setLeftPaneVisible(boolean b) { |
689 |
if(b != cbmiLeftPaneVisible.isSelected()) cbmiLeftPaneVisible.doClick(0); |
690 |
} |
691 |
|
692 |
protected boolean |
693 |
isLSConsoleVisible() { return cbmiLSConsoleShown.isSelected(); } |
694 |
|
695 |
protected void |
696 |
setLSConsoleVisible(boolean b) { |
697 |
if(b != cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0); |
698 |
} |
699 |
|
700 |
private void |
701 |
showLeftPane(boolean b) { |
702 |
ClassicPrefs.setShowLeftPane(b); |
703 |
|
704 |
mainPane.remove(hSplitPane); |
705 |
mainPane.remove(rightPane); |
706 |
|
707 |
if(b) { |
708 |
hSplitPane.setRightComponent(rightPane); |
709 |
mainPane.add(hSplitPane); |
710 |
if(ClassicPrefs.getSaveWindowProperties()) { |
711 |
int i = ClassicPrefs.getHSplitDividerLocation(); |
712 |
hSplitPane.setDividerLocation(i); |
713 |
} |
714 |
} else { |
715 |
mainPane.add(rightPane); |
716 |
} |
717 |
|
718 |
validate(); |
719 |
repaint(); |
720 |
} |
721 |
|
722 |
private void |
723 |
showStandardBar(boolean b) { |
724 |
ClassicPrefs.setShowStandardBar(b); |
725 |
standardBar.setVisible(b); |
726 |
validate(); |
727 |
repaint(); |
728 |
} |
729 |
|
730 |
private void |
731 |
showBottomPane(boolean b) { |
732 |
if(!b) ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation()); |
733 |
|
734 |
rightPane.remove(vSplitPane); |
735 |
rightPane.remove(channelsPane); |
736 |
|
737 |
if(b) { |
738 |
vSplitPane.setTopComponent(channelsPane); |
739 |
rightPane.add(vSplitPane); |
740 |
vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation()); |
741 |
} else { |
742 |
rightPane.add(channelsPane); |
743 |
} |
744 |
|
745 |
validate(); |
746 |
repaint(); |
747 |
} |
748 |
|
749 |
protected void |
750 |
setLSConsolePopOut(boolean b) { |
751 |
if(b == lsConsolePopOut) return; |
752 |
|
753 |
lsConsolePopOut = b; |
754 |
|
755 |
if(isLSConsoleShown()) setLSConsolePopOut0(b); |
756 |
} |
757 |
|
758 |
/** |
759 |
* Changes the pop-out state of the LS Console. |
760 |
* Invoke this method only when LS Console is shown. |
761 |
*/ |
762 |
private void |
763 |
setLSConsolePopOut0(boolean b) { |
764 |
if(b) { |
765 |
bottomPane.remove(lsConsolePane); |
766 |
showBottomPane(false); |
767 |
|
768 |
lsConsoleDlg = new LSConsoleDlg(this, lsConsolePane); |
769 |
lsConsoleDlg.setVisible(true); |
770 |
} else { |
771 |
if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false); |
772 |
lsConsoleDlg = null; |
773 |
bottomPane.add(lsConsolePane); |
774 |
showBottomPane(true); |
775 |
} |
776 |
} |
777 |
|
778 |
protected boolean |
779 |
isLSConsolePopOut() { return lsConsolePopOut; } |
780 |
|
781 |
protected boolean |
782 |
isLSConsoleShown() { return cbmiLSConsoleShown.isSelected(); } |
783 |
|
784 |
protected void |
785 |
setLSConsoleShown(boolean b) { cbmiLSConsoleShown.setSelected(b); } |
786 |
|
787 |
protected LSConsoleModel |
788 |
getLSConsoleModel() { return lsConsolePane.getModel(); } |
789 |
|
790 |
/** |
791 |
* Sets the text color of the LS Console. |
792 |
* @param c The text color of the LS Console. |
793 |
*/ |
794 |
protected void |
795 |
setLSConsoleTextColor(Color c) { lsConsolePane.setTextColor(c); } |
796 |
|
797 |
/** |
798 |
* Sets the background color of the LS Console. |
799 |
* @param c The background color of the LS Console. |
800 |
*/ |
801 |
protected void |
802 |
setLSConsoleBackgroundColor(Color c) { lsConsolePane.setBackgroundColor(c); } |
803 |
|
804 |
/** |
805 |
* Sets the notification messages' color of the LS Console. |
806 |
* @param c The notification messages' color of the LS Console. |
807 |
*/ |
808 |
protected void |
809 |
setLSConsoleNotifyColor(Color c) { lsConsolePane.setNotifyColor(c); } |
810 |
|
811 |
/** |
812 |
* Sets the warning messages' color of the LS Console. |
813 |
* @param c The warning messages' color of the LS Console. |
814 |
*/ |
815 |
protected void |
816 |
setLSConsoleWarningColor(Color c) { lsConsolePane.setWarningColor(c); } |
817 |
|
818 |
/** |
819 |
* Sets the error messages' color of the LS Console. |
820 |
* @param c The error messages' color of the LS Console. |
821 |
*/ |
822 |
protected void |
823 |
setLSConsoleErrorColor(Color c) { lsConsolePane.setErrorColor(c); } |
824 |
|
825 |
protected void |
826 |
showLSConsole(boolean b) { |
827 |
if(!b) { |
828 |
showBottomPane(false); |
829 |
if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false); |
830 |
lsConsolePane.hideAutoCompleteWindow(); |
831 |
return; |
832 |
} |
833 |
|
834 |
setLSConsolePopOut0(isLSConsolePopOut()); |
835 |
} |
836 |
|
837 |
/** |
838 |
* Adds the specified <code>JSChannelsPane</code> to the view. |
839 |
* @param chnPane The <code>JSChannelsPane</code> to be added. |
840 |
*/ |
841 |
public void |
842 |
addChannelsPane(JSChannelsPane chnPane) { |
843 |
insertChannelsPane(chnPane, getChannelsPaneCount()); |
844 |
} |
845 |
|
846 |
public void |
847 |
insertChannelsPane(JSChannelsPane chnPane, int idx) { |
848 |
chnPane.addListSelectionListener(this); |
849 |
|
850 |
if(getChannelsPaneCount() == 1) { |
851 |
channelsPane.remove(getChannelsPane(0)); |
852 |
channelsPane.add(tabbedPane); |
853 |
tabbedPane.addTab(getChannelsPane(0).getTitle(), getChannelsPane(0)); |
854 |
A4n.closeChannelsTab.setEnabled(true); |
855 |
A4n.editTabTitle.setEnabled(true); |
856 |
} |
857 |
|
858 |
getChannelsPaneList().insertElementAt(chnPane, idx); |
859 |
tabbedPane.insertTab(chnPane.getTitle(), null, chnPane, null, idx); |
860 |
tabbedPane.setSelectedComponent(chnPane); |
861 |
miList.insertElementAt(new JMenuItem(new A4n.MoveChannelsTo(chnPane)), idx); |
862 |
|
863 |
updateTabsMenu(); |
864 |
} |
865 |
|
866 |
/** |
867 |
* Gets the <code>JSChannelsPane</code> that is currently shown. |
868 |
* @return The currently shown <code>JSChannelsPane</code>. |
869 |
*/ |
870 |
public JSChannelsPane |
871 |
getSelectedChannelsPane() { |
872 |
if(getChannelsPaneList().size() == 1) return getChannelsPane(0); |
873 |
return (JSChannelsPane)tabbedPane.getSelectedComponent(); |
874 |
} |
875 |
|
876 |
/** |
877 |
* Sets the <code>JSChannelsPane</code> to be selected. |
878 |
* @param pane The <code>JSChannelsPane</code> to be shown. |
879 |
*/ |
880 |
public void |
881 |
setSelectedChannelsPane(JSChannelsPane pane) { |
882 |
if(getChannelsPaneList().size() == 1) return; |
883 |
tabbedPane.setSelectedComponent(pane); |
884 |
} |
885 |
|
886 |
/** |
887 |
* Removes the specified <code>JSChannelsPane</code> from the view. |
888 |
* @param chnPane The <code>JSChannelsPane</code> to be removed. |
889 |
* @return <code>true</code> if the specified code>JSChannelsPane</code> |
890 |
* is actually removed from the view, <code>false</code> otherwise. |
891 |
*/ |
892 |
public boolean |
893 |
removeChannelsPane(JSChannelsPane chnPane) { |
894 |
chnPane.removeListSelectionListener(this); |
895 |
|
896 |
tabbedPane.remove(chnPane); |
897 |
boolean b = super.removeChannelsPane(chnPane); |
898 |
for(int i = 0; i < miList.size(); i++) { |
899 |
A4n.MoveChannelsTo a = (A4n.MoveChannelsTo)miList.get(i).getAction(); |
900 |
if(a.getChannelsPane().equals(chnPane)) { |
901 |
miList.remove(i); |
902 |
break; |
903 |
} |
904 |
} |
905 |
|
906 |
updateTabsMenu(); |
907 |
|
908 |
if(getChannelsPaneCount() == 1) { |
909 |
A4n.closeChannelsTab.setEnabled(false); |
910 |
A4n.editTabTitle.setEnabled(false); |
911 |
tabbedPane.remove(getChannelsPane(0)); |
912 |
channelsPane.remove(tabbedPane); |
913 |
channelsPane.add(getChannelsPane(0)); |
914 |
} |
915 |
|
916 |
return b; |
917 |
} |
918 |
|
919 |
private void |
920 |
updateTabsMenu() { |
921 |
tabsMenu.removeAll(); |
922 |
|
923 |
for(JMenuItem mi : miList) { |
924 |
A4n.MoveChannelsTo a = (A4n.MoveChannelsTo)mi.getAction(); |
925 |
if(!a.getChannelsPane().equals(getSelectedChannelsPane())) tabsMenu.add(mi); |
926 |
} |
927 |
|
928 |
} |
929 |
|
930 |
public void |
931 |
updateTabTitle(JSChannelsPane chnPane) { |
932 |
tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), chnPane.getTitle()); |
933 |
} |
934 |
|
935 |
private void |
936 |
checkChannelSelection(JSChannelsPane pane) { |
937 |
if(!pane.hasSelectedChannel()) { |
938 |
A4n.duplicateChannels.putValue ( |
939 |
Action.NAME, i18n.getMenuLabel("channels.duplicate") |
940 |
); |
941 |
A4n.duplicateChannels.setEnabled(false); |
942 |
|
943 |
A4n.removeChannels.putValue ( |
944 |
Action.NAME, i18n.getMenuLabel("channels.RemoveChannel") |
945 |
); |
946 |
A4n.removeChannels.setEnabled(false); |
947 |
|
948 |
tabsMenu.setEnabled(false); |
949 |
|
950 |
A4n.moveChannelsOnTop.setEnabled(false); |
951 |
A4n.moveChannelsUp.setEnabled(false); |
952 |
A4n.moveChannelsDown.setEnabled(false); |
953 |
A4n.moveChannelsAtBottom.setEnabled(false); |
954 |
|
955 |
return; |
956 |
} |
957 |
|
958 |
A4n.duplicateChannels.setEnabled(true); |
959 |
A4n.removeChannels.setEnabled(true); |
960 |
|
961 |
if(getChannelsPaneCount() > 1) tabsMenu.setEnabled(true); |
962 |
|
963 |
if(pane.getSelectedChannelCount() > 1) { |
964 |
A4n.duplicateChannels.putValue ( |
965 |
Action.NAME, i18n.getMenuLabel("channels.duplicateChannels") |
966 |
); |
967 |
A4n.removeChannels.putValue ( |
968 |
Action.NAME, i18n.getMenuLabel("channels.RemoveChannels") |
969 |
); |
970 |
} else { |
971 |
A4n.duplicateChannels.putValue ( |
972 |
Action.NAME, i18n.getMenuLabel("channels.duplicate") |
973 |
); |
974 |
A4n.removeChannels.putValue ( |
975 |
Action.NAME, i18n.getMenuLabel("channels.RemoveChannel") |
976 |
); |
977 |
} |
978 |
|
979 |
A4n.moveChannelsOnTop.setEnabled(false); |
980 |
A4n.moveChannelsUp.setEnabled(true); |
981 |
A4n.moveChannelsDown.setEnabled(true); |
982 |
A4n.moveChannelsAtBottom.setEnabled(false); |
983 |
|
984 |
JSChannel[] chns = pane.getSelectedChannels(); |
985 |
|
986 |
for(int i = 0; i < chns.length; i++) { |
987 |
if(pane.getChannel(i) != chns[i]) { |
988 |
A4n.moveChannelsOnTop.setEnabled(true); |
989 |
break; |
990 |
} |
991 |
} |
992 |
|
993 |
if(chns[0] == pane.getFirstChannel()) A4n.moveChannelsUp.setEnabled(false); |
994 |
|
995 |
if(chns[chns.length - 1] == pane.getLastChannel()) |
996 |
A4n.moveChannelsDown.setEnabled(false); |
997 |
|
998 |
for(int i = chns.length - 1, j = pane.getChannelCount() - 1; i >= 0; i--, j--) { |
999 |
if(pane.getChannel(j) != chns[i]) { |
1000 |
A4n.moveChannelsAtBottom.setEnabled(true); |
1001 |
break; |
1002 |
} |
1003 |
} |
1004 |
} |
1005 |
|
1006 |
private void |
1007 |
checkTabSelection() { |
1008 |
int si = tabbedPane.getSelectedIndex(); |
1009 |
|
1010 |
if(si > 0) { |
1011 |
A4n.moveTab2Beginning.setEnabled(true); |
1012 |
A4n.moveTab2Left.setEnabled(true); |
1013 |
} else { |
1014 |
A4n.moveTab2Beginning.setEnabled(false); |
1015 |
A4n.moveTab2Left.setEnabled(false); |
1016 |
} |
1017 |
|
1018 |
if(si != -1 && si < tabbedPane.getTabCount() - 1) { |
1019 |
A4n.moveTab2Right.setEnabled(true); |
1020 |
A4n.moveTab2End.setEnabled(true); |
1021 |
} else { |
1022 |
A4n.moveTab2Right.setEnabled(false); |
1023 |
A4n.moveTab2End.setEnabled(false); |
1024 |
} |
1025 |
} |
1026 |
|
1027 |
/*public JTabbedPane |
1028 |
getTabbedPane() { return tabbedPane; }*/ |
1029 |
|
1030 |
public JMenu |
1031 |
getTabsMenu() { return tabsMenu; } |
1032 |
|
1033 |
public void |
1034 |
stateChanged(ChangeEvent e) { |
1035 |
updateTabsMenu(); |
1036 |
checkChannelSelection(getSelectedChannelsPane()); |
1037 |
checkTabSelection(); |
1038 |
} |
1039 |
|
1040 |
public void |
1041 |
valueChanged(ListSelectionEvent e) { |
1042 |
if(e.getValueIsAdjusting()) return; |
1043 |
if(e.getSource() != getSelectedChannelsPane()) return; |
1044 |
|
1045 |
checkChannelSelection(getSelectedChannelsPane()); |
1046 |
} |
1047 |
|
1048 |
public void |
1049 |
moveTab2Beginning() { |
1050 |
int idx = tabbedPane.getSelectedIndex(); |
1051 |
if(idx < 1) { |
1052 |
CC.getLogger().info("Can't move tab to beginning"); |
1053 |
return; |
1054 |
} |
1055 |
|
1056 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1057 |
if(getChannelsPane(idx) != c) |
1058 |
CC.getLogger().warning("Channels pane indices don't match"); |
1059 |
removeChannelsPane(c); |
1060 |
insertChannelsPane(c, 0); |
1061 |
tabbedPane.setSelectedComponent(c); |
1062 |
} |
1063 |
|
1064 |
public void |
1065 |
moveTab2Left() { |
1066 |
int idx = tabbedPane.getSelectedIndex(); |
1067 |
if(idx < 1) { |
1068 |
CC.getLogger().info("Can't move tab to left"); |
1069 |
return; |
1070 |
} |
1071 |
|
1072 |
|
1073 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1074 |
if(getChannelsPane(idx) != c) |
1075 |
CC.getLogger().warning("Channels pane indices don't match"); |
1076 |
removeChannelsPane(c); |
1077 |
insertChannelsPane(c, idx - 1); |
1078 |
tabbedPane.setSelectedComponent(c); |
1079 |
} |
1080 |
|
1081 |
public void |
1082 |
moveTab2Right() { |
1083 |
int idx = tabbedPane.getSelectedIndex(); |
1084 |
if(idx == -1 && idx >= tabbedPane.getTabCount()) { |
1085 |
CC.getLogger().info("Can't move tab to right"); |
1086 |
return; |
1087 |
} |
1088 |
|
1089 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1090 |
if(getChannelsPane(idx) != c) |
1091 |
CC.getLogger().warning("Channels pane indices don't match"); |
1092 |
removeChannelsPane(c); |
1093 |
insertChannelsPane(c, idx + 1); |
1094 |
tabbedPane.setSelectedComponent(c); |
1095 |
} |
1096 |
|
1097 |
public void |
1098 |
moveTab2End() { |
1099 |
int idx = tabbedPane.getSelectedIndex(); |
1100 |
if(idx == -1 && idx >= tabbedPane.getTabCount()) { |
1101 |
CC.getLogger().info("Can't move tab to right"); |
1102 |
return; |
1103 |
} |
1104 |
|
1105 |
JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent(); |
1106 |
if(getChannelsPane(idx) != c) |
1107 |
CC.getLogger().warning("Channels pane indices don't match"); |
1108 |
removeChannelsPane(c); |
1109 |
addChannelsPane(c); |
1110 |
tabbedPane.setSelectedComponent(c); |
1111 |
} |
1112 |
|
1113 |
protected void |
1114 |
runScript() { |
1115 |
String s = preferences().getStringProperty("lastScriptLocation"); |
1116 |
JFileChooser fc = new JFileChooser(s); |
1117 |
fc.setFileFilter(new LscpFileFilter()); |
1118 |
int result = fc.showOpenDialog(this); |
1119 |
if(result != JFileChooser.APPROVE_OPTION) return; |
1120 |
|
1121 |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
1122 |
preferences().setStringProperty("lastScriptLocation", path); |
1123 |
|
1124 |
runScript(fc.getSelectedFile()); |
1125 |
} |
1126 |
|
1127 |
private void |
1128 |
runScript(String script) { runScript(new File(script)); } |
1129 |
|
1130 |
private void |
1131 |
runScript(File script) { |
1132 |
FileReader fr; |
1133 |
try { fr = new FileReader(script); } |
1134 |
catch(FileNotFoundException e) { |
1135 |
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
1136 |
return; |
1137 |
} |
1138 |
|
1139 |
BufferedReader br = new BufferedReader(fr); |
1140 |
|
1141 |
try { |
1142 |
String s = br.readLine(); |
1143 |
while(s != null) { |
1144 |
getLSConsoleModel().setCommandLineText(s); |
1145 |
getLSConsoleModel().execCommand(); |
1146 |
s = br.readLine(); |
1147 |
} |
1148 |
} catch(Exception e) { |
1149 |
HF.showErrorMessage(e); |
1150 |
return; |
1151 |
} |
1152 |
|
1153 |
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
1154 |
if(!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0); |
1155 |
} |
1156 |
|
1157 |
String s = script.getAbsolutePath(); |
1158 |
recentScripts.remove(s); |
1159 |
recentScripts.insertElementAt(s, 0); |
1160 |
|
1161 |
updateRecentScriptsMenu(); |
1162 |
} |
1163 |
|
1164 |
protected void |
1165 |
clearRecentScripts() { |
1166 |
recentScripts.removeAllElements(); |
1167 |
updateRecentScriptsMenu(); |
1168 |
} |
1169 |
|
1170 |
protected void |
1171 |
updateRecentScriptsMenu() { |
1172 |
int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
1173 |
while(recentScripts.size() > size) { |
1174 |
recentScripts.removeElementAt(recentScripts.size() - 1); |
1175 |
} |
1176 |
|
1177 |
recentScriptsMenu.removeAll(); |
1178 |
|
1179 |
for(String script : recentScripts) { |
1180 |
JMenuItem mi = new JMenuItem(script); |
1181 |
recentScriptsMenu.add(mi); |
1182 |
mi.addActionListener(new RecentScriptHandler(script)); |
1183 |
} |
1184 |
|
1185 |
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
1186 |
} |
1187 |
|
1188 |
public void |
1189 |
installJSamplerHome() { |
1190 |
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
1191 |
chooser.setVisible(true); |
1192 |
if(chooser.isCancelled()) return; |
1193 |
|
1194 |
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
1195 |
} |
1196 |
|
1197 |
public void |
1198 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
1199 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
1200 |
owner, Res.iconWarning32, i18n.getError("error"), err, details |
1201 |
); |
1202 |
dlg.setVisible(true); |
1203 |
} |
1204 |
|
1205 |
public void |
1206 |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
1207 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
1208 |
owner, Res.iconWarning32, i18n.getError("error"), err, details |
1209 |
); |
1210 |
dlg.setVisible(true); |
1211 |
} |
1212 |
} |