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

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

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

revision 1143 by iliev, Mon Apr 2 21:18:31 2007 UTC revision 1767 by iliev, Mon Sep 8 00:19:27 2008 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-2006 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2008 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.fantasia;  package org.jsampler.view.fantasia;
24    
25  import java.awt.BorderLayout;  import java.awt.BorderLayout;
26    import java.awt.Dialog;
27  import java.awt.Dimension;  import java.awt.Dimension;
28    import java.awt.Frame;
29    import java.awt.Graphics;
30    import java.awt.GridBagConstraints;
31    import java.awt.GridBagLayout;
32    import java.awt.Insets;
33  import java.awt.Point;  import java.awt.Point;
34    
35  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
36  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
37    import java.awt.event.KeyEvent;
38  import java.awt.event.MouseAdapter;  import java.awt.event.MouseAdapter;
39  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
40    
41    import java.io.BufferedReader;
42    import java.io.File;
43    import java.io.FileNotFoundException;
44    import java.io.FileReader;
45    
46    import java.util.Vector;
47  import java.util.logging.Level;  import java.util.logging.Level;
48    
49    import javax.swing.BorderFactory;
50  import javax.swing.Box;  import javax.swing.Box;
51  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
52  import javax.swing.JCheckBoxMenuItem;  import javax.swing.JCheckBoxMenuItem;
53    import javax.swing.JComponent;
54    import javax.swing.JDialog;
55    import javax.swing.JFileChooser;
56    import javax.swing.JFrame;
57  import javax.swing.JMenu;  import javax.swing.JMenu;
58    import javax.swing.JMenuBar;
59  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
60  import javax.swing.JPanel;  import javax.swing.JPanel;
61  import javax.swing.JPopupMenu;  import javax.swing.JPopupMenu;
62    import javax.swing.JScrollPane;
63    import javax.swing.JSplitPane;
64  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
65    import javax.swing.KeyStroke;
66    import javax.swing.SwingUtilities;
67    import javax.swing.Timer;
68  import javax.swing.UIManager;  import javax.swing.UIManager;
 import javax.swing.plaf.synth.SynthLookAndFeel;  
69    
70  import net.sf.juife.TitleBar;  import net.sf.juife.TitleBar;
71    
72  import org.jsampler.CC;  import org.jsampler.CC;
73  import org.jsampler.HF;  import org.jsampler.HF;
74    import org.jsampler.LSConsoleModel;
75    import org.jsampler.Server;
76    
77  import org.jsampler.view.JSChannel;  import org.jsampler.view.JSChannel;
78  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
79  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.JSMainFrame;
80    import org.jsampler.view.LscpFileFilter;
81    
82    import org.jsampler.view.std.JSConnectDlg;
83    import org.jsampler.view.std.JSDetailedErrorDlg;
84    import org.jsampler.view.std.JSQuitDlg;
85    import org.jsampler.view.std.JSamplerHomeChooser;
86    
87    import static org.jsampler.view.fantasia.A4n.a4n;
88  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
89    import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
90    import static org.jsampler.view.std.StdPrefs.*;
91    
92    
93  /**  /**
# Line 61  import static org.jsampler.view.fantasia Line 95  import static org.jsampler.view.fantasia
95   * @author Grigor Iliev   * @author Grigor Iliev
96   */   */
97  public class MainFrame extends JSMainFrame {  public class MainFrame extends JSMainFrame {
98          private final static int TITLE_BAR_WIDTH = 420;          private final StandardBar standardBar = new StandardBar();
99          private final static int TITLE_BAR_HEIGHT = 29;          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
100            private final JPanel rootPane = new JPanel();
101            private final MainPane mainPane = new MainPane();
102            
103            private final JMenu recentScriptsMenu =
104                    new JMenu(i18n.getMenuLabel("actions.recentScripts"));
105            
106            private final JSplitPane hSplitPane;
107                    
108          private final ChannelsPane channelsPane = new ChannelsPane("");          private final LeftSidePane leftSidePane = new LeftSidePane();
109            private final RightSidePane rightSidePane = new RightSidePane();
110            private final JPanel rightPane;
111            
112            //private final StatusBar statusBar = new StatusBar();
113            
114            private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
115            private final Vector<String> recentScripts = new Vector<String>();
116                    
117            
118            private final JCheckBoxMenuItem cbmiToolBarVisible =
119                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
120            
121            private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
122                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
123            
124            private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
125                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
126            
127            private final Timer guiTimer = new Timer(1000, null);
128                    
129          /** Creates a new instance of <code>MainFrame</code> */          /** Creates a new instance of <code>MainFrame</code> */
130          public          public
131          MainFrame() {          MainFrame() {
                 try {  
                         SynthLookAndFeel synth = new SynthLookAndFeel();  
                         synth.load(MainFrame.class.getResourceAsStream("gui.xml"), MainFrame.class);  
                         UIManager.setLookAndFeel(synth);  
                 } catch(Exception e) {  
                         CC.getLogger().log(Level.INFO, HF.getErrorMessage(e), e);  
                 }  
                   
132                  setTitle(i18n.getLabel("MainFrame.title"));                  setTitle(i18n.getLabel("MainFrame.title"));
                 addChannelsPane(channelsPane);  
                 add(channelsPane);  
                 setUndecorated(true);  
                   
                 JToggleButton btn = new PixmapToggleButton(Res.iconPowerOff, Res.iconPowerOn) {  
                         public boolean  
                         contains(int x, int y) {  
                                 return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71;  
                         }  
                 };  
133                                    
134                  btn.setSelected(true);                  if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
                 btn.setAlignmentX(JPanel.LEFT_ALIGNMENT);  
                 btn.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { onWindowClose(); }  
                 });  
135                                    
136                    getContentPane().add(standardBar, BorderLayout.NORTH);
137                    //getContentPane().add(statusBar, BorderLayout.SOUTH);
138                                    
139                  FantasiaTitleBar tb = new FantasiaTitleBar();                  rightPane = createRightPane();
                 tb.setName("FantasiaTitleBar");  
                 tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS));  
                 tb.setOpaque(true);  
                 tb.add(Box.createRigidArea(new Dimension(4, 0)));  
                 tb.add(btn);  
                 tb.add(Box.createRigidArea(new Dimension(3, 0)));  
140                                    
141                    hSplitPane = new JSplitPane (
142                            JSplitPane.HORIZONTAL_SPLIT,
143                            true,   // continuousLayout
144                            leftSidePane, rightPane
145                    );
146                    hSplitPane.setResizeWeight(0.5);
147                                    
148                    rootPane.setLayout(new BorderLayout());
149                    rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));
150                    rootPane.setOpaque(false);
151                    rootPane.add(hSplitPane);
152                                    
153                  tb.add(createVSeparator());                  addMenu();
154                                    
155                  tb.add(Box.createRigidArea(new Dimension(275, 0)));                  addChannelsPane(mainPane.getChannelsPane());
156                                    
157                  tb.add(createVSeparator());                  getContentPane().add(rootPane);
158                                    
159                  tb.add(Box.createRigidArea(new Dimension(29, 0)));                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
160                    hSplitPane.setDividerLocation(i);
161                                    
162                  tb.add(createVSeparator());                  setSavedSize();
163                                    
164                  tb.add(Box.createRigidArea(new Dimension(40, 0)));                  guiTimer.start();
165            }
166            
167            private JPanel
168            createRightPane() {
169                    JPanel p = new JPanel();
170                    GridBagLayout gridbag = new GridBagLayout();
171                    GridBagConstraints c = new GridBagConstraints();
172                                    
173                  tb.add(createVSeparator());                  p.setLayout(gridbag);
174                                    
175                  tb.setPreferredSize(new Dimension(TITLE_BAR_WIDTH, TITLE_BAR_HEIGHT));                  c.fill = GridBagConstraints.BOTH;
                 tb.setMinimumSize(tb.getPreferredSize());  
                 tb.setMaximumSize(tb.getPreferredSize());  
                 add(tb, BorderLayout.SOUTH);  
176                                    
177                  getContentPane().setBackground(new java.awt.Color(0x818181));                  c.gridx = 1;
178                  getRootPane().setOpaque(false);                  c.gridy = 0;
179                  getLayeredPane().setOpaque(false);                  c.weightx = 1.0;
180                  //getContentPane().setVisible(false);                  c.weighty = 1.0;
181                    c.insets = new Insets(0, 3, 0, 0);
182                    gridbag.setConstraints(rightSidePane, c);
183                    p.add(rightSidePane);
184                    
185                    c.gridx = 0;
186                    c.gridy = 0;
187                    c.weightx = 0.0;
188                    c.weighty = 1.0;
189                    c.insets = new Insets(0, 3, 0, 3);
190                    c.fill = GridBagConstraints.VERTICAL;
191                    gridbag.setConstraints(mainPane, c);
192                    p.add(mainPane);
193                                    
194                  setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop());                  return p;
195            }
196            
197            private void
198            setSavedSize() {
199                    String s = preferences().getStringProperty("MainFrame.sizeAndLocation");
200                    if(s == null) {
201                            setDefaultSizeAndLocation();
202                            return;
203                    }
204                  pack();                  pack();
                   
                 String s = FantasiaPrefs.getWindowLocation();  
                   
205                  try {                  try {
206                          if(s == null) {                          int i = s.indexOf(',');
207                                  setDefaultLocation();                          int x = Integer.parseInt(s.substring(0, i));
                         } else {  
                                 int i = s.indexOf(',');  
                                 int x = Integer.parseInt(s.substring(0, i));  
208                                                    
209                                  s = s.substring(i + 1);                          s = s.substring(i + 1);
210                                  int y = Integer.parseInt(s);                          i = s.indexOf(',');
211                            int y = Integer.parseInt(s.substring(0, i));
212                                                    
213                                  setLocation(x, y);                          s = s.substring(i + 1);
214                          }                          i = s.indexOf(',');
215                            int width = Integer.parseInt(s.substring(0, i));
216                            
217                            s = s.substring(i + 1);
218                            int height = Integer.parseInt(s);
219                            
220                            setBounds(x, y, width, height);
221                  } catch(Exception x) {                  } catch(Exception x) {
222                          String msg = "Parsing of window size and location string failed";                          String msg = "Parsing of window size and location string failed";
223                          CC.getLogger().log(Level.INFO, msg, x);                          CC.getLogger().log(Level.INFO, msg, x);
224                          setDefaultLocation();                          setDefaultSizeAndLocation();
225                    }
226                    
227                    if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
228                            setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
229                  }                  }
230          }          }
231                    
232          private void          private void
233          setDefaultLocation() {          setDefaultSizeAndLocation() {
234                  Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();                  setPreferredSize(new Dimension(900, 600));
235                  setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2);                  pack();
236                    setLocationRelativeTo(null);
237          }          }
238                    
239                    
240          /** Invoked when this window is about to close. */          /** Invoked when this window is about to close. */
241          protected void          protected void
242          onWindowClose() {          onWindowClose() {
243                  FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop());                  boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
244                    if(b && CC.getSamplerModel().isModified()) {
245                            JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
246                            dlg.setVisible(true);
247                            if(dlg.isCancelled()) return;
248                    }
249                    
250                    leftSidePane.savePreferences();
251                    rightSidePane.savePreferences();
252                    
253                    int i = hSplitPane.getDividerLocation();
254                    preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
255                    
256                    preferences().setBoolProperty (
257                            "MainFrame.windowMaximized",
258                            (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
259                    );
260                    
261                    if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
262                            super.onWindowClose();
263                            return;
264                    }
265                                    
266                  java.awt.Point p = getLocation();                  java.awt.Point p = getLocation();
267                  Dimension d = getSize();                  Dimension d = getSize();
268                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
269                  sb.append(p.x).append(',').append(p.y + getSize().height - TITLE_BAR_HEIGHT);                  sb.append(p.x).append(',').append(p.y).append(',');
270                  FantasiaPrefs.setWindowLocation(sb.toString());                  sb.append(d.width).append(',').append(d.height);
271                    preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString());
272                    
273                    String[] list = recentScripts.toArray(new String[recentScripts.size()]);
274                    preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
275                    
276                    if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
277                            if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
278                    }
279                                    
280                  super.onWindowClose();                  super.onWindowClose();
281          }          }
282                    
283          private JPanel          private void
284          createVSeparator() {          addMenu() {
285                  JPanel p = new JPanel();                  JMenu m;
286                  p.setName("VSeparator");                  JMenuItem mi;
287                  p.setOpaque(false);                  
288                  p.setPreferredSize(new Dimension(2, 29));                  setJMenuBar(menuBar);
289                  p.setMinimumSize(p.getPreferredSize());                  
290                  p.setMaximumSize(p.getPreferredSize());                  // Actions
291                  return p;                  m = new FantasiaMenu(i18n.getMenuLabel("actions"));
292                    
293                    mi = new JMenuItem(a4n.refresh);
294                    mi.setIcon(null);
295                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
296                    m.add(mi);
297                    
298                    mi = new JMenuItem(a4n.samplerInfo);
299                    mi.setIcon(null);
300                    m.add(mi);
301                    
302                    mi = new JMenuItem(a4n.resetSampler);
303                    mi.setIcon(null);
304                    m.add(mi);
305                    
306                    m.addSeparator();
307                    
308                    JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
309                    m.add(exportMenu);
310                    
311                    mi = new JMenuItem(a4n.exportSamplerConfig);
312                    mi.setIcon(null);
313                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
314                    exportMenu.add(mi);
315                    
316                    mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
317                    mi.setIcon(null);
318                    exportMenu.add(mi);
319                    
320                    m.addSeparator();
321                    
322                    mi = new JMenuItem(a4n.loadScript);
323                    mi.setIcon(null);
324                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
325                    m.add(mi);
326                    
327                    String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
328                    for(String s : list) recentScripts.add(s);
329                    
330                    updateRecentScriptsMenu();
331                    
332                    m.add(recentScriptsMenu);
333                    
334                    m.addSeparator();
335                    
336                    mi = new JMenuItem(a4n.changeBackend);
337                    mi.setIcon(null);
338                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));
339                    m.add(mi);
340                    
341                    m.addSeparator();
342                    
343                    mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
344                    m.add(mi);
345                    mi.addActionListener(new ActionListener() {
346                            public void
347                            actionPerformed(ActionEvent e) { onWindowClose(); }
348                    });
349                    
350                    menuBar.add(m);
351                    
352                    
353                    // Edit
354                    m = new FantasiaMenu(i18n.getMenuLabel("edit"));
355                    menuBar.add(m);
356                    
357                    mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel"));
358                    m.add(mi);
359                    mi.addActionListener(new ActionListener() {
360                            public void
361                            actionPerformed(ActionEvent e) {
362                                    CC.getSamplerModel().addBackendChannel();
363                            }
364                    });
365                    
366                    m.addSeparator();
367                    
368                    mi = new JMenuItem(a4n.createMidiDevice);
369                    mi.setIcon(null);
370                    m.add(mi);
371                    
372                    mi = new JMenuItem(a4n.createAudioDevice);
373                    mi.setIcon(null);
374                    m.add(mi);
375                    
376                    m.addSeparator();
377                    
378                    mi = new JMenuItem(a4n.editPreferences);
379                    mi.setIcon(null);
380                    mi.setAccelerator(KeyStroke.getKeyStroke (
381                            KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
382                    ));
383                    m.add(mi);
384                    
385                    // View
386                    m = new FantasiaMenu(i18n.getMenuLabel("view"));
387                    menuBar.add(m);
388                    
389                    m.add(cbmiToolBarVisible);
390                    
391                    cbmiToolBarVisible.addActionListener(new ActionListener() {
392                            public void
393                            actionPerformed(ActionEvent e) {
394                                    showToolBar(cbmiToolBarVisible.getState());
395                            }
396                    });
397                    
398                    boolean b = preferences().getBoolProperty("toolBar.visible");
399                    cbmiToolBarVisible.setSelected(b);
400                    showToolBar(b);
401                    
402                    cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
403                            KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
404                    ));
405                    m.add(cbmiLeftSidePaneVisible);
406                    
407                    cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
408                            public void
409                            actionPerformed(ActionEvent e) {
410                                    showSidePane(cbmiLeftSidePaneVisible.getState());
411                            }
412                    });
413                    
414                    b = preferences().getBoolProperty("leftSidePane.visible");
415                    cbmiLeftSidePaneVisible.setSelected(b);
416                    showSidePane(b);
417                    
418                    cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
419                            KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
420                    ));
421                    m.add(cbmiRightSidePaneVisible);
422                    
423                    cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
424                            public void
425                            actionPerformed(ActionEvent e) {
426                                    showDevicesPane(cbmiRightSidePaneVisible.getState());
427                            }
428                    });
429                    
430                    b = preferences().getBoolProperty("rightSidePane.visible");
431                    cbmiRightSidePaneVisible.setSelected(b);
432                    showDevicesPane(b);
433                    
434                    
435                    // Window
436                    m = new FantasiaMenu(i18n.getMenuLabel("window"));
437                    menuBar.add(m);
438                    
439                    mi = new JMenuItem(a4n.windowLSConsole);
440                    mi.setIcon(null);
441                    m.add(mi);
442                    
443                    mi = new JMenuItem(a4n.windowInstrumentsDb);
444                    mi.setIcon(null);
445                    m.add(mi);
446                    
447                    
448                    // Help
449                    m = new FantasiaMenu(i18n.getMenuLabel("help"));
450                    
451                    mi = new JMenuItem(a4n.browseOnlineTutorial);
452                    mi.setIcon(null);
453                    m.add(mi);
454                    
455                    m.addSeparator();
456                    
457                    mi = new JMenuItem(a4n.helpAbout);
458                    mi.setIcon(null);
459                    m.add(mi);
460                    
461                    menuBar.add(m);
462          }          }
463                    
464            public RightSidePane
465            getRightSidePane() { return rightSidePane; }
466            
467          /**          /**
468           * This method does nothing, because <b>Fantasia</b> has exactly           * This method does nothing, because <b>Fantasia</b> has exactly
469           * one pane containing sampler channels, which can not be changed.           * one pane containing sampler channels, which can not be changed.
470           */           */
471          public void          public void
472          insertChannelsPane(JSChannelsPane pane, int idx) {          insertChannelsPane(JSChannelsPane pane, int idx) {
473                  getChannelsPaneList().removeAllElements();                  
                 addChannelsPane(pane);  
474          }          }
475                    
476          /**          /**
# Line 212  public class MainFrame extends JSMainFra Line 488  public class MainFrame extends JSMainFra
488          public void          public void
489          setSelectedChannelsPane(JSChannelsPane pane) { }          setSelectedChannelsPane(JSChannelsPane pane) { }
490                    
491          public static void          public void
492          repack(JSMainFrame frame) {          installJSamplerHome() {
493                  int y = frame.getLocation().y;                  JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
494                  int height = frame.getSize().height;                  chooser.setVisible(true);
495                  y += (height - frame.getPreferredSize().height);                  if(chooser.isCancelled()) return;
496                                    
497                  if((height - frame.getPreferredSize().height) > 0) {                  CC.changeJSamplerHome(chooser.getJSamplerHome());
                         frame.pack();  
                         frame.setLocation(frame.getLocation().x, y);  
                 } else {  
                         frame.setLocation(frame.getLocation().x, y);  
                         frame.pack();  
                 }  
498          }          }
499                    
500          public void          public void
501          installJSamplerHome() { }          showDetailedErrorMessage(Frame owner, String err, String details) {
502  }                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
503                            owner, Res.iconWarning32, i18n.getError("error"), err, details
504  class FantasiaTitleBar extends TitleBar {                  );
505          FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); }                  dlg.setVisible(true);
506            }
507                    
508          class ContextMenu extends MouseAdapter {          public void
509                  private final JPopupMenu cmenu = new JPopupMenu();          showDetailedErrorMessage(Dialog owner, String err, String details) {
510                    JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
511                            owner, Res.iconWarning32, i18n.getError("error"), err, details
512                    );
513                    dlg.setVisible(true);
514            }
515            
516            /**
517             * Gets the server address to which to connect. If the server should be
518             * manually selected, a dialog asking the user to choose a server is displayed.
519             */
520            public Server
521            getServer() {
522                    boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
523                    return getServer(b);
524            }
525            
526            /**
527             * Gets the server address to which to connect. If the server should be
528             * manually selected, a dialog asking the user to choose a server is displayed.
529             * @param manualSelect Determines whether the server should be manually selected.
530             */
531            public Server
532            getServer(boolean manualSelect) {
533                    if(manualSelect) {
534                            JSConnectDlg dlg = new JSConnectDlg();
535                            dlg.setVisible(true);
536                            return dlg.getSelectedServer();
537                    }
538                                    
539                  ContextMenu() {                  int i = preferences().getIntProperty(SERVER_INDEX);
540                          JMenuItem mi;                  int size = CC.getServerList().getServerCount();
541                                            if(size == 0) return null;
542                          final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem (                  if(i >= size) return CC.getServerList().getServer(0);
543                                  i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop")                  
544                          );                  return CC.getServerList().getServer(i);
545                          cmi.setIcon(null);          }
546                          cmi.setSelected(FantasiaPrefs.isAlwaysOnTop());          
547                                    public Timer
548                          cmenu.add(cmi);          getGuiTimer() { return guiTimer; }
549                                    
550                          cmi.addActionListener(new ActionListener() {          protected LSConsoleModel
551                                  public void          getLSConsoleModel() { return getLSConsolePane().getModel(); }
552                                  actionPerformed(ActionEvent e) {          
553                                          CC.getMainFrame().setAlwaysOnTop(cmi.isSelected());          protected LSConsolePane
554                                  }          getLSConsolePane() {
555                          });                  return getLSConsoleFrame().getLSConsolePane();
556            }
557            
558            protected LSConsoleFrame
559            getLSConsoleFrame() { return lsConsoleFrame; }
560            
561            protected boolean
562            runScript() {
563                    String s = preferences().getStringProperty("lastScriptLocation");
564                    JFileChooser fc = new JFileChooser(s);
565                    fc.setFileFilter(new LscpFileFilter());
566                    int result = fc.showOpenDialog(this);
567                    if(result != JFileChooser.APPROVE_OPTION) return false;
568                    
569                    String path = fc.getCurrentDirectory().getAbsolutePath();
570                    preferences().setStringProperty("lastScriptLocation", path);
571                                            
572                    runScript(fc.getSelectedFile());
573                    
574                    return true;
575            }
576            
577            private void
578            runScript(String script) { runScript(new File(script)); }
579            
580            private void
581            runScript(File script) {
582                    FileReader fr;
583                    try { fr = new FileReader(script); }
584                    catch(FileNotFoundException e) {
585                            HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
586                            return;
587                    }
588                    
589                    BufferedReader br = new BufferedReader(fr);
590                    
591                    try {
592                            String s = br.readLine();
593                            while(s != null) {
594                                    getLSConsoleModel().setCommandLineText(s);
595                                    getLSConsoleModel().execCommand();
596                                    s = br.readLine();
597                            }
598                    } catch(Exception e) {
599                            HF.showErrorMessage(e);
600                            return;
601                    }
602                    
603                    String s = script.getAbsolutePath();
604                    recentScripts.remove(s);
605                    recentScripts.insertElementAt(s, 0);
606                    
607                    updateRecentScriptsMenu();
608            }
609            
610            protected void
611            clearRecentScripts() {
612                    recentScripts.removeAllElements();
613                    updateRecentScriptsMenu();
614            }
615            
616            protected void
617            updateRecentScriptsMenu() {
618                    int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
619                    while(recentScripts.size() > size) {
620                            recentScripts.removeElementAt(recentScripts.size() - 1);
621                    }
622                    
623                    recentScriptsMenu.removeAll();
624                    
625                    for(String script : recentScripts) {
626                            JMenuItem mi = new JMenuItem(script);
627                            recentScriptsMenu.add(mi);
628                            mi.addActionListener(new RecentScriptHandler(script));
629                    }
630                    
631                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
632            }
633            
634            private void
635            showToolBar(boolean b) {
636                    preferences().setBoolProperty("toolBar.visible", b);
637                    standardBar.setVisible(b);
638            }
639            
640            private void
641            showSidePane(boolean b) {
642                    preferences().setBoolProperty("leftSidePane.visible", b);
643                    rootPane.remove(rightPane);
644                    rootPane.remove(hSplitPane);
645                    
646                    if(b) {
647                            hSplitPane.setRightComponent(rightPane);
648                            rootPane.add(hSplitPane);
649                            int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
650                                                    
651                          /*mi = new JMenuItem(A4n.moveChannelsUp);                          hSplitPane.setDividerLocation(i);
652                          mi.setIcon(null);                          hSplitPane.validate();
653                          cmenu.add(mi);                  } else {
654                            rootPane.add(rightPane);
655                                                    
656                          cmenu.addSeparator();                  }
657                    
658                    int w = getPreferredSize().width;
659                    int h = getSize().height;
660                    setSize(new Dimension(w, h));
661                    
662                    rootPane.revalidate();
663                    rootPane.validate();
664                    rootPane.repaint();
665                    
666                    SwingUtilities.invokeLater(new Runnable() {
667                            public void
668                            run() { sidePanesVisibilityChanged(); }
669                    });
670            }
671            
672            private void
673            showDevicesPane(boolean b) {
674                    preferences().setBoolProperty("rightSidePane.visible", b);
675                    
676                    int width = leftSidePane.getWidth();
677                    int height = leftSidePane.getPreferredSize().height;
678                    if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
679                    
680                    if(b) {
681                            int w = preferences().getIntProperty("devicesPane.width", 200);
682                                                    
683                          mi = new JMenuItem(A4n.removeChannels);                          int h = rightSidePane.getPreferredSize().height;
684                          mi.setIcon(null);                          rightSidePane.setPreferredSize(new Dimension(w, h));
685                          cmenu.add(mi);*/                  } else {
686                            int w = rightSidePane.getWidth();
687                            if(w > 0 && w < 200) w = 200;
688                            if(w != 0) preferences().setIntProperty("devicesPane.width", w);
689                  }                  }
690                                    
691                  public void                  hSplitPane.setResizeWeight(0.0);
692                  mousePressed(MouseEvent e) {                  rightSidePane.setVisible(b);
693                          if(e.isPopupTrigger()) show(e);                  hSplitPane.resetToPreferredSizes();
694                    
695                    int w = getPreferredSize().width;
696                    int h = getSize().height;
697                    setSize(new Dimension(w, h));
698                    
699                    rootPane.validate();
700                    rootPane.repaint();
701                    //hSplitPane.validate();
702                    
703                    SwingUtilities.invokeLater(new Runnable() {
704                            public void
705                            run() { sidePanesVisibilityChanged(); }
706                    });
707            }
708            
709            private void
710            sidePanesVisibilityChanged() {
711                    boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
712                    boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
713                    
714                    if(leftSidePaneVisible && rightSidePaneVisible) {
715                            hSplitPane.setResizeWeight(0.5);
716                    } else if(leftSidePaneVisible && !rightSidePaneVisible) {
717                            hSplitPane.setResizeWeight(1.0);
718                    }
719                    
720                    if(!leftSidePaneVisible && !rightSidePaneVisible) {
721                            standardBar.showFantasiaLogo(false);
722                            if(isResizable()) setResizable(false);
723                    } else {
724                            standardBar.showFantasiaLogo(true);
725                            if(!isResizable()) setResizable(true);
726                  }                  }
727            }
728                    
729            private class RecentScriptHandler implements ActionListener {
730                    private String script;
731                    
732                    RecentScriptHandler(String script) { this.script = script; }
733                    
734                  public void                  public void
735                  mouseReleased(MouseEvent e) {                  actionPerformed(ActionEvent e) {
736                          if(e.isPopupTrigger()) show(e);                          runScript(script);
737                            if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
738                                    a4n.windowLSConsole.actionPerformed(null);
739                            }
740                  }                  }
741            }
742                    
743                  void          private static class FantasiaMenu extends JMenu {
744                  show(MouseEvent e) {                  FantasiaMenu(String s) {
745                          cmenu.show(e.getComponent(), e.getX(), e.getY());                          super(s);
746                            setFont(getFont().deriveFont(java.awt.Font.BOLD));
747                            setOpaque(false);
748                    }
749            }
750    
751            private class FantasiaMenuBar extends JMenuBar {
752                    private Insets pixmapInsets = new Insets(6, 6, 0, 6);
753                    private Insets pixmapInsets2 = new Insets(6, 6, 6, 6);
754                    
755                    FantasiaMenuBar() {
756                            setOpaque(false);
757                    }
758                    
759                    protected void
760                    paintComponent(Graphics g) {
761                            super.paintComponent(g);
762                            if(standardBar.isVisible()) {
763                                    PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);
764                            } else {
765                                    PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2);
766                            }
767                  }                  }
768          }          }
769  }  }

Legend:
Removed from v.1143  
changed lines
  Added in v.1767

  ViewVC Help
Powered by ViewVC