/[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 842 by iliev, Thu Mar 16 18:08:34 2006 UTC revision 1496 by iliev, Mon Nov 19 22:22:22 2007 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-2007 Grigor Iliev <grigor@grigoriliev.com>
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.Dialog;
28  import java.awt.Dimension;  import java.awt.Dimension;
29    import java.awt.Frame;
30    
31  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
32  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
33  import java.awt.event.KeyEvent;  import java.awt.event.KeyEvent;
34    
35    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  import java.util.logging.Level;  import java.util.logging.Level;
42  import java.util.Vector;  import java.util.Vector;
43    
44  import javax.swing.Action;  import javax.swing.Action;
45  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
46  import javax.swing.JCheckBoxMenuItem;  import javax.swing.JCheckBoxMenuItem;
47    import javax.swing.JFileChooser;
48  import javax.swing.JMenu;  import javax.swing.JMenu;
49  import javax.swing.JMenuBar;  import javax.swing.JMenuBar;
50  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
# Line 52  import net.sf.juife.NavigationPage; Line 62  import net.sf.juife.NavigationPage;
62  import net.sf.juife.NavigationPane;  import net.sf.juife.NavigationPane;
63    
64  import org.jsampler.CC;  import org.jsampler.CC;
65    import org.jsampler.HF;
66    import org.jsampler.LSConsoleModel;
67    import org.jsampler.OrchestraModel;
68  import org.jsampler.Prefs;  import org.jsampler.Prefs;
69    
70  import org.jsampler.view.JSChannel;  import org.jsampler.view.JSChannel;
71  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
72    import org.jsampler.view.LscpFileFilter;
73    
74    import org.jsampler.view.std.JSDetailedErrorDlg;
75    import org.jsampler.view.std.JSamplerHomeChooser;
76    
77    import static org.jsampler.view.classic.A4n.a4n;
78  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
79    import static org.jsampler.view.classic.ClassicPrefs.preferences;
80  import static org.jsampler.view.classic.LeftPane.getLeftPane;  import static org.jsampler.view.classic.LeftPane.getLeftPane;
81    import static org.jsampler.view.std.StdPrefs.*;
82    
83  /**  /**
84   *   *
# Line 67  import static org.jsampler.view.classic. Line 86  import static org.jsampler.view.classic.
86   */   */
87  public class  public class
88  MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener {  MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener {
89          public static ImageIcon applicationIcon = null;          public static ImageIcon applicationIcon = Res.appIcon;
90                    
91          static {          private final ChannelsBar channelsBar = new ChannelsBar();
                 String s = "org/jsampler/view/classic/res/icons/app-icon.png";  
                 java.net.URL url = ClassLoader.getSystemClassLoader().getResource(s);  
                 if(url != null) applicationIcon = new ImageIcon(url);  
         }  
           
         private final Toolbar toolbar = new Toolbar();  
92          private final Statusbar statusbar = new Statusbar();          private final Statusbar statusbar = new Statusbar();
93          private final JMenuBar menuBar = new JMenuBar();          private final JMenuBar menuBar = new JMenuBar();
94            private final JMenu recentScriptsMenu =
95                    new JMenu(i18n.getMenuLabel("actions.recentScripts"));
96            private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab"));
97                    
98          private final JSplitPane splitPane;          private final JSplitPane vSplitPane;
99            private final JSplitPane hSplitPane;
100                    
101          private final JPanel mainPane = new JPanel();          private final JPanel mainPane = new JPanel();
102            private final StandardBar standardBar = new StandardBar();
103          private final JPanel channelsPane = new JPanel(new BorderLayout());          private final JPanel channelsPane = new JPanel(new BorderLayout());
104            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                    
109          private final JTabbedPane tabbedPane =          private final JTabbedPane tabbedPane =
110                  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"));  
111          private final Vector<JMenuItem> miList = new Vector<JMenuItem>();          private final Vector<JMenuItem> miList = new Vector<JMenuItem>();
112                    
113          /** Creates a new instance of JSMainFrame */          private final JCheckBoxMenuItem cbmiLeftPaneVisible =
114                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane"));
115            
116            private final JCheckBoxMenuItem cbmiStandardBarVisible =
117                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.standard"));
118            
119            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            /** Creates a new instance of <code>MainFrame</code>. */
128          public          public
129          MainFrame() {          MainFrame() {
130                  setTitle(i18n.getLabel("MainFrame.title"));                  setTitle(i18n.getLabel("MainFrame.title"));
131                                    
132                  getContentPane().add(toolbar, BorderLayout.NORTH);                  getContentPane().add(standardBar, BorderLayout.NORTH);
133                  getContentPane().add(mainPane);                  getContentPane().add(mainPane);
134                                    
135                  mainPane.setLayout(new BorderLayout());                  mainPane.setLayout(new BorderLayout());
# Line 107  MainFrame extends org.jsampler.view.JSMa Line 142  MainFrame extends org.jsampler.view.JSMa
142                                    
143                  channelsPane.add(getChannelsPane(0));                  channelsPane.add(getChannelsPane(0));
144                                    
145                  splitPane = new JSplitPane (                  bottomPane.setLayout(new BorderLayout());
146                    
147                    rightPane.setLayout(new BorderLayout());
148                    
149                    rightPane.add(channelsBar, BorderLayout.NORTH);
150                    rightPane.add(channelsPane);
151                    
152                    hSplitPane = new JSplitPane (
153                          JSplitPane.HORIZONTAL_SPLIT,                          JSplitPane.HORIZONTAL_SPLIT,
154                          true,   // continuousLayout                          true,   // continuousLayout
155                          getLeftPane(),                          getLeftPane(),
156                          channelsPane                          rightPane
157                  );                  );
158                                    
159                  splitPane.setOneTouchExpandable(true);                  hSplitPane.setOneTouchExpandable(true);
160                    if(ClassicPrefs.getSaveWindowProperties()) {
161                            hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation());
162                    }
163                    
164                    mainPane.add(hSplitPane);
165                                    
166                  mainPane.add(splitPane);                  
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                  if(applicationIcon != null) setIconImage(applicationIcon.getImage());                  if(applicationIcon != null) setIconImage(applicationIcon.getImage());
180                                    
181                  initMainFrame();                  initMainFrame();
182                    
183                  pack();                  pack();
184                                    
185                  if(Prefs.getSaveWindowProperties()) setSavedSize();                  if(ClassicPrefs.getSaveWindowProperties()) setSavedSize();
186                  else setDefaultSize();                  else setDefaultSize();
187                    
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                    
202                    //CC.getInstrumentsDbTreeModel(); // used to initialize the db tree model
203            }
204            
205            /** Invoked when this window is about to close. */
206            protected void
207            onWindowClose() {
208                    if(ClassicPrefs.getSaveWindowProperties()) {
209                            ClassicPrefs.setWindowMaximized (
210                                    "Mainframe", (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
211                            );
212                            
213                            setVisible(false);
214                            if(ClassicPrefs.getWindowMaximized("Mainframe")) {
215                                    //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                            ClassicPrefs.setWindowSizeAndLocation("Mainframe", sb.toString());
226                            
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                    String[] list = recentScripts.toArray(new String[recentScripts.size()]);
248                    preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
249                    
250                    if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
251                            lsConsolePane.saveConsoleHistory();
252                    }
253                    
254                    ClassicPrefs.setShowLSConsole(isLSConsoleShown());
255                    ClassicPrefs.setLSConsolePopOut(isLSConsolePopOut());
256                    
257                    ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation());
258                    super.onWindowClose();
259          }          }
260                    
261          private void          private void
# Line 143  MainFrame extends org.jsampler.view.JSMa Line 274  MainFrame extends org.jsampler.view.JSMa
274                    
275          private void          private void
276          setSavedSize() {          setSavedSize() {
277                  String s = Prefs.getWindowSizeAndLocation();                  String s = ClassicPrefs.getWindowSizeAndLocation("Mainframe");
278                  if(s == null) {                  if(s == null) {
279                          setDefaultSize();                          setDefaultSize();
280                          return;                          return;
# Line 171  MainFrame extends org.jsampler.view.JSMa Line 302  MainFrame extends org.jsampler.view.JSMa
302                          setDefaultSize();                          setDefaultSize();
303                  }                  }
304                                    
305                  if(Prefs.getWindowMaximized())                  if(ClassicPrefs.getWindowMaximized("Mainframe"))
306                          setExtendedState(getExtendedState() | MAXIMIZED_BOTH);                          setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
307          }          }
308                    
309          private void          private void
310          addMenu() {          addMenu() {
311                  JMenu m;                  JMenu m;
                 JMenu submenu;  
312                  JMenuItem mi;                  JMenuItem mi;
313                                    
314                  setJMenuBar(menuBar);                  setJMenuBar(menuBar);
# Line 187  MainFrame extends org.jsampler.view.JSMa Line 317  MainFrame extends org.jsampler.view.JSMa
317                  m = new JMenu(i18n.getMenuLabel("actions"));                  m = new JMenu(i18n.getMenuLabel("actions"));
318                  menuBar.add(m);                  menuBar.add(m);
319                                    
320                  mi = new JMenuItem(A4n.connect);                  mi = new JMenuItem(a4n.connect);
321                  mi.setIcon(null);                  mi.setIcon(null);
322                  //mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));                  //mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));
323                  m.add(mi);                  m.add(mi);
324                                    
325                  mi = new JMenuItem(A4n.refresh);                  mi = new JMenuItem(a4n.refresh);
326                  mi.setIcon(null);                  mi.setIcon(null);
327                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
328                  m.add(mi);                  m.add(mi);
329                                    
330                  mi = new JMenuItem(A4n.resetSampler);                  mi = new JMenuItem(a4n.resetSampler);
331                  mi.setIcon(null);                  mi.setIcon(null);
332                  m.add(mi);                  m.add(mi);
333                                    
# Line 205  MainFrame extends org.jsampler.view.JSMa Line 335  MainFrame extends org.jsampler.view.JSMa
335                  mi.setIcon(null);                  mi.setIcon(null);
336                  m.add(mi);                  m.add(mi);
337                                    
338                    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                    m.addSeparator();
354                    
355                    JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
356                    m.add(exportMenu);
357                    
358                    mi = new JMenuItem(a4n.exportSamplerConfig);
359                    mi.setIcon(null);
360                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
361                    exportMenu.add(mi);
362                    
363                    mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
364                    mi.setIcon(null);
365                    exportMenu.add(mi);
366                    
367                    m.addSeparator();
368                    
369                    mi = new JMenuItem(A4n.loadScript);
370                    mi.setIcon(null);
371                    m.add(mi);
372                    
373                    String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
374                    for(String s : list) recentScripts.add(s);
375                    
376                    updateRecentScriptsMenu();
377                    
378                    m.add(recentScriptsMenu);
379                    
380                  m.addSeparator();                  m.addSeparator();
381                                    
382                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
383                  m.add(mi);                  m.add(mi);
384                  mi.addActionListener(new ActionListener() {                  mi.addActionListener(new ActionListener() {
385                          public void                          public void
386                          actionPerformed(ActionEvent e) { CC.cleanExit(); }                          actionPerformed(ActionEvent e) { onWindowClose(); }
387                  });                  });
388                                    
389                  // Edit                  // Edit
390                  m = new JMenu(i18n.getMenuLabel("edit"));                  m = new JMenu(i18n.getMenuLabel("edit"));
391                  menuBar.add(m);                  menuBar.add(m);
392                                    
393                    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                  m.addSeparator();                  m.addSeparator();
424                                    
425                  mi = new JMenuItem(A4n.preferences);                  mi = new JMenuItem(A4n.preferences);
# Line 231  MainFrame extends org.jsampler.view.JSMa Line 433  MainFrame extends org.jsampler.view.JSMa
433                  m = new JMenu(i18n.getMenuLabel("view"));                  m = new JMenu(i18n.getMenuLabel("view"));
434                  menuBar.add(m);                  menuBar.add(m);
435                                    
436                    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                  final JCheckBoxMenuItem cbmi =                  final JCheckBoxMenuItem cbmi =
452                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbar"));                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.channels"));
453                                    
454                  m.add(cbmi);                  toolbarsMenu.add(cbmi);
455                  cbmi.addActionListener(new ActionListener() {                  cbmi.addActionListener(new ActionListener() {
456                          public void                          public void
457                          actionPerformed(ActionEvent e) { showToolbar(cbmi.getState()); }                          actionPerformed(ActionEvent e) { showChannelsBar(cbmi.getState()); }
458                  });                  });
459                                    
460                  boolean b = ClassicPrefs.shouldShowToolbar();                  b = ClassicPrefs.shouldShowChannelsBar();
461                  cbmi.setSelected(b);                  cbmi.setSelected(b);
462                  showToolbar(b);                  showChannelsBar(b);
                   
                 final JCheckBoxMenuItem cbmi1 =  
                         new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane"));  
463                                    
464                  m.add(cbmi1);                  m.add(cbmiLeftPaneVisible);
465                  cbmi1.addActionListener(new ActionListener() {                  cbmiLeftPaneVisible.addActionListener(new ActionListener() {
466                          public void                          public void
467                          actionPerformed(ActionEvent e) { showLeftPane(cbmi1.getState()); }                          actionPerformed(ActionEvent e) {
468                                    showLeftPane(cbmiLeftPaneVisible.getState());
469                            }
470                  });                  });
471                                    
472                  b = ClassicPrefs.shouldShowLeftPane();                  b = ClassicPrefs.shouldShowLeftPane();
473                  cbmi1.setSelected(b);                  cbmiLeftPaneVisible.setSelected(b);
474                  showLeftPane(b);                  showLeftPane(b);
475                                    
476                  final JCheckBoxMenuItem cbmi2 =                  final JCheckBoxMenuItem cbmi2 =
# Line 269  MainFrame extends org.jsampler.view.JSMa Line 485  MainFrame extends org.jsampler.view.JSMa
485                  cbmi2.setSelected(b);                  cbmi2.setSelected(b);
486                  showStatusbar(b);                  showStatusbar(b);
487                                    
488                    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                  // Channels                  // Channels
505                  m = new JMenu(i18n.getMenuLabel("channels"));                  m = new JMenu(i18n.getMenuLabel("channels"));
506                  menuBar.add(m);                  menuBar.add(m);
# Line 388  MainFrame extends org.jsampler.view.JSMa Line 620  MainFrame extends org.jsampler.view.JSMa
620                  m.add(mi);                  m.add(mi);
621                                    
622                                    
623                    // 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                  // Help                  // Help
633                  m = new JMenu(i18n.getMenuLabel("help"));                  m = new JMenu(i18n.getMenuLabel("help"));
                 menuBar.add(m);  
634                                    
635                  mi = new JMenuItem(A4n.helpAbout);                  mi = new JMenuItem(A4n.helpAbout);
636                  mi.setIcon(null);                  mi.setIcon(null);
637                  m.add(mi);                  m.add(mi);
638                    
639                    m.addSeparator();
640                    
641                    mi = new JMenuItem(a4n.browseOnlineTutorial);
642                    mi.setIcon(null);
643                    m.add(mi);
644                    
645                    menuBar.add(m);
646            }
647            
648            private class RecentScriptHandler implements ActionListener {
649                    private String script;
650                    
651                    RecentScriptHandler(String script) { this.script = script; }
652                    
653                    public void
654                    actionPerformed(ActionEvent e) {  runScript(script); }
655          }          }
656                    
657          private void          private void
# Line 403  MainFrame extends org.jsampler.view.JSMa Line 660  MainFrame extends org.jsampler.view.JSMa
660          }          }
661                    
662          private void          private void
663          showToolbar(boolean b) {          showChannelsBar(boolean b) {
664                  if(b) getContentPane().add(toolbar, BorderLayout.NORTH);                  channelsBar.setVisible(b);
665                  else getContentPane().remove(toolbar);                  ClassicPrefs.setShowChannelsBar(b);
                   
                 ClassicPrefs.setShowToolbar(b);  
666                                    
667                  validate();                  validate();
668                  repaint();                  repaint();
# Line 419  MainFrame extends org.jsampler.view.JSMa Line 674  MainFrame extends org.jsampler.view.JSMa
674                  statusbar.setVisible(b);                  statusbar.setVisible(b);
675          }          }
676                    
677            protected boolean
678            isLeftPaneVisible() { return cbmiLeftPaneVisible.isSelected(); }
679            
680            protected void
681            setLeftPaneVisible(boolean b) {
682                    if(b != cbmiLeftPaneVisible.isSelected()) cbmiLeftPaneVisible.doClick(0);
683            }
684            
685            protected boolean
686            isLSConsoleVisible() { return cbmiLSConsoleShown.isSelected(); }
687            
688            protected void
689            setLSConsoleVisible(boolean b) {
690                    if(b != cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
691            }
692            
693          private void          private void
694          showLeftPane(boolean b) {          showLeftPane(boolean b) {
695                  ClassicPrefs.setShowLeftPane(b);                  ClassicPrefs.setShowLeftPane(b);
696                                    
697                  mainPane.remove(splitPane);                  mainPane.remove(hSplitPane);
698                  mainPane.remove(channelsPane);                  mainPane.remove(rightPane);
699                    
700                    if(b) {
701                            hSplitPane.setRightComponent(rightPane);
702                            mainPane.add(hSplitPane);
703                            if(ClassicPrefs.getSaveWindowProperties()) {
704                                    int i = ClassicPrefs.getHSplitDividerLocation();
705                                    hSplitPane.setDividerLocation(i);
706                            }
707                    } else {
708                            mainPane.add(rightPane);
709                    }
710                    
711                    validate();
712                    repaint();
713            }
714            
715            private void
716            showStandardBar(boolean b) {
717                    ClassicPrefs.setShowStandardBar(b);
718                    standardBar.setVisible(b);
719                    validate();
720                    repaint();
721            }
722            
723            private void
724            showBottomPane(boolean b) {
725                    if(!b) ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation());
726                    
727                    rightPane.remove(vSplitPane);
728                    rightPane.remove(channelsPane);
729                                    
730                  if(b) {                  if(b) {
731                          splitPane.setRightComponent(channelsPane);                          vSplitPane.setTopComponent(channelsPane);
732                          mainPane.add(splitPane);                          rightPane.add(vSplitPane);
733                            vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
734                  } else {                  } else {
735                          mainPane.add(channelsPane);                          rightPane.add(channelsPane);
736                  }                  }
737                                    
738                  validate();                  validate();
739                  repaint();                  repaint();
740          }          }
741                    
742            protected void
743            setLSConsolePopOut(boolean b) {
744                    if(b == lsConsolePopOut) return;
745                    
746                    lsConsolePopOut = b;
747                    
748                    if(isLSConsoleShown()) setLSConsolePopOut0(b);
749            }
750            
751            /**
752             * Changes the pop-out state of the LS Console.
753             * Invoke this method only when LS Console is shown.
754             */
755            private void
756            setLSConsolePopOut0(boolean b) {
757                    if(b) {
758                            bottomPane.remove(lsConsolePane);
759                            showBottomPane(false);
760                            
761                            lsConsoleDlg = new LSConsoleDlg(this, lsConsolePane);
762                            lsConsoleDlg.setVisible(true);
763                    } else {
764                            if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
765                            lsConsoleDlg = null;
766                            bottomPane.add(lsConsolePane);
767                            showBottomPane(true);
768                    }
769            }
770            
771            protected boolean
772            isLSConsolePopOut() { return lsConsolePopOut; }
773            
774            protected boolean
775            isLSConsoleShown() { return cbmiLSConsoleShown.isSelected(); }
776            
777            protected void
778            setLSConsoleShown(boolean b) { cbmiLSConsoleShown.setSelected(b); }
779            
780            protected LSConsoleModel
781            getLSConsoleModel() { return lsConsolePane.getModel(); }
782            
783            /**
784             * Sets the text color of the LS Console.
785             * @param c The text color of the LS Console.
786             */
787            protected void
788            setLSConsoleTextColor(Color c) { lsConsolePane.setTextColor(c); }
789            
790            /**
791             * Sets the background color of the LS Console.
792             * @param c The background color of the LS Console.
793             */
794            protected void
795            setLSConsoleBackgroundColor(Color c) { lsConsolePane.setBackgroundColor(c); }
796            
797            /**
798             * Sets the notification messages' color of the LS Console.
799             * @param c The notification messages' color of the LS Console.
800             */
801            protected void
802            setLSConsoleNotifyColor(Color c) { lsConsolePane.setNotifyColor(c); }
803            
804            /**
805             * Sets the warning messages' color of the LS Console.
806             * @param c The warning messages' color of the LS Console.
807             */
808            protected void
809            setLSConsoleWarningColor(Color c) { lsConsolePane.setWarningColor(c); }
810            
811            /**
812             * Sets the error messages' color of the LS Console.
813             * @param c The error messages' color of the LS Console.
814             */
815            protected void
816            setLSConsoleErrorColor(Color c) { lsConsolePane.setErrorColor(c); }
817            
818            protected void
819            showLSConsole(boolean b) {
820                    if(!b) {
821                            showBottomPane(false);
822                            if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
823                            lsConsolePane.hideAutoCompleteWindow();
824                            return;
825                    }
826                    
827                    setLSConsolePopOut0(isLSConsolePopOut());
828            }
829            
830            /**
831             * Adds the specified <code>JSChannelsPane</code> to the view.
832             * @param chnPane The <code>JSChannelsPane</code> to be added.
833             */
834          public void          public void
835          addChannelsPane(JSChannelsPane chnPane) {          addChannelsPane(JSChannelsPane chnPane) {
836                  insertChannelsPane(chnPane, getChannelsPaneCount());                  insertChannelsPane(chnPane, getChannelsPaneCount());
# Line 462  MainFrame extends org.jsampler.view.JSMa Line 856  MainFrame extends org.jsampler.view.JSMa
856                  updateTabsMenu();                  updateTabsMenu();
857          }          }
858                    
859            /**
860             * Gets the <code>JSChannelsPane</code> that is currently shown.
861             * @return The currently shown <code>JSChannelsPane</code>.
862             */
863          public JSChannelsPane          public JSChannelsPane
864          getSelectedChannelsPane() {          getSelectedChannelsPane() {
865                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);
866                  return (JSChannelsPane)tabbedPane.getSelectedComponent();                  return (JSChannelsPane)tabbedPane.getSelectedComponent();
867          }          }
868                    
869            /**
870             * Sets the <code>JSChannelsPane</code> to be selected.
871             * @param pane The <code>JSChannelsPane</code> to be shown.
872             */
873          public void          public void
874          setSelectedChannelsPane(JSChannelsPane pane) {          setSelectedChannelsPane(JSChannelsPane pane) {
875                  if(getChannelsPaneList().size() == 1) return;                  if(getChannelsPaneList().size() == 1) return;
876                  tabbedPane.setSelectedComponent(pane);                  tabbedPane.setSelectedComponent(pane);
877          }          }
878                    
879            /**
880             * Removes the specified <code>JSChannelsPane</code> from the view.
881             * @param chnPane The <code>JSChannelsPane</code> to be removed.
882             * @return <code>true</code> if the specified code>JSChannelsPane</code>
883             * is actually removed from the view, <code>false</code> otherwise.
884             */
885          public boolean          public boolean
886          removeChannelsPane(JSChannelsPane chnPane) {          removeChannelsPane(JSChannelsPane chnPane) {
887                  chnPane.removeListSelectionListener(this);                  chnPane.removeListSelectionListener(this);
# Line 694  MainFrame extends org.jsampler.view.JSMa Line 1102  MainFrame extends org.jsampler.view.JSMa
1102                  addChannelsPane(c);                  addChannelsPane(c);
1103                  tabbedPane.setSelectedComponent(c);                  tabbedPane.setSelectedComponent(c);
1104          }          }
1105            
1106            protected void
1107            runScript() {
1108                    String s = preferences().getStringProperty("lastScriptLocation");
1109                    JFileChooser fc = new JFileChooser(s);
1110                    fc.setFileFilter(new LscpFileFilter());
1111                    int result = fc.showOpenDialog(this);
1112                    if(result != JFileChooser.APPROVE_OPTION) return;
1113                    
1114                    String path = fc.getCurrentDirectory().getAbsolutePath();
1115                    preferences().setStringProperty("lastScriptLocation", path);
1116                                            
1117                    runScript(fc.getSelectedFile());
1118            }
1119            
1120            private void
1121            runScript(String script) { runScript(new File(script)); }
1122            
1123            private void
1124            runScript(File script) {
1125                    FileReader fr;
1126                    try { fr = new FileReader(script); }
1127                    catch(FileNotFoundException e) {
1128                            HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
1129                            return;
1130                    }
1131                    
1132                    BufferedReader br = new BufferedReader(fr);
1133                    
1134                    try {
1135                            String s = br.readLine();
1136                            while(s != null) {
1137                                    getLSConsoleModel().setCommandLineText(s);
1138                                    getLSConsoleModel().execCommand();
1139                                    s = br.readLine();
1140                            }
1141                    } catch(Exception e) {
1142                            HF.showErrorMessage(e);
1143                            return;
1144                    }
1145                    
1146                    if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
1147                            if(!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
1148                    }
1149                    
1150                    String s = script.getAbsolutePath();
1151                    recentScripts.remove(s);
1152                    recentScripts.insertElementAt(s, 0);
1153                    
1154                    updateRecentScriptsMenu();
1155            }
1156            
1157            protected void
1158            clearRecentScripts() {
1159                    recentScripts.removeAllElements();
1160                    updateRecentScriptsMenu();
1161            }
1162            
1163            protected void
1164            updateRecentScriptsMenu() {
1165                    int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
1166                    while(recentScripts.size() > size) {
1167                            recentScripts.removeElementAt(recentScripts.size() - 1);
1168                    }
1169                    
1170                    recentScriptsMenu.removeAll();
1171                    
1172                    for(String script : recentScripts) {
1173                            JMenuItem mi = new JMenuItem(script);
1174                            recentScriptsMenu.add(mi);
1175                            mi.addActionListener(new RecentScriptHandler(script));
1176                    }
1177                    
1178                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
1179            }
1180            
1181            public void
1182            installJSamplerHome() {
1183                    JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
1184                    chooser.setVisible(true);
1185                    if(chooser.isCancelled()) return;
1186                    
1187                    CC.changeJSamplerHome(chooser.getJSamplerHome());
1188            }
1189            
1190            public void
1191            showDetailedErrorMessage(Frame owner, String err, String details) {
1192                    JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
1193                            owner, Res.iconWarning32, i18n.getError("error"), err, details
1194                    );
1195                    dlg.setVisible(true);
1196            }
1197            
1198            public void
1199            showDetailedErrorMessage(Dialog owner, String err, String details) {
1200                    JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
1201                            owner, Res.iconWarning32, i18n.getError("error"), err, details
1202                    );
1203                    dlg.setVisible(true);
1204            }
1205  }  }

Legend:
Removed from v.842  
changed lines
  Added in v.1496

  ViewVC Help
Powered by ViewVC