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