/[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 912 by iliev, Mon Aug 7 18:34:40 2006 UTC revision 1688 by iliev, Thu Feb 14 16:52:36 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 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.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.UIManager;  import javax.swing.UIManager;
 import javax.swing.plaf.synth.SynthLookAndFeel;  
68    
69  import net.sf.juife.TitleBar;  import net.sf.juife.TitleBar;
70    
71  import org.jsampler.CC;  import org.jsampler.CC;
72  import org.jsampler.HF;  import org.jsampler.HF;
73    import org.jsampler.LSConsoleModel;
74    import org.jsampler.Server;
75    
76  import org.jsampler.view.JSChannel;  import org.jsampler.view.JSChannel;
77  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
78  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.JSMainFrame;
79    import org.jsampler.view.LscpFileFilter;
80    
81    import org.jsampler.view.std.JSConnectDlg;
82    import org.jsampler.view.std.JSDetailedErrorDlg;
83    import org.jsampler.view.std.JSQuitDlg;
84    import org.jsampler.view.std.JSamplerHomeChooser;
85    
86    import static org.jsampler.view.fantasia.A4n.a4n;
87  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
88    import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
89    import static org.jsampler.view.std.StdPrefs.*;
90    
91    
92  /**  /**
# Line 61  import static org.jsampler.view.fantasia Line 94  import static org.jsampler.view.fantasia
94   * @author Grigor Iliev   * @author Grigor Iliev
95   */   */
96  public class MainFrame extends JSMainFrame {  public class MainFrame extends JSMainFrame {
97          private final static int TITLE_BAR_WIDTH = 420;          private final StandardBar standardBar = new StandardBar();
98          private final static int TITLE_BAR_HEIGHT = 29;          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
99            private final JPanel rootPane = new JPanel();
100            private final MainPane mainPane = new MainPane();
101            private final DevicesPane devicesPane = new DevicesPane();
102            private final JScrollPane spDevicesPane = new JScrollPane();
103            
104            private final JMenu recentScriptsMenu =
105                    new JMenu(i18n.getMenuLabel("actions.recentScripts"));
106            
107            private final JSplitPane hSplitPane;
108            
109            private final SidePane sidePane = new SidePane();
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 cbmiSidePaneVisible =
120                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane"));
121            
122            private final JCheckBoxMenuItem cbmiDevicesPaneVisible =
123                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane"));
124                    
125          /** Creates a new instance of <code>MainFrame</code> */          /** Creates a new instance of <code>MainFrame</code> */
126          public          public
127          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);  
                 }  
                   
128                  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;  
                         }  
                 };  
129                                    
130                  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(); }  
                 });  
131                                    
132                    getContentPane().add(standardBar, BorderLayout.NORTH);
133                                    
134                  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)));  
135                                    
136                    hSplitPane = new JSplitPane (
137                            JSplitPane.HORIZONTAL_SPLIT,
138                            true,   // continuousLayout
139                            sidePane, rightPane
140                    );
141                    hSplitPane.setResizeWeight(0.5);
142                                    
143                    rootPane.setLayout(new BorderLayout());
144                    rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));
145                    rootPane.setOpaque(false);
146                    rootPane.add(hSplitPane);
147                                    
148                  tb.add(createVSeparator());                  addMenu();
149                                    
150                  tb.add(Box.createRigidArea(new Dimension(275, 0)));                  addChannelsPane(mainPane.getChannelsPane());
151                                    
152                  tb.add(createVSeparator());                  getContentPane().add(rootPane);
153                                    
154                  tb.add(Box.createRigidArea(new Dimension(29, 0)));                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
155                    hSplitPane.setDividerLocation(i);
156                                    
157                  tb.add(createVSeparator());                  setSavedSize();
158                            }
159                  tb.add(Box.createRigidArea(new Dimension(40, 0)));          
160            private JPanel
161            createRightPane() {
162                    JPanel p = new JPanel();
163                    GridBagLayout gridbag = new GridBagLayout();
164                    GridBagConstraints c = new GridBagConstraints();
165                                    
166                  tb.add(createVSeparator());                  p.setLayout(gridbag);
167                                    
168                  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);  
169                                    
170                  getContentPane().setBackground(new java.awt.Color(0x818181));                  spDevicesPane.setViewportView(devicesPane);
171                  getRootPane().setOpaque(false);                  spDevicesPane.setBorder(BorderFactory.createEmptyBorder());
172                  getLayeredPane().setOpaque(false);                  int h = spDevicesPane.getMinimumSize().height;
173                  //getContentPane().setVisible(false);                  spDevicesPane.setMinimumSize(new Dimension(200, h));
174                    
175                    c.gridx = 1;
176                    c.gridy = 0;
177                    c.weightx = 1.0;
178                    c.weighty = 1.0;
179                    c.insets = new Insets(0, 3, 3, 0);
180                    gridbag.setConstraints(spDevicesPane, c);
181                    p.add(spDevicesPane);
182                    
183                    c.gridx = 0;
184                    c.gridy = 0;
185                    c.weightx = 0.0;
186                    c.weighty = 1.0;
187                    c.insets = new Insets(0, 3, 3, 3);
188                    c.fill = GridBagConstraints.VERTICAL;
189                    gridbag.setConstraints(mainPane, c);
190                    p.add(mainPane);
191                                    
192                  setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop());                  return p;
193            }
194            
195            private void
196            setSavedSize() {
197                    String s = preferences().getStringProperty("MainFrame.sizeAndLocation");
198                    if(s == null) {
199                            setDefaultSizeAndLocation();
200                            return;
201                    }
202                  pack();                  pack();
                   
                 String s = FantasiaPrefs.getWindowLocation();  
                   
203                  try {                  try {
204                          if(s == null) {                          int i = s.indexOf(',');
205                                  setDefaultLocation();                          int x = Integer.parseInt(s.substring(0, i));
                         } else {  
                                 int i = s.indexOf(',');  
                                 int x = Integer.parseInt(s.substring(0, i));  
206                                                    
207                                  s = s.substring(i + 1);                          s = s.substring(i + 1);
208                                  int y = Integer.parseInt(s);                          i = s.indexOf(',');
209                            int y = Integer.parseInt(s.substring(0, i));
210                                                    
211                                  setLocation(x, y);                          s = s.substring(i + 1);
212                          }                          i = s.indexOf(',');
213                            int width = Integer.parseInt(s.substring(0, i));
214                            
215                            s = s.substring(i + 1);
216                            int height = Integer.parseInt(s);
217                            
218                            setBounds(x, y, width, height);
219                  } catch(Exception x) {                  } catch(Exception x) {
220                          String msg = "Parsing of window size and location string failed";                          String msg = "Parsing of window size and location string failed";
221                          CC.getLogger().log(Level.INFO, msg, x);                          CC.getLogger().log(Level.INFO, msg, x);
222                          setDefaultLocation();                          setDefaultSizeAndLocation();
223                    }
224                    
225                    if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
226                            setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
227                  }                  }
228          }          }
229                    
230          private void          private void
231          setDefaultLocation() {          setDefaultSizeAndLocation() {
232                  Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();                  setPreferredSize(new Dimension(900, 600));
233                  setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2);                  pack();
234                    setLocationRelativeTo(null);
235          }          }
236                    
237                    
238          /** Invoked when this window is about to close. */          /** Invoked when this window is about to close. */
239          protected void          protected void
240          onWindowClose() {          onWindowClose() {
241                  FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop());                  boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
242                    if(b && CC.getSamplerModel().isModified()) {
243                            JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
244                            dlg.setVisible(true);
245                            if(dlg.isCancelled()) return;
246                    }
247                    
248                    sidePane.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                    cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
400                            KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
401                    ));
402                    m.add(cbmiSidePaneVisible);
403                    
404                    cbmiSidePaneVisible.addActionListener(new ActionListener() {
405                            public void
406                            actionPerformed(ActionEvent e) {
407                                    showSidePane(cbmiSidePaneVisible.getState());
408                            }
409                    });
410                    
411                    b = preferences().getBoolProperty("sidePane.visible");
412                    cbmiSidePaneVisible.setSelected(b);
413                    showSidePane(b);
414                    
415                    cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke (
416                            KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
417                    ));
418                    m.add(cbmiDevicesPaneVisible);
419                    
420                    cbmiDevicesPaneVisible.addActionListener(new ActionListener() {
421                            public void
422                            actionPerformed(ActionEvent e) {
423                                    showDevicesPane(cbmiDevicesPaneVisible.getState());
424                            }
425                    });
426                    
427                    b = preferences().getBoolProperty("devicesPane.visible");
428                    cbmiDevicesPaneVisible.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());
492                          frame.pack();          }
493                          frame.setLocation(frame.getLocation().x, y);          
494                  } else {          public void
495                          frame.setLocation(frame.getLocation().x, y);          showDetailedErrorMessage(Frame owner, String err, String details) {
496                          frame.pack();                  JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
497                            owner, Res.iconWarning32, i18n.getError("error"), err, details
498                    );
499                    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            /**
511             * 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                    int i = preferences().getIntProperty(SERVER_INDEX);
534                    int size = CC.getServerList().getServerCount();
535                    if(size == 0) return null;
536                    if(i >= size) return CC.getServerList().getServer(0);
537                    
538                    return CC.getServerList().getServer(i);
539          }          }
540                    
541            protected LSConsoleModel
542            getLSConsoleModel() { return getLSConsolePane().getModel(); }
543                    
544  }          protected LSConsolePane
545            getLSConsolePane() {
546  class FantasiaTitleBar extends TitleBar {                  return getLSConsoleFrame().getLSConsolePane();
547          FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); }          }
548            
549            protected LSConsoleFrame
550            getLSConsoleFrame() { return lsConsoleFrame; }
551                    
552          class ContextMenu extends MouseAdapter {          protected boolean
553                  private final JPopupMenu cmenu = new JPopupMenu();          runScript() {
554                    String s = preferences().getStringProperty("lastScriptLocation");
555                    JFileChooser fc = new JFileChooser(s);
556                    fc.setFileFilter(new LscpFileFilter());
557                    int result = fc.showOpenDialog(this);
558                    if(result != JFileChooser.APPROVE_OPTION) return false;
559                    
560                    String path = fc.getCurrentDirectory().getAbsolutePath();
561                    preferences().setStringProperty("lastScriptLocation", path);
562                                            
563                    runScript(fc.getSelectedFile());
564                                    
565                  ContextMenu() {                  return true;
566                          JMenuItem mi;          }
567                                    
568                          final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem (          private void
569                                  i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop")          runScript(String script) { runScript(new File(script)); }
570                          );          
571                          cmi.setIcon(null);          private void
572                          cmi.setSelected(FantasiaPrefs.isAlwaysOnTop());          runScript(File script) {
573                                            FileReader fr;
574                          cmenu.add(cmi);                  try { fr = new FileReader(script); }
575                                            catch(FileNotFoundException e) {
576                          cmi.addActionListener(new ActionListener() {                          HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
577                                  public void                          return;
578                                  actionPerformed(ActionEvent e) {                  }
579                                          CC.getMainFrame().setAlwaysOnTop(cmi.isSelected());                  
580                                  }                  BufferedReader br = new BufferedReader(fr);
581                          });                  
582                    try {
583                            String s = br.readLine();
584                            while(s != null) {
585                                    getLSConsoleModel().setCommandLineText(s);
586                                    getLSConsoleModel().execCommand();
587                                    s = br.readLine();
588                            }
589                    } catch(Exception e) {
590                            HF.showErrorMessage(e);
591                            return;
592                    }
593                    
594                    String s = script.getAbsolutePath();
595                    recentScripts.remove(s);
596                    recentScripts.insertElementAt(s, 0);
597                    
598                    updateRecentScriptsMenu();
599            }
600            
601            protected void
602            clearRecentScripts() {
603                    recentScripts.removeAllElements();
604                    updateRecentScriptsMenu();
605            }
606            
607            protected void
608            updateRecentScriptsMenu() {
609                    int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
610                    while(recentScripts.size() > size) {
611                            recentScripts.removeElementAt(recentScripts.size() - 1);
612                    }
613                    
614                    recentScriptsMenu.removeAll();
615                    
616                    for(String script : recentScripts) {
617                            JMenuItem mi = new JMenuItem(script);
618                            recentScriptsMenu.add(mi);
619                            mi.addActionListener(new RecentScriptHandler(script));
620                    }
621                    
622                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
623            }
624            
625            private void
626            showToolBar(boolean b) {
627                    preferences().setBoolProperty("toolBar.visible", b);
628                    standardBar.setVisible(b);
629            }
630            
631            private void
632            showSidePane(boolean b) {
633                    preferences().setBoolProperty("sidePane.visible", b);
634                    rootPane.remove(rightPane);
635                    rootPane.remove(hSplitPane);
636                    
637                    if(b) {
638                            hSplitPane.setRightComponent(rightPane);
639                            rootPane.add(hSplitPane);
640                            int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
641                                                    
642                          /*mi = new JMenuItem(A4n.moveChannelsUp);                          hSplitPane.setDividerLocation(i);
643                          mi.setIcon(null);                          hSplitPane.validate();
644                          cmenu.add(mi);                  } else {
645                            rootPane.add(rightPane);
646                                                    
647                          cmenu.addSeparator();                  }
648                    
649                    int w = getPreferredSize().width;
650                    int h = getSize().height;
651                    setSize(new Dimension(w, h));
652                    
653                    rootPane.revalidate();
654                    rootPane.validate();
655                    rootPane.repaint();
656                    
657                    SwingUtilities.invokeLater(new Runnable() {
658                            public void
659                            run() { sidePanesVisibilityChanged(); }
660                    });
661            }
662            
663            private void
664            showDevicesPane(boolean b) {
665                    preferences().setBoolProperty("devicesPane.visible", b);
666                    
667                    int width = sidePane.getWidth();
668                    int height = sidePane.getPreferredSize().height;
669                    if(width != 0) sidePane.setPreferredSize(new Dimension(width, height));
670                    
671                    if(b) {
672                            int w = preferences().getIntProperty("devicesPane.width", 200);
673                                                    
674                          mi = new JMenuItem(A4n.removeChannels);                          int h = spDevicesPane.getPreferredSize().height;
675                          mi.setIcon(null);                          spDevicesPane.setPreferredSize(new Dimension(w, h));
676                          cmenu.add(mi);*/                  } else {
677                            int w = spDevicesPane.getWidth();
678                            if(w > 0 && w < 200) w = 200;
679                            if(w != 0) preferences().setIntProperty("devicesPane.width", w);
680                  }                  }
681                                    
682                  public void                  hSplitPane.setResizeWeight(0.0);
683                  mousePressed(MouseEvent e) {                  spDevicesPane.setVisible(b);
684                          if(e.isPopupTrigger()) show(e);                  hSplitPane.resetToPreferredSizes();
685                    
686                    int w = getPreferredSize().width;
687                    int h = getSize().height;
688                    setSize(new Dimension(w, h));
689                    
690                    rootPane.validate();
691                    rootPane.repaint();
692                    //hSplitPane.validate();
693                    
694                    SwingUtilities.invokeLater(new Runnable() {
695                            public void
696                            run() { sidePanesVisibilityChanged(); }
697                    });
698            }
699            
700            private void
701            sidePanesVisibilityChanged() {
702                    boolean sidePaneVisible = cbmiSidePaneVisible.isSelected();
703                    boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected();
704                    
705                    if(sidePaneVisible && devicesPaneVisible) {
706                            hSplitPane.setResizeWeight(0.5);
707                    } else if(sidePaneVisible && !devicesPaneVisible) {
708                            hSplitPane.setResizeWeight(1.0);
709                    }
710                    
711                    if(!sidePaneVisible && !devicesPaneVisible) {
712                            standardBar.showFantasiaLogo(false);
713                            if(isResizable()) setResizable(false);
714                    } else {
715                            standardBar.showFantasiaLogo(true);
716                            if(!isResizable()) setResizable(true);
717                  }                  }
718            }
719                    
720            private class RecentScriptHandler implements ActionListener {
721                    private String script;
722                    
723                    RecentScriptHandler(String script) { this.script = script; }
724                    
725                  public void                  public void
726                  mouseReleased(MouseEvent e) {                  actionPerformed(ActionEvent e) {
727                          if(e.isPopupTrigger()) show(e);                          runScript(script);
728                            if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
729                                    a4n.windowLSConsole.actionPerformed(null);
730                            }
731                  }                  }
732            }
733                    
734                  void          private static class FantasiaMenu extends JMenu {
735                  show(MouseEvent e) {                  FantasiaMenu(String s) {
736                          cmenu.show(e.getComponent(), e.getX(), e.getY());                          super(s);
737                            setFont(getFont().deriveFont(java.awt.Font.BOLD));
738                            setOpaque(false);
739                    }
740            }
741    
742            private class FantasiaMenuBar extends JMenuBar {
743                    private Insets pixmapInsets = new Insets(6, 6, 0, 6);
744                    private Insets pixmapInsets2 = new Insets(6, 6, 6, 6);
745                    
746                    FantasiaMenuBar() {
747                            setOpaque(false);
748                    }
749                    
750                    protected void
751                    paintComponent(Graphics g) {
752                            super.paintComponent(g);
753                            if(standardBar.isVisible()) {
754                                    PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);
755                            } else {
756                                    PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2);
757                            }
758                  }                  }
759          }          }
760  }  }

Legend:
Removed from v.912  
changed lines
  Added in v.1688

  ViewVC Help
Powered by ViewVC