/[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 1285 by iliev, Fri Aug 10 19:55:03 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                  splitPane.setOneTouchExpandable(true);                  hSplitPane.setOneTouchExpandable(true);
159                    if(ClassicPrefs.getSaveWindowProperties()) {
160                            hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation());
161                    }
162                    
163                    mainPane.add(hSplitPane);
164                                    
165                  mainPane.add(splitPane);                  
166                    vSplitPane = new JSplitPane (
167                            JSplitPane.VERTICAL_SPLIT,
168                            true,   // continuousLayout
169                            channelsPane,
170                            bottomPane
171                    );
172                    
173                    vSplitPane.setDividerSize(3);
174                    vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
175                    
176                    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                    StringBuffer sb = new StringBuffer();
247                    for(String s : recentScripts) sb.append(s).append("\n");
248                    preferences().setStringProperty(RECENT_LSCP_SCRIPTS, sb.toString());
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 s = preferences().getStringProperty(RECENT_LSCP_SCRIPTS);
374                    BufferedReader br = new BufferedReader(new StringReader(s));
375                    
376                    try {
377                            s = br.readLine();
378                            while(s != null) {
379                                    recentScripts.add(s);
380                                    s = br.readLine();
381                            }
382                    } catch(Exception x) {
383                            CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
384                    }
385                    
386                    updateRecentScriptsMenu();
387                    
388                    m.add(recentScriptsMenu);
389                    
390                  m.addSeparator();                  m.addSeparator();
391                                    
392                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));                  mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
393                  m.add(mi);                  m.add(mi);
394                  mi.addActionListener(new ActionListener() {                  mi.addActionListener(new ActionListener() {
395                          public void                          public void
396                          actionPerformed(ActionEvent e) { CC.cleanExit(); }                          actionPerformed(ActionEvent e) { onWindowClose(); }
397                  });                  });
398                                    
399                  // Edit                  // Edit
400                  m = new JMenu(i18n.getMenuLabel("edit"));                  m = new JMenu(i18n.getMenuLabel("edit"));
401                  menuBar.add(m);                  menuBar.add(m);
402                                    
403                    mi = new JMenuItem(i18n.getMenuLabel("edit.audioDevices"));
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().showAudioDevicesPage();
410                            }
411                    });
412                    
413                    mi = new JMenuItem(i18n.getMenuLabel("edit.midiDevices"));
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().showMidiDevicesPage();
420                            }
421                    });
422                    
423                    mi = new JMenuItem(i18n.getMenuLabel("edit.orchestras"));
424                    m.add(mi);
425                    mi.addActionListener(new ActionListener() {
426                            public void
427                            actionPerformed(ActionEvent e) {
428                                    if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0);
429                                    LeftPane.getLeftPane().showManageOrchestrasPage();
430                            }
431                    });
432                    
433                  m.addSeparator();                  m.addSeparator();
434                                    
435                  mi = new JMenuItem(A4n.preferences);                  mi = new JMenuItem(A4n.preferences);
# Line 231  MainFrame extends org.jsampler.view.JSMa Line 443  MainFrame extends org.jsampler.view.JSMa
443                  m = new JMenu(i18n.getMenuLabel("view"));                  m = new JMenu(i18n.getMenuLabel("view"));
444                  menuBar.add(m);                  menuBar.add(m);
445                                    
446                    JMenu toolbarsMenu = new JMenu(i18n.getMenuLabel("view.toolbars"));
447                    m.add(toolbarsMenu);
448                    
449                    toolbarsMenu.add(cbmiStandardBarVisible);
450                    cbmiStandardBarVisible.addActionListener(new ActionListener() {
451                            public void
452                            actionPerformed(ActionEvent e) {
453                                    showStandardBar(cbmiStandardBarVisible.getState());
454                            }
455                    });
456                    
457                    boolean b = ClassicPrefs.shouldShowStandardBar();
458                    cbmiStandardBarVisible.setSelected(b);
459                    showStandardBar(b);
460                    
461                  final JCheckBoxMenuItem cbmi =                  final JCheckBoxMenuItem cbmi =
462                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbar"));                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.channels"));
463                                    
464                  m.add(cbmi);                  toolbarsMenu.add(cbmi);
465                  cbmi.addActionListener(new ActionListener() {                  cbmi.addActionListener(new ActionListener() {
466                          public void                          public void
467                          actionPerformed(ActionEvent e) { showToolbar(cbmi.getState()); }                          actionPerformed(ActionEvent e) { showChannelsBar(cbmi.getState()); }
468                  });                  });
469                                    
470                  boolean b = ClassicPrefs.shouldShowToolbar();                  b = ClassicPrefs.shouldShowChannelsBar();
471                  cbmi.setSelected(b);                  cbmi.setSelected(b);
472                  showToolbar(b);                  showChannelsBar(b);
473                                    
474                  final JCheckBoxMenuItem cbmi1 =                  m.add(cbmiLeftPaneVisible);
475                          new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane"));                  cbmiLeftPaneVisible.addActionListener(new ActionListener() {
                   
                 m.add(cbmi1);  
                 cbmi1.addActionListener(new ActionListener() {  
476                          public void                          public void
477                          actionPerformed(ActionEvent e) { showLeftPane(cbmi1.getState()); }                          actionPerformed(ActionEvent e) {
478                                    showLeftPane(cbmiLeftPaneVisible.getState());
479                            }
480                  });                  });
481                                    
482                  b = ClassicPrefs.shouldShowLeftPane();                  b = ClassicPrefs.shouldShowLeftPane();
483                  cbmi1.setSelected(b);                  cbmiLeftPaneVisible.setSelected(b);
484                  showLeftPane(b);                  showLeftPane(b);
485                                    
486                  final JCheckBoxMenuItem cbmi2 =                  final JCheckBoxMenuItem cbmi2 =
# Line 269  MainFrame extends org.jsampler.view.JSMa Line 495  MainFrame extends org.jsampler.view.JSMa
495                  cbmi2.setSelected(b);                  cbmi2.setSelected(b);
496                  showStatusbar(b);                  showStatusbar(b);
497                                    
498                    m.addSeparator();
499                    
500                    setLSConsolePopOut(ClassicPrefs.isLSConsolePopOut());
501                    cbmiLSConsoleShown.setSelected(ClassicPrefs.shouldShowLSConsole());
502                    showLSConsole(ClassicPrefs.shouldShowLSConsole());
503                    
504                    cbmiLSConsoleShown.addActionListener(new ActionListener() {
505                            public void
506                            actionPerformed(ActionEvent e) {
507                                    showLSConsole(cbmiLSConsoleShown.isSelected());
508                            }
509                    });
510                    m.add(cbmiLSConsoleShown);
511                    
512                    lsConsolePane.updateLSConsoleViewMode();
513                    
514                  // Channels                  // Channels
515                  m = new JMenu(i18n.getMenuLabel("channels"));                  m = new JMenu(i18n.getMenuLabel("channels"));
516                  menuBar.add(m);                  menuBar.add(m);
# Line 388  MainFrame extends org.jsampler.view.JSMa Line 630  MainFrame extends org.jsampler.view.JSMa
630                  m.add(mi);                  m.add(mi);
631                                    
632                                    
633                    // Window
634                    m = new JMenu(i18n.getMenuLabel("window"));
635                    menuBar.add(m);
636                    
637                    mi = new JMenuItem(A4n.windowInstrumentsDb);
638                    mi.setIcon(null);
639                    m.add(mi);
640                    
641                    
642                  // Help                  // Help
643                  m = new JMenu(i18n.getMenuLabel("help"));                  m = new JMenu(i18n.getMenuLabel("help"));
644                  menuBar.add(m);                  menuBar.add(m);
# Line 397  MainFrame extends org.jsampler.view.JSMa Line 648  MainFrame extends org.jsampler.view.JSMa
648                  m.add(mi);                  m.add(mi);
649          }          }
650                    
651            private class RecentScriptHandler implements ActionListener {
652                    private String script;
653                    
654                    RecentScriptHandler(String script) { this.script = script; }
655                    
656                    public void
657                    actionPerformed(ActionEvent e) {  runScript(script); }
658            }
659            
660          private void          private void
661          handleEvents() {          handleEvents() {
662                  tabbedPane.addChangeListener(this);                  tabbedPane.addChangeListener(this);
663          }          }
664                    
665          private void          private void
666          showToolbar(boolean b) {          showChannelsBar(boolean b) {
667                  if(b) getContentPane().add(toolbar, BorderLayout.NORTH);                  channelsBar.setVisible(b);
668                  else getContentPane().remove(toolbar);                  ClassicPrefs.setShowChannelsBar(b);
                   
                 ClassicPrefs.setShowToolbar(b);  
669                                    
670                  validate();                  validate();
671                  repaint();                  repaint();
# Line 419  MainFrame extends org.jsampler.view.JSMa Line 677  MainFrame extends org.jsampler.view.JSMa
677                  statusbar.setVisible(b);                  statusbar.setVisible(b);
678          }          }
679                    
680            protected boolean
681            isLeftPaneVisible() { return cbmiLeftPaneVisible.isSelected(); }
682            
683            protected void
684            setLeftPaneVisible(boolean b) {
685                    if(b != cbmiLeftPaneVisible.isSelected()) cbmiLeftPaneVisible.doClick(0);
686            }
687            
688            protected boolean
689            isLSConsoleVisible() { return cbmiLSConsoleShown.isSelected(); }
690            
691            protected void
692            setLSConsoleVisible(boolean b) {
693                    if(b != cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
694            }
695            
696          private void          private void
697          showLeftPane(boolean b) {          showLeftPane(boolean b) {
698                  ClassicPrefs.setShowLeftPane(b);                  ClassicPrefs.setShowLeftPane(b);
699                                    
700                  mainPane.remove(splitPane);                  mainPane.remove(hSplitPane);
701                  mainPane.remove(channelsPane);                  mainPane.remove(rightPane);
702                                    
703                  if(b) {                  if(b) {
704                          splitPane.setRightComponent(channelsPane);                          hSplitPane.setRightComponent(rightPane);
705                          mainPane.add(splitPane);                          mainPane.add(hSplitPane);
706                            if(ClassicPrefs.getSaveWindowProperties()) {
707                                    int i = ClassicPrefs.getHSplitDividerLocation();
708                                    hSplitPane.setDividerLocation(i);
709                            }
710                  } else {                  } else {
711                          mainPane.add(channelsPane);                          mainPane.add(rightPane);
712                  }                  }
713                                    
714                  validate();                  validate();
715                  repaint();                  repaint();
716          }          }
717                    
718            private void
719            showStandardBar(boolean b) {
720                    ClassicPrefs.setShowStandardBar(b);
721                    standardBar.setVisible(b);
722                    validate();
723                    repaint();
724            }
725            
726            private void
727            showBottomPane(boolean b) {
728                    if(!b) ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation());
729                    
730                    rightPane.remove(vSplitPane);
731                    rightPane.remove(channelsPane);
732                    
733                    if(b) {
734                            vSplitPane.setTopComponent(channelsPane);
735                            rightPane.add(vSplitPane);
736                            vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
737                    } else {
738                            rightPane.add(channelsPane);
739                    }
740                    
741                    validate();
742                    repaint();
743            }
744            
745            protected void
746            setLSConsolePopOut(boolean b) {
747                    if(b == lsConsolePopOut) return;
748                    
749                    lsConsolePopOut = b;
750                    
751                    if(isLSConsoleShown()) setLSConsolePopOut0(b);
752            }
753            
754            /**
755             * Changes the pop-out state of the LS Console.
756             * Invoke this method only when LS Console is shown.
757             */
758            private void
759            setLSConsolePopOut0(boolean b) {
760                    if(b) {
761                            bottomPane.remove(lsConsolePane);
762                            showBottomPane(false);
763                            
764                            lsConsoleDlg = new LSConsoleDlg(this, lsConsolePane);
765                            lsConsoleDlg.setVisible(true);
766                    } else {
767                            if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
768                            lsConsoleDlg = null;
769                            bottomPane.add(lsConsolePane);
770                            showBottomPane(true);
771                    }
772            }
773            
774            protected boolean
775            isLSConsolePopOut() { return lsConsolePopOut; }
776            
777            protected boolean
778            isLSConsoleShown() { return cbmiLSConsoleShown.isSelected(); }
779            
780            protected void
781            setLSConsoleShown(boolean b) { cbmiLSConsoleShown.setSelected(b); }
782            
783            protected LSConsoleModel
784            getLSConsoleModel() { return lsConsolePane.getModel(); }
785            
786            /**
787             * Sets the text color of the LS Console.
788             * @param c The text color of the LS Console.
789             */
790            protected void
791            setLSConsoleTextColor(Color c) { lsConsolePane.setTextColor(c); }
792            
793            /**
794             * Sets the background color of the LS Console.
795             * @param c The background color of the LS Console.
796             */
797            protected void
798            setLSConsoleBackgroundColor(Color c) { lsConsolePane.setBackgroundColor(c); }
799            
800            /**
801             * Sets the notification messages' color of the LS Console.
802             * @param c The notification messages' color of the LS Console.
803             */
804            protected void
805            setLSConsoleNotifyColor(Color c) { lsConsolePane.setNotifyColor(c); }
806            
807            /**
808             * Sets the warning messages' color of the LS Console.
809             * @param c The warning messages' color of the LS Console.
810             */
811            protected void
812            setLSConsoleWarningColor(Color c) { lsConsolePane.setWarningColor(c); }
813            
814            /**
815             * Sets the error messages' color of the LS Console.
816             * @param c The error messages' color of the LS Console.
817             */
818            protected void
819            setLSConsoleErrorColor(Color c) { lsConsolePane.setErrorColor(c); }
820            
821            protected void
822            showLSConsole(boolean b) {
823                    if(!b) {
824                            showBottomPane(false);
825                            if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
826                            lsConsolePane.hideAutoCompleteWindow();
827                            return;
828                    }
829                    
830                    setLSConsolePopOut0(isLSConsolePopOut());
831            }
832            
833            /**
834             * Adds the specified <code>JSChannelsPane</code> to the view.
835             * @param chnPane The <code>JSChannelsPane</code> to be added.
836             */
837          public void          public void
838          addChannelsPane(JSChannelsPane chnPane) {          addChannelsPane(JSChannelsPane chnPane) {
839                  insertChannelsPane(chnPane, getChannelsPaneCount());                  insertChannelsPane(chnPane, getChannelsPaneCount());
# Line 462  MainFrame extends org.jsampler.view.JSMa Line 859  MainFrame extends org.jsampler.view.JSMa
859                  updateTabsMenu();                  updateTabsMenu();
860          }          }
861                    
862            /**
863             * Gets the <code>JSChannelsPane</code> that is currently shown.
864             * @return The currently shown <code>JSChannelsPane</code>.
865             */
866          public JSChannelsPane          public JSChannelsPane
867          getSelectedChannelsPane() {          getSelectedChannelsPane() {
868                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);                  if(getChannelsPaneList().size() == 1) return getChannelsPane(0);
869                  return (JSChannelsPane)tabbedPane.getSelectedComponent();                  return (JSChannelsPane)tabbedPane.getSelectedComponent();
870          }          }
871                    
872            /**
873             * Sets the <code>JSChannelsPane</code> to be selected.
874             * @param pane The <code>JSChannelsPane</code> to be shown.
875             */
876          public void          public void
877          setSelectedChannelsPane(JSChannelsPane pane) {          setSelectedChannelsPane(JSChannelsPane pane) {
878                  if(getChannelsPaneList().size() == 1) return;                  if(getChannelsPaneList().size() == 1) return;
879                  tabbedPane.setSelectedComponent(pane);                  tabbedPane.setSelectedComponent(pane);
880          }          }
881                    
882            /**
883             * Removes the specified <code>JSChannelsPane</code> from the view.
884             * @param chnPane The <code>JSChannelsPane</code> to be removed.
885             * @return <code>true</code> if the specified code>JSChannelsPane</code>
886             * is actually removed from the view, <code>false</code> otherwise.
887             */
888          public boolean          public boolean
889          removeChannelsPane(JSChannelsPane chnPane) {          removeChannelsPane(JSChannelsPane chnPane) {
890                  chnPane.removeListSelectionListener(this);                  chnPane.removeListSelectionListener(this);
# Line 694  MainFrame extends org.jsampler.view.JSMa Line 1105  MainFrame extends org.jsampler.view.JSMa
1105                  addChannelsPane(c);                  addChannelsPane(c);
1106                  tabbedPane.setSelectedComponent(c);                  tabbedPane.setSelectedComponent(c);
1107          }          }
1108            
1109            protected void
1110            runScript() {
1111                    String s = preferences().getStringProperty("lastScriptLocation");
1112                    JFileChooser fc = new JFileChooser(s);
1113                    fc.setFileFilter(new LscpFileFilter());
1114                    int result = fc.showOpenDialog(this);
1115                    if(result != JFileChooser.APPROVE_OPTION) return;
1116                    
1117                    String path = fc.getCurrentDirectory().getAbsolutePath();
1118                    preferences().setStringProperty("lastScriptLocation", path);
1119                                            
1120                    runScript(fc.getSelectedFile());
1121            }
1122            
1123            private void
1124            runScript(String script) { runScript(new File(script)); }
1125            
1126            private void
1127            runScript(File script) {
1128                    FileReader fr;
1129                    try { fr = new FileReader(script); }
1130                    catch(FileNotFoundException e) {
1131                            HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
1132                            return;
1133                    }
1134                    
1135                    BufferedReader br = new BufferedReader(fr);
1136                    
1137                    try {
1138                            String s = br.readLine();
1139                            while(s != null) {
1140                                    getLSConsoleModel().setCommandLineText(s);
1141                                    getLSConsoleModel().execCommand();
1142                                    s = br.readLine();
1143                            }
1144                    } catch(Exception e) {
1145                            HF.showErrorMessage(e);
1146                            return;
1147                    }
1148                    
1149                    if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
1150                            if(!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
1151                    }
1152                    
1153                    String s = script.getAbsolutePath();
1154                    recentScripts.remove(s);
1155                    recentScripts.insertElementAt(s, 0);
1156                    
1157                    updateRecentScriptsMenu();
1158            }
1159            
1160            protected void
1161            clearRecentScripts() {
1162                    recentScripts.removeAllElements();
1163                    updateRecentScriptsMenu();
1164            }
1165            
1166            protected void
1167            updateRecentScriptsMenu() {
1168                    int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
1169                    while(recentScripts.size() > size) {
1170                            recentScripts.removeElementAt(recentScripts.size() - 1);
1171                    }
1172                    
1173                    recentScriptsMenu.removeAll();
1174                    
1175                    for(String script : recentScripts) {
1176                            JMenuItem mi = new JMenuItem(script);
1177                            recentScriptsMenu.add(mi);
1178                            mi.addActionListener(new RecentScriptHandler(script));
1179                    }
1180                    
1181                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
1182            }
1183            
1184            public void
1185            installJSamplerHome() {
1186                    JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
1187                    chooser.setVisible(true);
1188                    if(chooser.isCancelled()) return;
1189                    
1190                    CC.changeJSamplerHome(chooser.getJSamplerHome());
1191            }
1192            
1193            public void
1194            showDetailedErrorMessage(Frame owner, String err, String details) {
1195                    new DetailedErrorDlg(owner, i18n.getError("error"), err, details).setVisible(true);
1196            }
1197            
1198            public void
1199            showDetailedErrorMessage(Dialog owner, String err, String details) {
1200                    new DetailedErrorDlg(owner, i18n.getError("error"), err, details).setVisible(true);
1201            }
1202  }  }

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

  ViewVC Help
Powered by ViewVC