/[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 1204 by iliev, Thu May 24 21:43:45 2007 UTC revision 1323 by iliev, Tue Sep 4 15:41:13 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>   *   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 26  import java.awt.BorderLayout; Line 26  import java.awt.BorderLayout;
26  import java.awt.Dialog;  import java.awt.Dialog;
27  import java.awt.Dimension;  import java.awt.Dimension;
28  import java.awt.Frame;  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    
75  import org.jsampler.view.JSChannel;  import org.jsampler.view.JSChannel;
76  import org.jsampler.view.JSChannelsPane;  import org.jsampler.view.JSChannelsPane;
77  import org.jsampler.view.JSMainFrame;  import org.jsampler.view.JSMainFrame;
78    import org.jsampler.view.LscpFileFilter;
79    
80    import org.jsampler.view.std.JSamplerHomeChooser;
81    
82    import static org.jsampler.view.fantasia.A4n.a4n;
83  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;  import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
84    import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
85    import static org.jsampler.view.std.StdPrefs.*;
86    
87    
88  /**  /**
# Line 63  import static org.jsampler.view.fantasia Line 90  import static org.jsampler.view.fantasia
90   * @author Grigor Iliev   * @author Grigor Iliev
91   */   */
92  public class MainFrame extends JSMainFrame {  public class MainFrame extends JSMainFrame {
93          private final static int TITLE_BAR_WIDTH = 420;          private final StandardBar standardBar = new StandardBar();
94          private final static int TITLE_BAR_HEIGHT = 29;          private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
95            private final JPanel rootPane = new JPanel();
96            private final MainPane mainPane = new MainPane();
97            private final DevicesPane devicesPane = new DevicesPane();
98            private final JScrollPane spDevicesPane = new JScrollPane();
99            
100            private final JMenu recentScriptsMenu =
101                    new JMenu(i18n.getMenuLabel("actions.recentScripts"));
102            
103            private final JSplitPane hSplitPane;
104            
105            private final SidePane sidePane = new SidePane();
106            private final JPanel rightPane;
107            
108            private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
109            private final Vector<String> recentScripts = new Vector<String>();
110                    
111            
112            private final JCheckBoxMenuItem cbmiToolBarVisible =
113                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
114            
115            private final JCheckBoxMenuItem cbmiSidePaneVisible =
116                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane"));
117                    
118          private final ChannelsPane channelsPane = new ChannelsPane("");          private final JCheckBoxMenuItem cbmiDevicesPaneVisible =
119                            new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane"));
120                    
121          /** Creates a new instance of <code>MainFrame</code> */          /** Creates a new instance of <code>MainFrame</code> */
122          public          public
123          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);  
                 }  
                   
124                  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;  
                         }  
                 };  
                   
                 btn.setSelected(true);  
                 btn.setAlignmentX(JPanel.LEFT_ALIGNMENT);  
                 btn.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { onWindowClose(); }  
                 });  
125                                    
126                    if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
127                                    
128                  FantasiaTitleBar tb = new FantasiaTitleBar();                  getContentPane().add(standardBar, BorderLayout.NORTH);
                 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)));  
129                                    
130                    rightPane = createRightPane();
131                                    
132                    hSplitPane = new JSplitPane (
133                            JSplitPane.HORIZONTAL_SPLIT,
134                            true,   // continuousLayout
135                            sidePane, rightPane
136                    );
137                    hSplitPane.setResizeWeight(0.5);
138                                    
139                  tb.add(createVSeparator());                  rootPane.setLayout(new BorderLayout());
140                    rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));
141                    rootPane.setOpaque(false);
142                    rootPane.add(hSplitPane);
143                                    
144                  tb.add(Box.createRigidArea(new Dimension(275, 0)));                  addMenu();
145                                    
146                  tb.add(createVSeparator());                  addChannelsPane(mainPane.getChannelsPane());
147                                    
148                  tb.add(Box.createRigidArea(new Dimension(29, 0)));                  getContentPane().add(rootPane);
149                                    
150                  tb.add(createVSeparator());                  int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
151                    hSplitPane.setDividerLocation(i);
152                                    
153                  tb.add(Box.createRigidArea(new Dimension(40, 0)));                  setSavedSize();
154            }
155            
156            private JPanel
157            createRightPane() {
158                    JPanel p = new JPanel();
159                    GridBagLayout gridbag = new GridBagLayout();
160                    GridBagConstraints c = new GridBagConstraints();
161                                    
162                  tb.add(createVSeparator());                  p.setLayout(gridbag);
163                                    
164                  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);  
165                                    
166                  getContentPane().setBackground(new java.awt.Color(0x818181));                  spDevicesPane.setViewportView(devicesPane);
167                  getRootPane().setOpaque(false);                  spDevicesPane.setBorder(BorderFactory.createEmptyBorder());
168                  getLayeredPane().setOpaque(false);                  int h = spDevicesPane.getMinimumSize().height;
169                  //getContentPane().setVisible(false);                  spDevicesPane.setMinimumSize(new Dimension(200, h));
170                    
171                    c.gridx = 1;
172                    c.gridy = 0;
173                    c.weightx = 1.0;
174                    c.weighty = 1.0;
175                    c.insets = new Insets(0, 3, 3, 0);
176                    gridbag.setConstraints(spDevicesPane, c);
177                    p.add(spDevicesPane);
178                    
179                    c.gridx = 0;
180                    c.gridy = 0;
181                    c.weightx = 0.0;
182                    c.weighty = 1.0;
183                    c.insets = new Insets(0, 3, 3, 3);
184                    c.fill = GridBagConstraints.VERTICAL;
185                    gridbag.setConstraints(mainPane, c);
186                    p.add(mainPane);
187                                    
188                  setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop());                  return p;
189            }
190            
191            private void
192            setSavedSize() {
193                    String s = preferences().getStringProperty("MainFrame.sizeAndLocation");
194                    if(s == null) {
195                            setDefaultSizeAndLocation();
196                            return;
197                    }
198                  pack();                  pack();
                   
                 String s = FantasiaPrefs.getWindowLocation();  
                   
199                  try {                  try {
200                          if(s == null) {                          int i = s.indexOf(',');
201                                  setDefaultLocation();                          int x = Integer.parseInt(s.substring(0, i));
                         } else {  
                                 int i = s.indexOf(',');  
                                 int x = Integer.parseInt(s.substring(0, i));  
202                                                    
203                                  s = s.substring(i + 1);                          s = s.substring(i + 1);
204                                  int y = Integer.parseInt(s);                          i = s.indexOf(',');
205                            int y = Integer.parseInt(s.substring(0, i));
206                                                    
207                                  setLocation(x, y);                          s = s.substring(i + 1);
208                          }                          i = s.indexOf(',');
209                            int width = Integer.parseInt(s.substring(0, i));
210                            
211                            s = s.substring(i + 1);
212                            int height = Integer.parseInt(s);
213                            
214                            setBounds(x, y, width, height);
215                  } catch(Exception x) {                  } catch(Exception x) {
216                          String msg = "Parsing of window size and location string failed";                          String msg = "Parsing of window size and location string failed";
217                          CC.getLogger().log(Level.INFO, msg, x);                          CC.getLogger().log(Level.INFO, msg, x);
218                          setDefaultLocation();                          setDefaultSizeAndLocation();
219                    }
220                    
221                    if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
222                            setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
223                  }                  }
224          }          }
225                    
226          private void          private void
227          setDefaultLocation() {          setDefaultSizeAndLocation() {
228                  Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();                  setPreferredSize(new Dimension(900, 600));
229                  setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2);                  pack();
230                    setLocationRelativeTo(null);
231          }          }
232                    
233                    
234          /** Invoked when this window is about to close. */          /** Invoked when this window is about to close. */
235          protected void          protected void
236          onWindowClose() {          onWindowClose() {
237                  FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop());                  sidePane.savePreferences();
238                    
239                    int i = hSplitPane.getDividerLocation();
240                    preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
241                    
242                    preferences().setBoolProperty (
243                            "MainFrame.windowMaximized",
244                            (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
245                    );
246                    
247                    if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
248                            super.onWindowClose();
249                            return;
250                    }
251                                    
252                  java.awt.Point p = getLocation();                  java.awt.Point p = getLocation();
253                  Dimension d = getSize();                  Dimension d = getSize();
254                  StringBuffer sb = new StringBuffer();                  StringBuffer sb = new StringBuffer();
255                  sb.append(p.x).append(',').append(p.y + getSize().height - TITLE_BAR_HEIGHT);                  sb.append(p.x).append(',').append(p.y).append(',');
256                  FantasiaPrefs.setWindowLocation(sb.toString());                  sb.append(d.width).append(',').append(d.height);
257                    preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString());
258                    
259                    String[] list = recentScripts.toArray(new String[recentScripts.size()]);
260                    preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
261                    
262                    if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
263                            if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
264                    }
265                                    
266                  super.onWindowClose();                  super.onWindowClose();
267          }          }
268                    
269          private JPanel          private void
270          createVSeparator() {          addMenu() {
271                  JPanel p = new JPanel();                  JMenu m;
272                  p.setName("VSeparator");                  JMenuItem mi;
273                  p.setOpaque(false);                  
274                  p.setPreferredSize(new Dimension(2, 29));                  setJMenuBar(menuBar);
275                  p.setMinimumSize(p.getPreferredSize());                  
276                  p.setMaximumSize(p.getPreferredSize());                  // Actions
277                  return p;                  m = new FantasiaMenu(i18n.getMenuLabel("actions"));
278                    
279                    mi = new JMenuItem(a4n.connect);
280                    mi.setIcon(null);
281                    //mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));
282                    m.add(mi);
283                    
284                    mi = new JMenuItem(a4n.samplerInfo);
285                    mi.setIcon(null);
286                    m.add(mi);
287                    
288                    m.addSeparator();
289                    
290                    JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
291                    m.add(exportMenu);
292                    
293                    mi = new JMenuItem(a4n.exportSamplerConfig);
294                    mi.setIcon(null);
295                    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
296                    exportMenu.add(mi);
297                    
298                    mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
299                    mi.setIcon(null);
300                    exportMenu.add(mi);
301                    
302                    m.addSeparator();
303                    
304                    mi = new JMenuItem(a4n.loadScript);
305                    mi.setIcon(null);
306                    m.add(mi);
307                    
308                    String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
309                    for(String s : list) recentScripts.add(s);
310                    
311                    updateRecentScriptsMenu();
312                    
313                    m.add(recentScriptsMenu);
314                    
315                    m.addSeparator();
316                    
317                    mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
318                    m.add(mi);
319                    mi.addActionListener(new ActionListener() {
320                            public void
321                            actionPerformed(ActionEvent e) { onWindowClose(); }
322                    });
323                    
324                    menuBar.add(m);
325                    
326                    
327                    // Edit
328                    m = new FantasiaMenu(i18n.getMenuLabel("edit"));
329                    menuBar.add(m);
330                    
331                    mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel"));
332                    m.add(mi);
333                    mi.addActionListener(new ActionListener() {
334                            public void
335                            actionPerformed(ActionEvent e) {
336                                    CC.getSamplerModel().addBackendChannel();
337                            }
338                    });
339                    
340                    m.addSeparator();
341                    
342                    mi = new JMenuItem(a4n.createMidiDevice);
343                    mi.setIcon(null);
344                    m.add(mi);
345                    
346                    mi = new JMenuItem(a4n.createAudioDevice);
347                    mi.setIcon(null);
348                    m.add(mi);
349                    
350                    m.addSeparator();
351                    
352                    mi = new JMenuItem(a4n.editPreferences);
353                    mi.setIcon(null);
354                    mi.setAccelerator(KeyStroke.getKeyStroke (
355                            KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
356                    ));
357                    m.add(mi);
358                    
359                    // View
360                    m = new FantasiaMenu(i18n.getMenuLabel("view"));
361                    menuBar.add(m);
362                    
363                    m.add(cbmiToolBarVisible);
364                    
365                    cbmiToolBarVisible.addActionListener(new ActionListener() {
366                            public void
367                            actionPerformed(ActionEvent e) {
368                                    showToolBar(cbmiToolBarVisible.getState());
369                            }
370                    });
371                    
372                    boolean b = preferences().getBoolProperty("toolBar.visible");
373                    cbmiToolBarVisible.setSelected(b);
374                    showToolBar(b);
375                    
376                    cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
377                            KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
378                    ));
379                    m.add(cbmiSidePaneVisible);
380                    
381                    cbmiSidePaneVisible.addActionListener(new ActionListener() {
382                            public void
383                            actionPerformed(ActionEvent e) {
384                                    showSidePane(cbmiSidePaneVisible.getState());
385                            }
386                    });
387                    
388                    b = preferences().getBoolProperty("sidePane.visible");
389                    cbmiSidePaneVisible.setSelected(b);
390                    showSidePane(b);
391                    
392                    cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke (
393                            KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
394                    ));
395                    m.add(cbmiDevicesPaneVisible);
396                    
397                    cbmiDevicesPaneVisible.addActionListener(new ActionListener() {
398                            public void
399                            actionPerformed(ActionEvent e) {
400                                    showDevicesPane(cbmiDevicesPaneVisible.getState());
401                            }
402                    });
403                    
404                    b = preferences().getBoolProperty("devicesPane.visible");
405                    cbmiDevicesPaneVisible.setSelected(b);
406                    showDevicesPane(b);
407                    
408                    
409                    // Window
410                    m = new FantasiaMenu(i18n.getMenuLabel("window"));
411                    menuBar.add(m);
412                    
413                    mi = new JMenuItem(a4n.windowLSConsole);
414                    mi.setIcon(null);
415                    m.add(mi);
416                    
417                    mi = new JMenuItem(a4n.windowInstrumentsDb);
418                    mi.setIcon(null);
419                    m.add(mi);
420                    
421                    
422                    // Help
423                    m = new FantasiaMenu(i18n.getMenuLabel("help"));
424                    
425                    mi = new JMenuItem(a4n.helpAbout);
426                    mi.setIcon(null);
427                    m.add(mi);
428                    
429                    menuBar.add(m);
430          }          }
431                    
432          /**          /**
# Line 195  public class MainFrame extends JSMainFra Line 435  public class MainFrame extends JSMainFra
435           */           */
436          public void          public void
437          insertChannelsPane(JSChannelsPane pane, int idx) {          insertChannelsPane(JSChannelsPane pane, int idx) {
438                  getChannelsPaneList().removeAllElements();                  
                 addChannelsPane(pane);  
439          }          }
440                    
441          /**          /**
# Line 214  public class MainFrame extends JSMainFra Line 453  public class MainFrame extends JSMainFra
453          public void          public void
454          setSelectedChannelsPane(JSChannelsPane pane) { }          setSelectedChannelsPane(JSChannelsPane pane) { }
455                    
         public static void  
         repack(JSMainFrame frame) {  
                 int y = frame.getLocation().y;  
                 int height = frame.getSize().height;  
                 y += (height - frame.getPreferredSize().height);  
                   
                 if((height - frame.getPreferredSize().height) > 0) {  
                         frame.pack();  
                         frame.setLocation(frame.getLocation().x, y);  
                 } else {  
                         frame.setLocation(frame.getLocation().x, y);  
                         frame.pack();  
                 }  
         }  
           
456          public void          public void
457          installJSamplerHome() { }          installJSamplerHome() {
458                    JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
459                    chooser.setVisible(true);
460                    if(chooser.isCancelled()) return;
461                    
462                    CC.changeJSamplerHome(chooser.getJSamplerHome());
463            }
464                    
465          public void          public void
466          showDetailedErrorMessage(Frame owner, String err, String details) {          showDetailedErrorMessage(Frame owner, String err, String details) {
# Line 241  public class MainFrame extends JSMainFra Line 471  public class MainFrame extends JSMainFra
471          showDetailedErrorMessage(Dialog owner, String err, String details) {          showDetailedErrorMessage(Dialog owner, String err, String details) {
472                  // TODO:                  // TODO:
473          }          }
 }  
   
 class FantasiaTitleBar extends TitleBar {  
         FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); }  
474                    
475          class ContextMenu extends MouseAdapter {          protected LSConsoleModel
476                  private final JPopupMenu cmenu = new JPopupMenu();          getLSConsoleModel() { return getLSConsolePane().getModel(); }
477            
478            protected LSConsolePane
479            getLSConsolePane() {
480                    return getLSConsoleFrame().getLSConsolePane();
481            }
482            
483            protected LSConsoleFrame
484            getLSConsoleFrame() { return lsConsoleFrame; }
485            
486            protected void
487            runScript() {
488                    String s = preferences().getStringProperty("lastScriptLocation");
489                    JFileChooser fc = new JFileChooser(s);
490                    fc.setFileFilter(new LscpFileFilter());
491                    int result = fc.showOpenDialog(this);
492                    if(result != JFileChooser.APPROVE_OPTION) return;
493                    
494                    String path = fc.getCurrentDirectory().getAbsolutePath();
495                    preferences().setStringProperty("lastScriptLocation", path);
496                                            
497                    runScript(fc.getSelectedFile());
498            }
499            
500            private void
501            runScript(String script) { runScript(new File(script)); }
502            
503            private void
504            runScript(File script) {
505                    FileReader fr;
506                    try { fr = new FileReader(script); }
507                    catch(FileNotFoundException e) {
508                            HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
509                            return;
510                    }
511                                    
512                  ContextMenu() {                  BufferedReader br = new BufferedReader(fr);
513                          JMenuItem mi;                  
514                                            try {
515                          final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem (                          String s = br.readLine();
516                                  i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop")                          while(s != null) {
517                          );                                  getLSConsoleModel().setCommandLineText(s);
518                          cmi.setIcon(null);                                  getLSConsoleModel().execCommand();
519                          cmi.setSelected(FantasiaPrefs.isAlwaysOnTop());                                  s = br.readLine();
520                                                    }
521                          cmenu.add(cmi);                  } catch(Exception e) {
522                                                    HF.showErrorMessage(e);
523                          cmi.addActionListener(new ActionListener() {                          return;
524                                  public void                  }
525                                  actionPerformed(ActionEvent e) {                  
526                                          CC.getMainFrame().setAlwaysOnTop(cmi.isSelected());                  String s = script.getAbsolutePath();
527                                  }                  recentScripts.remove(s);
528                          });                  recentScripts.insertElementAt(s, 0);
529                    
530                    updateRecentScriptsMenu();
531            }
532            
533            protected void
534            clearRecentScripts() {
535                    recentScripts.removeAllElements();
536                    updateRecentScriptsMenu();
537            }
538            
539            protected void
540            updateRecentScriptsMenu() {
541                    int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
542                    while(recentScripts.size() > size) {
543                            recentScripts.removeElementAt(recentScripts.size() - 1);
544                    }
545                    
546                    recentScriptsMenu.removeAll();
547                    
548                    for(String script : recentScripts) {
549                            JMenuItem mi = new JMenuItem(script);
550                            recentScriptsMenu.add(mi);
551                            mi.addActionListener(new RecentScriptHandler(script));
552                    }
553                    
554                    recentScriptsMenu.setEnabled(recentScripts.size() != 0);
555            }
556            
557            private void
558            showToolBar(boolean b) {
559                    preferences().setBoolProperty("toolBar.visible", b);
560                    standardBar.setVisible(b);
561            }
562            
563            private void
564            showSidePane(boolean b) {
565                    preferences().setBoolProperty("sidePane.visible", b);
566                    rootPane.remove(rightPane);
567                    rootPane.remove(hSplitPane);
568                    
569                    if(b) {
570                            hSplitPane.setRightComponent(rightPane);
571                            rootPane.add(hSplitPane);
572                            int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
573                            System.out.println("side pane: " + i);
574                                                    
575                          /*mi = new JMenuItem(A4n.moveChannelsUp);                          hSplitPane.setDividerLocation(i);
576                          mi.setIcon(null);                          hSplitPane.validate();
577                          cmenu.add(mi);                  } else {
578                            rootPane.add(rightPane);
579                                                    
580                          cmenu.addSeparator();                  }
581                    
582                    int w = getPreferredSize().width;
583                    int h = getSize().height;
584                    setSize(new Dimension(w, h));
585                    
586                    rootPane.revalidate();
587                    rootPane.validate();
588                    rootPane.repaint();
589                    
590                    SwingUtilities.invokeLater(new Runnable() {
591                            public void
592                            run() { sidePanesVisibilityChanged(); }
593                    });
594            }
595            
596            private void
597            showDevicesPane(boolean b) {
598                    preferences().setBoolProperty("devicesPane.visible", b);
599                    
600                    int width = sidePane.getWidth();
601                    int height = sidePane.getPreferredSize().height;
602                    if(width != 0) sidePane.setPreferredSize(new Dimension(width, height));
603                    
604                    if(b) {
605                            int w = preferences().getIntProperty("devicesPane.width", 200);
606                                                    
607                          mi = new JMenuItem(A4n.removeChannels);                          int h = spDevicesPane.getPreferredSize().height;
608                          mi.setIcon(null);                          spDevicesPane.setPreferredSize(new Dimension(w, h));
609                          cmenu.add(mi);*/                  } else {
610                            int w = spDevicesPane.getWidth();
611                            if(w > 0 && w < 200) w = 200;
612                            if(w != 0) preferences().setIntProperty("devicesPane.width", w);
613                  }                  }
614                                    
615                  public void                  hSplitPane.setResizeWeight(0.0);
616                  mousePressed(MouseEvent e) {                  spDevicesPane.setVisible(b);
617                          if(e.isPopupTrigger()) show(e);                  hSplitPane.resetToPreferredSizes();
618                    
619                    int w = getPreferredSize().width;
620                    int h = getSize().height;
621                    setSize(new Dimension(w, h));
622                    
623                    rootPane.validate();
624                    rootPane.repaint();
625                    //hSplitPane.validate();
626                    
627                    SwingUtilities.invokeLater(new Runnable() {
628                            public void
629                            run() { sidePanesVisibilityChanged(); }
630                    });
631            }
632            
633            private void
634            sidePanesVisibilityChanged() {
635                    boolean sidePaneVisible = cbmiSidePaneVisible.isSelected();
636                    boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected();
637                    
638                    if(sidePaneVisible && devicesPaneVisible) {
639                            hSplitPane.setResizeWeight(0.5);
640                    } else if(sidePaneVisible && !devicesPaneVisible) {
641                            hSplitPane.setResizeWeight(1.0);
642                  }                  }
643                    
644                    if(!sidePaneVisible && !devicesPaneVisible) {
645                            standardBar.showFantasiaLogo(false);
646                            if(isResizable()) setResizable(false);
647                    } else {
648                            standardBar.showFantasiaLogo(true);
649                            if(!isResizable()) setResizable(true);
650                    }
651            }
652                    
653            private class RecentScriptHandler implements ActionListener {
654                    private String script;
655                    
656                    RecentScriptHandler(String script) { this.script = script; }
657                    
658                  public void                  public void
659                  mouseReleased(MouseEvent e) {                  actionPerformed(ActionEvent e) {
660                          if(e.isPopupTrigger()) show(e);                          runScript(script);
661                            if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
662                                    a4n.windowLSConsole.actionPerformed(null);
663                            }
664                  }                  }
665            }
666                    
667                  void          private static class FantasiaMenu extends JMenu {
668                  show(MouseEvent e) {                  FantasiaMenu(String s) {
669                          cmenu.show(e.getComponent(), e.getX(), e.getY());                          super(s);
670                            setFont(getFont().deriveFont(java.awt.Font.BOLD));
671                            setOpaque(false);
672                    }
673            }
674    
675            private class FantasiaMenuBar extends JMenuBar {
676                    private Insets pixmapInsets = new Insets(6, 6, 0, 6);
677                    private Insets pixmapInsets2 = new Insets(6, 6, 6, 6);
678                    
679                    FantasiaMenuBar() {
680                            setOpaque(false);
681                    }
682                    
683                    protected void
684                    paintComponent(Graphics g) {
685                            super.paintComponent(g);
686                            if(standardBar.isVisible()) {
687                                    PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);
688                            } else {
689                                    PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2);
690                            }
691                  }                  }
692          }          }
693  }  }

Legend:
Removed from v.1204  
changed lines
  Added in v.1323

  ViewVC Help
Powered by ViewVC