/[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 911 - (hide annotations) (download)
Mon Aug 7 18:25:58 2006 UTC (17 years, 8 months ago) by iliev
File size: 29760 byte(s)
updating to JSampler 0.3a

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

  ViewVC Help
Powered by ViewVC