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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1883 - (show annotations) (download)
Sun Apr 5 09:15:35 2009 UTC (15 years ago) by iliev
File size: 27995 byte(s)
* fixed the channel order when exporting sampler configuration
* don't mute channels muted by solo channel when exporting
   sampler configuration
* don't ask whether to replace a file on Mac OS when using
  native file choosers

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5 *
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 import java.awt.Color;
27 import java.awt.Composite;
28 import java.awt.Dialog;
29 import java.awt.Dimension;
30 import java.awt.Frame;
31 import java.awt.Graphics;
32 import java.awt.Graphics2D;
33 import java.awt.GridBagConstraints;
34 import java.awt.GridBagLayout;
35 import java.awt.Insets;
36 import java.awt.Paint;
37 import java.awt.Rectangle;
38
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.awt.event.KeyEvent;
42
43 import java.beans.PropertyChangeEvent;
44 import java.beans.PropertyChangeListener;
45
46 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
53 import javax.swing.BorderFactory;
54 import javax.swing.BoxLayout;
55 import javax.swing.JCheckBoxMenuItem;
56 import javax.swing.JMenu;
57 import javax.swing.JMenuBar;
58 import javax.swing.JMenuItem;
59 import javax.swing.JPanel;
60 import javax.swing.JSplitPane;
61 import javax.swing.KeyStroke;
62 import javax.swing.SwingUtilities;
63 import javax.swing.Timer;
64
65 import javax.swing.event.ListSelectionEvent;
66 import javax.swing.event.ListSelectionListener;
67
68 import org.jsampler.CC;
69 import org.jsampler.HF;
70 import org.jsampler.LSConsoleModel;
71 import org.jsampler.Server;
72
73 import org.jsampler.view.JSChannelsPane;
74 import org.jsampler.view.SessionViewConfig;
75
76 import org.jsampler.view.fantasia.basic.FantasiaPainter;
77 import org.jsampler.view.fantasia.basic.FantasiaPanel;
78 import org.jsampler.view.fantasia.basic.FantasiaSubPanel;
79
80 import org.jsampler.view.std.JSBackendLogFrame;
81 import org.jsampler.view.std.JSConnectDlg;
82 import org.jsampler.view.std.JSDetailedErrorDlg;
83 import org.jsampler.view.std.JSQuitDlg;
84 import org.jsampler.view.std.JSamplerHomeChooser;
85 import org.jsampler.view.std.StdMainFrame;
86 import org.jsampler.view.std.StdUtils;
87
88 import static org.jsampler.view.fantasia.A4n.a4n;
89 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
90 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
91 import static org.jsampler.view.std.StdPrefs.*;
92
93
94 /**
95 *
96 * @author Grigor Iliev
97 */
98 public class MainFrame extends StdMainFrame {
99 public final static int MAX_CHANNEL_LANE_NUMBER = 8;
100
101 private final StandardBar standardBar = new StandardBar();
102 private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
103 private final JPanel rootPane = new RootPane();
104 private final BottomPane bottomPane;
105 private final MainPane mainPane;
106 private final PianoKeyboardPane pianoKeyboardPane;
107
108 private final JMenu recentScriptsMenu =
109 new JMenu(i18n.getMenuLabel("actions.recentScripts"));
110
111 private final JSplitPane hSplitPane;
112
113 private final LeftSidePane leftSidePane;
114 private final RightSidePane rightSidePane;
115 private final JPanel rightPane;
116
117 //private final StatusBar statusBar = new StatusBar();
118
119 private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
120 private final Vector<String> recentScripts = new Vector<String>();
121
122 private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
123
124
125 private final JCheckBoxMenuItem cbmiToolBarVisible =
126 new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
127
128 private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
129 new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
130
131 private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
132 new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
133
134 private final JCheckBoxMenuItem cbmiMidiKeyboardVisible =
135 new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard"));
136
137 private final Timer guiTimer = new Timer(1000, null);
138
139 /** Creates a new instance of <code>MainFrame</code> */
140 public
141 MainFrame() {
142 setTitle(i18n.getLabel("MainFrame.title"));
143 //setUndecorated(true);
144 if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
145
146 CC.setMainFrame(this); // TODO:
147 mainPane = new MainPane();
148 leftSidePane = new LeftSidePane();
149 rightSidePane = new RightSidePane();
150
151 setSelectedChannelsPane(mainPane.getChannelsPane(0));
152
153 getContentPane().add(standardBar, BorderLayout.NORTH);
154
155 rightPane = createRightPane();
156
157 hSplitPane = new JSplitPane (
158 JSplitPane.HORIZONTAL_SPLIT,
159 true, // continuousLayout
160 leftSidePane, rightPane
161 );
162 hSplitPane.setResizeWeight(0.5);
163
164 pianoKeyboardPane = new PianoKeyboardPane();
165
166 for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
167 addChannelsPane(mainPane.getChannelsPane(i));
168 getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
169 }
170
171 PropertyChangeListener l = new PropertyChangeListener() {
172 public void
173 propertyChange(PropertyChangeEvent e) {
174 onChangeChannelLaneCount();
175 }
176 };
177
178 preferences().addPropertyChangeListener("channelLanes.count", l);
179
180 int h = preferences().getIntProperty("midiKeyboard.height");
181 setMidiKeyboardHeight(h);
182
183 l = new PropertyChangeListener() {
184 public void
185 propertyChange(PropertyChangeEvent e) {
186 int h = preferences().getIntProperty("midiKeyboard.height");
187 setMidiKeyboardHeight(h);
188 }
189 };
190
191 CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
192
193 bottomPane = new BottomPane();
194
195 hSplitPane.setOpaque(false);
196 rootPane.add(hSplitPane);
197 rootPane.add(bottomPane, BorderLayout.SOUTH);
198 add(rootPane);
199
200 if(CC.isMacOS()) {
201 try {
202 String s = "org.jsampler.view.fantasia.MacOSApplicationHandler";
203 Class.forName(s).newInstance(); }
204 catch(Throwable e) { }
205 }
206
207 addMenu();
208
209 if(CC.getViewConfig().isUsingScreenMenuBar()) {
210 // fix for moving the menu bar on top of the screen
211 // when running on Mac OS and third party plugin is used
212 ((ViewConfig)CC.getViewConfig()).restoreMenuProperties();
213 }
214
215 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
216 hSplitPane.setDividerLocation(i);
217
218 setSavedSize();
219
220 guiTimer.start();
221 }
222
223 private JPanel
224 createRightPane() {
225 JPanel p = new FantasiaPanel();
226 p.setOpaque(false);
227
228 GridBagLayout gridbag = new GridBagLayout();
229 GridBagConstraints c = new GridBagConstraints();
230
231 p.setLayout(gridbag);
232
233 c.fill = GridBagConstraints.BOTH;
234
235 c.gridx = 1;
236 c.gridy = 0;
237 c.weightx = 1.0;
238 c.weighty = 1.0;
239 c.insets = new Insets(0, 3, 0, 0);
240 gridbag.setConstraints(rightSidePane, c);
241 p.add(rightSidePane);
242
243 c.gridx = 0;
244 c.gridy = 0;
245 c.weightx = 0.0;
246 c.weighty = 1.0;
247 c.insets = new Insets(0, 0, 0, 3);
248 c.fill = GridBagConstraints.VERTICAL;
249 gridbag.setConstraints(mainPane, c);
250 p.add(mainPane);
251
252 return p;
253 }
254
255 private void
256 setSavedSize() {
257 Rectangle r = StdUtils.getWindowBounds("MainFrame");
258 if(r == null) {
259 setDefaultSizeAndLocation();
260 return;
261 }
262
263 setBounds(r);
264 }
265
266 private void
267 setDefaultSizeAndLocation() {
268 setPreferredSize(new Dimension(900, 600));
269 pack();
270 setLocationRelativeTo(null);
271 }
272
273
274 /** Invoked when this window is about to close. */
275 @Override
276 public void
277 onWindowClose() {
278 boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
279 if(b && CC.getSamplerModel().isModified()) {
280 JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
281 dlg.setVisible(true);
282 if(dlg.isCancelled()) return;
283 }
284
285 leftSidePane.savePreferences();
286 rightSidePane.savePreferences();
287
288 int i = hSplitPane.getDividerLocation();
289 preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
290
291 preferences().setBoolProperty (
292 "MainFrame.windowMaximized",
293 (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
294 );
295
296 if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
297 super.onWindowClose();
298 return;
299 }
300
301 StdUtils.saveWindowBounds("MainFrame", getBounds());
302
303 String[] list = recentScripts.toArray(new String[recentScripts.size()]);
304 preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
305
306 if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
307 if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
308 }
309
310 if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer();
311 if(getLSConsolePane() != null) getLSConsolePane().disconnect();
312
313 super.onWindowClose();
314 }
315
316 private void
317 onChangeChannelLaneCount() {
318 int newCount = preferences().getIntProperty("channelLanes.count");
319 if(newCount < 1 || newCount > MAX_CHANNEL_LANE_NUMBER) return;
320 if(newCount == getChannelsPaneCount()) return;
321 int current = getChannelsPaneIndex(getSelectedChannelsPane());
322
323 if(newCount > getChannelsPaneCount()) {
324 int d = newCount - getChannelsPaneCount();
325 for(int i = 0; i < d; i++) {
326 JSChannelsPane p = mainPane.addChannelsPane();
327 addChannelsPane(p);
328 p.addListSelectionListener(pianoKeyboardPane);
329 }
330 } else {
331 int d = getChannelsPaneCount() - newCount;
332 for(int i = 0; i < d; i++) {
333 int idx = getChannelsPaneCount() - 1 - i;
334 if(getChannelsPane(idx).getChannelCount() > 0) {
335 String s;
336 s = i18n.getError("MainFrame.notEmptyChannelLane!", idx + 1);
337 HF.showErrorMessage(s);
338 return;
339 }
340 }
341
342 for(int i = 0; i < d; i++) {
343 int idx = getChannelsPaneCount() - 1;
344 JSChannelsPane p = getChannelsPane(idx);
345 removeChannelsPane(p);
346 p.removeListSelectionListener(pianoKeyboardPane);
347 mainPane.removeChannelsPane(idx);
348 }
349 }
350
351 if(newCount == 1) {
352 mainPane.getButtonsPanel().setVisible(false);
353 } else if(!mainPane.getButtonsPanel().isVisible()) {
354 mainPane.getButtonsPanel().setVisible(true);
355 }
356 mainPane.getButtonsPanel().setButtonNumber(newCount);
357 if(current < 0 || current >= getChannelsPaneCount()) current = 0;
358 setSelectedChannelsPane(getChannelsPane(current));
359 }
360
361 @Override
362 public void
363 setVisible(boolean b) {
364 if(b == isVisible()) return;
365
366 super.setVisible(b);
367
368 if(b && preferences().getBoolProperty("MainFrame.windowMaximized")) {
369 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
370 }
371 }
372
373 private void
374 addMenu() {
375 JMenu m;
376 JMenuItem mi;
377
378 setJMenuBar(menuBar);
379
380 // Actions
381 m = new FantasiaMenu(i18n.getMenuLabel("actions"));
382
383 mi = new JMenuItem(a4n.refresh);
384 mi.setIcon(null);
385 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
386 m.add(mi);
387
388 mi = new JMenuItem(a4n.samplerInfo);
389 mi.setIcon(null);
390 m.add(mi);
391
392 mi = new JMenuItem(a4n.resetSampler);
393 mi.setIcon(null);
394 m.add(mi);
395
396 m.addSeparator();
397
398 JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
399 m.add(exportMenu);
400
401 int modKey = CC.getViewConfig().getDefaultModKey();
402
403 mi = new JMenuItem(a4n.exportSamplerConfig);
404 mi.setIcon(null);
405 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
406 exportMenu.add(mi);
407
408 mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
409 mi.setIcon(null);
410 exportMenu.add(mi);
411
412 m.addSeparator();
413
414 mi = new JMenuItem(a4n.loadScript);
415 mi.setIcon(null);
416 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
417 m.add(mi);
418
419 String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
420 for(String s : list) recentScripts.add(s);
421
422 updateRecentScriptsMenu();
423
424 m.add(recentScriptsMenu);
425
426 m.addSeparator();
427
428 mi = new JMenuItem(a4n.changeBackend);
429 mi.setIcon(null);
430 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
431 m.add(mi);
432
433 m.addSeparator();
434
435 mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
436 m.add(mi);
437 mi.addActionListener(new ActionListener() {
438 public void
439 actionPerformed(ActionEvent e) { onWindowClose(); }
440 });
441
442 menuBar.add(m);
443
444
445 // Edit
446 m = new FantasiaMenu(i18n.getMenuLabel("edit"));
447 menuBar.add(m);
448
449 mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel"));
450 m.add(mi);
451 mi.addActionListener(new ActionListener() {
452 public void
453 actionPerformed(ActionEvent e) {
454 CC.getSamplerModel().addBackendChannel();
455 }
456 });
457
458 m.addSeparator();
459
460 mi = new JMenuItem(a4n.createMidiDevice);
461 mi.setIcon(null);
462 m.add(mi);
463
464 mi = new JMenuItem(a4n.createAudioDevice);
465 mi.setIcon(null);
466 m.add(mi);
467
468 m.addSeparator();
469
470 mi = new JMenuItem(a4n.editPreferences);
471 mi.setIcon(null);
472 mi.setAccelerator(KeyStroke.getKeyStroke (
473 KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
474 ));
475 m.add(mi);
476
477 // View
478 m = new FantasiaMenu(i18n.getMenuLabel("view"));
479 menuBar.add(m);
480
481 m.add(cbmiToolBarVisible);
482
483 cbmiToolBarVisible.addActionListener(new ActionListener() {
484 public void
485 actionPerformed(ActionEvent e) {
486 showToolBar(cbmiToolBarVisible.getState());
487 }
488 });
489
490 boolean b = preferences().getBoolProperty("toolBar.visible");
491 cbmiToolBarVisible.setSelected(b);
492 showToolBar(b);
493
494 cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
495 KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
496 ));
497 m.add(cbmiLeftSidePaneVisible);
498
499 cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
500 public void
501 actionPerformed(ActionEvent e) {
502 showSidePane(cbmiLeftSidePaneVisible.getState());
503 }
504 });
505
506 b = preferences().getBoolProperty("leftSidePane.visible");
507 cbmiLeftSidePaneVisible.setSelected(b);
508 showSidePane(b);
509
510 cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
511 KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
512 ));
513 m.add(cbmiRightSidePaneVisible);
514
515 cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
516 public void
517 actionPerformed(ActionEvent e) {
518 showDevicesPane(cbmiRightSidePaneVisible.getState());
519 }
520 });
521
522 b = preferences().getBoolProperty("rightSidePane.visible");
523 cbmiRightSidePaneVisible.setSelected(b);
524 showDevicesPane(b);
525
526 m.addSeparator();
527
528 m.add(cbmiMidiKeyboardVisible);
529
530 cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {
531 public void
532 actionPerformed(ActionEvent e) {
533 setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState());
534 }
535 });
536
537 b = preferences().getBoolProperty("midiKeyboard.visible");
538 cbmiMidiKeyboardVisible.setSelected(b);
539 setMidiKeyboardVisible(b);
540
541
542 // Channels
543 m = new FantasiaMenu(i18n.getMenuLabel("channels"));
544
545 mi = new JMenuItem(i18n.getMenuLabel("channels.newChannel"));
546 mi.addActionListener(new ActionListener() {
547 public void
548 actionPerformed(ActionEvent e) {
549 CC.getSamplerModel().addBackendChannel();
550 }
551 });
552 m.add(mi);
553
554 m.addSeparator();
555
556 MenuManager.ChannelViewGroup group = new MenuManager.ChannelViewGroup();
557 MenuManager.getMenuManager().registerChannelViewGroup(group);
558
559 for(JMenuItem menuItem : group.getMenuItems()) m.add(menuItem);
560
561 m.addSeparator();
562
563 m.add(new JMenuItem(a4n.moveChannelsOnTop));
564 m.add(new JMenuItem(a4n.moveChannelsUp));
565 m.add(new JMenuItem(a4n.moveChannelsDown));
566 m.add(new JMenuItem(a4n.moveChannelsAtBottom));
567
568 m.add(new ToPanelMenu());
569
570 m.addSeparator();
571
572 mi = new JMenuItem(a4n.selectAllChannels);
573 mi.setIcon(null);
574 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey));
575 m.add(mi);
576
577 mi = new JMenuItem(a4n.deselectChannels);
578 mi.setIcon(null);
579 mi.setAccelerator(KeyStroke.getKeyStroke (
580 KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK
581 ));
582 m.add(mi);
583
584 menuBar.add(m);
585
586 // Window
587 m = new FantasiaMenu(i18n.getMenuLabel("window"));
588 menuBar.add(m);
589
590 mi = new JMenuItem(a4n.windowLSConsole);
591 mi.setIcon(null);
592 m.add(mi);
593
594 mi = new JMenuItem(a4n.windowInstrumentsDb);
595 mi.setIcon(null);
596 m.add(mi);
597
598 m.addSeparator();
599
600 final JMenuItem mi2 = new JMenuItem(i18n.getMenuLabel("window.backendLog"));
601 m.add(mi2);
602 mi2.addActionListener(new ActionListener() {
603 public void
604 actionPerformed(ActionEvent e) {
605 if(getBackendLogFrame().isVisible()) {
606 getBackendLogFrame().setVisible(false);
607 }
608
609 getBackendLogFrame().setVisible(true);
610 }
611 });
612
613 mi2.setEnabled(CC.getBackendProcess() != null);
614
615 CC.addBackendProcessListener(new ActionListener() {
616 public void
617 actionPerformed(ActionEvent e) {
618 mi2.setEnabled(CC.getBackendProcess() != null);
619 }
620 });
621
622
623 // Help
624 m = new FantasiaMenu(i18n.getMenuLabel("help"));
625
626 mi = new JMenuItem(a4n.browseOnlineTutorial);
627 mi.setIcon(null);
628 m.add(mi);
629
630 m.addSeparator();
631
632 mi = new JMenuItem(a4n.helpAbout);
633 mi.setIcon(null);
634 m.add(mi);
635
636 menuBar.add(m);
637 }
638
639 public static class ToPanelMenu extends FantasiaMenu implements ListSelectionListener {
640 public
641 ToPanelMenu() {
642 super(i18n.getMenuLabel("channels.toPanel"));
643 setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
644
645 CC.getMainFrame().addChannelsPaneSelectionListener(this);
646
647 for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
648 JSChannelsPane p = CC.getMainFrame().getChannelsPane(i);
649 add(new JMenuItem(new A4n.MoveChannelsToPanel(p)));
650 p.addListSelectionListener(this);
651 }
652 }
653
654 @Override
655 public void
656 valueChanged(ListSelectionEvent e) {
657 setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
658 }
659 }
660
661 public RightSidePane
662 getRightSidePane() { return rightSidePane; }
663
664 @Override
665 public A4n
666 getA4n() { return A4n.a4n; }
667
668 /**
669 * This method does nothing, because <b>Fantasia</b> has constant
670 * number of panes containing sampler channels, which can not be changed.
671 */
672 @Override
673 public void
674 insertChannelsPane(JSChannelsPane pane, int idx) {
675
676 }
677
678 @Override
679 public JSChannelsPane
680 getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); }
681
682 @Override
683 public void
684 setSelectedChannelsPane(JSChannelsPane pane) {
685 mainPane.setSelectedChannelsPane(pane);
686 fireChannelsPaneSelectionChanged();
687 }
688
689 @Override
690 public void
691 installJSamplerHome() {
692 JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
693 chooser.setVisible(true);
694 if(chooser.isCancelled()) return;
695
696 CC.changeJSamplerHome(chooser.getJSamplerHome());
697 }
698
699 @Override
700 public void
701 showDetailedErrorMessage(Frame owner, String err, String details) {
702 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
703 owner, Res.iconWarning32, i18n.getError("error"), err, details
704 );
705 dlg.setVisible(true);
706 }
707
708 @Override
709 public void
710 showDetailedErrorMessage(Dialog owner, String err, String details) {
711 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
712 owner, Res.iconWarning32, i18n.getError("error"), err, details
713 );
714 dlg.setVisible(true);
715 }
716
717 /**
718 * Gets the server address to which to connect. If the server should be
719 * manually selected, a dialog asking the user to choose a server is displayed.
720 */
721 @Override
722 public Server
723 getServer() {
724 boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
725 return getServer(b);
726 }
727
728 /**
729 * Gets the server address to which to connect. If the server should be
730 * manually selected, a dialog asking the user to choose a server is displayed.
731 * @param manualSelect Determines whether the server should be manually selected.
732 */
733 @Override
734 public Server
735 getServer(boolean manualSelect) {
736 if(manualSelect) {
737 JSConnectDlg dlg = new JSConnectDlg();
738 dlg.setVisible(true);
739
740 return dlg.getSelectedServer();
741 }
742
743 int i = preferences().getIntProperty(SERVER_INDEX);
744 int size = CC.getServerList().getServerCount();
745 if(size == 0) return null;
746 if(i >= size) return CC.getServerList().getServer(0);
747
748 return CC.getServerList().getServer(i);
749 }
750
751 public Timer
752 getGuiTimer() { return guiTimer; }
753
754 @Override
755 public LSConsoleModel
756 getLSConsoleModel() { return getLSConsolePane().getModel(); }
757
758 protected LSConsolePane
759 getLSConsolePane() {
760 return getLSConsoleFrame().getLSConsolePane();
761 }
762
763 protected LSConsoleFrame
764 getLSConsoleFrame() { return lsConsoleFrame; }
765
766 public JSBackendLogFrame
767 getBackendLogFrame() { return backendLogFrame; }
768
769 protected boolean
770 runScript() {
771 File f = StdUtils.showOpenLscpFileChooser();
772 if(f == null) return false;
773 runScript(f);
774
775 return true;
776 }
777
778 @Override
779 public void
780 runScript(String script) { runScript(new File(script)); }
781
782 private void
783 runScript(File script) {
784 FileReader fr;
785 try { fr = new FileReader(script); }
786 catch(FileNotFoundException e) {
787 HF.showErrorMessage(i18n.getError("fileNotFound!"));
788 return;
789 }
790
791 String prefix = "#jsampler.fantasia: ";
792 Vector<String> v = new Vector<String>();
793 BufferedReader br = new BufferedReader(fr);
794
795 try {
796 String s = br.readLine();
797 while(s != null) {
798 getLSConsoleModel().setCommandLineText(s);
799 getLSConsoleModel().execCommand();
800 if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
801 s = br.readLine();
802 }
803 } catch(Exception e) {
804 HF.showErrorMessage(e);
805 return;
806 }
807
808 String s = script.getAbsolutePath();
809 recentScripts.remove(s);
810 recentScripts.insertElementAt(s, 0);
811
812 updateRecentScriptsMenu();
813
814 CC.getViewConfig().setSessionViewConfig(
815 new SessionViewConfig(v.toArray(new String[v.size()]))
816 );
817 }
818
819 protected void
820 clearRecentScripts() {
821 recentScripts.removeAllElements();
822 updateRecentScriptsMenu();
823 }
824
825 protected void
826 updateRecentScriptsMenu() {
827 int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
828 while(recentScripts.size() > size) {
829 recentScripts.removeElementAt(recentScripts.size() - 1);
830 }
831
832 recentScriptsMenu.removeAll();
833
834 for(String script : recentScripts) {
835 JMenuItem mi = new JMenuItem(script);
836 recentScriptsMenu.add(mi);
837 mi.addActionListener(new RecentScriptHandler(script));
838 }
839
840 recentScriptsMenu.setEnabled(recentScripts.size() != 0);
841 }
842
843 private void
844 showToolBar(boolean b) {
845 preferences().setBoolProperty("toolBar.visible", b);
846 standardBar.setVisible(b);
847 }
848
849 private void
850 showSidePane(boolean b) {
851 preferences().setBoolProperty("leftSidePane.visible", b);
852 rootPane.remove(rightPane);
853 rootPane.remove(hSplitPane);
854
855 if(b) {
856 hSplitPane.setRightComponent(rightPane);
857 rootPane.add(hSplitPane);
858 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
859
860 hSplitPane.setDividerLocation(i);
861 hSplitPane.validate();
862 } else {
863 rootPane.add(rightPane);
864
865 }
866
867 int w = getPreferredSize().width;
868 int h = getSize().height;
869 setSize(new Dimension(w, h));
870
871 rootPane.revalidate();
872 rootPane.validate();
873 rootPane.repaint();
874
875 SwingUtilities.invokeLater(new Runnable() {
876 public void
877 run() { sidePanesVisibilityChanged(); }
878 });
879 }
880
881 private void
882 showDevicesPane(boolean b) {
883 preferences().setBoolProperty("rightSidePane.visible", b);
884
885 int width = leftSidePane.getWidth();
886 int height = leftSidePane.getPreferredSize().height;
887 if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
888
889 if(b) {
890 int w = preferences().getIntProperty("devicesPane.width", 200);
891
892 int h = rightSidePane.getPreferredSize().height;
893 rightSidePane.setPreferredSize(new Dimension(w, h));
894 } else {
895 int w = rightSidePane.getWidth();
896 if(w > 0 && w < 200) w = 200;
897 if(w != 0) preferences().setIntProperty("devicesPane.width", w);
898 }
899
900 hSplitPane.setResizeWeight(0.0);
901 rightSidePane.setVisible(b);
902 hSplitPane.resetToPreferredSizes();
903
904 int w = getPreferredSize().width;
905 int h = getSize().height;
906 setSize(new Dimension(w, h));
907
908 rootPane.validate();
909 rootPane.repaint();
910 //hSplitPane.validate();
911
912 SwingUtilities.invokeLater(new Runnable() {
913 public void
914 run() { sidePanesVisibilityChanged(); }
915 });
916 }
917
918 public void
919 setMidiKeyboardVisible(boolean b) {
920 preferences().setBoolProperty("midiKeyboard.visible", b);
921 pianoKeyboardPane.setVisible(b);
922
923 if(cbmiMidiKeyboardVisible.isSelected() != b) {
924 cbmiMidiKeyboardVisible.setSelected(b);
925 }
926
927 if(standardBar.btnMidiKeyboard.isSelected() != b) {
928 standardBar.btnMidiKeyboard.setSelected(b);
929 }
930
931 if(pianoKeyboardPane.btnPower.isSelected() != b) {
932 pianoKeyboardPane.btnPower.setSelected(b);
933 }
934
935 rootPane.validate();
936 rootPane.repaint();
937 }
938
939 public void
940 setMidiKeyboardHeight(int height) {
941 Dimension d = pianoKeyboardPane.getPreferredSize();
942 d = new Dimension(d.width, height);
943 pianoKeyboardPane.setPreferredSize(d);
944 pianoKeyboardPane.setMinimumSize(d);
945 pianoKeyboardPane.revalidate();
946 pianoKeyboardPane.repaint();
947 }
948
949 private void
950 sidePanesVisibilityChanged() {
951 boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
952 boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
953
954 if(leftSidePaneVisible && rightSidePaneVisible) {
955 hSplitPane.setResizeWeight(0.5);
956 } else if(leftSidePaneVisible && !rightSidePaneVisible) {
957 hSplitPane.setResizeWeight(1.0);
958 }
959
960 if(!leftSidePaneVisible && !rightSidePaneVisible) {
961 standardBar.showFantasiaLogo(false);
962 if(isResizable()) setResizable(false);
963 } else {
964 standardBar.showFantasiaLogo(true);
965 if(!isResizable()) setResizable(true);
966 }
967 }
968
969 private class RecentScriptHandler implements ActionListener {
970 private String script;
971
972 RecentScriptHandler(String script) { this.script = script; }
973
974 @Override
975 public void
976 actionPerformed(ActionEvent e) {
977 runScript(script);
978 if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
979 a4n.windowLSConsole.actionPerformed(null);
980 }
981 }
982 }
983
984 private static class FantasiaMenu extends JMenu {
985 FantasiaMenu(String s) {
986 super(s);
987 setFont(getFont().deriveFont(java.awt.Font.BOLD));
988 setOpaque(false);
989 setContentAreaFilled(false);
990 }
991 }
992
993 private class FantasiaMenuBar extends JMenuBar {
994 FantasiaMenuBar() {
995 setOpaque(false);
996 setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
997 }
998
999 @Override
1000 protected void
1001 paintComponent(Graphics g) {
1002 //super.paintComponent(g);
1003 Graphics2D g2 = (Graphics2D)g;
1004
1005 Paint oldPaint = g2.getPaint();
1006 Composite oldComposite = g2.getComposite();
1007
1008 double h = getSize().getHeight();
1009 double w = getSize().getWidth();
1010
1011 FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
1012
1013 FantasiaPainter.Border b;
1014
1015
1016 if(standardBar.isVisible()) {
1017 b = new FantasiaPainter.Border(true, true, false, true);
1018 FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
1019 } else {
1020 b = new FantasiaPainter.Border(true, true, true, true);
1021 FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
1022 }
1023
1024 g2.setPaint(oldPaint);
1025 g2.setComposite(oldComposite);
1026 }
1027 }
1028
1029 class RootPane extends FantasiaSubPanel {
1030 private final Color color1 = new Color(0x454545);
1031 private final Color color2 = new Color(0x2e2e2e);
1032
1033 RootPane() {
1034 setLayout(new BorderLayout());
1035 setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
1036 setOpaque(false);
1037
1038 }
1039
1040 @Override
1041 public void
1042 paintComponent(Graphics g) {
1043 Graphics2D g2 = (Graphics2D)g;
1044
1045 Paint oldPaint = g2.getPaint();
1046 Composite oldComposite = g2.getComposite();
1047
1048 double h = getSize().getHeight();
1049 double w = getSize().getWidth();
1050
1051 FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
1052 paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
1053
1054 g2.setPaint(oldPaint);
1055 g2.setComposite(oldComposite);
1056 }
1057 }
1058
1059 class BottomPane extends FantasiaPanel {
1060 BottomPane() {
1061 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1062 setOpaque(false);
1063 add(pianoKeyboardPane);
1064
1065 }
1066 }
1067 }

  ViewVC Help
Powered by ViewVC