/[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 1327 by iliev, Fri Sep 7 12:09:59 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.JSamplerHomeChooser;
75    
76    import static org.jsampler.view.classic.A4n.a4n;
77  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
78    import static org.jsampler.view.classic.ClassicPrefs.preferences;
79  import static org.jsampler.view.classic.LeftPane.getLeftPane;  import static org.jsampler.view.classic.LeftPane.getLeftPane;
80    import static org.jsampler.view.std.StdPrefs.*;
81    
82  /**  /**
83   *   *
# Line 67  import static org.jsampler.view.classic. Line 85  import static org.jsampler.view.classic.
85   */   */
86  public class  public class
87  MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener {  MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener {
88          public static ImageIcon applicationIcon = null;          public static ImageIcon applicationIcon = Res.appIcon;
89                    
90          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();  
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 StandardBar standardBar = new StandardBar();
102          private final JPanel channelsPane = new JPanel(new BorderLayout());          private final JPanel channelsPane = new JPanel(new BorderLayout());
103            private final JPanel rightPane = new JPanel();
104            private final JPanel bottomPane = new JPanel();
105            private final LSConsolePane lsConsolePane = new LSConsolePane(this);
106            private LSConsoleDlg lsConsoleDlg = null;
107                    
108          private final JTabbedPane tabbedPane =          private final JTabbedPane tabbedPane =
109                  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"));  
110          private final Vector<JMenuItem> miList = new Vector<JMenuItem>();          private final Vector<JMenuItem> miList = new Vector<JMenuItem>();
111                    
112          /** Creates a new instance of JSMainFrame */          private final JCheckBoxMenuItem cbmiLeftPaneVisible =
113                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane"));
114            
115            private final JCheckBoxMenuItem cbmiStandardBarVisible =
116                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.standard"));
117            
118            private final JCheckBoxMenuItem cbmiLSConsoleShown =
119                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.lsconsole"));
120            
121            private boolean lsConsolePopOut;
122            
123            private final Vector<String> recentScripts = new Vector<String>();
124                    
125            
126            /** Creates a new instance of <code>MainFrame</code>. */
127          public          public
128          MainFrame() {          MainFrame() {
129                  setTitle(i18n.getLabel("MainFrame.title"));                  setTitle(i18n.getLabel("MainFrame.title"));
130                                    
131                  getContentPane().add(toolbar, BorderLayout.NORTH);                  getContentPane().add(standardBar, BorderLayout.NORTH);
132                  getContentPane().add(mainPane);                  getContentPane().add(mainPane);
133                                    
134                  mainPane.setLayout(new BorderLayout());                  mainPane.setLayout(new BorderLayout());
# Line 107  MainFrame extends org.jsampler.view.JSMa Line 141  MainFrame extends org.jsampler.view.JSMa
141                                    
142                  channelsPane.add(getChannelsPane(0));                  channelsPane.add(getChannelsPane(0));
143                                    
144                  splitPane = new JSplitPane (                  bottomPane.setLayout(new BorderLayout());
145                    
146                    rightPane.setLayout(new BorderLayout());
147                    
148                    rightPane.add(channelsBar, BorderLayout.NORTH);
149                    rightPane.add(channelsPane);
150                    
151                    hSplitPane = new JSplitPane (
152                          JSplitPane.HORIZONTAL_SPLIT,                          JSplitPane.HORIZONTAL_SPLIT,
153                          true,   // continuousLayout                          true,   // continuousLayout
154                          getLeftPane(),                          getLeftPane(),
155                          channelsPane                          rightPane
156                    );
157                    
158                    hSplitPane.setOneTouchExpandable(true);
159                    if(ClassicPrefs.getSaveWindowProperties()) {
160                            hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation());
161                    }
162                    
163                    mainPane.add(hSplitPane);
164                    
165                    
166                    vSplitPane = new JSplitPane (
167                            JSplitPane.VERTICAL_SPLIT,
168                            true,   // continuousLayout
169                            channelsPane,
170                            bottomPane
171                  );                  );
172                                    
173                  splitPane.setOneTouchExpandable(true);                  vSplitPane.setDividerSize(3);
174                    vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
175                                    
176                  mainPane.add(splitPane);                  rightPane.add(vSplitPane);
177                                    
178                  if(applicationIcon != null) setIconImage(applicationIcon.getImage());                  if(applicationIcon != null) setIconImage(applicationIcon.getImage());
179                                    
180                  initMainFrame();                  initMainFrame();
181                    
182                  pack();                  pack();
183                                    
184                  if(Prefs.getSaveWindowProperties()) setSavedSize();                  if(ClassicPrefs.getSaveWindowProperties()) setSavedSize();
185                  else setDefaultSize();                  else setDefaultSize();
186                    
187                    if(ClassicPrefs.getSaveLeftPaneState()) {
188                            NavigationPage page =
189                                    getLeftPane().getPages()[ClassicPrefs.getLeftPanePageIndex()];
190                            
191                            getLeftPane().getModel().addPage(page);
192                            getLeftPane().getModel().clearHistory();
193                            
194                            int idx = ClassicPrefs.getCurrentOrchestraIndex();
195                            if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) {
196                                    OrchestraModel om = CC.getOrchestras().getOrchestra(idx);
197                                    getLeftPane().getOrchestrasPage().setSelectedOrchestra(om);
198                            }
199                    }
200                    
201                    //CC.getInstrumentsDbTreeModel(); // used to initialize the db tree model
202            }
203            
204            /** Invoked when this window is about to close. */
205            protected void
206            onWindowClose() {
207                    if(ClassicPrefs.getSaveWindowProperties()) {
208                            ClassicPrefs.setWindowMaximized (
209                                    "Mainframe", (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
210                            );
211                            
212                            setVisible(false);
213                            if(ClassicPrefs.getWindowMaximized("Mainframe")) {
214                                    //setExtendedState(getExtendedState() & ~MAXIMIZED_BOTH);
215                                    CC.cleanExit();
216                                    return;
217                            }
218                            
219                            java.awt.Point p = getLocation();
220                            Dimension d = getSize();
221                            StringBuffer sb = new StringBuffer();
222                            sb.append(p.x).append(',').append(p.y).append(',');
223                            sb.append(d.width).append(',').append(d.height);
224                            ClassicPrefs.setWindowSizeAndLocation("Mainframe", sb.toString());
225                            
226                            ClassicPrefs.setHSplitDividerLocation(hSplitPane.getDividerLocation());
227                    }
228                    
229                    if(ClassicPrefs.getSaveLeftPaneState()) {
230                            int idx = 0;
231                            for(int i = 0; i < getLeftPane().getPages().length; i++) {
232                                    if(getLeftPane().getPages()[i] == getLeftPane().getCurrentPage()) {
233                                            idx = i;
234                                            break;
235                                    }
236                            }
237                            
238                            ClassicPrefs.setLeftPanePageIndex(idx);
239                            
240                            idx = getLeftPane().getOrchestrasPage().getCurrentOrchestraIndex();
241                            
242                            if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount())
243                                    ClassicPrefs.setCurrentOrchestraIndex(idx);
244                    }
245                    
246                    String[] list = recentScripts.toArray(new String[recentScripts.size()]);
247                    preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
248                    
249                    if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
250                            lsConsolePane.saveConsoleHistory();
251                    }
252                    
253                    ClassicPrefs.setShowLSConsole(isLSConsoleShown());
254                    ClassicPrefs.setLSConsolePopOut(isLSConsolePopOut());
255                    
256                    ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation());
257                    super.onWindowClose();
258          }          }
259                    
260          private void          private void
# Line 143  MainFrame extends org.jsampler.view.JSMa Line 273  MainFrame extends org.jsampler.view.JSMa
273                    
274          private void          private void
275          setSavedSize() {          setSavedSize() {
276                  String s = Prefs.getWindowSizeAndLocation();                  String s = ClassicPrefs.getWindowSizeAndLocation("Mainframe");
277                  if(s == null) {                  if(s == null) {
278                          setDefaultSize();                          setDefaultSize();
279                          return;                          return;
# Line 171  MainFrame extends org.jsampler.view.JSMa Line 301  MainFrame extends org.jsampler.view.JSMa
301                          setDefaultSize();                          setDefaultSize();
302                  }                  }
303                                    
304                  if(Prefs.getWindowMaximized())                  if(ClassicPrefs.getWindowMaximized("Mainframe"))
305                          setExtendedState(getExtendedState() | MAXIMIZED_BOTH);                          setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
306          }          }
307                    
308          private void          private void
309          addMenu() {          addMenu() {
310                  JMenu m;                  JMenu m;
                 JMenu submenu;  
311                  JMenuItem mi;                  JMenuItem mi;
312                                    
313                  setJMenuBar(menuBar);                  setJMenuBar(menuBar);
# Line 187  MainFrame extends org.jsampler.view.JSMa Line 316  MainFrame extends org.jsampler.view.JSMa
316                  m = new JMenu(i18n.getMenuLabel("actions"));                  m = new JMenu(i18n.getMenuLabel("actions"));
317                  menuBar.add(m);                  menuBar.add(m);
318                                    
319                  mi = new JMenuItem(A4n.connect);                  mi = new JMenuItem(a4n.connect);
320                  mi.setIcon(null);                  mi.setIcon(null);
321                  //mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));                  //mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));
322                  m.add(mi);                  m.add(mi);
323                                    
324                  mi = new JMenuItem(A4n.refresh);                  mi = new JMenuItem(a4n.refresh);
325                  mi.setIcon(null);                  mi.setIcon(null);
326                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));                  mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
327                  m.add(mi);                  m.add(mi);
328                                    
329                  mi = new JMenuItem(A4n.resetSampler);                  mi = new JMenuItem(a4n.resetSampler);
330                  mi.setIcon(null);                  mi.setIcon(null);
331                  m.add(mi);                  m.add(mi);
332                                    
# Line 205  MainFrame extends org.jsampler.view.JSMa Line 334  MainFrame extends org.jsampler.view.JSMa
334                  mi.setIcon(null);                  mi.setIcon(null);
335                  m.add(mi);                  m.add(mi);
336                                    
337                    JMenu midiInstrMenu = new JMenu(i18n.getMenuLabel("actions.midiInstruments"));
338                    m.add(midiInstrMenu);
339                    
340                    mi = new JMenuItem(A4n.addMidiInstrumentMap);
341                    mi.setIcon(null);
342                    midiInstrMenu.add(mi);
343                    
344                    mi = new JMenuItem(A4n.removeMidiInstrumentMap);
345                    mi.setIcon(null);
346                    midiInstrMenu.add(mi);
347                    
348                    mi = new JMenuItem(A4n.addMidiInstrumentWizard);
349                    mi.setIcon(null);
350                    midiInstrMenu.add(mi);
351                    
352                    m.addSeparator();
353                    
354                    JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
355                    m.add(exportMenu);
356                    
357                    mi = new JMenuItem(a4n.exportSamplerConfig);
358                    mi.setIcon(null);
359                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
360                    exportMenu.add(mi);
361                    
362                    mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
363                    mi.setIcon(null);
364                    exportMenu.add(mi);
365                    
366                    m.addSeparator();
367                    
368                    mi = new JMenuItem(A4n.loadScript);
369                    mi.setIcon(null);
370                    m.add(mi);
371                    
372                    String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
373                    for(String s : list) recentScripts.add(s);
374                    
375                    updateRecentScriptsMenu();
376                    
377                    m.add(recentScriptsMenu);
378                    
379                  m.addSeparator();                  m.addSeparator();
380                                    
381                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
382                  m.add(mi);                  m.add(mi);
383                  mi.addActionListener(new ActionListener() {                  mi.addActionListener(new ActionListener() {
384                          public void                          public void
385                          actionPerformed(ActionEvent e) { CC.cleanExit(); }                          actionPerformed(ActionEvent e) { onWindowClose(); }
386                  });                  });
387                                    
388                  // Edit                  // Edit
389                  m = new JMenu(i18n.getMenuLabel("edit"));                  m = new JMenu(i18n.getMenuLabel("edit"));
390                  menuBar.add(m);                  menuBar.add(m);
391                                    
392                    mi = new JMenuItem(i18n.getMenuLabel("edit.audioDevices"));
393                    m.add(mi);
394                    mi.addActionListener(new ActionListener() {
395                            public void
396                            actionPerformed(ActionEvent e) {
397                                    if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0);
398                                    LeftPane.getLeftPane().showAudioDevicesPage();
399                            }
400                    });
401                    
402                    mi = new JMenuItem(i18n.getMenuLabel("edit.midiDevices"));
403                    m.add(mi);
404                    mi.addActionListener(new ActionListener() {
405                            public void
406                            actionPerformed(ActionEvent e) {
407                                    if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0);
408                                    LeftPane.getLeftPane().showMidiDevicesPage();
409                            }
410                    });
411                    
412                    mi = new JMenuItem(i18n.getMenuLabel("edit.orchestras"));
413                    m.add(mi);
414                    mi.addActionListener(new ActionListener() {
415                            public void
416                            actionPerformed(ActionEvent e) {
417                                    if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0);
418                                    LeftPane.getLeftPane().showManageOrchestrasPage();
419                            }
420                    });
421                    
422                  m.addSeparator();                  m.addSeparator();
423                                    
424                  mi = new JMenuItem(A4n.preferences);                  mi = new JMenuItem(A4n.preferences);
# Line 231  MainFrame extends org.jsampler.view.JSMa Line 432  MainFrame extends org.jsampler.view.JSMa
432                  m = new JMenu(i18n.getMenuLabel("view"));                  m = new JMenu(i18n.getMenuLabel("view"));
433                  menuBar.add(m);                  menuBar.add(m);
434                                    
435                    JMenu toolbarsMenu = new JMenu(i18n.getMenuLabel("view.toolbars"));
436                    m.add(toolbarsMenu);
437                    
438                    toolbarsMenu.add(cbmiStandardBarVisible);
439                    cbmiStandardBarVisible.addActionListener(new ActionListener() {
440                            public void
441                            actionPerformed(ActionEvent e) {
442                                    showStandardBar(cbmiStandardBarVisible.getState());
443                            }
444                    });
445                    
446                    boolean b = ClassicPrefs.shouldShowStandardBar();
447                    cbmiStandardBarVisible.setSelected(b);
448                    showStandardBar(b);
449                    
450                  final JCheckBoxMenuItem cbmi =                  final JCheckBoxMenuItem cbmi =
451                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbar"));                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.channels"));
452                                    
453                  m.add(cbmi);                  toolbarsMenu.add(cbmi);
454                  cbmi.addActionListener(new ActionListener() {                  cbmi.addActionListener(new ActionListener() {
455                          public void                          public void
456                          actionPerformed(ActionEvent e) { showToolbar(cbmi.getState()); }                          actionPerformed(ActionEvent e) { showChannelsBar(cbmi.getState()); }
457                  });                  });
458                                    
459                  boolean b = ClassicPrefs.shouldShowToolbar();                  b = ClassicPrefs.shouldShowChannelsBar();
460                  cbmi.setSelected(b);                  cbmi.setSelected(b);
461                  showToolbar(b);                  showChannelsBar(b);
462                                    
463                  final JCheckBoxMenuItem cbmi1 =                  m.add(cbmiLeftPaneVisible);
464                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane"));                  cbmiLeftPaneVisible.addActionListener(new ActionListener() {
                   
                 m.add(cbmi1);  
                 cbmi1.addActionListener(new ActionListener() {  
465                          public void                          public void
466                          actionPerformed(ActionEvent e) { showLeftPane(cbmi1.getState()); }                          actionPerformed(ActionEvent e) {
467                                    showLeftPane(cbmiLeftPaneVisible.getState());
468                            }
469                  });                  });
470                                    
471                  b = ClassicPrefs.shouldShowLeftPane();                  b = ClassicPrefs.shouldShowLeftPane();
472                  cbmi1.setSelected(b);                  cbmiLeftPaneVisible.setSelected(b);
473                  showLeftPane(b);                  showLeftPane(b);
474                                    
475                  final JCheckBoxMenuItem cbmi2 =                  final JCheckBoxMenuItem cbmi2 =
# Line 269  MainFrame extends org.jsampler.view.JSMa Line 484  MainFrame extends org.jsampler.view.JSMa
484                  cbmi2.setSelected(b);                  cbmi2.setSelected(b);
485                  showStatusbar(b);                  showStatusbar(b);
486                                    
487                    m.addSeparator();
488                    
489                    setLSConsolePopOut(ClassicPrefs.isLSConsolePopOut());
490                    cbmiLSConsoleShown.setSelected(ClassicPrefs.shouldShowLSConsole());
491                    showLSConsole(ClassicPrefs.shouldShowLSConsole());
492                    
493                    cbmiLSConsoleShown.addActionListener(new ActionListener() {
494                            public void
495                            actionPerformed(ActionEvent e) {
496                                    showLSConsole(cbmiLSConsoleShown.isSelected());
497                            }
498                    });
499                    m.add(cbmiLSConsoleShown);
500                    
501                    lsConsolePane.updateLSConsoleViewMode();
502                    
503                  // Channels                  // Channels
504                  m = new JMenu(i18n.getMenuLabel("channels"));                  m = new JMenu(i18n.getMenuLabel("channels"));
505                  menuBar.add(m);                  menuBar.add(m);
# Line 388  MainFrame extends org.jsampler.view.JSMa Line 619  MainFrame extends org.jsampler.view.JSMa
619                  m.add(mi);                  m.add(mi);
620                                    
621                                    
622                    // Window
623                    m = new JMenu(i18n.getMenuLabel("window"));
624                    menuBar.add(m);
625                    
626                    mi = new JMenuItem(A4n.windowInstrumentsDb);
627                    mi.setIcon(null);
628                    m.add(mi);
629                    
630                    
631                  // Help                  // Help
632                  m = new JMenu(i18n.getMenuLabel("help"));                  m = new JMenu(i18n.getMenuLabel("help"));
633                  menuBar.add(m);                  menuBar.add(m);
# Line 397  MainFrame extends org.jsampler.view.JSMa Line 637  MainFrame extends org.jsampler.view.JSMa
637                  m.add(mi);                  m.add(mi);
638          }          }
639                    
640            private class RecentScriptHandler implements ActionListener {
641                    private String script;
642                    
643                    RecentScriptHandler(String script) { this.script = script; }
644                    
645                    public void
646                    actionPerformed(ActionEvent e) {  runScript(script); }
647            }
648            
649          private void          private void
650          handleEvents() {          handleEvents() {
651                  tabbedPane.addChangeListener(this);                  tabbedPane.addChangeListener(this);
652          }          }
653                    
654          private void          private void
655          showToolbar(boolean b) {          showChannelsBar(boolean b) {
656                  if(b) getContentPane().add(toolbar, BorderLayout.NORTH);                  channelsBar.setVisible(b);
657                  else getContentPane().remove(toolbar);                  ClassicPrefs.setShowChannelsBar(b);
                   
                 ClassicPrefs.setShowToolbar(b);  
658                                    
659                  validate();                  validate();
660                  repaint();                  repaint();
# Line 419  MainFrame extends org.jsampler.view.JSMa Line 666  MainFrame extends org.jsampler.view.JSMa
666                  statusbar.setVisible(b);                  statusbar.setVisible(b);
667          }          }
668                    
669            protected boolean
670            isLeftPaneVisible() { return cbmiLeftPaneVisible.isSelected(); }
671            
672            protected void
673            setLeftPaneVisible(boolean b) {
674                    if(b != cbmiLeftPaneVisible.isSelected()) cbmiLeftPaneVisible.doClick(0);
675            }
676            
677            protected boolean
678            isLSConsoleVisible() { return cbmiLSConsoleShown.isSelected(); }
679            
680            protected void
681            setLSConsoleVisible(boolean b) {
682                    if(b != cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
683            }
684            
685          private void          private void
686          showLeftPane(boolean b) {          showLeftPane(boolean b) {
687                  ClassicPrefs.setShowLeftPane(b);                  ClassicPrefs.setShowLeftPane(b);
688                                    
689                  mainPane.remove(splitPane);                  mainPane.remove(hSplitPane);
690                  mainPane.remove(channelsPane);                  mainPane.remove(rightPane);
691                                    
692                  if(b) {                  if(b) {
693                          splitPane.setRightComponent(channelsPane);                          hSplitPane.setRightComponent(rightPane);
694                          mainPane.add(splitPane);                          mainPane.add(hSplitPane);
695                            if(ClassicPrefs.getSaveWindowProperties()) {
696                                    int i = ClassicPrefs.getHSplitDividerLocation();
697                                    hSplitPane.setDividerLocation(i);
698                            }
699                  } else {                  } else {
700                          mainPane.add(channelsPane);                          mainPane.add(rightPane);
701                  }                  }
702                                    
703                  validate();                  validate();
704                  repaint();                  repaint();
705          }          }
706                    
707            private void
708            showStandardBar(boolean b) {
709                    ClassicPrefs.setShowStandardBar(b);
710                    standardBar.setVisible(b);
711                    validate();
712                    repaint();
713            }
714            
715            private void
716            showBottomPane(boolean b) {
717                    if(!b) ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation());
718                    
719                    rightPane.remove(vSplitPane);
720                    rightPane.remove(channelsPane);
721                    
722                    if(b) {
723                            vSplitPane.setTopComponent(channelsPane);
724                            rightPane.add(vSplitPane);
725                            vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
726                    } else {
727                            rightPane.add(channelsPane);
728                    }
729                    
730                    validate();
731                    repaint();
732            }
733            
734            protected void
735            setLSConsolePopOut(boolean b) {
736                    if(b == lsConsolePopOut) return;
737                    
738                    lsConsolePopOut = b;
739                    
740                    if(isLSConsoleShown()) setLSConsolePopOut0(b);
741            }
742            
743            /**
744             * Changes the pop-out state of the LS Console.
745             * Invoke this method only when LS Console is shown.
746             */
747            private void
748            setLSConsolePopOut0(boolean b) {
749                    if(b) {
750                            bottomPane.remove(lsConsolePane);
751                            showBottomPane(false);
752                            
753                            lsConsoleDlg = new LSConsoleDlg(this, lsConsolePane);
754                            lsConsoleDlg.setVisible(true);
755                    } else {
756                            if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
757                            lsConsoleDlg = null;
758                            bottomPane.add(lsConsolePane);
759                            showBottomPane(true);
760                    }
761            }
762            
763            protected boolean
764            isLSConsolePopOut() { return lsConsolePopOut; }
765            
766            protected boolean
767            isLSConsoleShown() { return cbmiLSConsoleShown.isSelected(); }
768            
769            protected void
770            setLSConsoleShown(boolean b) { cbmiLSConsoleShown.setSelected(b); }
771            
772            protected LSConsoleModel
773            getLSConsoleModel() { return lsConsolePane.getModel(); }
774            
775            /**
776             * Sets the text color of the LS Console.
777             * @param c The text color of the LS Console.
778             */
779            protected void
780            setLSConsoleTextColor(Color c) { lsConsolePane.setTextColor(c); }
781            
782            /**
783             * Sets the background color of the LS Console.
784             * @param c The background color of the LS Console.
785             */
786            protected void
787            setLSConsoleBackgroundColor(Color c) { lsConsolePane.setBackgroundColor(c); }
788            
789            /**
790             * Sets the notification messages' color of the LS Console.
791             * @param c The notification messages' color of the LS Console.
792             */
793            protected void
794            setLSConsoleNotifyColor(Color c) { lsConsolePane.setNotifyColor(c); }
795            
796            /**
797             * Sets the warning messages' color of the LS Console.
798             * @param c The warning messages' color of the LS Console.
799             */
800            protected void
801            setLSConsoleWarningColor(Color c) { lsConsolePane.setWarningColor(c); }
802            
803            /**
804             * Sets the error messages' color of the LS Console.
805             * @param c The error messages' color of the LS Console.
806             */
807            protected void
808            setLSConsoleErrorColor(Color c) { lsConsolePane.setErrorColor(c); }
809            
810            protected void
811            showLSConsole(boolean b) {
812                    if(!b) {
813                            showBottomPane(false);
814                            if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
815                            lsConsolePane.hideAutoCompleteWindow();
816                            return;
817                    }
818                    
819                    setLSConsolePopOut0(isLSConsolePopOut());
820            }
821            
822            /**
823             * Adds the specified <code>JSChannelsPane</code> to the view.
824             * @param chnPane The <code>JSChannelsPane</code> to be added.
825             */
826          public void          public void
827          addChannelsPane(JSChannelsPane chnPane) {          addChannelsPane(JSChannelsPane chnPane) {
828                  insertChannelsPane(chnPane, getChannelsPaneCount());                  insertChannelsPane(chnPane, getChannelsPaneCount());
# Line 462  MainFrame extends org.jsampler.view.JSMa Line 848  MainFrame extends org.jsampler.view.JSMa
848                  updateTabsMenu();                  updateTabsMenu();
849          }          }
850                    
851            /**
852             * Gets the <code>JSChannelsPane</code> that is currently shown.
853             * @return The currently shown <code>JSChannelsPane</code>.
854             */
855          public JSChannelsPane          public JSChannelsPane
856          getSelectedChannelsPane() {          getSelectedChannelsPane() {
857                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);
858                  return (JSChannelsPane)tabbedPane.getSelectedComponent();                  return (JSChannelsPane)tabbedPane.getSelectedComponent();
859          }          }
860                    
861            /**
862             * Sets the <code>JSChannelsPane</code> to be selected.
863             * @param pane The <code>JSChannelsPane</code> to be shown.
864             */
865          public void          public void
866          setSelectedChannelsPane(JSChannelsPane pane) {          setSelectedChannelsPane(JSChannelsPane pane) {
867                  if(getChannelsPaneList().size() == 1) return;                  if(getChannelsPaneList().size() == 1) return;
868                  tabbedPane.setSelectedComponent(pane);                  tabbedPane.setSelectedComponent(pane);
869          }          }
870                    
871            /**
872             * Removes the specified <code>JSChannelsPane</code> from the view.
873             * @param chnPane The <code>JSChannelsPane</code> to be removed.
874             * @return <code>true</code> if the specified code>JSChannelsPane</code>
875             * is actually removed from the view, <code>false</code> otherwise.
876             */
877          public boolean          public boolean
878          removeChannelsPane(JSChannelsPane chnPane) {          removeChannelsPane(JSChannelsPane chnPane) {
879                  chnPane.removeListSelectionListener(this);                  chnPane.removeListSelectionListener(this);
# Line 694  MainFrame extends org.jsampler.view.JSMa Line 1094  MainFrame extends org.jsampler.view.JSMa
1094                  addChannelsPane(c);                  addChannelsPane(c);
1095                  tabbedPane.setSelectedComponent(c);                  tabbedPane.setSelectedComponent(c);
1096          }          }
1097            
1098            protected void
1099            runScript() {
1100                    String s = preferences().getStringProperty("lastScriptLocation");
1101                    JFileChooser fc = new JFileChooser(s);
1102                    fc.setFileFilter(new LscpFileFilter());
1103                    int result = fc.showOpenDialog(this);
1104                    if(result != JFileChooser.APPROVE_OPTION) return;
1105                    
1106                    String path = fc.getCurrentDirectory().getAbsolutePath();
1107                    preferences().setStringProperty("lastScriptLocation", path);
1108                                            
1109                    runScript(fc.getSelectedFile());
1110            }
1111            
1112            private void
1113            runScript(String script) { runScript(new File(script)); }
1114            
1115            private void
1116            runScript(File script) {
1117                    FileReader fr;
1118                    try { fr = new FileReader(script); }
1119                    catch(FileNotFoundException e) {
1120                            HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
1121                            return;
1122                    }
1123                    
1124                    BufferedReader br = new BufferedReader(fr);
1125                    
1126                    try {
1127                            String s = br.readLine();
1128                            while(s != null) {
1129                                    getLSConsoleModel().setCommandLineText(s);
1130                                    getLSConsoleModel().execCommand();
1131                                    s = br.readLine();
1132                            }
1133                    } catch(Exception e) {
1134                            HF.showErrorMessage(e);
1135                            return;
1136                    }
1137                    
1138                    if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
1139                            if(!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
1140                    }
1141                    
1142                    String s = script.getAbsolutePath();
1143                    recentScripts.remove(s);
1144                    recentScripts.insertElementAt(s, 0);
1145                    
1146                    updateRecentScriptsMenu();
1147            }
1148            
1149            protected void
1150            clearRecentScripts() {
1151                    recentScripts.removeAllElements();
1152                    updateRecentScriptsMenu();
1153            }
1154            
1155            protected void
1156            updateRecentScriptsMenu() {
1157                    int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
1158                    while(recentScripts.size() > size) {
1159                            recentScripts.removeElementAt(recentScripts.size() - 1);
1160                    }
1161                    
1162                    recentScriptsMenu.removeAll();
1163                    
1164                    for(String script : recentScripts) {
1165                            JMenuItem mi = new JMenuItem(script);
1166                            recentScriptsMenu.add(mi);
1167                            mi.addActionListener(new RecentScriptHandler(script));
1168                    }
1169                    
1170                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
1171            }
1172            
1173            public void
1174            installJSamplerHome() {
1175                    JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
1176                    chooser.setVisible(true);
1177                    if(chooser.isCancelled()) return;
1178                    
1179                    CC.changeJSamplerHome(chooser.getJSamplerHome());
1180            }
1181            
1182            public void
1183            showDetailedErrorMessage(Frame owner, String err, String details) {
1184                    new DetailedErrorDlg(owner, i18n.getError("error"), err, details).setVisible(true);
1185            }
1186            
1187            public void
1188            showDetailedErrorMessage(Dialog owner, String err, String details) {
1189                    new DetailedErrorDlg(owner, i18n.getError("error"), err, details).setVisible(true);
1190            }
1191  }  }

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

  ViewVC Help
Powered by ViewVC