/[svn]/jsampler/trunk/src/org/jsampler/view/classic/MainFrame.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/MainFrame.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1327 - (show annotations) (download)
Fri Sep 7 12:09:59 2007 UTC (16 years, 7 months ago) by iliev
File size: 32088 byte(s)
* Implemented more proper retrieval of the MIDI/audio driver settings
* Implemented new table cell editor for editing string list
  parameters with possibilities
* Some javadoc documentation fixes

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

  ViewVC Help
Powered by ViewVC