/[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 1786 - (hide annotations) (download)
Wed Oct 8 22:38:15 2008 UTC (15 years, 7 months ago) by iliev
File size: 23949 byte(s)
* Implemented option to launch the backend if it is not yet started
  (choose Edit/Preferences, then click the `Backend' tab)
* LSCP scripts can now be run by passing them to jsampler
  as command-line arguments
* The scripts in the `scripts' directory now pass the command-line
  arguments to the respective jsampler distribution
* ant: the default target is now build-fantasia
* bugfix: backend address was always set to 127.0.0.1 when adding
  backend to the backend list

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

  ViewVC Help
Powered by ViewVC