/[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 2288 - (show annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 29324 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

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

  ViewVC Help
Powered by ViewVC