/[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 1143 - (show annotations) (download)
Mon Apr 2 21:18:31 2007 UTC (17 years, 1 month ago) by iliev
File size: 31515 byte(s)
* upgrading to version 0.4a

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

  ViewVC Help
Powered by ViewVC