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