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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1734 - (hide annotations) (download)
Sun May 4 18:40:13 2008 UTC (15 years, 11 months ago) by iliev
File size: 20149 byte(s)
* bugfix: JSampler took forever to load a configuration with
  too many sampler channels
* Implemented option to show different channel view when
  the mouse pointer is over sampler channel
  (choose Edit/Preferences, then click the `Defaults' tab)

1 iliev 912 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1729 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 912 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.view.fantasia;
24    
25     import java.awt.BorderLayout;
26 iliev 1204 import java.awt.Dialog;
27 iliev 912 import java.awt.Dimension;
28 iliev 1204 import java.awt.Frame;
29 iliev 1285 import java.awt.Graphics;
30     import java.awt.GridBagConstraints;
31     import java.awt.GridBagLayout;
32     import java.awt.Insets;
33 iliev 912 import java.awt.Point;
34    
35     import java.awt.event.ActionEvent;
36     import java.awt.event.ActionListener;
37 iliev 1285 import java.awt.event.KeyEvent;
38 iliev 912 import java.awt.event.MouseAdapter;
39     import java.awt.event.MouseEvent;
40    
41 iliev 1285 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 iliev 912 import java.util.logging.Level;
48    
49 iliev 1285 import javax.swing.BorderFactory;
50 iliev 912 import javax.swing.Box;
51     import javax.swing.BoxLayout;
52     import javax.swing.JCheckBoxMenuItem;
53 iliev 1323 import javax.swing.JComponent;
54 iliev 1285 import javax.swing.JDialog;
55     import javax.swing.JFileChooser;
56     import javax.swing.JFrame;
57 iliev 912 import javax.swing.JMenu;
58 iliev 1285 import javax.swing.JMenuBar;
59 iliev 912 import javax.swing.JMenuItem;
60     import javax.swing.JPanel;
61     import javax.swing.JPopupMenu;
62 iliev 1285 import javax.swing.JScrollPane;
63     import javax.swing.JSplitPane;
64 iliev 912 import javax.swing.JToggleButton;
65 iliev 1285 import javax.swing.KeyStroke;
66     import javax.swing.SwingUtilities;
67 iliev 1734 import javax.swing.Timer;
68 iliev 912 import javax.swing.UIManager;
69    
70     import net.sf.juife.TitleBar;
71    
72     import org.jsampler.CC;
73     import org.jsampler.HF;
74 iliev 1285 import org.jsampler.LSConsoleModel;
75 iliev 1688 import org.jsampler.Server;
76 iliev 912
77     import org.jsampler.view.JSChannel;
78     import org.jsampler.view.JSChannelsPane;
79     import org.jsampler.view.JSMainFrame;
80 iliev 1285 import org.jsampler.view.LscpFileFilter;
81 iliev 912
82 iliev 1688 import org.jsampler.view.std.JSConnectDlg;
83 iliev 1355 import org.jsampler.view.std.JSDetailedErrorDlg;
84 iliev 1567 import org.jsampler.view.std.JSQuitDlg;
85 iliev 1285 import org.jsampler.view.std.JSamplerHomeChooser;
86    
87     import static org.jsampler.view.fantasia.A4n.a4n;
88 iliev 912 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
89 iliev 1285 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
90     import static org.jsampler.view.std.StdPrefs.*;
91 iliev 912
92    
93     /**
94     *
95     * @author Grigor Iliev
96     */
97     public class MainFrame extends JSMainFrame {
98 iliev 1323 private final StandardBar standardBar = new StandardBar();
99 iliev 1285 private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
100 iliev 1323 private final JPanel rootPane = new JPanel();
101 iliev 1285 private final MainPane mainPane = new MainPane();
102 iliev 912
103 iliev 1285 private final JMenu recentScriptsMenu =
104     new JMenu(i18n.getMenuLabel("actions.recentScripts"));
105 iliev 912
106 iliev 1285 private final JSplitPane hSplitPane;
107    
108 iliev 1729 private final LeftSidePane leftSidePane = new LeftSidePane();
109     private final RightSidePane rightSidePane = new RightSidePane();
110 iliev 1323 private final JPanel rightPane;
111 iliev 1285
112 iliev 1311 private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
113 iliev 1285 private final Vector<String> recentScripts = new Vector<String>();
114    
115    
116 iliev 1323 private final JCheckBoxMenuItem cbmiToolBarVisible =
117     new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
118    
119 iliev 1729 private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
120     new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
121 iliev 1323
122 iliev 1729 private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
123     new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
124 iliev 1323
125 iliev 1734 private final Timer guiTimer = new Timer(1000, null);
126    
127 iliev 912 /** Creates a new instance of <code>MainFrame</code> */
128     public
129     MainFrame() {
130     setTitle(i18n.getLabel("MainFrame.title"));
131    
132 iliev 1285 if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
133 iliev 912
134 iliev 1285 getContentPane().add(standardBar, BorderLayout.NORTH);
135 iliev 912
136 iliev 1323 rightPane = createRightPane();
137 iliev 912
138 iliev 1285 hSplitPane = new JSplitPane (
139     JSplitPane.HORIZONTAL_SPLIT,
140     true, // continuousLayout
141 iliev 1729 leftSidePane, rightPane
142 iliev 1285 );
143 iliev 1323 hSplitPane.setResizeWeight(0.5);
144 iliev 912
145 iliev 1323 rootPane.setLayout(new BorderLayout());
146     rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));
147     rootPane.setOpaque(false);
148     rootPane.add(hSplitPane);
149 iliev 912
150 iliev 1323 addMenu();
151    
152     addChannelsPane(mainPane.getChannelsPane());
153    
154     getContentPane().add(rootPane);
155    
156 iliev 1285 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
157     hSplitPane.setDividerLocation(i);
158 iliev 912
159 iliev 1285 setSavedSize();
160 iliev 1734
161     guiTimer.start();
162 iliev 1285 }
163    
164     private JPanel
165     createRightPane() {
166     JPanel p = new JPanel();
167     GridBagLayout gridbag = new GridBagLayout();
168     GridBagConstraints c = new GridBagConstraints();
169 iliev 912
170 iliev 1285 p.setLayout(gridbag);
171 iliev 912
172 iliev 1285 c.fill = GridBagConstraints.BOTH;
173 iliev 912
174 iliev 1285 c.gridx = 1;
175     c.gridy = 0;
176     c.weightx = 1.0;
177     c.weighty = 1.0;
178 iliev 1729 c.insets = new Insets(0, 3, 0, 0);
179     gridbag.setConstraints(rightSidePane, c);
180     p.add(rightSidePane);
181 iliev 912
182 iliev 1285 c.gridx = 0;
183     c.gridy = 0;
184     c.weightx = 0.0;
185     c.weighty = 1.0;
186 iliev 1729 c.insets = new Insets(0, 3, 0, 3);
187 iliev 1285 c.fill = GridBagConstraints.VERTICAL;
188     gridbag.setConstraints(mainPane, c);
189     p.add(mainPane);
190 iliev 912
191 iliev 1285 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 iliev 912 pack();
202     try {
203 iliev 1285 int i = s.indexOf(',');
204     int x = Integer.parseInt(s.substring(0, i));
205 iliev 912
206 iliev 1285 s = s.substring(i + 1);
207     i = s.indexOf(',');
208     int y = Integer.parseInt(s.substring(0, i));
209 iliev 912
210 iliev 1285 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 iliev 912 } catch(Exception x) {
219     String msg = "Parsing of window size and location string failed";
220     CC.getLogger().log(Level.INFO, msg, x);
221 iliev 1285 setDefaultSizeAndLocation();
222 iliev 912 }
223 iliev 1285
224     if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
225     setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
226     }
227 iliev 912 }
228    
229     private void
230 iliev 1285 setDefaultSizeAndLocation() {
231     setPreferredSize(new Dimension(900, 600));
232     pack();
233     setLocationRelativeTo(null);
234 iliev 912 }
235    
236    
237     /** Invoked when this window is about to close. */
238     protected void
239     onWindowClose() {
240 iliev 1688 boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
241     if(b && CC.getSamplerModel().isModified()) {
242 iliev 1567 JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
243     dlg.setVisible(true);
244     if(dlg.isCancelled()) return;
245     }
246    
247 iliev 1729 leftSidePane.savePreferences();
248     rightSidePane.savePreferences();
249 iliev 912
250 iliev 1285 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 iliev 912 java.awt.Point p = getLocation();
264     Dimension d = getSize();
265     StringBuffer sb = new StringBuffer();
266 iliev 1285 sb.append(p.x).append(',').append(p.y).append(',');
267     sb.append(d.width).append(',').append(d.height);
268     preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString());
269 iliev 912
270 iliev 1308 String[] list = recentScripts.toArray(new String[recentScripts.size()]);
271     preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
272 iliev 1285
273     if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
274     if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
275     }
276    
277 iliev 912 super.onWindowClose();
278     }
279    
280 iliev 1285 private void
281     addMenu() {
282     JMenu m;
283     JMenuItem mi;
284    
285     setJMenuBar(menuBar);
286    
287     // Actions
288     m = new FantasiaMenu(i18n.getMenuLabel("actions"));
289    
290 iliev 1688 mi = new JMenuItem(a4n.refresh);
291 iliev 1285 mi.setIcon(null);
292 iliev 1688 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
293 iliev 1285 m.add(mi);
294    
295     mi = new JMenuItem(a4n.samplerInfo);
296     mi.setIcon(null);
297     m.add(mi);
298    
299 iliev 1688 mi = new JMenuItem(a4n.resetSampler);
300     mi.setIcon(null);
301     m.add(mi);
302    
303 iliev 1285 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 iliev 1688 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
322 iliev 1285 m.add(mi);
323    
324 iliev 1308 String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
325     for(String s : list) recentScripts.add(s);
326 iliev 1285
327     updateRecentScriptsMenu();
328    
329     m.add(recentScriptsMenu);
330    
331     m.addSeparator();
332    
333 iliev 1688 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 iliev 1285 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 iliev 1323 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 iliev 1285 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 iliev 1323 // View
383     m = new FantasiaMenu(i18n.getMenuLabel("view"));
384     menuBar.add(m);
385 iliev 1285
386 iliev 1323 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 iliev 1729 cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
400 iliev 1323 KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
401     ));
402 iliev 1729 m.add(cbmiLeftSidePaneVisible);
403 iliev 1323
404 iliev 1729 cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
405 iliev 1323 public void
406     actionPerformed(ActionEvent e) {
407 iliev 1729 showSidePane(cbmiLeftSidePaneVisible.getState());
408 iliev 1323 }
409     });
410    
411 iliev 1729 b = preferences().getBoolProperty("leftSidePane.visible");
412     cbmiLeftSidePaneVisible.setSelected(b);
413 iliev 1323 showSidePane(b);
414    
415 iliev 1729 cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
416 iliev 1323 KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
417     ));
418 iliev 1729 m.add(cbmiRightSidePaneVisible);
419 iliev 1323
420 iliev 1729 cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
421 iliev 1323 public void
422     actionPerformed(ActionEvent e) {
423 iliev 1729 showDevicesPane(cbmiRightSidePaneVisible.getState());
424 iliev 1323 }
425     });
426    
427 iliev 1729 b = preferences().getBoolProperty("rightSidePane.visible");
428     cbmiRightSidePaneVisible.setSelected(b);
429 iliev 1323 showDevicesPane(b);
430    
431    
432 iliev 1285 // 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 iliev 1496 mi = new JMenuItem(a4n.browseOnlineTutorial);
449     mi.setIcon(null);
450     m.add(mi);
451    
452     m.addSeparator();
453    
454 iliev 1285 mi = new JMenuItem(a4n.helpAbout);
455     mi.setIcon(null);
456     m.add(mi);
457    
458     menuBar.add(m);
459 iliev 912 }
460    
461     /**
462     * This method does nothing, because <b>Fantasia</b> has exactly
463     * one pane containing sampler channels, which can not be changed.
464     */
465     public void
466     insertChannelsPane(JSChannelsPane pane, int idx) {
467 iliev 1285
468 iliev 912 }
469    
470     /**
471     * This method always returns the <code>JSChannelsPane</code> at index 0,
472     * because the <b>Fantasia</b> view has exactly one pane containing sampler channels.
473     * @return The <code>JSChannelsPane</code> at index 0.
474     */
475     public JSChannelsPane
476     getSelectedChannelsPane() { return getChannelsPane(0); }
477    
478     /**
479     * This method does nothing because the <b>Fantasia</b> view has
480     * exactly one pane containing sampler channels which is always shown.
481     */
482     public void
483     setSelectedChannelsPane(JSChannelsPane pane) { }
484    
485 iliev 1285 public void
486     installJSamplerHome() {
487     JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
488     chooser.setVisible(true);
489     if(chooser.isCancelled()) return;
490 iliev 912
491 iliev 1285 CC.changeJSamplerHome(chooser.getJSamplerHome());
492 iliev 912 }
493    
494 iliev 1143 public void
495 iliev 1204 showDetailedErrorMessage(Frame owner, String err, String details) {
496 iliev 1355 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
497     owner, Res.iconWarning32, i18n.getError("error"), err, details
498     );
499     dlg.setVisible(true);
500 iliev 1204 }
501    
502     public void
503     showDetailedErrorMessage(Dialog owner, String err, String details) {
504 iliev 1355 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
505     owner, Res.iconWarning32, i18n.getError("error"), err, details
506     );
507     dlg.setVisible(true);
508 iliev 1204 }
509 iliev 912
510 iliev 1688 /**
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 iliev 1734 public Timer
542     getGuiTimer() { return guiTimer; }
543    
544 iliev 1285 protected LSConsoleModel
545     getLSConsoleModel() { return getLSConsolePane().getModel(); }
546    
547     protected LSConsolePane
548     getLSConsolePane() {
549     return getLSConsoleFrame().getLSConsolePane();
550     }
551    
552     protected LSConsoleFrame
553 iliev 1311 getLSConsoleFrame() { return lsConsoleFrame; }
554 iliev 1285
555 iliev 1688 protected boolean
556 iliev 1285 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 iliev 1688 if(result != JFileChooser.APPROVE_OPTION) return false;
562 iliev 912
563 iliev 1285 String path = fc.getCurrentDirectory().getAbsolutePath();
564     preferences().setStringProperty("lastScriptLocation", path);
565    
566     runScript(fc.getSelectedFile());
567 iliev 1688
568     return true;
569 iliev 1285 }
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 iliev 912 }
582    
583 iliev 1285 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 iliev 912 }
596 iliev 1285
597     String s = script.getAbsolutePath();
598     recentScripts.remove(s);
599     recentScripts.insertElementAt(s, 0);
600    
601     updateRecentScriptsMenu();
602     }
603 iliev 912
604 iliev 1285 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 iliev 1323 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 iliev 1729 preferences().setBoolProperty("leftSidePane.visible", b);
637 iliev 1323 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     hSplitPane.setDividerLocation(i);
646     hSplitPane.validate();
647     } else {
648     rootPane.add(rightPane);
649    
650     }
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 iliev 1729 preferences().setBoolProperty("rightSidePane.visible", b);
669 iliev 1323
670 iliev 1729 int width = leftSidePane.getWidth();
671     int height = leftSidePane.getPreferredSize().height;
672     if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
673 iliev 1323
674     if(b) {
675     int w = preferences().getIntProperty("devicesPane.width", 200);
676    
677 iliev 1729 int h = rightSidePane.getPreferredSize().height;
678     rightSidePane.setPreferredSize(new Dimension(w, h));
679 iliev 1323 } else {
680 iliev 1729 int w = rightSidePane.getWidth();
681 iliev 1323 if(w > 0 && w < 200) w = 200;
682     if(w != 0) preferences().setIntProperty("devicesPane.width", w);
683     }
684    
685     hSplitPane.setResizeWeight(0.0);
686 iliev 1729 rightSidePane.setVisible(b);
687 iliev 1323 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 iliev 1729 boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
706     boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
707 iliev 1323
708 iliev 1729 if(leftSidePaneVisible && rightSidePaneVisible) {
709 iliev 1323 hSplitPane.setResizeWeight(0.5);
710 iliev 1729 } else if(leftSidePaneVisible && !rightSidePaneVisible) {
711 iliev 1323 hSplitPane.setResizeWeight(1.0);
712     }
713    
714 iliev 1729 if(!leftSidePaneVisible && !rightSidePaneVisible) {
715 iliev 1323 standardBar.showFantasiaLogo(false);
716     if(isResizable()) setResizable(false);
717     } else {
718     standardBar.showFantasiaLogo(true);
719     if(!isResizable()) setResizable(true);
720     }
721     }
722    
723 iliev 1285 private class RecentScriptHandler implements ActionListener {
724     private String script;
725    
726     RecentScriptHandler(String script) { this.script = script; }
727    
728 iliev 912 public void
729 iliev 1285 actionPerformed(ActionEvent e) {
730     runScript(script);
731     if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
732     a4n.windowLSConsole.actionPerformed(null);
733     }
734 iliev 912 }
735 iliev 1285 }
736 iliev 912
737 iliev 1285 private static class FantasiaMenu extends JMenu {
738     FantasiaMenu(String s) {
739     super(s);
740     setFont(getFont().deriveFont(java.awt.Font.BOLD));
741     setOpaque(false);
742 iliev 912 }
743     }
744 iliev 1285
745 iliev 1323 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 iliev 1285
749     FantasiaMenuBar() {
750     setOpaque(false);
751     }
752    
753     protected void
754     paintComponent(Graphics g) {
755     super.paintComponent(g);
756 iliev 1323 if(standardBar.isVisible()) {
757     PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);
758     } else {
759     PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2);
760     }
761 iliev 1285 }
762     }
763 iliev 912 }

  ViewVC Help
Powered by ViewVC