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