/[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 1688 - (hide annotations) (download)
Thu Feb 14 16:52:36 2008 UTC (16 years, 2 months ago) by iliev
File size: 20111 byte(s)
* Implemented a backend list with option to manually choose a backend
  to connect on startup(Edit/Preferences, then click the `Backend' tab)
  and option to change the backend without restarting JSampler
  (Actions/Change Backend or Ctrl + B)

* Added confirmation messages for removing sampler channels and
  audio/MIDI devices (Edit/Preferences, then click the `View' tab)

1 iliev 912 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1285 * Copyright (C) 2005-2007 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 912 import javax.swing.UIManager;
68    
69     import net.sf.juife.TitleBar;
70    
71     import org.jsampler.CC;
72     import org.jsampler.HF;
73 iliev 1285 import org.jsampler.LSConsoleModel;
74 iliev 1688 import org.jsampler.Server;
75 iliev 912
76     import org.jsampler.view.JSChannel;
77     import org.jsampler.view.JSChannelsPane;
78     import org.jsampler.view.JSMainFrame;
79 iliev 1285 import org.jsampler.view.LscpFileFilter;
80 iliev 912
81 iliev 1688 import org.jsampler.view.std.JSConnectDlg;
82 iliev 1355 import org.jsampler.view.std.JSDetailedErrorDlg;
83 iliev 1567 import org.jsampler.view.std.JSQuitDlg;
84 iliev 1285 import org.jsampler.view.std.JSamplerHomeChooser;
85    
86     import static org.jsampler.view.fantasia.A4n.a4n;
87 iliev 912 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
88 iliev 1285 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
89     import static org.jsampler.view.std.StdPrefs.*;
90 iliev 912
91    
92     /**
93     *
94     * @author Grigor Iliev
95     */
96     public class MainFrame extends JSMainFrame {
97 iliev 1323 private final StandardBar standardBar = new StandardBar();
98 iliev 1285 private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
99 iliev 1323 private final JPanel rootPane = new JPanel();
100 iliev 1285 private final MainPane mainPane = new MainPane();
101     private final DevicesPane devicesPane = new DevicesPane();
102 iliev 1323 private final JScrollPane spDevicesPane = new JScrollPane();
103 iliev 912
104 iliev 1285 private final JMenu recentScriptsMenu =
105     new JMenu(i18n.getMenuLabel("actions.recentScripts"));
106 iliev 912
107 iliev 1285 private final JSplitPane hSplitPane;
108    
109     private final SidePane sidePane = new SidePane();
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     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 iliev 912 /** Creates a new instance of <code>MainFrame</code> */
126     public
127     MainFrame() {
128     setTitle(i18n.getLabel("MainFrame.title"));
129    
130 iliev 1285 if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
131 iliev 912
132 iliev 1285 getContentPane().add(standardBar, BorderLayout.NORTH);
133 iliev 912
134 iliev 1323 rightPane = createRightPane();
135 iliev 912
136 iliev 1285 hSplitPane = new JSplitPane (
137     JSplitPane.HORIZONTAL_SPLIT,
138     true, // continuousLayout
139 iliev 1323 sidePane, rightPane
140 iliev 1285 );
141 iliev 1323 hSplitPane.setResizeWeight(0.5);
142 iliev 912
143 iliev 1323 rootPane.setLayout(new BorderLayout());
144     rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0));
145     rootPane.setOpaque(false);
146     rootPane.add(hSplitPane);
147 iliev 912
148 iliev 1323 addMenu();
149    
150     addChannelsPane(mainPane.getChannelsPane());
151    
152     getContentPane().add(rootPane);
153    
154 iliev 1285 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
155     hSplitPane.setDividerLocation(i);
156 iliev 912
157 iliev 1285 setSavedSize();
158     }
159    
160     private JPanel
161     createRightPane() {
162     JPanel p = new JPanel();
163     GridBagLayout gridbag = new GridBagLayout();
164     GridBagConstraints c = new GridBagConstraints();
165 iliev 912
166 iliev 1285 p.setLayout(gridbag);
167 iliev 912
168 iliev 1285 c.fill = GridBagConstraints.BOTH;
169 iliev 912
170 iliev 1323 spDevicesPane.setViewportView(devicesPane);
171     spDevicesPane.setBorder(BorderFactory.createEmptyBorder());
172     int h = spDevicesPane.getMinimumSize().height;
173     spDevicesPane.setMinimumSize(new Dimension(200, h));
174 iliev 1318
175 iliev 1285 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 iliev 1323 gridbag.setConstraints(spDevicesPane, c);
181     p.add(spDevicesPane);
182 iliev 912
183 iliev 1285 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 iliev 912
192 iliev 1285 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 iliev 912 pack();
203     try {
204 iliev 1285 int i = s.indexOf(',');
205     int x = Integer.parseInt(s.substring(0, i));
206 iliev 912
207 iliev 1285 s = s.substring(i + 1);
208     i = s.indexOf(',');
209     int y = Integer.parseInt(s.substring(0, i));
210 iliev 912
211 iliev 1285 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 iliev 912 } catch(Exception x) {
220     String msg = "Parsing of window size and location string failed";
221     CC.getLogger().log(Level.INFO, msg, x);
222 iliev 1285 setDefaultSizeAndLocation();
223 iliev 912 }
224 iliev 1285
225     if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
226     setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
227     }
228 iliev 912 }
229    
230     private void
231 iliev 1285 setDefaultSizeAndLocation() {
232     setPreferredSize(new Dimension(900, 600));
233     pack();
234     setLocationRelativeTo(null);
235 iliev 912 }
236    
237    
238     /** Invoked when this window is about to close. */
239     protected void
240     onWindowClose() {
241 iliev 1688 boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
242     if(b && CC.getSamplerModel().isModified()) {
243 iliev 1567 JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
244     dlg.setVisible(true);
245     if(dlg.isCancelled()) return;
246     }
247    
248 iliev 1285 sidePane.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     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 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 1285 protected LSConsoleModel
542     getLSConsoleModel() { return getLSConsolePane().getModel(); }
543    
544     protected LSConsolePane
545     getLSConsolePane() {
546     return getLSConsoleFrame().getLSConsolePane();
547     }
548    
549     protected LSConsoleFrame
550 iliev 1311 getLSConsoleFrame() { return lsConsoleFrame; }
551 iliev 1285
552 iliev 1688 protected boolean
553 iliev 1285 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 iliev 1688 if(result != JFileChooser.APPROVE_OPTION) return false;
559 iliev 912
560 iliev 1285 String path = fc.getCurrentDirectory().getAbsolutePath();
561     preferences().setStringProperty("lastScriptLocation", path);
562    
563     runScript(fc.getSelectedFile());
564 iliev 1688
565     return true;
566 iliev 1285 }
567    
568     private void
569     runScript(String script) { runScript(new File(script)); }
570    
571     private void
572     runScript(File script) {
573     FileReader fr;
574     try { fr = new FileReader(script); }
575     catch(FileNotFoundException e) {
576     HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
577     return;
578 iliev 912 }
579    
580 iliev 1285 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 iliev 912 }
593 iliev 1285
594     String s = script.getAbsolutePath();
595     recentScripts.remove(s);
596     recentScripts.insertElementAt(s, 0);
597    
598     updateRecentScriptsMenu();
599     }
600 iliev 912
601 iliev 1285 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 iliev 1323 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     hSplitPane.setDividerLocation(i);
643     hSplitPane.validate();
644     } else {
645     rootPane.add(rightPane);
646    
647     }
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     int h = spDevicesPane.getPreferredSize().height;
675     spDevicesPane.setPreferredSize(new Dimension(w, h));
676     } 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     hSplitPane.setResizeWeight(0.0);
683     spDevicesPane.setVisible(b);
684     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 iliev 1285 private class RecentScriptHandler implements ActionListener {
721     private String script;
722    
723     RecentScriptHandler(String script) { this.script = script; }
724    
725 iliev 912 public void
726 iliev 1285 actionPerformed(ActionEvent e) {
727     runScript(script);
728     if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
729     a4n.windowLSConsole.actionPerformed(null);
730     }
731 iliev 912 }
732 iliev 1285 }
733 iliev 912
734 iliev 1285 private static class FantasiaMenu extends JMenu {
735     FantasiaMenu(String s) {
736     super(s);
737     setFont(getFont().deriveFont(java.awt.Font.BOLD));
738     setOpaque(false);
739 iliev 912 }
740     }
741 iliev 1285
742 iliev 1323 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 iliev 1285
746     FantasiaMenuBar() {
747     setOpaque(false);
748     }
749    
750     protected void
751     paintComponent(Graphics g) {
752     super.paintComponent(g);
753 iliev 1323 if(standardBar.isVisible()) {
754     PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets);
755     } else {
756     PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2);
757     }
758 iliev 1285 }
759     }
760 iliev 912 }

  ViewVC Help
Powered by ViewVC