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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1204 - (hide annotations) (download)
Thu May 24 21:43:45 2007 UTC (16 years, 11 months ago) by iliev
File size: 32073 byte(s)
upgrading to version 0.5a

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

  ViewVC Help
Powered by ViewVC