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