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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 910 by iliev, Thu Mar 16 18:08:34 2006 UTC revision 911 by iliev, Mon Aug 7 18:25:58 2006 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005 Grigor Kirilov Iliev   *   Copyright (C) 2005, 2006 Grigor Kirilov Iliev
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 23  Line 23 
23  package org.jsampler.view.classic;  package org.jsampler.view.classic;
24    
25  import java.awt.BorderLayout;  import java.awt.BorderLayout;
26    import java.awt.Color;
27  import java.awt.Dimension;  import java.awt.Dimension;
28    
29  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
30  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
31  import java.awt.event.KeyEvent;  import java.awt.event.KeyEvent;
32    
33    import java.io.BufferedReader;
34    import java.io.File;
35    import java.io.FileNotFoundException;
36    import java.io.FileReader;
37    import java.io.StringReader;
38    
39  import java.util.logging.Level;  import java.util.logging.Level;
40  import java.util.Vector;  import java.util.Vector;
41    
42  import javax.swing.Action;  import javax.swing.Action;
43  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
44  import javax.swing.JCheckBoxMenuItem;  import javax.swing.JCheckBoxMenuItem;
45    import javax.swing.JFileChooser;
46  import javax.swing.JMenu;  import javax.swing.JMenu;
47  import javax.swing.JMenuBar;  import javax.swing.JMenuBar;
48  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
# Line 52  import net.sf.juife.NavigationPage; Line 60  import net.sf.juife.NavigationPage;
60  import net.sf.juife.NavigationPane;  import net.sf.juife.NavigationPane;
61    
62  import org.jsampler.CC;  import org.jsampler.CC;
63    import org.jsampler.HF;
64    import org.jsampler.LSConsoleModel;
65    import org.jsampler.OrchestraModel;
66  import org.jsampler.Prefs;  import org.jsampler.Prefs;
67    
68  import org.jsampler.view.JSChannel;  import org.jsampler.view.JSChannel;
69  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
70    import org.jsampler.view.LscpFileFilter;
71    
72  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
73  import static org.jsampler.view.classic.LeftPane.getLeftPane;  import static org.jsampler.view.classic.LeftPane.getLeftPane;
# Line 78  MainFrame extends org.jsampler.view.JSMa Line 90  MainFrame extends org.jsampler.view.JSMa
90          private final Toolbar toolbar = new Toolbar();          private final Toolbar toolbar = new Toolbar();
91          private final Statusbar statusbar = new Statusbar();          private final Statusbar statusbar = new Statusbar();
92          private final JMenuBar menuBar = new JMenuBar();          private final JMenuBar menuBar = new JMenuBar();
93            private final JMenu recentScriptsMenu =
94                    new JMenu(i18n.getMenuLabel("actions.recentScripts"));
95            private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab"));
96                    
97          private final JSplitPane splitPane;          private final JSplitPane vSplitPane;
98            private final JSplitPane hSplitPane;
99                    
100          private final JPanel mainPane = new JPanel();          private final JPanel mainPane = new JPanel();
101          private final JPanel channelsPane = new JPanel(new BorderLayout());          private final JPanel channelsPane = new JPanel(new BorderLayout());
102            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                    
107          private final JTabbedPane tabbedPane =          private final JTabbedPane tabbedPane =
108                  new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT);                  new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT);
         private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab"));  
109          private final Vector<JMenuItem> miList = new Vector<JMenuItem>();          private final Vector<JMenuItem> miList = new Vector<JMenuItem>();
110                    
111            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          /** Creates a new instance of JSMainFrame */          /** Creates a new instance of JSMainFrame */
123          public          public
124          MainFrame() {          MainFrame() {
# Line 107  MainFrame extends org.jsampler.view.JSMa Line 137  MainFrame extends org.jsampler.view.JSMa
137                                    
138                  channelsPane.add(getChannelsPane(0));                  channelsPane.add(getChannelsPane(0));
139                                    
140                  splitPane = new JSplitPane (                  bottomPane.setLayout(new BorderLayout());
141                    
142                    rightPane.setLayout(new BorderLayout());
143                    rightPane.add(channelsPane);
144                    
145                    hSplitPane = new JSplitPane (
146                          JSplitPane.HORIZONTAL_SPLIT,                          JSplitPane.HORIZONTAL_SPLIT,
147                          true,   // continuousLayout                          true,   // continuousLayout
148                          getLeftPane(),                          getLeftPane(),
149                          channelsPane                          rightPane
150                    );
151                    
152                    hSplitPane.setOneTouchExpandable(true);
153                    if(ClassicPrefs.getSaveWindowProperties()) {
154                            hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation());
155                    }
156                    
157                    mainPane.add(hSplitPane);
158                    
159                    
160                    vSplitPane = new JSplitPane (
161                            JSplitPane.VERTICAL_SPLIT,
162                            true,   // continuousLayout
163                            channelsPane,
164                            bottomPane
165                  );                  );
166                                    
167                  splitPane.setOneTouchExpandable(true);                  vSplitPane.setDividerSize(3);
168                    vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
169                                    
170                  mainPane.add(splitPane);                  rightPane.add(vSplitPane);
171                                    
172                  if(applicationIcon != null) setIconImage(applicationIcon.getImage());                  if(applicationIcon != null) setIconImage(applicationIcon.getImage());
173                                    
174                  initMainFrame();                  initMainFrame();
175                    
176                  pack();                  pack();
177                                    
178                  if(Prefs.getSaveWindowProperties()) setSavedSize();                  if(ClassicPrefs.getSaveWindowProperties()) setSavedSize();
179                  else setDefaultSize();                  else setDefaultSize();
180                    
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            }
195            
196            /** 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          private void          private void
# Line 143  MainFrame extends org.jsampler.view.JSMa Line 267  MainFrame extends org.jsampler.view.JSMa
267                    
268          private void          private void
269          setSavedSize() {          setSavedSize() {
270                  String s = Prefs.getWindowSizeAndLocation();                  String s = ClassicPrefs.getWindowSizeAndLocation();
271                  if(s == null) {                  if(s == null) {
272                          setDefaultSize();                          setDefaultSize();
273                          return;                          return;
# Line 171  MainFrame extends org.jsampler.view.JSMa Line 295  MainFrame extends org.jsampler.view.JSMa
295                          setDefaultSize();                          setDefaultSize();
296                  }                  }
297                                    
298                  if(Prefs.getWindowMaximized())                  if(ClassicPrefs.getWindowMaximized())
299                          setExtendedState(getExtendedState() | MAXIMIZED_BOTH);                          setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
300          }          }
301                    
302          private void          private void
303          addMenu() {          addMenu() {
304                  JMenu m;                  JMenu m;
                 JMenu submenu;  
305                  JMenuItem mi;                  JMenuItem mi;
306                                    
307                  setJMenuBar(menuBar);                  setJMenuBar(menuBar);
# Line 207  MainFrame extends org.jsampler.view.JSMa Line 330  MainFrame extends org.jsampler.view.JSMa
330                                    
331                  m.addSeparator();                  m.addSeparator();
332                                    
333                    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                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
360                  m.add(mi);                  m.add(mi);
361                  mi.addActionListener(new ActionListener() {                  mi.addActionListener(new ActionListener() {
# Line 218  MainFrame extends org.jsampler.view.JSMa Line 367  MainFrame extends org.jsampler.view.JSMa
367                  m = new JMenu(i18n.getMenuLabel("edit"));                  m = new JMenu(i18n.getMenuLabel("edit"));
368                  menuBar.add(m);                  menuBar.add(m);
369                                    
370                    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                  m.addSeparator();                  m.addSeparator();
401                                    
402                  mi = new JMenuItem(A4n.preferences);                  mi = new JMenuItem(A4n.preferences);
# Line 244  MainFrame extends org.jsampler.view.JSMa Line 423  MainFrame extends org.jsampler.view.JSMa
423                  cbmi.setSelected(b);                  cbmi.setSelected(b);
424                  showToolbar(b);                  showToolbar(b);
425                                    
426                  final JCheckBoxMenuItem cbmi1 =                  m.add(cbmiLeftPaneVisible);
427                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane"));                  cbmiLeftPaneVisible.addActionListener(new ActionListener() {
                   
                 m.add(cbmi1);  
                 cbmi1.addActionListener(new ActionListener() {  
428                          public void                          public void
429                          actionPerformed(ActionEvent e) { showLeftPane(cbmi1.getState()); }                          actionPerformed(ActionEvent e) {
430                                    showLeftPane(cbmiLeftPaneVisible.getState());
431                            }
432                  });                  });
433                                    
434                  b = ClassicPrefs.shouldShowLeftPane();                  b = ClassicPrefs.shouldShowLeftPane();
435                  cbmi1.setSelected(b);                  cbmiLeftPaneVisible.setSelected(b);
436                  showLeftPane(b);                  showLeftPane(b);
437                                    
438                  final JCheckBoxMenuItem cbmi2 =                  final JCheckBoxMenuItem cbmi2 =
# Line 269  MainFrame extends org.jsampler.view.JSMa Line 447  MainFrame extends org.jsampler.view.JSMa
447                  cbmi2.setSelected(b);                  cbmi2.setSelected(b);
448                  showStatusbar(b);                  showStatusbar(b);
449                                    
450                    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                  // Channels                  // Channels
467                  m = new JMenu(i18n.getMenuLabel("channels"));                  m = new JMenu(i18n.getMenuLabel("channels"));
468                  menuBar.add(m);                  menuBar.add(m);
# Line 397  MainFrame extends org.jsampler.view.JSMa Line 591  MainFrame extends org.jsampler.view.JSMa
591                  m.add(mi);                  m.add(mi);
592          }          }
593                    
594            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          private void          private void
604          handleEvents() {          handleEvents() {
605                  tabbedPane.addChangeListener(this);                  tabbedPane.addChangeListener(this);
# Line 419  MainFrame extends org.jsampler.view.JSMa Line 622  MainFrame extends org.jsampler.view.JSMa
622                  statusbar.setVisible(b);                  statusbar.setVisible(b);
623          }          }
624                    
625            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          private void          private void
642          showLeftPane(boolean b) {          showLeftPane(boolean b) {
643                  ClassicPrefs.setShowLeftPane(b);                  ClassicPrefs.setShowLeftPane(b);
644                                    
645                  mainPane.remove(splitPane);                  mainPane.remove(hSplitPane);
646                  mainPane.remove(channelsPane);                  mainPane.remove(rightPane);
647                                    
648                  if(b) {                  if(b) {
649                          splitPane.setRightComponent(channelsPane);                          hSplitPane.setRightComponent(rightPane);
650                          mainPane.add(splitPane);                          mainPane.add(hSplitPane);
651                            if(ClassicPrefs.getSaveWindowProperties()) {
652                                    int i = ClassicPrefs.getHSplitDividerLocation();
653                                    hSplitPane.setDividerLocation(i);
654                            }
655                  } else {                  } else {
656                          mainPane.add(channelsPane);                          mainPane.add(rightPane);
657                  }                  }
658                                    
659                  validate();                  validate();
660                  repaint();                  repaint();
661          }          }
662                    
663            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          public void          public void
775          addChannelsPane(JSChannelsPane chnPane) {          addChannelsPane(JSChannelsPane chnPane) {
776                  insertChannelsPane(chnPane, getChannelsPaneCount());                  insertChannelsPane(chnPane, getChannelsPaneCount());
# Line 462  MainFrame extends org.jsampler.view.JSMa Line 796  MainFrame extends org.jsampler.view.JSMa
796                  updateTabsMenu();                  updateTabsMenu();
797          }          }
798                    
799            /**
800             * Gets the <code>JSChannelsPane</code> that is currently shown.
801             * @return The currently shown <code>JSChannelsPane</code>.
802             */
803          public JSChannelsPane          public JSChannelsPane
804          getSelectedChannelsPane() {          getSelectedChannelsPane() {
805                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);
806                  return (JSChannelsPane)tabbedPane.getSelectedComponent();                  return (JSChannelsPane)tabbedPane.getSelectedComponent();
807          }          }
808                    
809            /**
810             * Sets the <code>JSChannelsPane</code> to be selected.
811             * @param pane The <code>JSChannelsPane</code> to be shown.
812             */
813          public void          public void
814          setSelectedChannelsPane(JSChannelsPane pane) {          setSelectedChannelsPane(JSChannelsPane pane) {
815                  if(getChannelsPaneList().size() == 1) return;                  if(getChannelsPaneList().size() == 1) return;
816                  tabbedPane.setSelectedComponent(pane);                  tabbedPane.setSelectedComponent(pane);
817          }          }
818                    
819            /**
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          public boolean          public boolean
826          removeChannelsPane(JSChannelsPane chnPane) {          removeChannelsPane(JSChannelsPane chnPane) {
827                  chnPane.removeListSelectionListener(this);                  chnPane.removeListSelectionListener(this);
# Line 694  MainFrame extends org.jsampler.view.JSMa Line 1042  MainFrame extends org.jsampler.view.JSMa
1042                  addChannelsPane(c);                  addChannelsPane(c);
1043                  tabbedPane.setSelectedComponent(c);                  tabbedPane.setSelectedComponent(c);
1044          }          }
1045            
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  }  }

Legend:
Removed from v.910  
changed lines
  Added in v.911

  ViewVC Help
Powered by ViewVC