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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1864 - (show annotations) (download)
Sat Mar 14 20:44:58 2009 UTC (15 years, 1 month ago) by iliev
File size: 34136 byte(s)
* Fixed bug in the parameter table when editing
  string list parameters with no possibilities
* Mac OS integration, work in progress:
* ant: added new target build-fantasia-osx
* Moved the menu bar on top of the screen
* Use custom application icon
* Register LSCP scripts to be opened with Fantasia
* Changed shortcut keys (use command key instead of ctrl key)

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.classic;
24
25 import java.awt.BorderLayout;
26 import java.awt.Color;
27 import java.awt.Dialog;
28 import java.awt.Dimension;
29 import java.awt.Frame;
30 import java.awt.Rectangle;
31
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.awt.event.KeyEvent;
35
36 import java.io.BufferedReader;
37 import java.io.File;
38 import java.io.FileNotFoundException;
39 import java.io.FileReader;
40
41 import java.util.Vector;
42
43 import javax.swing.Action;
44 import javax.swing.ImageIcon;
45 import javax.swing.JCheckBoxMenuItem;
46 import javax.swing.JFileChooser;
47 import javax.swing.JMenu;
48 import javax.swing.JMenuBar;
49 import javax.swing.JMenuItem;
50 import javax.swing.JPanel;
51 import javax.swing.JSplitPane;
52 import javax.swing.JTabbedPane;
53 import javax.swing.KeyStroke;
54
55 import javax.swing.event.ChangeEvent;
56 import javax.swing.event.ChangeListener;
57 import javax.swing.event.ListSelectionEvent;
58 import javax.swing.event.ListSelectionListener;
59
60 import net.sf.juife.NavigationPage;
61
62 import org.jsampler.CC;
63 import org.jsampler.HF;
64 import org.jsampler.LSConsoleModel;
65 import org.jsampler.OrchestraModel;
66 import org.jsampler.Server;
67
68 import org.jsampler.view.JSChannel;
69 import org.jsampler.view.JSChannelsPane;
70 import org.jsampler.view.LscpFileFilter;
71
72 import org.jsampler.view.std.JSBackendLogFrame;
73 import org.jsampler.view.std.JSConnectDlg;
74 import org.jsampler.view.std.JSDetailedErrorDlg;
75 import org.jsampler.view.std.JSQuitDlg;
76 import org.jsampler.view.std.JSamplerHomeChooser;
77 import org.jsampler.view.std.StdUtils;
78
79 import static org.jsampler.view.classic.A4n.a4n;
80 import static org.jsampler.view.classic.ClassicI18n.i18n;
81 import static org.jsampler.view.classic.ClassicPrefs.preferences;
82 import static org.jsampler.view.classic.LeftPane.getLeftPane;
83 import static org.jsampler.view.std.StdPrefs.*;
84
85 /**
86 *
87 * @author Grigor Iliev
88 */
89 public class
90 MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener {
91 public static ImageIcon applicationIcon = Res.appIcon;
92
93 private final ChannelsBar channelsBar = new ChannelsBar();
94 private final Statusbar statusbar = new Statusbar();
95 private final JMenuBar menuBar = new JMenuBar();
96 private final JMenu recentScriptsMenu =
97 new JMenu(i18n.getMenuLabel("actions.recentScripts"));
98 private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab"));
99
100 private final JSplitPane vSplitPane;
101 private final JSplitPane hSplitPane;
102
103 private final JPanel mainPane = new JPanel();
104 private final StandardBar standardBar = new StandardBar();
105 private final JPanel channelsPane = new JPanel(new BorderLayout());
106 private final JPanel rightPane = new JPanel();
107 private final JPanel bottomPane = new JPanel();
108 private final LSConsolePane lsConsolePane = new LSConsolePane(this);
109 private LSConsoleDlg lsConsoleDlg = null;
110 private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
111
112 private final JTabbedPane tabbedPane =
113 new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT);
114 private final Vector<JMenuItem> miList = new Vector<JMenuItem>();
115
116 private final JCheckBoxMenuItem cbmiLeftPaneVisible =
117 new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane"));
118
119 private final JCheckBoxMenuItem cbmiStandardBarVisible =
120 new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.standard"));
121
122 private final JCheckBoxMenuItem cbmiLSConsoleShown =
123 new JCheckBoxMenuItem(i18n.getMenuLabel("view.lsconsole"));
124
125 private boolean lsConsolePopOut;
126
127 private final Vector<String> recentScripts = new Vector<String>();
128
129
130 /** Creates a new instance of <code>MainFrame</code>. */
131 public
132 MainFrame() {
133 setTitle(i18n.getLabel("MainFrame.title"));
134
135 CC.setMainFrame(this); // TODO:
136
137 getContentPane().add(standardBar, BorderLayout.NORTH);
138 getContentPane().add(mainPane);
139
140 mainPane.setLayout(new BorderLayout());
141 mainPane.add(statusbar, BorderLayout.SOUTH);
142
143 ChannelsPane p = new ChannelsPane("Untitled");
144 p.addListSelectionListener(this);
145 getChannelsPaneList().add(p);
146 miList.add(new JMenuItem(new A4n.MoveChannelsTo(p)));
147
148 channelsPane.add(getChannelsPane(0));
149
150 bottomPane.setLayout(new BorderLayout());
151
152 rightPane.setLayout(new BorderLayout());
153
154 rightPane.add(channelsBar, BorderLayout.NORTH);
155 rightPane.add(channelsPane);
156
157 hSplitPane = new JSplitPane (
158 JSplitPane.HORIZONTAL_SPLIT,
159 true, // continuousLayout
160 getLeftPane(),
161 rightPane
162 );
163
164 hSplitPane.setOneTouchExpandable(true);
165 if(ClassicPrefs.getSaveWindowProperties()) {
166 hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation());
167 }
168
169 mainPane.add(hSplitPane);
170
171
172 vSplitPane = new JSplitPane (
173 JSplitPane.VERTICAL_SPLIT,
174 true, // continuousLayout
175 channelsPane,
176 bottomPane
177 );
178
179 vSplitPane.setDividerSize(3);
180 vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
181
182 rightPane.add(vSplitPane);
183
184 if(applicationIcon != null) setIconImage(applicationIcon.getImage());
185
186 initMainFrame();
187
188 pack();
189
190 if(ClassicPrefs.getSaveWindowProperties()) setSavedSize();
191 else setDefaultSize();
192
193 if(ClassicPrefs.getSaveLeftPaneState()) {
194 NavigationPage page =
195 getLeftPane().getPages()[ClassicPrefs.getLeftPanePageIndex()];
196
197 getLeftPane().getModel().addPage(page);
198 getLeftPane().getModel().clearHistory();
199
200 int idx = ClassicPrefs.getCurrentOrchestraIndex();
201 if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) {
202 OrchestraModel om = CC.getOrchestras().getOrchestra(idx);
203 getLeftPane().getOrchestrasPage().setSelectedOrchestra(om);
204 }
205 }
206
207 //CC.getInstrumentsDbTreeModel(); // used to initialize the db tree model
208 }
209
210 /** Invoked when this window is about to close. */
211 @Override
212 public void
213 onWindowClose() {
214 boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
215 if(b && CC.getSamplerModel().isModified()) {
216 JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
217 dlg.setVisible(true);
218 if(dlg.isCancelled()) return;
219 }
220
221 if(ClassicPrefs.getSaveWindowProperties()) {
222 ClassicPrefs.setWindowMaximized (
223 "Mainframe", (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
224 );
225
226 setVisible(false);
227 if(ClassicPrefs.getWindowMaximized("MainFrame")) {
228 //setExtendedState(getExtendedState() & ~MAXIMIZED_BOTH);
229 CC.cleanExit();
230 return;
231 }
232
233 StdUtils.saveWindowBounds("MainFrame", getBounds());
234
235 ClassicPrefs.setHSplitDividerLocation(hSplitPane.getDividerLocation());
236 }
237
238 if(ClassicPrefs.getSaveLeftPaneState()) {
239 int idx = 0;
240 for(int i = 0; i < getLeftPane().getPages().length; i++) {
241 if(getLeftPane().getPages()[i] == getLeftPane().getCurrentPage()) {
242 idx = i;
243 break;
244 }
245 }
246
247 ClassicPrefs.setLeftPanePageIndex(idx);
248
249 idx = getLeftPane().getOrchestrasPage().getCurrentOrchestraIndex();
250
251 if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount())
252 ClassicPrefs.setCurrentOrchestraIndex(idx);
253 }
254
255 String[] list = recentScripts.toArray(new String[recentScripts.size()]);
256 preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
257
258 if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
259 lsConsolePane.saveConsoleHistory();
260 }
261
262 ClassicPrefs.setShowLSConsole(isLSConsoleShown());
263 ClassicPrefs.setLSConsolePopOut(isLSConsolePopOut());
264
265 ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation());
266
267 if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer();
268 if(lsConsolePane != null) lsConsolePane.disconnect();
269 super.onWindowClose();
270 }
271
272 @Override
273 public void
274 setVisible(boolean b) {
275 if(b == isVisible()) return;
276
277 super.setVisible(b);
278
279 if(ClassicPrefs.getWindowMaximized("MainFrame")) {
280 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
281 }
282 }
283
284 private void
285 initMainFrame() {
286 addMenu();
287 handleEvents();
288 }
289
290 private void
291 setDefaultSize() {
292 Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
293 double width = dimension.getWidth();
294 double height = dimension.getHeight();
295 setBounds(50, 100, (int) width - 100, (int) height - 200);
296 }
297
298 private void
299 setSavedSize() {
300 Rectangle r = StdUtils.getWindowBounds("MainFrame");
301 if(r == null) {
302 setDefaultSize();
303 return;
304 }
305
306 setBounds(r);
307 }
308
309 private void
310 addMenu() {
311 JMenu m;
312 JMenuItem mi;
313
314 setJMenuBar(menuBar);
315
316 // Actions
317 m = new JMenu(i18n.getMenuLabel("actions"));
318 menuBar.add(m);
319
320 mi = new JMenuItem(a4n.refresh);
321 mi.setIcon(null);
322 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
323 m.add(mi);
324
325 mi = new JMenuItem(A4n.samplerInfo);
326 mi.setIcon(null);
327 m.add(mi);
328
329 mi = new JMenuItem(a4n.resetSampler);
330 mi.setIcon(null);
331 m.add(mi);
332
333 JMenu midiInstrMenu = new JMenu(i18n.getMenuLabel("actions.midiInstruments"));
334 m.add(midiInstrMenu);
335
336 mi = new JMenuItem(A4n.addMidiInstrumentMap);
337 mi.setIcon(null);
338 midiInstrMenu.add(mi);
339
340 mi = new JMenuItem(A4n.removeMidiInstrumentMap);
341 mi.setIcon(null);
342 midiInstrMenu.add(mi);
343
344 mi = new JMenuItem(A4n.addMidiInstrumentWizard);
345 mi.setIcon(null);
346 midiInstrMenu.add(mi);
347
348 m.addSeparator();
349
350 JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
351 m.add(exportMenu);
352
353 int modKey = CC.getViewConfig().getDefaultModKey();
354 mi = new JMenuItem(a4n.exportSamplerConfig);
355 mi.setIcon(null);
356 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
357 exportMenu.add(mi);
358
359 mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
360 mi.setIcon(null);
361 exportMenu.add(mi);
362
363 m.addSeparator();
364
365 mi = new JMenuItem(A4n.loadScript);
366 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
367 mi.setIcon(null);
368 m.add(mi);
369
370 String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
371 for(String s : list) recentScripts.add(s);
372
373 updateRecentScriptsMenu();
374
375 m.add(recentScriptsMenu);
376
377 m.addSeparator();
378
379 mi = new JMenuItem(a4n.changeBackend);
380 mi.setIcon(null);
381 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
382 m.add(mi);
383
384 m.addSeparator();
385
386 mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
387 m.add(mi);
388 mi.addActionListener(new ActionListener() {
389 public void
390 actionPerformed(ActionEvent e) { onWindowClose(); }
391 });
392
393 // Edit
394 m = new JMenu(i18n.getMenuLabel("edit"));
395 menuBar.add(m);
396
397 mi = new JMenuItem(i18n.getMenuLabel("edit.audioDevices"));
398 m.add(mi);
399 mi.addActionListener(new ActionListener() {
400 public void
401 actionPerformed(ActionEvent e) {
402 if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0);
403 LeftPane.getLeftPane().showAudioDevicesPage();
404 }
405 });
406
407 mi = new JMenuItem(i18n.getMenuLabel("edit.midiDevices"));
408 m.add(mi);
409 mi.addActionListener(new ActionListener() {
410 public void
411 actionPerformed(ActionEvent e) {
412 if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0);
413 LeftPane.getLeftPane().showMidiDevicesPage();
414 }
415 });
416
417 mi = new JMenuItem(i18n.getMenuLabel("edit.orchestras"));
418 m.add(mi);
419 mi.addActionListener(new ActionListener() {
420 public void
421 actionPerformed(ActionEvent e) {
422 if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0);
423 LeftPane.getLeftPane().showManageOrchestrasPage();
424 }
425 });
426
427 m.addSeparator();
428
429 mi = new JMenuItem(A4n.preferences);
430 mi.setIcon(null);
431 mi.setAccelerator(KeyStroke.getKeyStroke (
432 KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
433 ));
434 m.add(mi);
435
436 // View
437 m = new JMenu(i18n.getMenuLabel("view"));
438 menuBar.add(m);
439
440 JMenu toolbarsMenu = new JMenu(i18n.getMenuLabel("view.toolbars"));
441 m.add(toolbarsMenu);
442
443 toolbarsMenu.add(cbmiStandardBarVisible);
444 cbmiStandardBarVisible.addActionListener(new ActionListener() {
445 public void
446 actionPerformed(ActionEvent e) {
447 showStandardBar(cbmiStandardBarVisible.getState());
448 }
449 });
450
451 boolean b = ClassicPrefs.shouldShowStandardBar();
452 cbmiStandardBarVisible.setSelected(b);
453 showStandardBar(b);
454
455 final JCheckBoxMenuItem cbmi =
456 new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.channels"));
457
458 toolbarsMenu.add(cbmi);
459 cbmi.addActionListener(new ActionListener() {
460 public void
461 actionPerformed(ActionEvent e) { showChannelsBar(cbmi.getState()); }
462 });
463
464 b = ClassicPrefs.shouldShowChannelsBar();
465 cbmi.setSelected(b);
466 showChannelsBar(b);
467
468 m.add(cbmiLeftPaneVisible);
469 cbmiLeftPaneVisible.addActionListener(new ActionListener() {
470 public void
471 actionPerformed(ActionEvent e) {
472 showLeftPane(cbmiLeftPaneVisible.getState());
473 }
474 });
475
476 b = ClassicPrefs.shouldShowLeftPane();
477 cbmiLeftPaneVisible.setSelected(b);
478 showLeftPane(b);
479
480 final JCheckBoxMenuItem cbmi2 =
481 new JCheckBoxMenuItem(i18n.getMenuLabel("view.statusbar"));
482
483 m.add(cbmi2);
484 cbmi2.addActionListener(new ActionListener() {
485 public void
486 actionPerformed(ActionEvent e) { showStatusbar(cbmi2.getState()); }
487 });
488 b = ClassicPrefs.shouldShowStatusbar();
489 cbmi2.setSelected(b);
490 showStatusbar(b);
491
492 m.addSeparator();
493
494 setLSConsolePopOut(ClassicPrefs.isLSConsolePopOut());
495 cbmiLSConsoleShown.setSelected(ClassicPrefs.shouldShowLSConsole());
496 showLSConsole(ClassicPrefs.shouldShowLSConsole());
497
498 cbmiLSConsoleShown.addActionListener(new ActionListener() {
499 public void
500 actionPerformed(ActionEvent e) {
501 showLSConsole(cbmiLSConsoleShown.isSelected());
502 }
503 });
504 m.add(cbmiLSConsoleShown);
505
506 lsConsolePane.updateLSConsoleViewMode();
507
508 // Channels
509 m = new JMenu(i18n.getMenuLabel("channels"));
510 menuBar.add(m);
511
512 mi = new JMenuItem(A4n.newChannel);
513 mi.setIcon(null);
514 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, modKey));
515 m.add(mi);
516
517 mi = new JMenuItem(A4n.newChannelWizard);
518 mi.setIcon(null);
519 mi.setAccelerator(KeyStroke.getKeyStroke (
520 KeyEvent.VK_N, modKey | KeyEvent.SHIFT_MASK)
521 );
522 m.add(mi);
523
524 mi = new JMenuItem(a4n.duplicateChannels);
525 mi.setIcon(null);
526 m.add(mi);
527
528 m.addSeparator();
529
530 mi = new JMenuItem(a4n.moveChannelsOnTop);
531 mi.setIcon(null);
532 mi.setAccelerator(KeyStroke.getKeyStroke (
533 KeyEvent.VK_UP, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK
534 ));
535 m.add(mi);
536
537 mi = new JMenuItem(a4n.moveChannelsUp);
538 mi.setIcon(null);
539 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK));
540 m.add(mi);
541
542 mi = new JMenuItem(a4n.moveChannelsDown);
543 mi.setIcon(null);
544 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_MASK));
545 m.add(mi);
546
547 mi = new JMenuItem(a4n.moveChannelsAtBottom);
548 mi.setIcon(null);
549 mi.setAccelerator(KeyStroke.getKeyStroke (
550 KeyEvent.VK_DOWN, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK
551 ));
552 m.add(mi);
553
554 tabsMenu.setEnabled(false);
555 m.add(tabsMenu);
556
557 m.addSeparator();
558
559 mi = new JMenuItem(a4n.selectAllChannels);
560 mi.setIcon(null);
561 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey));
562 m.add(mi);
563
564 mi = new JMenuItem(a4n.deselectChannels);
565 mi.setIcon(null);
566 mi.setAccelerator(KeyStroke.getKeyStroke (
567 KeyEvent.VK_A, KeyEvent.SHIFT_MASK | modKey
568 ));
569 m.add(mi);
570
571 m.addSeparator();
572
573 mi = new JMenuItem(a4n.removeChannels);
574 mi.setIcon(null);
575 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.SHIFT_MASK));
576 m.add(mi);
577
578
579 // Tabs
580 m = new JMenu(i18n.getMenuLabel("tabs"));
581 menuBar.add(m);
582
583 mi = new JMenuItem(A4n.newChannelsTab);
584 mi.setIcon(null);
585 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, modKey));
586 m.add(mi);
587
588 mi = new JMenuItem(A4n.editTabTitle);
589 mi.setIcon(null);
590 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
591 m.add(mi);
592
593 m.addSeparator();
594
595 mi = new JMenuItem(A4n.moveTab2Beginning);
596 mi.setIcon(null);
597 mi.setAccelerator(KeyStroke.getKeyStroke (
598 KeyEvent.VK_LEFT, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK
599 ));
600 m.add(mi);
601
602 mi = new JMenuItem(A4n.moveTab2Left);
603 mi.setIcon(null);
604 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK));
605 m.add(mi);
606
607 mi = new JMenuItem(A4n.moveTab2Right);
608 mi.setIcon(null);
609 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK));
610 m.add(mi);
611
612 mi = new JMenuItem(A4n.moveTab2End);
613 mi.setIcon(null);
614 mi.setAccelerator(KeyStroke.getKeyStroke (
615 KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK
616 ));
617 m.add(mi);
618
619 m.addSeparator();
620
621 mi = new JMenuItem(A4n.closeChannelsTab);
622 mi.setIcon(null);
623 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, modKey));
624 m.add(mi);
625
626
627 // Window
628 m = new JMenu(i18n.getMenuLabel("window"));
629 menuBar.add(m);
630
631 mi = new JMenuItem(A4n.windowInstrumentsDb);
632 mi.setIcon(null);
633 m.add(mi);
634
635 final JMenuItem mi2 = new JMenuItem(i18n.getMenuLabel("window.backendLog"));
636 m.add(mi2);
637 mi2.addActionListener(new ActionListener() {
638 public void
639 actionPerformed(ActionEvent e) {
640 if(getBackendLogFrame().isVisible()) {
641 getBackendLogFrame().setVisible(false);
642 }
643
644 getBackendLogFrame().setVisible(true);
645 }
646 });
647
648 mi2.setEnabled(CC.getBackendProcess() != null);
649
650 CC.addBackendProcessListener(new ActionListener() {
651 public void
652 actionPerformed(ActionEvent e) {
653 mi2.setEnabled(CC.getBackendProcess() != null);
654 }
655 });
656
657
658 // Help
659 m = new JMenu(i18n.getMenuLabel("help"));
660
661 mi = new JMenuItem(A4n.helpAbout);
662 mi.setIcon(null);
663 m.add(mi);
664
665 m.addSeparator();
666
667 mi = new JMenuItem(a4n.browseOnlineTutorial);
668 mi.setIcon(null);
669 m.add(mi);
670
671 menuBar.add(m);
672 }
673
674 private class RecentScriptHandler implements ActionListener {
675 private String script;
676
677 RecentScriptHandler(String script) { this.script = script; }
678
679 @Override
680 public void
681 actionPerformed(ActionEvent e) { runScript(script); }
682 }
683
684 private void
685 handleEvents() {
686 tabbedPane.addChangeListener(this);
687 }
688
689 private void
690 showChannelsBar(boolean b) {
691 channelsBar.setVisible(b);
692 ClassicPrefs.setShowChannelsBar(b);
693
694 validate();
695 repaint();
696 }
697
698 private void
699 showStatusbar(boolean b) {
700 ClassicPrefs.setShowStatusbar(b);
701 statusbar.setVisible(b);
702 }
703
704 protected boolean
705 isLeftPaneVisible() { return cbmiLeftPaneVisible.isSelected(); }
706
707 protected void
708 setLeftPaneVisible(boolean b) {
709 if(b != cbmiLeftPaneVisible.isSelected()) cbmiLeftPaneVisible.doClick(0);
710 }
711
712 protected boolean
713 isLSConsoleVisible() { return cbmiLSConsoleShown.isSelected(); }
714
715 protected void
716 setLSConsoleVisible(boolean b) {
717 if(b != cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
718 }
719
720 private void
721 showLeftPane(boolean b) {
722 ClassicPrefs.setShowLeftPane(b);
723
724 mainPane.remove(hSplitPane);
725 mainPane.remove(rightPane);
726
727 if(b) {
728 hSplitPane.setRightComponent(rightPane);
729 mainPane.add(hSplitPane);
730 if(ClassicPrefs.getSaveWindowProperties()) {
731 int i = ClassicPrefs.getHSplitDividerLocation();
732 hSplitPane.setDividerLocation(i);
733 }
734 } else {
735 mainPane.add(rightPane);
736 }
737
738 validate();
739 repaint();
740 }
741
742 private void
743 showStandardBar(boolean b) {
744 ClassicPrefs.setShowStandardBar(b);
745 standardBar.setVisible(b);
746 validate();
747 repaint();
748 }
749
750 private void
751 showBottomPane(boolean b) {
752 if(!b) ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation());
753
754 rightPane.remove(vSplitPane);
755 rightPane.remove(channelsPane);
756
757 if(b) {
758 vSplitPane.setTopComponent(channelsPane);
759 rightPane.add(vSplitPane);
760 vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation());
761 } else {
762 rightPane.add(channelsPane);
763 }
764
765 validate();
766 repaint();
767 }
768
769 protected void
770 setLSConsolePopOut(boolean b) {
771 if(b == lsConsolePopOut) return;
772
773 lsConsolePopOut = b;
774
775 if(isLSConsoleShown()) setLSConsolePopOut0(b);
776 }
777
778 /**
779 * Changes the pop-out state of the LS Console.
780 * Invoke this method only when LS Console is shown.
781 */
782 private void
783 setLSConsolePopOut0(boolean b) {
784 if(b) {
785 bottomPane.remove(lsConsolePane);
786 showBottomPane(false);
787
788 lsConsoleDlg = new LSConsoleDlg(this, lsConsolePane);
789 lsConsoleDlg.setVisible(true);
790 } else {
791 if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
792 lsConsoleDlg = null;
793 bottomPane.add(lsConsolePane);
794 showBottomPane(true);
795 }
796 }
797
798 protected boolean
799 isLSConsolePopOut() { return lsConsolePopOut; }
800
801 protected boolean
802 isLSConsoleShown() { return cbmiLSConsoleShown.isSelected(); }
803
804 protected void
805 setLSConsoleShown(boolean b) { cbmiLSConsoleShown.setSelected(b); }
806
807 protected LSConsoleModel
808 getLSConsoleModel() { return lsConsolePane.getModel(); }
809
810 protected JSBackendLogFrame
811 getBackendLogFrame() { return backendLogFrame; }
812
813 /**
814 * Sets the text color of the LS Console.
815 * @param c The text color of the LS Console.
816 */
817 protected void
818 setLSConsoleTextColor(Color c) { lsConsolePane.setTextColor(c); }
819
820 /**
821 * Sets the background color of the LS Console.
822 * @param c The background color of the LS Console.
823 */
824 protected void
825 setLSConsoleBackgroundColor(Color c) { lsConsolePane.setBackgroundColor(c); }
826
827 /**
828 * Sets the notification messages' color of the LS Console.
829 * @param c The notification messages' color of the LS Console.
830 */
831 protected void
832 setLSConsoleNotifyColor(Color c) { lsConsolePane.setNotifyColor(c); }
833
834 /**
835 * Sets the warning messages' color of the LS Console.
836 * @param c The warning messages' color of the LS Console.
837 */
838 protected void
839 setLSConsoleWarningColor(Color c) { lsConsolePane.setWarningColor(c); }
840
841 /**
842 * Sets the error messages' color of the LS Console.
843 * @param c The error messages' color of the LS Console.
844 */
845 protected void
846 setLSConsoleErrorColor(Color c) { lsConsolePane.setErrorColor(c); }
847
848 protected void
849 showLSConsole(boolean b) {
850 if(!b) {
851 showBottomPane(false);
852 if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false);
853 lsConsolePane.hideAutoCompleteWindow();
854 return;
855 }
856
857 setLSConsolePopOut0(isLSConsolePopOut());
858 }
859
860 /**
861 * Adds the specified <code>JSChannelsPane</code> to the view.
862 * @param chnPane The <code>JSChannelsPane</code> to be added.
863 */
864 @Override
865 public void
866 addChannelsPane(JSChannelsPane chnPane) {
867 insertChannelsPane(chnPane, getChannelsPaneCount());
868 }
869
870 @Override
871 public void
872 insertChannelsPane(JSChannelsPane chnPane, int idx) {
873 chnPane.addListSelectionListener(this);
874
875 if(getChannelsPaneCount() == 1) {
876 channelsPane.remove(getChannelsPane(0));
877 channelsPane.add(tabbedPane);
878 tabbedPane.addTab(getChannelsPane(0).getTitle(), getChannelsPane(0));
879 A4n.closeChannelsTab.setEnabled(true);
880 A4n.editTabTitle.setEnabled(true);
881 }
882
883 getChannelsPaneList().insertElementAt(chnPane, idx);
884 tabbedPane.insertTab(chnPane.getTitle(), null, chnPane, null, idx);
885 tabbedPane.setSelectedComponent(chnPane);
886 miList.insertElementAt(new JMenuItem(new A4n.MoveChannelsTo(chnPane)), idx);
887
888 updateTabsMenu();
889 }
890
891 /**
892 * Gets the <code>JSChannelsPane</code> that is currently shown.
893 * @return The currently shown <code>JSChannelsPane</code>.
894 */
895 @Override
896 public JSChannelsPane
897 getSelectedChannelsPane() {
898 if(getChannelsPaneList().size() == 1) return getChannelsPane(0);
899 return (JSChannelsPane)tabbedPane.getSelectedComponent();
900 }
901
902 /**
903 * Sets the <code>JSChannelsPane</code> to be selected.
904 * @param pane The <code>JSChannelsPane</code> to be shown.
905 */
906 @Override
907 public void
908 setSelectedChannelsPane(JSChannelsPane pane) {
909 if(getChannelsPaneList().size() == 1) return;
910 tabbedPane.setSelectedComponent(pane);
911 fireChannelsPaneSelectionChanged();
912 }
913
914 /**
915 * Removes the specified <code>JSChannelsPane</code> from the view.
916 * @param chnPane The <code>JSChannelsPane</code> to be removed.
917 * @return <code>true</code> if the specified code>JSChannelsPane</code>
918 * is actually removed from the view, <code>false</code> otherwise.
919 */
920 @Override
921 public boolean
922 removeChannelsPane(JSChannelsPane chnPane) {
923 chnPane.removeListSelectionListener(this);
924
925 tabbedPane.remove(chnPane);
926 boolean b = super.removeChannelsPane(chnPane);
927 for(int i = 0; i < miList.size(); i++) {
928 A4n.MoveChannelsTo a = (A4n.MoveChannelsTo)miList.get(i).getAction();
929 if(a.getChannelsPane().equals(chnPane)) {
930 miList.remove(i);
931 break;
932 }
933 }
934
935 updateTabsMenu();
936
937 if(getChannelsPaneCount() == 1) {
938 A4n.closeChannelsTab.setEnabled(false);
939 A4n.editTabTitle.setEnabled(false);
940 tabbedPane.remove(getChannelsPane(0));
941 channelsPane.remove(tabbedPane);
942 channelsPane.add(getChannelsPane(0));
943 }
944
945 return b;
946 }
947
948 private void
949 updateTabsMenu() {
950 tabsMenu.removeAll();
951
952 for(JMenuItem mi : miList) {
953 A4n.MoveChannelsTo a = (A4n.MoveChannelsTo)mi.getAction();
954 if(!a.getChannelsPane().equals(getSelectedChannelsPane())) tabsMenu.add(mi);
955 }
956
957 }
958
959 public void
960 updateTabTitle(JSChannelsPane chnPane) {
961 tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), chnPane.getTitle());
962 }
963
964 private void
965 checkChannelSelection(JSChannelsPane pane) {
966 if(!pane.hasSelectedChannel()) {
967 a4n.duplicateChannels.putValue (
968 Action.NAME, i18n.getMenuLabel("channels.duplicate")
969 );
970 a4n.duplicateChannels.setEnabled(false);
971
972 a4n.removeChannels.putValue (
973 Action.NAME, i18n.getMenuLabel("channels.RemoveChannel")
974 );
975 a4n.removeChannels.setEnabled(false);
976
977 tabsMenu.setEnabled(false);
978
979 a4n.moveChannelsOnTop.setEnabled(false);
980 a4n.moveChannelsUp.setEnabled(false);
981 a4n.moveChannelsDown.setEnabled(false);
982 a4n.moveChannelsAtBottom.setEnabled(false);
983
984 return;
985 }
986
987 a4n.duplicateChannels.setEnabled(true);
988 a4n.removeChannels.setEnabled(true);
989
990 if(getChannelsPaneCount() > 1) tabsMenu.setEnabled(true);
991
992 if(pane.getSelectedChannelCount() > 1) {
993 a4n.duplicateChannels.putValue (
994 Action.NAME, i18n.getMenuLabel("channels.duplicateChannels")
995 );
996 a4n.removeChannels.putValue (
997 Action.NAME, i18n.getMenuLabel("channels.RemoveChannels")
998 );
999 } else {
1000 a4n.duplicateChannels.putValue (
1001 Action.NAME, i18n.getMenuLabel("channels.duplicate")
1002 );
1003 a4n.removeChannels.putValue (
1004 Action.NAME, i18n.getMenuLabel("channels.RemoveChannel")
1005 );
1006 }
1007
1008 a4n.moveChannelsOnTop.setEnabled(false);
1009 a4n.moveChannelsUp.setEnabled(true);
1010 a4n.moveChannelsDown.setEnabled(true);
1011 a4n.moveChannelsAtBottom.setEnabled(false);
1012
1013 JSChannel[] chns = pane.getSelectedChannels();
1014
1015 for(int i = 0; i < chns.length; i++) {
1016 if(pane.getChannel(i) != chns[i]) {
1017 a4n.moveChannelsOnTop.setEnabled(true);
1018 break;
1019 }
1020 }
1021
1022 if(chns[0] == pane.getFirstChannel()) a4n.moveChannelsUp.setEnabled(false);
1023
1024 if(chns[chns.length - 1] == pane.getLastChannel())
1025 a4n.moveChannelsDown.setEnabled(false);
1026
1027 for(int i = chns.length - 1, j = pane.getChannelCount() - 1; i >= 0; i--, j--) {
1028 if(pane.getChannel(j) != chns[i]) {
1029 a4n.moveChannelsAtBottom.setEnabled(true);
1030 break;
1031 }
1032 }
1033 }
1034
1035 private void
1036 checkTabSelection() {
1037 int si = tabbedPane.getSelectedIndex();
1038
1039 if(si > 0) {
1040 A4n.moveTab2Beginning.setEnabled(true);
1041 A4n.moveTab2Left.setEnabled(true);
1042 } else {
1043 A4n.moveTab2Beginning.setEnabled(false);
1044 A4n.moveTab2Left.setEnabled(false);
1045 }
1046
1047 if(si != -1 && si < tabbedPane.getTabCount() - 1) {
1048 A4n.moveTab2Right.setEnabled(true);
1049 A4n.moveTab2End.setEnabled(true);
1050 } else {
1051 A4n.moveTab2Right.setEnabled(false);
1052 A4n.moveTab2End.setEnabled(false);
1053 }
1054 }
1055
1056 /*public JTabbedPane
1057 getTabbedPane() { return tabbedPane; }*/
1058
1059 public JMenu
1060 getTabsMenu() { return tabsMenu; }
1061
1062 @Override
1063 public void
1064 stateChanged(ChangeEvent e) {
1065 updateTabsMenu();
1066 checkChannelSelection(getSelectedChannelsPane());
1067 checkTabSelection();
1068 }
1069
1070 @Override
1071 public void
1072 valueChanged(ListSelectionEvent e) {
1073 if(e.getValueIsAdjusting()) return;
1074 if(e.getSource() != getSelectedChannelsPane()) return;
1075
1076 checkChannelSelection(getSelectedChannelsPane());
1077 }
1078
1079 public void
1080 moveTab2Beginning() {
1081 int idx = tabbedPane.getSelectedIndex();
1082 if(idx < 1) {
1083 CC.getLogger().info("Can't move tab to beginning");
1084 return;
1085 }
1086
1087 JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent();
1088 if(getChannelsPane(idx) != c)
1089 CC.getLogger().warning("Channels pane indices don't match");
1090 removeChannelsPane(c);
1091 insertChannelsPane(c, 0);
1092 tabbedPane.setSelectedComponent(c);
1093 }
1094
1095 public void
1096 moveTab2Left() {
1097 int idx = tabbedPane.getSelectedIndex();
1098 if(idx < 1) {
1099 CC.getLogger().info("Can't move tab to left");
1100 return;
1101 }
1102
1103
1104 JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent();
1105 if(getChannelsPane(idx) != c)
1106 CC.getLogger().warning("Channels pane indices don't match");
1107 removeChannelsPane(c);
1108 insertChannelsPane(c, idx - 1);
1109 tabbedPane.setSelectedComponent(c);
1110 }
1111
1112 public void
1113 moveTab2Right() {
1114 int idx = tabbedPane.getSelectedIndex();
1115 if(idx == -1 && idx >= tabbedPane.getTabCount()) {
1116 CC.getLogger().info("Can't move tab to right");
1117 return;
1118 }
1119
1120 JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent();
1121 if(getChannelsPane(idx) != c)
1122 CC.getLogger().warning("Channels pane indices don't match");
1123 removeChannelsPane(c);
1124 insertChannelsPane(c, idx + 1);
1125 tabbedPane.setSelectedComponent(c);
1126 }
1127
1128 public void
1129 moveTab2End() {
1130 int idx = tabbedPane.getSelectedIndex();
1131 if(idx == -1 && idx >= tabbedPane.getTabCount()) {
1132 CC.getLogger().info("Can't move tab to right");
1133 return;
1134 }
1135
1136 JSChannelsPane c = (JSChannelsPane)tabbedPane.getSelectedComponent();
1137 if(getChannelsPane(idx) != c)
1138 CC.getLogger().warning("Channels pane indices don't match");
1139 removeChannelsPane(c);
1140 addChannelsPane(c);
1141 tabbedPane.setSelectedComponent(c);
1142 }
1143
1144 protected void
1145 runScript() {
1146 String s = preferences().getStringProperty("lastScriptLocation");
1147 JFileChooser fc = new JFileChooser(s);
1148 fc.setFileFilter(new LscpFileFilter());
1149 int result = fc.showOpenDialog(this);
1150 if(result != JFileChooser.APPROVE_OPTION) return;
1151
1152 String path = fc.getCurrentDirectory().getAbsolutePath();
1153 preferences().setStringProperty("lastScriptLocation", path);
1154
1155 runScript(fc.getSelectedFile());
1156 }
1157
1158 @Override
1159 public void
1160 runScript(String script) { runScript(new File(script)); }
1161
1162 private void
1163 runScript(File script) {
1164 FileReader fr;
1165 try { fr = new FileReader(script); }
1166 catch(FileNotFoundException e) {
1167 HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
1168 return;
1169 }
1170
1171 BufferedReader br = new BufferedReader(fr);
1172
1173 try {
1174 String s = br.readLine();
1175 while(s != null) {
1176 getLSConsoleModel().setCommandLineText(s);
1177 getLSConsoleModel().execCommand();
1178 s = br.readLine();
1179 }
1180 } catch(Exception e) {
1181 HF.showErrorMessage(e);
1182 return;
1183 }
1184
1185 if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
1186 if(!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0);
1187 }
1188
1189 String s = script.getAbsolutePath();
1190 recentScripts.remove(s);
1191 recentScripts.insertElementAt(s, 0);
1192
1193 updateRecentScriptsMenu();
1194 }
1195
1196 protected void
1197 clearRecentScripts() {
1198 recentScripts.removeAllElements();
1199 updateRecentScriptsMenu();
1200 }
1201
1202 protected void
1203 updateRecentScriptsMenu() {
1204 int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
1205 while(recentScripts.size() > size) {
1206 recentScripts.removeElementAt(recentScripts.size() - 1);
1207 }
1208
1209 recentScriptsMenu.removeAll();
1210
1211 for(String script : recentScripts) {
1212 JMenuItem mi = new JMenuItem(script);
1213 recentScriptsMenu.add(mi);
1214 mi.addActionListener(new RecentScriptHandler(script));
1215 }
1216
1217 recentScriptsMenu.setEnabled(recentScripts.size() != 0);
1218 }
1219
1220 @Override
1221 public void
1222 installJSamplerHome() {
1223 JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
1224 chooser.setVisible(true);
1225 if(chooser.isCancelled()) return;
1226
1227 CC.changeJSamplerHome(chooser.getJSamplerHome());
1228 }
1229
1230 @Override
1231 public void
1232 showDetailedErrorMessage(Frame owner, String err, String details) {
1233 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
1234 owner, Res.iconWarning32, i18n.getError("error"), err, details
1235 );
1236 dlg.setVisible(true);
1237 }
1238
1239 @Override
1240 public void
1241 showDetailedErrorMessage(Dialog owner, String err, String details) {
1242 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
1243 owner, Res.iconWarning32, i18n.getError("error"), err, details
1244 );
1245 dlg.setVisible(true);
1246 }
1247
1248 /**
1249 * Gets the server address to which to connect. If the server should be
1250 * manually selected, a dialog asking the user to choose a server is displayed.
1251 */
1252 @Override
1253 public Server
1254 getServer() {
1255 boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
1256 return getServer(b);
1257 }
1258
1259 /**
1260 * Gets the server address to which to connect. If the server should be
1261 * manually selected, a dialog asking the user to choose a server is displayed.
1262 * @param manualSelect Determines whether the server should be manually selected.
1263 */
1264 @Override
1265 public Server
1266 getServer(boolean manualSelect) {
1267 if(manualSelect) {
1268 JSConnectDlg dlg = new JSConnectDlg();
1269 dlg.setVisible(true);
1270 return dlg.getSelectedServer();
1271 }
1272
1273 int i = preferences().getIntProperty(SERVER_INDEX);
1274 int size = CC.getServerList().getServerCount();
1275 if(size == 0) return null;
1276 if(i >= size) return CC.getServerList().getServer(0);
1277
1278 return CC.getServerList().getServer(i);
1279 }
1280 }

  ViewVC Help
Powered by ViewVC