/[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 1729 - (hide annotations) (download)
Tue Apr 29 22:22:40 2008 UTC (16 years ago) by iliev
File size: 19991 byte(s)
* Added support for handling lost files in the Instruments Database
  (In the Instruments Database window choose Actions/Check For Lost Files)
* Fantasia: Added option to show the Instruments Database
  on the Right-Side Pane of the Fantasia's main window
  (choose Edit/Preferences, then click the `View' tab)
* Added new menu item in the Instruments Database window: Edit/Find
* Some minor bugfixes and enhancements

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

  ViewVC Help
Powered by ViewVC