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

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

  ViewVC Help
Powered by ViewVC