/[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 2192 - (show annotations) (download)
Fri Jun 24 21:34:51 2011 UTC (12 years, 10 months ago) by iliev
File size: 29140 byte(s)
* Initial implementation of Sampler Browser
  (choose Window/Sampler Browser) - another way to view/edit
  the sampler configuration (work in progress - for now only
  support for viewing/editing send effects)

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

  ViewVC Help
Powered by ViewVC