1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
23 |
package org.jsampler.view.fantasia; |
package org.jsampler.view.fantasia; |
24 |
|
|
25 |
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
26 |
|
import java.awt.Color; |
27 |
|
import java.awt.Composite; |
28 |
|
import java.awt.Dialog; |
29 |
import java.awt.Dimension; |
import java.awt.Dimension; |
30 |
import java.awt.Point; |
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 |
|
|
38 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
39 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
40 |
import java.awt.event.MouseAdapter; |
import java.awt.event.KeyEvent; |
|
import java.awt.event.MouseEvent; |
|
41 |
|
|
42 |
|
import java.beans.PropertyChangeEvent; |
43 |
|
import java.beans.PropertyChangeListener; |
44 |
|
|
45 |
|
import java.io.BufferedReader; |
46 |
|
import java.io.File; |
47 |
|
import java.io.FileNotFoundException; |
48 |
|
import java.io.FileReader; |
49 |
|
|
50 |
|
import java.util.Vector; |
51 |
import java.util.logging.Level; |
import java.util.logging.Level; |
52 |
|
|
53 |
import javax.swing.Box; |
import javax.swing.BorderFactory; |
54 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
55 |
import javax.swing.JCheckBoxMenuItem; |
import javax.swing.JCheckBoxMenuItem; |
56 |
|
import javax.swing.JFileChooser; |
57 |
import javax.swing.JMenu; |
import javax.swing.JMenu; |
58 |
|
import javax.swing.JMenuBar; |
59 |
import javax.swing.JMenuItem; |
import javax.swing.JMenuItem; |
60 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
61 |
import javax.swing.JPopupMenu; |
import javax.swing.JSplitPane; |
62 |
import javax.swing.JToggleButton; |
import javax.swing.KeyStroke; |
63 |
import javax.swing.UIManager; |
import javax.swing.SwingUtilities; |
64 |
import javax.swing.plaf.synth.SynthLookAndFeel; |
import javax.swing.Timer; |
|
|
|
|
import net.sf.juife.TitleBar; |
|
65 |
|
|
66 |
import org.jsampler.CC; |
import org.jsampler.CC; |
67 |
import org.jsampler.HF; |
import org.jsampler.HF; |
68 |
|
import org.jsampler.LSConsoleModel; |
69 |
|
import org.jsampler.Server; |
70 |
|
|
|
import org.jsampler.view.JSChannel; |
|
71 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
72 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
73 |
|
import org.jsampler.view.LscpFileFilter; |
74 |
|
|
75 |
|
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
76 |
|
import org.jsampler.view.fantasia.basic.FantasiaPanel; |
77 |
|
import org.jsampler.view.fantasia.basic.FantasiaSubPanel; |
78 |
|
|
79 |
|
import org.jsampler.view.std.JSConnectDlg; |
80 |
|
import org.jsampler.view.std.JSDetailedErrorDlg; |
81 |
|
import org.jsampler.view.std.JSQuitDlg; |
82 |
|
import org.jsampler.view.std.JSamplerHomeChooser; |
83 |
|
|
84 |
|
import static org.jsampler.view.fantasia.A4n.a4n; |
85 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
86 |
|
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
87 |
|
import static org.jsampler.view.std.StdPrefs.*; |
88 |
|
|
89 |
|
|
90 |
/** |
/** |
92 |
* @author Grigor Iliev |
* @author Grigor Iliev |
93 |
*/ |
*/ |
94 |
public class MainFrame extends JSMainFrame { |
public class MainFrame extends JSMainFrame { |
95 |
private final static int TITLE_BAR_WIDTH = 420; |
private final StandardBar standardBar = new StandardBar(); |
96 |
private final static int TITLE_BAR_HEIGHT = 29; |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
97 |
|
private final JPanel rootPane = new RootPane(); |
98 |
|
private final BottomPane bottomPane; |
99 |
|
private final MainPane mainPane; |
100 |
|
private final PianoKeyboardPane pianoKeyboardPane; |
101 |
|
|
102 |
|
private final JMenu recentScriptsMenu = |
103 |
|
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
104 |
|
|
105 |
|
private final JSplitPane hSplitPane; |
106 |
|
|
107 |
|
private final LeftSidePane leftSidePane; |
108 |
|
private final RightSidePane rightSidePane; |
109 |
|
private final JPanel rightPane; |
110 |
|
|
111 |
|
//private final StatusBar statusBar = new StatusBar(); |
112 |
|
|
113 |
private final ChannelsPane channelsPane = new ChannelsPane(""); |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
114 |
|
private final Vector<String> recentScripts = new Vector<String>(); |
115 |
|
|
116 |
|
|
117 |
|
private final JCheckBoxMenuItem cbmiToolBarVisible = |
118 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
119 |
|
|
120 |
|
private final JCheckBoxMenuItem cbmiLeftSidePaneVisible = |
121 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane")); |
122 |
|
|
123 |
|
private final JCheckBoxMenuItem cbmiRightSidePaneVisible = |
124 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane")); |
125 |
|
|
126 |
|
private final JCheckBoxMenuItem cbmiMidiKeyboardVisible = |
127 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard")); |
128 |
|
|
129 |
|
private final Timer guiTimer = new Timer(1000, null); |
130 |
|
|
131 |
/** Creates a new instance of <code>MainFrame</code> */ |
/** Creates a new instance of <code>MainFrame</code> */ |
132 |
public |
public |
133 |
MainFrame() { |
MainFrame() { |
|
try { |
|
|
SynthLookAndFeel synth = new SynthLookAndFeel(); |
|
|
synth.load(MainFrame.class.getResourceAsStream("gui.xml"), MainFrame.class); |
|
|
UIManager.setLookAndFeel(synth); |
|
|
} catch(Exception e) { |
|
|
CC.getLogger().log(Level.INFO, HF.getErrorMessage(e), e); |
|
|
} |
|
|
|
|
134 |
setTitle(i18n.getLabel("MainFrame.title")); |
setTitle(i18n.getLabel("MainFrame.title")); |
135 |
addChannelsPane(channelsPane); |
//setUndecorated(true); |
136 |
add(channelsPane); |
if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage()); |
|
setUndecorated(true); |
|
|
|
|
|
JToggleButton btn = new PixmapToggleButton(Res.iconPowerOff, Res.iconPowerOn) { |
|
|
public boolean |
|
|
contains(int x, int y) { |
|
|
return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71; |
|
|
} |
|
|
}; |
|
137 |
|
|
138 |
btn.setSelected(true); |
CC.setMainFrame(this); // TODO: |
139 |
btn.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
mainPane = new MainPane(); |
140 |
btn.addActionListener(new ActionListener() { |
leftSidePane = new LeftSidePane(); |
141 |
public void |
rightSidePane = new RightSidePane(); |
142 |
actionPerformed(ActionEvent e) { onWindowClose(); } |
|
143 |
}); |
setSelectedChannelsPane(mainPane.getChannelsPane(0)); |
144 |
|
|
145 |
|
getContentPane().add(standardBar, BorderLayout.NORTH); |
146 |
|
|
147 |
FantasiaTitleBar tb = new FantasiaTitleBar(); |
rightPane = createRightPane(); |
|
tb.setName("FantasiaTitleBar"); |
|
|
tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS)); |
|
|
tb.setOpaque(true); |
|
|
tb.add(Box.createRigidArea(new Dimension(4, 0))); |
|
|
tb.add(btn); |
|
|
tb.add(Box.createRigidArea(new Dimension(3, 0))); |
|
148 |
|
|
149 |
|
hSplitPane = new JSplitPane ( |
150 |
|
JSplitPane.HORIZONTAL_SPLIT, |
151 |
|
true, // continuousLayout |
152 |
|
leftSidePane, rightPane |
153 |
|
); |
154 |
|
hSplitPane.setResizeWeight(0.5); |
155 |
|
|
156 |
|
pianoKeyboardPane = new PianoKeyboardPane(); |
157 |
|
|
158 |
|
for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) { |
159 |
|
addChannelsPane(mainPane.getChannelsPane(i)); |
160 |
|
getChannelsPane(i).addListSelectionListener(pianoKeyboardPane); |
161 |
|
} |
162 |
|
|
|
tb.add(createVSeparator()); |
|
163 |
|
|
164 |
tb.add(Box.createRigidArea(new Dimension(275, 0))); |
int h = preferences().getIntProperty("midiKeyboard.height"); |
165 |
|
setMidiKeyboardHeight(h); |
166 |
|
|
167 |
tb.add(createVSeparator()); |
PropertyChangeListener l = new PropertyChangeListener() { |
168 |
|
public void |
169 |
|
propertyChange(PropertyChangeEvent e) { |
170 |
|
int h = preferences().getIntProperty("midiKeyboard.height"); |
171 |
|
setMidiKeyboardHeight(h); |
172 |
|
} |
173 |
|
}; |
174 |
|
|
175 |
tb.add(Box.createRigidArea(new Dimension(29, 0))); |
CC.preferences().addPropertyChangeListener("midiKeyboard.height", l); |
176 |
|
|
177 |
tb.add(createVSeparator()); |
bottomPane = new BottomPane(); |
178 |
|
|
179 |
tb.add(Box.createRigidArea(new Dimension(40, 0))); |
hSplitPane.setOpaque(false); |
180 |
|
rootPane.add(hSplitPane); |
181 |
|
rootPane.add(bottomPane, BorderLayout.SOUTH); |
182 |
|
add(rootPane); |
183 |
|
|
184 |
tb.add(createVSeparator()); |
addMenu(); |
185 |
|
|
186 |
tb.setPreferredSize(new Dimension(TITLE_BAR_WIDTH, TITLE_BAR_HEIGHT)); |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
187 |
tb.setMinimumSize(tb.getPreferredSize()); |
hSplitPane.setDividerLocation(i); |
|
tb.setMaximumSize(tb.getPreferredSize()); |
|
|
add(tb, BorderLayout.SOUTH); |
|
188 |
|
|
189 |
getContentPane().setBackground(new java.awt.Color(0x818181)); |
setSavedSize(); |
|
getRootPane().setOpaque(false); |
|
|
getLayeredPane().setOpaque(false); |
|
|
//getContentPane().setVisible(false); |
|
190 |
|
|
191 |
setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop()); |
guiTimer.start(); |
192 |
pack(); |
} |
193 |
|
|
194 |
|
private JPanel |
195 |
|
createRightPane() { |
196 |
|
JPanel p = new FantasiaPanel(); |
197 |
|
p.setOpaque(false); |
198 |
|
|
199 |
|
GridBagLayout gridbag = new GridBagLayout(); |
200 |
|
GridBagConstraints c = new GridBagConstraints(); |
201 |
|
|
202 |
|
p.setLayout(gridbag); |
203 |
|
|
204 |
String s = FantasiaPrefs.getWindowLocation(); |
c.fill = GridBagConstraints.BOTH; |
205 |
|
|
206 |
|
c.gridx = 1; |
207 |
|
c.gridy = 0; |
208 |
|
c.weightx = 1.0; |
209 |
|
c.weighty = 1.0; |
210 |
|
c.insets = new Insets(0, 3, 0, 0); |
211 |
|
gridbag.setConstraints(rightSidePane, c); |
212 |
|
p.add(rightSidePane); |
213 |
|
|
214 |
|
c.gridx = 0; |
215 |
|
c.gridy = 0; |
216 |
|
c.weightx = 0.0; |
217 |
|
c.weighty = 1.0; |
218 |
|
c.insets = new Insets(0, 0, 0, 3); |
219 |
|
c.fill = GridBagConstraints.VERTICAL; |
220 |
|
gridbag.setConstraints(mainPane, c); |
221 |
|
p.add(mainPane); |
222 |
|
|
223 |
|
return p; |
224 |
|
} |
225 |
|
|
226 |
|
private void |
227 |
|
setSavedSize() { |
228 |
|
String s = preferences().getStringProperty("MainFrame.sizeAndLocation"); |
229 |
|
if(s == null) { |
230 |
|
setDefaultSizeAndLocation(); |
231 |
|
return; |
232 |
|
} |
233 |
|
pack(); |
234 |
try { |
try { |
235 |
if(s == null) { |
int i = s.indexOf(','); |
236 |
setDefaultLocation(); |
int x = Integer.parseInt(s.substring(0, i)); |
|
} else { |
|
|
int i = s.indexOf(','); |
|
|
int x = Integer.parseInt(s.substring(0, i)); |
|
237 |
|
|
238 |
s = s.substring(i + 1); |
s = s.substring(i + 1); |
239 |
int y = Integer.parseInt(s); |
i = s.indexOf(','); |
240 |
|
int y = Integer.parseInt(s.substring(0, i)); |
241 |
|
|
242 |
setLocation(x, y); |
s = s.substring(i + 1); |
243 |
} |
i = s.indexOf(','); |
244 |
|
int width = Integer.parseInt(s.substring(0, i)); |
245 |
|
|
246 |
|
s = s.substring(i + 1); |
247 |
|
int height = Integer.parseInt(s); |
248 |
|
|
249 |
|
setBounds(x, y, width, height); |
250 |
} catch(Exception x) { |
} catch(Exception x) { |
251 |
String msg = "Parsing of window size and location string failed"; |
String msg = "Parsing of window size and location string failed"; |
252 |
CC.getLogger().log(Level.INFO, msg, x); |
CC.getLogger().log(Level.INFO, msg, x); |
253 |
setDefaultLocation(); |
setDefaultSizeAndLocation(); |
254 |
|
} |
255 |
|
|
256 |
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
257 |
|
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
258 |
} |
} |
259 |
} |
} |
260 |
|
|
261 |
private void |
private void |
262 |
setDefaultLocation() { |
setDefaultSizeAndLocation() { |
263 |
Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
setPreferredSize(new Dimension(900, 600)); |
264 |
setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2); |
pack(); |
265 |
|
setLocationRelativeTo(null); |
266 |
} |
} |
267 |
|
|
268 |
|
|
269 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
270 |
|
@Override |
271 |
protected void |
protected void |
272 |
onWindowClose() { |
onWindowClose() { |
273 |
FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop()); |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
274 |
|
if(b && CC.getSamplerModel().isModified()) { |
275 |
|
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
276 |
|
dlg.setVisible(true); |
277 |
|
if(dlg.isCancelled()) return; |
278 |
|
} |
279 |
|
|
280 |
|
leftSidePane.savePreferences(); |
281 |
|
rightSidePane.savePreferences(); |
282 |
|
|
283 |
|
int i = hSplitPane.getDividerLocation(); |
284 |
|
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
285 |
|
|
286 |
|
preferences().setBoolProperty ( |
287 |
|
"MainFrame.windowMaximized", |
288 |
|
(getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
289 |
|
); |
290 |
|
|
291 |
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
292 |
|
super.onWindowClose(); |
293 |
|
return; |
294 |
|
} |
295 |
|
|
296 |
java.awt.Point p = getLocation(); |
java.awt.Point p = getLocation(); |
297 |
Dimension d = getSize(); |
Dimension d = getSize(); |
298 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |
299 |
sb.append(p.x).append(',').append(p.y + getSize().height - TITLE_BAR_HEIGHT); |
sb.append(p.x).append(',').append(p.y).append(','); |
300 |
FantasiaPrefs.setWindowLocation(sb.toString()); |
sb.append(d.width).append(',').append(d.height); |
301 |
|
preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString()); |
302 |
|
|
303 |
|
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
304 |
|
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
305 |
|
|
306 |
|
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
307 |
|
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
308 |
|
} |
309 |
|
|
310 |
super.onWindowClose(); |
super.onWindowClose(); |
311 |
} |
} |
312 |
|
|
313 |
private JPanel |
private void |
314 |
createVSeparator() { |
addMenu() { |
315 |
JPanel p = new JPanel(); |
JMenu m; |
316 |
p.setName("VSeparator"); |
JMenuItem mi; |
317 |
p.setOpaque(false); |
|
318 |
p.setPreferredSize(new Dimension(2, 29)); |
setJMenuBar(menuBar); |
319 |
p.setMinimumSize(p.getPreferredSize()); |
|
320 |
p.setMaximumSize(p.getPreferredSize()); |
// Actions |
321 |
return p; |
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
322 |
|
|
323 |
|
mi = new JMenuItem(a4n.refresh); |
324 |
|
mi.setIcon(null); |
325 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
326 |
|
m.add(mi); |
327 |
|
|
328 |
|
mi = new JMenuItem(a4n.samplerInfo); |
329 |
|
mi.setIcon(null); |
330 |
|
m.add(mi); |
331 |
|
|
332 |
|
mi = new JMenuItem(a4n.resetSampler); |
333 |
|
mi.setIcon(null); |
334 |
|
m.add(mi); |
335 |
|
|
336 |
|
m.addSeparator(); |
337 |
|
|
338 |
|
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
339 |
|
m.add(exportMenu); |
340 |
|
|
341 |
|
mi = new JMenuItem(a4n.exportSamplerConfig); |
342 |
|
mi.setIcon(null); |
343 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
344 |
|
exportMenu.add(mi); |
345 |
|
|
346 |
|
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
347 |
|
mi.setIcon(null); |
348 |
|
exportMenu.add(mi); |
349 |
|
|
350 |
|
m.addSeparator(); |
351 |
|
|
352 |
|
mi = new JMenuItem(a4n.loadScript); |
353 |
|
mi.setIcon(null); |
354 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
355 |
|
m.add(mi); |
356 |
|
|
357 |
|
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
358 |
|
for(String s : list) recentScripts.add(s); |
359 |
|
|
360 |
|
updateRecentScriptsMenu(); |
361 |
|
|
362 |
|
m.add(recentScriptsMenu); |
363 |
|
|
364 |
|
m.addSeparator(); |
365 |
|
|
366 |
|
mi = new JMenuItem(a4n.changeBackend); |
367 |
|
mi.setIcon(null); |
368 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
369 |
|
m.add(mi); |
370 |
|
|
371 |
|
m.addSeparator(); |
372 |
|
|
373 |
|
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
374 |
|
m.add(mi); |
375 |
|
mi.addActionListener(new ActionListener() { |
376 |
|
public void |
377 |
|
actionPerformed(ActionEvent e) { onWindowClose(); } |
378 |
|
}); |
379 |
|
|
380 |
|
menuBar.add(m); |
381 |
|
|
382 |
|
|
383 |
|
// Edit |
384 |
|
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
385 |
|
menuBar.add(m); |
386 |
|
|
387 |
|
mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel")); |
388 |
|
m.add(mi); |
389 |
|
mi.addActionListener(new ActionListener() { |
390 |
|
public void |
391 |
|
actionPerformed(ActionEvent e) { |
392 |
|
CC.getSamplerModel().addBackendChannel(); |
393 |
|
} |
394 |
|
}); |
395 |
|
|
396 |
|
m.addSeparator(); |
397 |
|
|
398 |
|
mi = new JMenuItem(a4n.createMidiDevice); |
399 |
|
mi.setIcon(null); |
400 |
|
m.add(mi); |
401 |
|
|
402 |
|
mi = new JMenuItem(a4n.createAudioDevice); |
403 |
|
mi.setIcon(null); |
404 |
|
m.add(mi); |
405 |
|
|
406 |
|
m.addSeparator(); |
407 |
|
|
408 |
|
mi = new JMenuItem(a4n.editPreferences); |
409 |
|
mi.setIcon(null); |
410 |
|
mi.setAccelerator(KeyStroke.getKeyStroke ( |
411 |
|
KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
412 |
|
)); |
413 |
|
m.add(mi); |
414 |
|
|
415 |
|
// View |
416 |
|
m = new FantasiaMenu(i18n.getMenuLabel("view")); |
417 |
|
menuBar.add(m); |
418 |
|
|
419 |
|
m.add(cbmiToolBarVisible); |
420 |
|
|
421 |
|
cbmiToolBarVisible.addActionListener(new ActionListener() { |
422 |
|
public void |
423 |
|
actionPerformed(ActionEvent e) { |
424 |
|
showToolBar(cbmiToolBarVisible.getState()); |
425 |
|
} |
426 |
|
}); |
427 |
|
|
428 |
|
boolean b = preferences().getBoolProperty("toolBar.visible"); |
429 |
|
cbmiToolBarVisible.setSelected(b); |
430 |
|
showToolBar(b); |
431 |
|
|
432 |
|
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
433 |
|
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
434 |
|
)); |
435 |
|
m.add(cbmiLeftSidePaneVisible); |
436 |
|
|
437 |
|
cbmiLeftSidePaneVisible.addActionListener(new ActionListener() { |
438 |
|
public void |
439 |
|
actionPerformed(ActionEvent e) { |
440 |
|
showSidePane(cbmiLeftSidePaneVisible.getState()); |
441 |
|
} |
442 |
|
}); |
443 |
|
|
444 |
|
b = preferences().getBoolProperty("leftSidePane.visible"); |
445 |
|
cbmiLeftSidePaneVisible.setSelected(b); |
446 |
|
showSidePane(b); |
447 |
|
|
448 |
|
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
449 |
|
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
450 |
|
)); |
451 |
|
m.add(cbmiRightSidePaneVisible); |
452 |
|
|
453 |
|
cbmiRightSidePaneVisible.addActionListener(new ActionListener() { |
454 |
|
public void |
455 |
|
actionPerformed(ActionEvent e) { |
456 |
|
showDevicesPane(cbmiRightSidePaneVisible.getState()); |
457 |
|
} |
458 |
|
}); |
459 |
|
|
460 |
|
b = preferences().getBoolProperty("rightSidePane.visible"); |
461 |
|
cbmiRightSidePaneVisible.setSelected(b); |
462 |
|
showDevicesPane(b); |
463 |
|
|
464 |
|
m.addSeparator(); |
465 |
|
|
466 |
|
m.add(cbmiMidiKeyboardVisible); |
467 |
|
|
468 |
|
cbmiMidiKeyboardVisible.addActionListener(new ActionListener() { |
469 |
|
public void |
470 |
|
actionPerformed(ActionEvent e) { |
471 |
|
setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState()); |
472 |
|
} |
473 |
|
}); |
474 |
|
|
475 |
|
b = preferences().getBoolProperty("midiKeyboard.visible"); |
476 |
|
cbmiMidiKeyboardVisible.setSelected(b); |
477 |
|
setMidiKeyboardVisible(b); |
478 |
|
|
479 |
|
|
480 |
|
// Window |
481 |
|
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
482 |
|
menuBar.add(m); |
483 |
|
|
484 |
|
mi = new JMenuItem(a4n.windowLSConsole); |
485 |
|
mi.setIcon(null); |
486 |
|
m.add(mi); |
487 |
|
|
488 |
|
mi = new JMenuItem(a4n.windowInstrumentsDb); |
489 |
|
mi.setIcon(null); |
490 |
|
m.add(mi); |
491 |
|
|
492 |
|
|
493 |
|
// Help |
494 |
|
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
495 |
|
|
496 |
|
mi = new JMenuItem(a4n.browseOnlineTutorial); |
497 |
|
mi.setIcon(null); |
498 |
|
m.add(mi); |
499 |
|
|
500 |
|
m.addSeparator(); |
501 |
|
|
502 |
|
mi = new JMenuItem(a4n.helpAbout); |
503 |
|
mi.setIcon(null); |
504 |
|
m.add(mi); |
505 |
|
|
506 |
|
menuBar.add(m); |
507 |
} |
} |
508 |
|
|
509 |
|
public RightSidePane |
510 |
|
getRightSidePane() { return rightSidePane; } |
511 |
|
|
512 |
/** |
/** |
513 |
* This method does nothing, because <b>Fantasia</b> has exactly |
* This method does nothing, because <b>Fantasia</b> has constant |
514 |
* one pane containing sampler channels, which can not be changed. |
* number of panes containing sampler channels, which can not be changed. |
515 |
*/ |
*/ |
516 |
|
@Override |
517 |
public void |
public void |
518 |
insertChannelsPane(JSChannelsPane pane, int idx) { |
insertChannelsPane(JSChannelsPane pane, int idx) { |
519 |
getChannelsPaneList().removeAllElements(); |
|
520 |
addChannelsPane(pane); |
} |
521 |
|
|
522 |
|
@Override |
523 |
|
public JSChannelsPane |
524 |
|
getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); } |
525 |
|
|
526 |
|
@Override |
527 |
|
public void |
528 |
|
setSelectedChannelsPane(JSChannelsPane pane) { |
529 |
|
mainPane.setSelectedChannelsPane(pane); |
530 |
|
fireChannelsPaneSelectionChanged(); |
531 |
|
} |
532 |
|
|
533 |
|
@Override |
534 |
|
public void |
535 |
|
installJSamplerHome() { |
536 |
|
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
537 |
|
chooser.setVisible(true); |
538 |
|
if(chooser.isCancelled()) return; |
539 |
|
|
540 |
|
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
541 |
|
} |
542 |
|
|
543 |
|
@Override |
544 |
|
public void |
545 |
|
showDetailedErrorMessage(Frame owner, String err, String details) { |
546 |
|
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
547 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
548 |
|
); |
549 |
|
dlg.setVisible(true); |
550 |
|
} |
551 |
|
|
552 |
|
@Override |
553 |
|
public void |
554 |
|
showDetailedErrorMessage(Dialog owner, String err, String details) { |
555 |
|
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
556 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
557 |
|
); |
558 |
|
dlg.setVisible(true); |
559 |
} |
} |
560 |
|
|
561 |
/** |
/** |
562 |
* This method always returns the <code>JSChannelsPane</code> at index 0, |
* Gets the server address to which to connect. If the server should be |
563 |
* because the <b>Fantasia</b> view has exactly one pane containing sampler channels. |
* manually selected, a dialog asking the user to choose a server is displayed. |
|
* @return The <code>JSChannelsPane</code> at index 0. |
|
564 |
*/ |
*/ |
565 |
public JSChannelsPane |
@Override |
566 |
getSelectedChannelsPane() { return getChannelsPane(0); } |
public Server |
567 |
|
getServer() { |
568 |
|
boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP); |
569 |
|
return getServer(b); |
570 |
|
} |
571 |
|
|
572 |
/** |
/** |
573 |
* This method does nothing because the <b>Fantasia</b> view has |
* Gets the server address to which to connect. If the server should be |
574 |
* exactly one pane containing sampler channels which is always shown. |
* manually selected, a dialog asking the user to choose a server is displayed. |
575 |
|
* @param manualSelect Determines whether the server should be manually selected. |
576 |
*/ |
*/ |
577 |
public void |
@Override |
578 |
setSelectedChannelsPane(JSChannelsPane pane) { } |
public Server |
579 |
|
getServer(boolean manualSelect) { |
580 |
|
if(manualSelect) { |
581 |
|
JSConnectDlg dlg = new JSConnectDlg(); |
582 |
|
dlg.setVisible(true); |
583 |
|
return dlg.getSelectedServer(); |
584 |
|
} |
585 |
|
|
586 |
|
int i = preferences().getIntProperty(SERVER_INDEX); |
587 |
|
int size = CC.getServerList().getServerCount(); |
588 |
|
if(size == 0) return null; |
589 |
|
if(i >= size) return CC.getServerList().getServer(0); |
590 |
|
|
591 |
|
return CC.getServerList().getServer(i); |
592 |
|
} |
593 |
|
|
594 |
|
public Timer |
595 |
|
getGuiTimer() { return guiTimer; } |
596 |
|
|
597 |
|
protected LSConsoleModel |
598 |
|
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
599 |
|
|
600 |
|
protected LSConsolePane |
601 |
|
getLSConsolePane() { |
602 |
|
return getLSConsoleFrame().getLSConsolePane(); |
603 |
|
} |
604 |
|
|
605 |
|
protected LSConsoleFrame |
606 |
|
getLSConsoleFrame() { return lsConsoleFrame; } |
607 |
|
|
608 |
|
protected boolean |
609 |
|
runScript() { |
610 |
|
String s = preferences().getStringProperty("lastScriptLocation"); |
611 |
|
JFileChooser fc = new JFileChooser(s); |
612 |
|
fc.setFileFilter(new LscpFileFilter()); |
613 |
|
int result = fc.showOpenDialog(this); |
614 |
|
if(result != JFileChooser.APPROVE_OPTION) return false; |
615 |
|
|
616 |
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
617 |
|
preferences().setStringProperty("lastScriptLocation", path); |
618 |
|
|
619 |
|
runScript(fc.getSelectedFile()); |
620 |
|
|
621 |
|
return true; |
622 |
|
} |
623 |
|
|
624 |
|
private void |
625 |
|
runScript(String script) { runScript(new File(script)); } |
626 |
|
|
627 |
|
private void |
628 |
|
runScript(File script) { |
629 |
|
FileReader fr; |
630 |
|
try { fr = new FileReader(script); } |
631 |
|
catch(FileNotFoundException e) { |
632 |
|
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
633 |
|
return; |
634 |
|
} |
635 |
|
|
636 |
|
BufferedReader br = new BufferedReader(fr); |
637 |
|
|
638 |
|
try { |
639 |
|
String s = br.readLine(); |
640 |
|
while(s != null) { |
641 |
|
getLSConsoleModel().setCommandLineText(s); |
642 |
|
getLSConsoleModel().execCommand(); |
643 |
|
s = br.readLine(); |
644 |
|
} |
645 |
|
} catch(Exception e) { |
646 |
|
HF.showErrorMessage(e); |
647 |
|
return; |
648 |
|
} |
649 |
|
|
650 |
|
String s = script.getAbsolutePath(); |
651 |
|
recentScripts.remove(s); |
652 |
|
recentScripts.insertElementAt(s, 0); |
653 |
|
|
654 |
|
updateRecentScriptsMenu(); |
655 |
|
} |
656 |
|
|
657 |
|
protected void |
658 |
|
clearRecentScripts() { |
659 |
|
recentScripts.removeAllElements(); |
660 |
|
updateRecentScriptsMenu(); |
661 |
|
} |
662 |
|
|
663 |
|
protected void |
664 |
|
updateRecentScriptsMenu() { |
665 |
|
int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
666 |
|
while(recentScripts.size() > size) { |
667 |
|
recentScripts.removeElementAt(recentScripts.size() - 1); |
668 |
|
} |
669 |
|
|
670 |
|
recentScriptsMenu.removeAll(); |
671 |
|
|
672 |
|
for(String script : recentScripts) { |
673 |
|
JMenuItem mi = new JMenuItem(script); |
674 |
|
recentScriptsMenu.add(mi); |
675 |
|
mi.addActionListener(new RecentScriptHandler(script)); |
676 |
|
} |
677 |
|
|
678 |
|
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
679 |
|
} |
680 |
|
|
681 |
|
private void |
682 |
|
showToolBar(boolean b) { |
683 |
|
preferences().setBoolProperty("toolBar.visible", b); |
684 |
|
standardBar.setVisible(b); |
685 |
|
} |
686 |
|
|
687 |
|
private void |
688 |
|
showSidePane(boolean b) { |
689 |
|
preferences().setBoolProperty("leftSidePane.visible", b); |
690 |
|
rootPane.remove(rightPane); |
691 |
|
rootPane.remove(hSplitPane); |
692 |
|
|
693 |
|
if(b) { |
694 |
|
hSplitPane.setRightComponent(rightPane); |
695 |
|
rootPane.add(hSplitPane); |
696 |
|
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
697 |
|
|
698 |
|
hSplitPane.setDividerLocation(i); |
699 |
|
hSplitPane.validate(); |
700 |
|
} else { |
701 |
|
rootPane.add(rightPane); |
702 |
|
|
703 |
|
} |
704 |
|
|
705 |
|
int w = getPreferredSize().width; |
706 |
|
int h = getSize().height; |
707 |
|
setSize(new Dimension(w, h)); |
708 |
|
|
709 |
|
rootPane.revalidate(); |
710 |
|
rootPane.validate(); |
711 |
|
rootPane.repaint(); |
712 |
|
|
713 |
|
SwingUtilities.invokeLater(new Runnable() { |
714 |
|
public void |
715 |
|
run() { sidePanesVisibilityChanged(); } |
716 |
|
}); |
717 |
|
} |
718 |
|
|
719 |
public static void |
private void |
720 |
repack(JSMainFrame frame) { |
showDevicesPane(boolean b) { |
721 |
int y = frame.getLocation().y; |
preferences().setBoolProperty("rightSidePane.visible", b); |
722 |
int height = frame.getSize().height; |
|
723 |
y += (height - frame.getPreferredSize().height); |
int width = leftSidePane.getWidth(); |
724 |
|
int height = leftSidePane.getPreferredSize().height; |
725 |
if((height - frame.getPreferredSize().height) > 0) { |
if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height)); |
726 |
frame.pack(); |
|
727 |
frame.setLocation(frame.getLocation().x, y); |
if(b) { |
728 |
|
int w = preferences().getIntProperty("devicesPane.width", 200); |
729 |
|
|
730 |
|
int h = rightSidePane.getPreferredSize().height; |
731 |
|
rightSidePane.setPreferredSize(new Dimension(w, h)); |
732 |
} else { |
} else { |
733 |
frame.setLocation(frame.getLocation().x, y); |
int w = rightSidePane.getWidth(); |
734 |
frame.pack(); |
if(w > 0 && w < 200) w = 200; |
735 |
|
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
736 |
|
} |
737 |
|
|
738 |
|
hSplitPane.setResizeWeight(0.0); |
739 |
|
rightSidePane.setVisible(b); |
740 |
|
hSplitPane.resetToPreferredSizes(); |
741 |
|
|
742 |
|
int w = getPreferredSize().width; |
743 |
|
int h = getSize().height; |
744 |
|
setSize(new Dimension(w, h)); |
745 |
|
|
746 |
|
rootPane.validate(); |
747 |
|
rootPane.repaint(); |
748 |
|
//hSplitPane.validate(); |
749 |
|
|
750 |
|
SwingUtilities.invokeLater(new Runnable() { |
751 |
|
public void |
752 |
|
run() { sidePanesVisibilityChanged(); } |
753 |
|
}); |
754 |
|
} |
755 |
|
|
756 |
|
public void |
757 |
|
setMidiKeyboardVisible(boolean b) { |
758 |
|
preferences().setBoolProperty("midiKeyboard.visible", b); |
759 |
|
pianoKeyboardPane.setVisible(b); |
760 |
|
|
761 |
|
if(cbmiMidiKeyboardVisible.isSelected() != b) { |
762 |
|
cbmiMidiKeyboardVisible.setSelected(b); |
763 |
|
} |
764 |
|
|
765 |
|
if(standardBar.btnMidiKeyboard.isSelected() != b) { |
766 |
|
standardBar.btnMidiKeyboard.setSelected(b); |
767 |
|
} |
768 |
|
|
769 |
|
if(pianoKeyboardPane.btnPower.isSelected() != b) { |
770 |
|
pianoKeyboardPane.btnPower.setSelected(b); |
771 |
} |
} |
772 |
|
|
773 |
|
rootPane.validate(); |
774 |
|
rootPane.repaint(); |
775 |
} |
} |
776 |
|
|
777 |
public void |
public void |
778 |
installJSamplerHome() { } |
setMidiKeyboardHeight(int height) { |
779 |
} |
Dimension d = pianoKeyboardPane.getPreferredSize(); |
780 |
|
d = new Dimension(d.width, height); |
781 |
class FantasiaTitleBar extends TitleBar { |
pianoKeyboardPane.setPreferredSize(d); |
782 |
FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); } |
pianoKeyboardPane.setMinimumSize(d); |
783 |
|
pianoKeyboardPane.revalidate(); |
784 |
|
pianoKeyboardPane.repaint(); |
785 |
|
} |
786 |
|
|
787 |
class ContextMenu extends MouseAdapter { |
private void |
788 |
private final JPopupMenu cmenu = new JPopupMenu(); |
sidePanesVisibilityChanged() { |
789 |
|
boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected(); |
790 |
|
boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected(); |
791 |
|
|
792 |
|
if(leftSidePaneVisible && rightSidePaneVisible) { |
793 |
|
hSplitPane.setResizeWeight(0.5); |
794 |
|
} else if(leftSidePaneVisible && !rightSidePaneVisible) { |
795 |
|
hSplitPane.setResizeWeight(1.0); |
796 |
|
} |
797 |
|
|
798 |
ContextMenu() { |
if(!leftSidePaneVisible && !rightSidePaneVisible) { |
799 |
JMenuItem mi; |
standardBar.showFantasiaLogo(false); |
800 |
|
if(isResizable()) setResizable(false); |
801 |
final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem ( |
} else { |
802 |
i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop") |
standardBar.showFantasiaLogo(true); |
803 |
); |
if(!isResizable()) setResizable(true); |
|
cmi.setIcon(null); |
|
|
cmi.setSelected(FantasiaPrefs.isAlwaysOnTop()); |
|
|
|
|
|
cmenu.add(cmi); |
|
|
|
|
|
cmi.addActionListener(new ActionListener() { |
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
CC.getMainFrame().setAlwaysOnTop(cmi.isSelected()); |
|
|
} |
|
|
}); |
|
|
|
|
|
/*mi = new JMenuItem(A4n.moveChannelsUp); |
|
|
mi.setIcon(null); |
|
|
cmenu.add(mi); |
|
|
|
|
|
cmenu.addSeparator(); |
|
|
|
|
|
mi = new JMenuItem(A4n.removeChannels); |
|
|
mi.setIcon(null); |
|
|
cmenu.add(mi);*/ |
|
804 |
} |
} |
805 |
|
} |
806 |
|
|
807 |
|
private class RecentScriptHandler implements ActionListener { |
808 |
|
private String script; |
809 |
|
|
810 |
|
RecentScriptHandler(String script) { this.script = script; } |
811 |
|
|
812 |
|
@Override |
813 |
public void |
public void |
814 |
mousePressed(MouseEvent e) { |
actionPerformed(ActionEvent e) { |
815 |
if(e.isPopupTrigger()) show(e); |
runScript(script); |
816 |
|
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
817 |
|
a4n.windowLSConsole.actionPerformed(null); |
818 |
|
} |
819 |
|
} |
820 |
|
} |
821 |
|
|
822 |
|
private static class FantasiaMenu extends JMenu { |
823 |
|
FantasiaMenu(String s) { |
824 |
|
super(s); |
825 |
|
setFont(getFont().deriveFont(java.awt.Font.BOLD)); |
826 |
|
setOpaque(false); |
827 |
|
setContentAreaFilled(false); |
828 |
|
} |
829 |
|
} |
830 |
|
|
831 |
|
private class FantasiaMenuBar extends JMenuBar { |
832 |
|
FantasiaMenuBar() { |
833 |
|
setOpaque(false); |
834 |
|
setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0)); |
835 |
|
} |
836 |
|
|
837 |
|
@Override |
838 |
|
protected void |
839 |
|
paintComponent(Graphics g) { |
840 |
|
//super.paintComponent(g); |
841 |
|
Graphics2D g2 = (Graphics2D)g; |
842 |
|
|
843 |
|
Paint oldPaint = g2.getPaint(); |
844 |
|
Composite oldComposite = g2.getComposite(); |
845 |
|
|
846 |
|
double h = getSize().getHeight(); |
847 |
|
double w = getSize().getWidth(); |
848 |
|
|
849 |
|
FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5); |
850 |
|
|
851 |
|
FantasiaPainter.Border b; |
852 |
|
|
853 |
|
|
854 |
|
if(standardBar.isVisible()) { |
855 |
|
b = new FantasiaPainter.Border(true, true, false, true); |
856 |
|
FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b); |
857 |
|
} else { |
858 |
|
b = new FantasiaPainter.Border(true, true, true, true); |
859 |
|
FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b); |
860 |
|
} |
861 |
|
|
862 |
|
g2.setPaint(oldPaint); |
863 |
|
g2.setComposite(oldComposite); |
864 |
|
} |
865 |
|
} |
866 |
|
|
867 |
|
class RootPane extends FantasiaSubPanel { |
868 |
|
private final Color color1 = new Color(0x454545); |
869 |
|
private final Color color2 = new Color(0x2e2e2e); |
870 |
|
|
871 |
|
RootPane() { |
872 |
|
setLayout(new BorderLayout()); |
873 |
|
setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10)); |
874 |
|
setOpaque(false); |
875 |
|
|
876 |
} |
} |
877 |
|
|
878 |
|
@Override |
879 |
public void |
public void |
880 |
mouseReleased(MouseEvent e) { |
paintComponent(Graphics g) { |
881 |
if(e.isPopupTrigger()) show(e); |
Graphics2D g2 = (Graphics2D)g; |
882 |
|
|
883 |
|
Paint oldPaint = g2.getPaint(); |
884 |
|
Composite oldComposite = g2.getComposite(); |
885 |
|
|
886 |
|
double h = getSize().getHeight(); |
887 |
|
double w = getSize().getWidth(); |
888 |
|
|
889 |
|
FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false); |
890 |
|
paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2); |
891 |
|
|
892 |
|
g2.setPaint(oldPaint); |
893 |
|
g2.setComposite(oldComposite); |
894 |
} |
} |
895 |
|
} |
896 |
|
|
897 |
void |
class BottomPane extends FantasiaPanel { |
898 |
show(MouseEvent e) { |
BottomPane() { |
899 |
cmenu.show(e.getComponent(), e.getX(), e.getY()); |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
900 |
|
setOpaque(false); |
901 |
|
add(pianoKeyboardPane); |
902 |
|
|
903 |
} |
} |
904 |
} |
} |
905 |
} |
} |