/[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 1785 - (hide annotations) (download)
Tue Oct 7 00:07:14 2008 UTC (15 years, 6 months ago) by iliev
File size: 23663 byte(s)
* Fantasia: Implemented multiple channels panels
* Fantasia: Refactoring - all basic UI components moved to
  org.jsampler.view.fantasia.basic package

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 1778 import java.awt.Color;
27     import java.awt.Composite;
28 iliev 1204 import java.awt.Dialog;
29 iliev 912 import java.awt.Dimension;
30 iliev 1204 import java.awt.Frame;
31 iliev 1285 import java.awt.Graphics;
32 iliev 1778 import java.awt.Graphics2D;
33 iliev 1285 import java.awt.GridBagConstraints;
34     import java.awt.GridBagLayout;
35     import java.awt.Insets;
36 iliev 1778 import java.awt.Paint;
37 iliev 912
38     import java.awt.event.ActionEvent;
39     import java.awt.event.ActionListener;
40 iliev 1285 import java.awt.event.KeyEvent;
41 iliev 912
42 iliev 1778 import java.beans.PropertyChangeEvent;
43     import java.beans.PropertyChangeListener;
44    
45 iliev 1285 import java.io.BufferedReader;
46     import java.io.File;
47     import java.io.FileNotFoundException;
48     import java.io.FileReader;
49    
50     import java.util.Vector;
51 iliev 912 import java.util.logging.Level;
52    
53 iliev 1285 import javax.swing.BorderFactory;
54 iliev 1778 import javax.swing.BoxLayout;
55 iliev 912 import javax.swing.JCheckBoxMenuItem;
56 iliev 1285 import javax.swing.JFileChooser;
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 iliev 1285 import javax.swing.JSplitPane;
62     import javax.swing.KeyStroke;
63     import javax.swing.SwingUtilities;
64 iliev 1734 import javax.swing.Timer;
65 iliev 912
66     import org.jsampler.CC;
67     import org.jsampler.HF;
68 iliev 1285 import org.jsampler.LSConsoleModel;
69 iliev 1688 import org.jsampler.Server;
70 iliev 912
71     import org.jsampler.view.JSChannelsPane;
72     import org.jsampler.view.JSMainFrame;
73 iliev 1285 import org.jsampler.view.LscpFileFilter;
74 iliev 912
75 iliev 1785 import org.jsampler.view.fantasia.basic.FantasiaPainter;
76     import org.jsampler.view.fantasia.basic.FantasiaPanel;
77     import org.jsampler.view.fantasia.basic.FantasiaSubPanel;
78    
79 iliev 1688 import org.jsampler.view.std.JSConnectDlg;
80 iliev 1355 import org.jsampler.view.std.JSDetailedErrorDlg;
81 iliev 1567 import org.jsampler.view.std.JSQuitDlg;
82 iliev 1285 import org.jsampler.view.std.JSamplerHomeChooser;
83    
84     import static org.jsampler.view.fantasia.A4n.a4n;
85 iliev 912 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
86 iliev 1285 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
87     import static org.jsampler.view.std.StdPrefs.*;
88 iliev 912
89    
90     /**
91     *
92     * @author Grigor Iliev
93     */
94     public class MainFrame extends JSMainFrame {
95 iliev 1323 private final StandardBar standardBar = new StandardBar();
96 iliev 1285 private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
97 iliev 1778 private final JPanel rootPane = new RootPane();
98     private final BottomPane bottomPane;
99 iliev 1785 private final MainPane mainPane;
100 iliev 1776 private final PianoKeyboardPane pianoKeyboardPane;
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 1785 private final LeftSidePane leftSidePane;
108     private final RightSidePane rightSidePane;
109 iliev 1323 private final JPanel rightPane;
110 iliev 1285
111 iliev 1767 //private final StatusBar statusBar = new StatusBar();
112    
113 iliev 1311 private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
114 iliev 1285 private final Vector<String> recentScripts = new Vector<String>();
115    
116    
117 iliev 1323 private final JCheckBoxMenuItem cbmiToolBarVisible =
118     new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
119    
120 iliev 1729 private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
121     new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
122 iliev 1323
123 iliev 1729 private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
124     new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
125 iliev 1323
126 iliev 1776 private final JCheckBoxMenuItem cbmiMidiKeyboardVisible =
127     new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard"));
128    
129 iliev 1734 private final Timer guiTimer = new Timer(1000, null);
130    
131 iliev 912 /** Creates a new instance of <code>MainFrame</code> */
132     public
133     MainFrame() {
134     setTitle(i18n.getLabel("MainFrame.title"));
135 iliev 1778 //setUndecorated(true);
136 iliev 1285 if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
137 iliev 912
138 iliev 1785 CC.setMainFrame(this); // TODO:
139     mainPane = new MainPane();
140     leftSidePane = new LeftSidePane();
141     rightSidePane = new RightSidePane();
142    
143     setSelectedChannelsPane(mainPane.getChannelsPane(0));
144    
145 iliev 1285 getContentPane().add(standardBar, BorderLayout.NORTH);
146 iliev 912
147 iliev 1323 rightPane = createRightPane();
148 iliev 912
149 iliev 1285 hSplitPane = new JSplitPane (
150     JSplitPane.HORIZONTAL_SPLIT,
151     true, // continuousLayout
152 iliev 1729 leftSidePane, rightPane
153 iliev 1285 );
154 iliev 1323 hSplitPane.setResizeWeight(0.5);
155 iliev 912
156 iliev 1785 pianoKeyboardPane = new PianoKeyboardPane();
157 iliev 1776
158 iliev 1785 for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
159     addChannelsPane(mainPane.getChannelsPane(i));
160     getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
161     }
162    
163    
164 iliev 1778 int h = preferences().getIntProperty("midiKeyboard.height");
165     setMidiKeyboardHeight(h);
166 iliev 1776
167 iliev 1778 PropertyChangeListener l = new PropertyChangeListener() {
168     public void
169     propertyChange(PropertyChangeEvent e) {
170     int h = preferences().getIntProperty("midiKeyboard.height");
171     setMidiKeyboardHeight(h);
172     }
173     };
174 iliev 1776
175 iliev 1778 CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
176 iliev 1776
177 iliev 1778 bottomPane = new BottomPane();
178    
179     hSplitPane.setOpaque(false);
180 iliev 1323 rootPane.add(hSplitPane);
181 iliev 1778 rootPane.add(bottomPane, BorderLayout.SOUTH);
182     add(rootPane);
183 iliev 912
184 iliev 1323 addMenu();
185    
186 iliev 1285 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
187     hSplitPane.setDividerLocation(i);
188 iliev 912
189 iliev 1285 setSavedSize();
190 iliev 1734
191     guiTimer.start();
192 iliev 1285 }
193    
194     private JPanel
195     createRightPane() {
196 iliev 1778 JPanel p = new FantasiaPanel();
197     p.setOpaque(false);
198    
199 iliev 1285 GridBagLayout gridbag = new GridBagLayout();
200     GridBagConstraints c = new GridBagConstraints();
201 iliev 912
202 iliev 1285 p.setLayout(gridbag);
203 iliev 912
204 iliev 1285 c.fill = GridBagConstraints.BOTH;
205 iliev 912
206 iliev 1285 c.gridx = 1;
207     c.gridy = 0;
208     c.weightx = 1.0;
209     c.weighty = 1.0;
210 iliev 1729 c.insets = new Insets(0, 3, 0, 0);
211     gridbag.setConstraints(rightSidePane, c);
212     p.add(rightSidePane);
213 iliev 912
214 iliev 1285 c.gridx = 0;
215     c.gridy = 0;
216     c.weightx = 0.0;
217     c.weighty = 1.0;
218 iliev 1778 c.insets = new Insets(0, 0, 0, 3);
219 iliev 1285 c.fill = GridBagConstraints.VERTICAL;
220     gridbag.setConstraints(mainPane, c);
221     p.add(mainPane);
222 iliev 912
223 iliev 1285 return p;
224     }
225    
226     private void
227     setSavedSize() {
228     String s = preferences().getStringProperty("MainFrame.sizeAndLocation");
229     if(s == null) {
230     setDefaultSizeAndLocation();
231     return;
232     }
233 iliev 912 pack();
234     try {
235 iliev 1285 int i = s.indexOf(',');
236     int x = Integer.parseInt(s.substring(0, i));
237 iliev 912
238 iliev 1285 s = s.substring(i + 1);
239     i = s.indexOf(',');
240     int y = Integer.parseInt(s.substring(0, i));
241 iliev 912
242 iliev 1285 s = s.substring(i + 1);
243     i = s.indexOf(',');
244     int width = Integer.parseInt(s.substring(0, i));
245    
246     s = s.substring(i + 1);
247     int height = Integer.parseInt(s);
248    
249     setBounds(x, y, width, height);
250 iliev 912 } catch(Exception x) {
251     String msg = "Parsing of window size and location string failed";
252     CC.getLogger().log(Level.INFO, msg, x);
253 iliev 1285 setDefaultSizeAndLocation();
254 iliev 912 }
255 iliev 1285
256     if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
257     setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
258     }
259 iliev 912 }
260    
261     private void
262 iliev 1285 setDefaultSizeAndLocation() {
263     setPreferredSize(new Dimension(900, 600));
264     pack();
265     setLocationRelativeTo(null);
266 iliev 912 }
267    
268    
269     /** Invoked when this window is about to close. */
270 iliev 1778 @Override
271 iliev 912 protected void
272     onWindowClose() {
273 iliev 1688 boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
274     if(b && CC.getSamplerModel().isModified()) {
275 iliev 1567 JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
276     dlg.setVisible(true);
277     if(dlg.isCancelled()) return;
278     }
279    
280 iliev 1729 leftSidePane.savePreferences();
281     rightSidePane.savePreferences();
282 iliev 912
283 iliev 1285 int i = hSplitPane.getDividerLocation();
284     preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
285    
286     preferences().setBoolProperty (
287     "MainFrame.windowMaximized",
288     (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
289     );
290    
291     if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
292     super.onWindowClose();
293     return;
294     }
295    
296 iliev 912 java.awt.Point p = getLocation();
297     Dimension d = getSize();
298     StringBuffer sb = new StringBuffer();
299 iliev 1285 sb.append(p.x).append(',').append(p.y).append(',');
300     sb.append(d.width).append(',').append(d.height);
301     preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString());
302 iliev 912
303 iliev 1308 String[] list = recentScripts.toArray(new String[recentScripts.size()]);
304     preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
305 iliev 1285
306     if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
307     if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
308     }
309    
310 iliev 912 super.onWindowClose();
311     }
312    
313 iliev 1285 private void
314     addMenu() {
315     JMenu m;
316     JMenuItem mi;
317    
318     setJMenuBar(menuBar);
319    
320     // Actions
321     m = new FantasiaMenu(i18n.getMenuLabel("actions"));
322    
323 iliev 1688 mi = new JMenuItem(a4n.refresh);
324 iliev 1285 mi.setIcon(null);
325 iliev 1688 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
326 iliev 1285 m.add(mi);
327    
328     mi = new JMenuItem(a4n.samplerInfo);
329     mi.setIcon(null);
330     m.add(mi);
331    
332 iliev 1688 mi = new JMenuItem(a4n.resetSampler);
333     mi.setIcon(null);
334     m.add(mi);
335    
336 iliev 1285 m.addSeparator();
337    
338     JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
339     m.add(exportMenu);
340    
341     mi = new JMenuItem(a4n.exportSamplerConfig);
342     mi.setIcon(null);
343     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK));
344     exportMenu.add(mi);
345    
346     mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
347     mi.setIcon(null);
348     exportMenu.add(mi);
349    
350     m.addSeparator();
351    
352     mi = new JMenuItem(a4n.loadScript);
353     mi.setIcon(null);
354 iliev 1688 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
355 iliev 1285 m.add(mi);
356    
357 iliev 1308 String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
358     for(String s : list) recentScripts.add(s);
359 iliev 1285
360     updateRecentScriptsMenu();
361    
362     m.add(recentScriptsMenu);
363    
364     m.addSeparator();
365    
366 iliev 1688 mi = new JMenuItem(a4n.changeBackend);
367     mi.setIcon(null);
368     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK));
369     m.add(mi);
370    
371     m.addSeparator();
372    
373 iliev 1285 mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
374     m.add(mi);
375     mi.addActionListener(new ActionListener() {
376     public void
377     actionPerformed(ActionEvent e) { onWindowClose(); }
378     });
379    
380     menuBar.add(m);
381    
382    
383     // Edit
384     m = new FantasiaMenu(i18n.getMenuLabel("edit"));
385     menuBar.add(m);
386    
387 iliev 1323 mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel"));
388     m.add(mi);
389     mi.addActionListener(new ActionListener() {
390     public void
391     actionPerformed(ActionEvent e) {
392     CC.getSamplerModel().addBackendChannel();
393     }
394     });
395    
396     m.addSeparator();
397    
398     mi = new JMenuItem(a4n.createMidiDevice);
399     mi.setIcon(null);
400     m.add(mi);
401    
402     mi = new JMenuItem(a4n.createAudioDevice);
403     mi.setIcon(null);
404     m.add(mi);
405    
406     m.addSeparator();
407    
408 iliev 1285 mi = new JMenuItem(a4n.editPreferences);
409     mi.setIcon(null);
410     mi.setAccelerator(KeyStroke.getKeyStroke (
411     KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
412     ));
413     m.add(mi);
414    
415 iliev 1323 // View
416     m = new FantasiaMenu(i18n.getMenuLabel("view"));
417     menuBar.add(m);
418 iliev 1285
419 iliev 1323 m.add(cbmiToolBarVisible);
420    
421     cbmiToolBarVisible.addActionListener(new ActionListener() {
422     public void
423     actionPerformed(ActionEvent e) {
424     showToolBar(cbmiToolBarVisible.getState());
425     }
426     });
427    
428     boolean b = preferences().getBoolProperty("toolBar.visible");
429     cbmiToolBarVisible.setSelected(b);
430     showToolBar(b);
431    
432 iliev 1729 cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
433 iliev 1323 KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
434     ));
435 iliev 1729 m.add(cbmiLeftSidePaneVisible);
436 iliev 1323
437 iliev 1729 cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
438 iliev 1323 public void
439     actionPerformed(ActionEvent e) {
440 iliev 1729 showSidePane(cbmiLeftSidePaneVisible.getState());
441 iliev 1323 }
442     });
443    
444 iliev 1729 b = preferences().getBoolProperty("leftSidePane.visible");
445     cbmiLeftSidePaneVisible.setSelected(b);
446 iliev 1323 showSidePane(b);
447    
448 iliev 1729 cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
449 iliev 1323 KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK
450     ));
451 iliev 1729 m.add(cbmiRightSidePaneVisible);
452 iliev 1323
453 iliev 1729 cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
454 iliev 1323 public void
455     actionPerformed(ActionEvent e) {
456 iliev 1729 showDevicesPane(cbmiRightSidePaneVisible.getState());
457 iliev 1323 }
458     });
459    
460 iliev 1729 b = preferences().getBoolProperty("rightSidePane.visible");
461     cbmiRightSidePaneVisible.setSelected(b);
462 iliev 1323 showDevicesPane(b);
463    
464 iliev 1776 m.addSeparator();
465 iliev 1323
466 iliev 1776 m.add(cbmiMidiKeyboardVisible);
467    
468     cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {
469     public void
470     actionPerformed(ActionEvent e) {
471 iliev 1778 setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState());
472 iliev 1776 }
473     });
474    
475     b = preferences().getBoolProperty("midiKeyboard.visible");
476     cbmiMidiKeyboardVisible.setSelected(b);
477 iliev 1778 setMidiKeyboardVisible(b);
478 iliev 1776
479    
480 iliev 1285 // Window
481     m = new FantasiaMenu(i18n.getMenuLabel("window"));
482     menuBar.add(m);
483    
484     mi = new JMenuItem(a4n.windowLSConsole);
485     mi.setIcon(null);
486     m.add(mi);
487    
488     mi = new JMenuItem(a4n.windowInstrumentsDb);
489     mi.setIcon(null);
490     m.add(mi);
491    
492    
493     // Help
494     m = new FantasiaMenu(i18n.getMenuLabel("help"));
495    
496 iliev 1496 mi = new JMenuItem(a4n.browseOnlineTutorial);
497     mi.setIcon(null);
498     m.add(mi);
499    
500     m.addSeparator();
501    
502 iliev 1285 mi = new JMenuItem(a4n.helpAbout);
503     mi.setIcon(null);
504     m.add(mi);
505    
506     menuBar.add(m);
507 iliev 912 }
508    
509 iliev 1767 public RightSidePane
510     getRightSidePane() { return rightSidePane; }
511    
512 iliev 912 /**
513 iliev 1785 * This method does nothing, because <b>Fantasia</b> has constant
514     * number of panes containing sampler channels, which can not be changed.
515 iliev 912 */
516 iliev 1778 @Override
517 iliev 912 public void
518     insertChannelsPane(JSChannelsPane pane, int idx) {
519 iliev 1285
520 iliev 912 }
521    
522 iliev 1778 @Override
523 iliev 912 public JSChannelsPane
524 iliev 1785 getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); }
525 iliev 912
526 iliev 1778 @Override
527 iliev 912 public void
528 iliev 1785 setSelectedChannelsPane(JSChannelsPane pane) {
529     mainPane.setSelectedChannelsPane(pane);
530     fireChannelsPaneSelectionChanged();
531     }
532 iliev 912
533 iliev 1778 @Override
534 iliev 1285 public void
535     installJSamplerHome() {
536     JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
537     chooser.setVisible(true);
538     if(chooser.isCancelled()) return;
539 iliev 912
540 iliev 1285 CC.changeJSamplerHome(chooser.getJSamplerHome());
541 iliev 912 }
542    
543 iliev 1778 @Override
544 iliev 1143 public void
545 iliev 1204 showDetailedErrorMessage(Frame owner, String err, String details) {
546 iliev 1355 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
547     owner, Res.iconWarning32, i18n.getError("error"), err, details
548     );
549     dlg.setVisible(true);
550 iliev 1204 }
551    
552 iliev 1778 @Override
553 iliev 1204 public void
554     showDetailedErrorMessage(Dialog owner, String err, String details) {
555 iliev 1355 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
556     owner, Res.iconWarning32, i18n.getError("error"), err, details
557     );
558     dlg.setVisible(true);
559 iliev 1204 }
560 iliev 912
561 iliev 1688 /**
562     * Gets the server address to which to connect. If the server should be
563     * manually selected, a dialog asking the user to choose a server is displayed.
564     */
565 iliev 1778 @Override
566 iliev 1688 public Server
567     getServer() {
568     boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
569     return getServer(b);
570     }
571    
572     /**
573     * Gets the server address to which to connect. If the server should be
574     * manually selected, a dialog asking the user to choose a server is displayed.
575     * @param manualSelect Determines whether the server should be manually selected.
576     */
577 iliev 1778 @Override
578 iliev 1688 public Server
579     getServer(boolean manualSelect) {
580     if(manualSelect) {
581     JSConnectDlg dlg = new JSConnectDlg();
582     dlg.setVisible(true);
583     return dlg.getSelectedServer();
584     }
585    
586     int i = preferences().getIntProperty(SERVER_INDEX);
587     int size = CC.getServerList().getServerCount();
588     if(size == 0) return null;
589     if(i >= size) return CC.getServerList().getServer(0);
590    
591     return CC.getServerList().getServer(i);
592     }
593    
594 iliev 1734 public Timer
595     getGuiTimer() { return guiTimer; }
596    
597 iliev 1285 protected LSConsoleModel
598     getLSConsoleModel() { return getLSConsolePane().getModel(); }
599    
600     protected LSConsolePane
601     getLSConsolePane() {
602     return getLSConsoleFrame().getLSConsolePane();
603     }
604    
605     protected LSConsoleFrame
606 iliev 1311 getLSConsoleFrame() { return lsConsoleFrame; }
607 iliev 1285
608 iliev 1688 protected boolean
609 iliev 1285 runScript() {
610     String s = preferences().getStringProperty("lastScriptLocation");
611     JFileChooser fc = new JFileChooser(s);
612     fc.setFileFilter(new LscpFileFilter());
613     int result = fc.showOpenDialog(this);
614 iliev 1688 if(result != JFileChooser.APPROVE_OPTION) return false;
615 iliev 912
616 iliev 1285 String path = fc.getCurrentDirectory().getAbsolutePath();
617     preferences().setStringProperty("lastScriptLocation", path);
618    
619     runScript(fc.getSelectedFile());
620 iliev 1688
621     return true;
622 iliev 1285 }
623    
624     private void
625     runScript(String script) { runScript(new File(script)); }
626    
627     private void
628     runScript(File script) {
629     FileReader fr;
630     try { fr = new FileReader(script); }
631     catch(FileNotFoundException e) {
632     HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
633     return;
634 iliev 912 }
635    
636 iliev 1285 BufferedReader br = new BufferedReader(fr);
637    
638     try {
639     String s = br.readLine();
640     while(s != null) {
641     getLSConsoleModel().setCommandLineText(s);
642     getLSConsoleModel().execCommand();
643     s = br.readLine();
644     }
645     } catch(Exception e) {
646     HF.showErrorMessage(e);
647     return;
648 iliev 912 }
649 iliev 1285
650     String s = script.getAbsolutePath();
651     recentScripts.remove(s);
652     recentScripts.insertElementAt(s, 0);
653    
654     updateRecentScriptsMenu();
655     }
656 iliev 912
657 iliev 1285 protected void
658     clearRecentScripts() {
659     recentScripts.removeAllElements();
660     updateRecentScriptsMenu();
661     }
662    
663     protected void
664     updateRecentScriptsMenu() {
665     int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
666     while(recentScripts.size() > size) {
667     recentScripts.removeElementAt(recentScripts.size() - 1);
668     }
669    
670     recentScriptsMenu.removeAll();
671    
672     for(String script : recentScripts) {
673     JMenuItem mi = new JMenuItem(script);
674     recentScriptsMenu.add(mi);
675     mi.addActionListener(new RecentScriptHandler(script));
676     }
677    
678     recentScriptsMenu.setEnabled(recentScripts.size() != 0);
679     }
680    
681 iliev 1323 private void
682     showToolBar(boolean b) {
683     preferences().setBoolProperty("toolBar.visible", b);
684     standardBar.setVisible(b);
685     }
686    
687     private void
688     showSidePane(boolean b) {
689 iliev 1729 preferences().setBoolProperty("leftSidePane.visible", b);
690 iliev 1323 rootPane.remove(rightPane);
691     rootPane.remove(hSplitPane);
692    
693     if(b) {
694     hSplitPane.setRightComponent(rightPane);
695     rootPane.add(hSplitPane);
696     int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
697    
698     hSplitPane.setDividerLocation(i);
699     hSplitPane.validate();
700     } else {
701     rootPane.add(rightPane);
702    
703     }
704    
705     int w = getPreferredSize().width;
706     int h = getSize().height;
707     setSize(new Dimension(w, h));
708    
709     rootPane.revalidate();
710     rootPane.validate();
711     rootPane.repaint();
712    
713     SwingUtilities.invokeLater(new Runnable() {
714     public void
715     run() { sidePanesVisibilityChanged(); }
716     });
717     }
718    
719     private void
720     showDevicesPane(boolean b) {
721 iliev 1729 preferences().setBoolProperty("rightSidePane.visible", b);
722 iliev 1323
723 iliev 1729 int width = leftSidePane.getWidth();
724     int height = leftSidePane.getPreferredSize().height;
725     if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
726 iliev 1323
727     if(b) {
728     int w = preferences().getIntProperty("devicesPane.width", 200);
729    
730 iliev 1729 int h = rightSidePane.getPreferredSize().height;
731     rightSidePane.setPreferredSize(new Dimension(w, h));
732 iliev 1323 } else {
733 iliev 1729 int w = rightSidePane.getWidth();
734 iliev 1323 if(w > 0 && w < 200) w = 200;
735     if(w != 0) preferences().setIntProperty("devicesPane.width", w);
736     }
737    
738     hSplitPane.setResizeWeight(0.0);
739 iliev 1729 rightSidePane.setVisible(b);
740 iliev 1323 hSplitPane.resetToPreferredSizes();
741    
742     int w = getPreferredSize().width;
743     int h = getSize().height;
744     setSize(new Dimension(w, h));
745    
746     rootPane.validate();
747     rootPane.repaint();
748     //hSplitPane.validate();
749    
750     SwingUtilities.invokeLater(new Runnable() {
751     public void
752     run() { sidePanesVisibilityChanged(); }
753     });
754     }
755    
756 iliev 1778 public void
757     setMidiKeyboardVisible(boolean b) {
758 iliev 1776 preferences().setBoolProperty("midiKeyboard.visible", b);
759 iliev 1778 pianoKeyboardPane.setVisible(b);
760    
761     if(cbmiMidiKeyboardVisible.isSelected() != b) {
762     cbmiMidiKeyboardVisible.setSelected(b);
763 iliev 1776 }
764    
765 iliev 1778 if(standardBar.btnMidiKeyboard.isSelected() != b) {
766     standardBar.btnMidiKeyboard.setSelected(b);
767     }
768    
769     if(pianoKeyboardPane.btnPower.isSelected() != b) {
770     pianoKeyboardPane.btnPower.setSelected(b);
771     }
772    
773     rootPane.validate();
774     rootPane.repaint();
775 iliev 1776 }
776    
777 iliev 1778 public void
778     setMidiKeyboardHeight(int height) {
779     Dimension d = pianoKeyboardPane.getPreferredSize();
780     d = new Dimension(d.width, height);
781     pianoKeyboardPane.setPreferredSize(d);
782     pianoKeyboardPane.setMinimumSize(d);
783     pianoKeyboardPane.revalidate();
784     pianoKeyboardPane.repaint();
785     }
786    
787 iliev 1776 private void
788 iliev 1323 sidePanesVisibilityChanged() {
789 iliev 1729 boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
790     boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
791 iliev 1323
792 iliev 1729 if(leftSidePaneVisible && rightSidePaneVisible) {
793 iliev 1323 hSplitPane.setResizeWeight(0.5);
794 iliev 1729 } else if(leftSidePaneVisible && !rightSidePaneVisible) {
795 iliev 1323 hSplitPane.setResizeWeight(1.0);
796     }
797    
798 iliev 1729 if(!leftSidePaneVisible && !rightSidePaneVisible) {
799 iliev 1323 standardBar.showFantasiaLogo(false);
800     if(isResizable()) setResizable(false);
801     } else {
802     standardBar.showFantasiaLogo(true);
803     if(!isResizable()) setResizable(true);
804     }
805     }
806    
807 iliev 1285 private class RecentScriptHandler implements ActionListener {
808     private String script;
809    
810     RecentScriptHandler(String script) { this.script = script; }
811    
812 iliev 1778 @Override
813 iliev 912 public void
814 iliev 1285 actionPerformed(ActionEvent e) {
815     runScript(script);
816     if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
817     a4n.windowLSConsole.actionPerformed(null);
818     }
819 iliev 912 }
820 iliev 1285 }
821 iliev 912
822 iliev 1285 private static class FantasiaMenu extends JMenu {
823     FantasiaMenu(String s) {
824     super(s);
825     setFont(getFont().deriveFont(java.awt.Font.BOLD));
826     setOpaque(false);
827 iliev 1776 setContentAreaFilled(false);
828 iliev 912 }
829     }
830 iliev 1285
831 iliev 1323 private class FantasiaMenuBar extends JMenuBar {
832 iliev 1285 FantasiaMenuBar() {
833     setOpaque(false);
834 iliev 1778 setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
835 iliev 1285 }
836    
837 iliev 1778 @Override
838 iliev 1285 protected void
839     paintComponent(Graphics g) {
840 iliev 1778 //super.paintComponent(g);
841     Graphics2D g2 = (Graphics2D)g;
842    
843     Paint oldPaint = g2.getPaint();
844     Composite oldComposite = g2.getComposite();
845    
846     double h = getSize().getHeight();
847     double w = getSize().getWidth();
848    
849     FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
850    
851     FantasiaPainter.Border b;
852    
853    
854 iliev 1323 if(standardBar.isVisible()) {
855 iliev 1778 b = new FantasiaPainter.Border(true, true, false, true);
856     FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
857 iliev 1323 } else {
858 iliev 1778 b = new FantasiaPainter.Border(true, true, true, true);
859     FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
860 iliev 1323 }
861 iliev 1778
862     g2.setPaint(oldPaint);
863     g2.setComposite(oldComposite);
864 iliev 1285 }
865     }
866 iliev 1778
867     class RootPane extends FantasiaSubPanel {
868     private final Color color1 = new Color(0x454545);
869     private final Color color2 = new Color(0x2e2e2e);
870    
871     RootPane() {
872     setLayout(new BorderLayout());
873     setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
874     setOpaque(false);
875    
876     }
877    
878     @Override
879     public void
880     paintComponent(Graphics g) {
881     Graphics2D g2 = (Graphics2D)g;
882    
883     Paint oldPaint = g2.getPaint();
884     Composite oldComposite = g2.getComposite();
885    
886     double h = getSize().getHeight();
887     double w = getSize().getWidth();
888    
889     FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
890     paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
891    
892     g2.setPaint(oldPaint);
893     g2.setComposite(oldComposite);
894     }
895     }
896    
897     class BottomPane extends FantasiaPanel {
898     BottomPane() {
899     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
900     setOpaque(false);
901     add(pianoKeyboardPane);
902    
903     }
904     }
905 iliev 912 }

  ViewVC Help
Powered by ViewVC