/[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 1355 - (hide annotations) (download)
Mon Sep 17 23:55:27 2007 UTC (16 years, 7 months ago) by iliev
File size: 32259 byte(s)
* Added support for formatting the instruments database
* Now database instruments and directories can have multiline descriptions
* Fantasia: added detailed error dialog

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

  ViewVC Help
Powered by ViewVC