/[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 1872 - (show annotations) (download)
Mon Mar 23 15:34:50 2009 UTC (15 years, 1 month ago) by iliev
File size: 27987 byte(s)
* Variable number of channel lanes
  (choose Edit/Preferences, then click the `Channels' tab)

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 protected LSConsoleModel
755 getLSConsoleModel() { return getLSConsolePane().getModel(); }
756
757 protected LSConsolePane
758 getLSConsolePane() {
759 return getLSConsoleFrame().getLSConsolePane();
760 }
761
762 protected LSConsoleFrame
763 getLSConsoleFrame() { return lsConsoleFrame; }
764
765 public JSBackendLogFrame
766 getBackendLogFrame() { return backendLogFrame; }
767
768 protected boolean
769 runScript() {
770 File f = StdUtils.showOpenLscpFileChooser();
771 if(f == null) return false;
772 runScript(f);
773
774 return true;
775 }
776
777 @Override
778 public void
779 runScript(String script) { runScript(new File(script)); }
780
781 private void
782 runScript(File script) {
783 FileReader fr;
784 try { fr = new FileReader(script); }
785 catch(FileNotFoundException e) {
786 HF.showErrorMessage(i18n.getError("fileNotFound!"));
787 return;
788 }
789
790 String prefix = "#jsampler.fantasia: ";
791 Vector<String> v = new Vector<String>();
792 BufferedReader br = new BufferedReader(fr);
793
794 try {
795 String s = br.readLine();
796 while(s != null) {
797 getLSConsoleModel().setCommandLineText(s);
798 getLSConsoleModel().execCommand();
799 if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
800 s = br.readLine();
801 }
802 } catch(Exception e) {
803 HF.showErrorMessage(e);
804 return;
805 }
806
807 String s = script.getAbsolutePath();
808 recentScripts.remove(s);
809 recentScripts.insertElementAt(s, 0);
810
811 updateRecentScriptsMenu();
812
813 CC.getViewConfig().setSessionViewConfig(
814 new SessionViewConfig(v.toArray(new String[v.size()]))
815 );
816 }
817
818 protected void
819 clearRecentScripts() {
820 recentScripts.removeAllElements();
821 updateRecentScriptsMenu();
822 }
823
824 protected void
825 updateRecentScriptsMenu() {
826 int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
827 while(recentScripts.size() > size) {
828 recentScripts.removeElementAt(recentScripts.size() - 1);
829 }
830
831 recentScriptsMenu.removeAll();
832
833 for(String script : recentScripts) {
834 JMenuItem mi = new JMenuItem(script);
835 recentScriptsMenu.add(mi);
836 mi.addActionListener(new RecentScriptHandler(script));
837 }
838
839 recentScriptsMenu.setEnabled(recentScripts.size() != 0);
840 }
841
842 private void
843 showToolBar(boolean b) {
844 preferences().setBoolProperty("toolBar.visible", b);
845 standardBar.setVisible(b);
846 }
847
848 private void
849 showSidePane(boolean b) {
850 preferences().setBoolProperty("leftSidePane.visible", b);
851 rootPane.remove(rightPane);
852 rootPane.remove(hSplitPane);
853
854 if(b) {
855 hSplitPane.setRightComponent(rightPane);
856 rootPane.add(hSplitPane);
857 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
858
859 hSplitPane.setDividerLocation(i);
860 hSplitPane.validate();
861 } else {
862 rootPane.add(rightPane);
863
864 }
865
866 int w = getPreferredSize().width;
867 int h = getSize().height;
868 setSize(new Dimension(w, h));
869
870 rootPane.revalidate();
871 rootPane.validate();
872 rootPane.repaint();
873
874 SwingUtilities.invokeLater(new Runnable() {
875 public void
876 run() { sidePanesVisibilityChanged(); }
877 });
878 }
879
880 private void
881 showDevicesPane(boolean b) {
882 preferences().setBoolProperty("rightSidePane.visible", b);
883
884 int width = leftSidePane.getWidth();
885 int height = leftSidePane.getPreferredSize().height;
886 if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
887
888 if(b) {
889 int w = preferences().getIntProperty("devicesPane.width", 200);
890
891 int h = rightSidePane.getPreferredSize().height;
892 rightSidePane.setPreferredSize(new Dimension(w, h));
893 } else {
894 int w = rightSidePane.getWidth();
895 if(w > 0 && w < 200) w = 200;
896 if(w != 0) preferences().setIntProperty("devicesPane.width", w);
897 }
898
899 hSplitPane.setResizeWeight(0.0);
900 rightSidePane.setVisible(b);
901 hSplitPane.resetToPreferredSizes();
902
903 int w = getPreferredSize().width;
904 int h = getSize().height;
905 setSize(new Dimension(w, h));
906
907 rootPane.validate();
908 rootPane.repaint();
909 //hSplitPane.validate();
910
911 SwingUtilities.invokeLater(new Runnable() {
912 public void
913 run() { sidePanesVisibilityChanged(); }
914 });
915 }
916
917 public void
918 setMidiKeyboardVisible(boolean b) {
919 preferences().setBoolProperty("midiKeyboard.visible", b);
920 pianoKeyboardPane.setVisible(b);
921
922 if(cbmiMidiKeyboardVisible.isSelected() != b) {
923 cbmiMidiKeyboardVisible.setSelected(b);
924 }
925
926 if(standardBar.btnMidiKeyboard.isSelected() != b) {
927 standardBar.btnMidiKeyboard.setSelected(b);
928 }
929
930 if(pianoKeyboardPane.btnPower.isSelected() != b) {
931 pianoKeyboardPane.btnPower.setSelected(b);
932 }
933
934 rootPane.validate();
935 rootPane.repaint();
936 }
937
938 public void
939 setMidiKeyboardHeight(int height) {
940 Dimension d = pianoKeyboardPane.getPreferredSize();
941 d = new Dimension(d.width, height);
942 pianoKeyboardPane.setPreferredSize(d);
943 pianoKeyboardPane.setMinimumSize(d);
944 pianoKeyboardPane.revalidate();
945 pianoKeyboardPane.repaint();
946 }
947
948 private void
949 sidePanesVisibilityChanged() {
950 boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
951 boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
952
953 if(leftSidePaneVisible && rightSidePaneVisible) {
954 hSplitPane.setResizeWeight(0.5);
955 } else if(leftSidePaneVisible && !rightSidePaneVisible) {
956 hSplitPane.setResizeWeight(1.0);
957 }
958
959 if(!leftSidePaneVisible && !rightSidePaneVisible) {
960 standardBar.showFantasiaLogo(false);
961 if(isResizable()) setResizable(false);
962 } else {
963 standardBar.showFantasiaLogo(true);
964 if(!isResizable()) setResizable(true);
965 }
966 }
967
968 private class RecentScriptHandler implements ActionListener {
969 private String script;
970
971 RecentScriptHandler(String script) { this.script = script; }
972
973 @Override
974 public void
975 actionPerformed(ActionEvent e) {
976 runScript(script);
977 if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
978 a4n.windowLSConsole.actionPerformed(null);
979 }
980 }
981 }
982
983 private static class FantasiaMenu extends JMenu {
984 FantasiaMenu(String s) {
985 super(s);
986 setFont(getFont().deriveFont(java.awt.Font.BOLD));
987 setOpaque(false);
988 setContentAreaFilled(false);
989 }
990 }
991
992 private class FantasiaMenuBar extends JMenuBar {
993 FantasiaMenuBar() {
994 setOpaque(false);
995 setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
996 }
997
998 @Override
999 protected void
1000 paintComponent(Graphics g) {
1001 //super.paintComponent(g);
1002 Graphics2D g2 = (Graphics2D)g;
1003
1004 Paint oldPaint = g2.getPaint();
1005 Composite oldComposite = g2.getComposite();
1006
1007 double h = getSize().getHeight();
1008 double w = getSize().getWidth();
1009
1010 FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
1011
1012 FantasiaPainter.Border b;
1013
1014
1015 if(standardBar.isVisible()) {
1016 b = new FantasiaPainter.Border(true, true, false, true);
1017 FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
1018 } else {
1019 b = new FantasiaPainter.Border(true, true, true, true);
1020 FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
1021 }
1022
1023 g2.setPaint(oldPaint);
1024 g2.setComposite(oldComposite);
1025 }
1026 }
1027
1028 class RootPane extends FantasiaSubPanel {
1029 private final Color color1 = new Color(0x454545);
1030 private final Color color2 = new Color(0x2e2e2e);
1031
1032 RootPane() {
1033 setLayout(new BorderLayout());
1034 setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
1035 setOpaque(false);
1036
1037 }
1038
1039 @Override
1040 public void
1041 paintComponent(Graphics g) {
1042 Graphics2D g2 = (Graphics2D)g;
1043
1044 Paint oldPaint = g2.getPaint();
1045 Composite oldComposite = g2.getComposite();
1046
1047 double h = getSize().getHeight();
1048 double w = getSize().getWidth();
1049
1050 FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
1051 paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
1052
1053 g2.setPaint(oldPaint);
1054 g2.setComposite(oldComposite);
1055 }
1056 }
1057
1058 class BottomPane extends FantasiaPanel {
1059 BottomPane() {
1060 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1061 setOpaque(false);
1062 add(pianoKeyboardPane);
1063
1064 }
1065 }
1066 }

  ViewVC Help
Powered by ViewVC