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-2007 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.Dialog; |
27 |
import java.awt.Dimension; |
import java.awt.Dimension; |
28 |
|
import java.awt.Frame; |
29 |
|
import java.awt.Graphics; |
30 |
|
import java.awt.GridBagConstraints; |
31 |
|
import java.awt.GridBagLayout; |
32 |
|
import java.awt.Insets; |
33 |
import java.awt.Point; |
import java.awt.Point; |
34 |
|
|
35 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
36 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
37 |
|
import java.awt.event.KeyEvent; |
38 |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
39 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
40 |
|
|
41 |
|
import java.io.BufferedReader; |
42 |
|
import java.io.File; |
43 |
|
import java.io.FileNotFoundException; |
44 |
|
import java.io.FileReader; |
45 |
|
|
46 |
|
import java.util.Vector; |
47 |
import java.util.logging.Level; |
import java.util.logging.Level; |
48 |
|
|
49 |
|
import javax.swing.BorderFactory; |
50 |
import javax.swing.Box; |
import javax.swing.Box; |
51 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
52 |
import javax.swing.JCheckBoxMenuItem; |
import javax.swing.JCheckBoxMenuItem; |
53 |
|
import javax.swing.JComponent; |
54 |
|
import javax.swing.JDialog; |
55 |
|
import javax.swing.JFileChooser; |
56 |
|
import javax.swing.JFrame; |
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.JPopupMenu; |
62 |
|
import javax.swing.JScrollPane; |
63 |
|
import javax.swing.JSplitPane; |
64 |
import javax.swing.JToggleButton; |
import javax.swing.JToggleButton; |
65 |
|
import javax.swing.KeyStroke; |
66 |
|
import javax.swing.SwingUtilities; |
67 |
import javax.swing.UIManager; |
import javax.swing.UIManager; |
|
import javax.swing.plaf.synth.SynthLookAndFeel; |
|
68 |
|
|
69 |
import net.sf.juife.TitleBar; |
import net.sf.juife.TitleBar; |
70 |
|
|
71 |
import org.jsampler.CC; |
import org.jsampler.CC; |
72 |
import org.jsampler.HF; |
import org.jsampler.HF; |
73 |
|
import org.jsampler.LSConsoleModel; |
74 |
|
|
75 |
import org.jsampler.view.JSChannel; |
import org.jsampler.view.JSChannel; |
76 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
77 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
78 |
|
import org.jsampler.view.LscpFileFilter; |
79 |
|
|
80 |
|
import org.jsampler.view.std.JSDetailedErrorDlg; |
81 |
|
import org.jsampler.view.std.JSamplerHomeChooser; |
82 |
|
|
83 |
|
import static org.jsampler.view.fantasia.A4n.a4n; |
84 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
85 |
|
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
86 |
|
import static org.jsampler.view.std.StdPrefs.*; |
87 |
|
|
88 |
|
|
89 |
/** |
/** |
91 |
* @author Grigor Iliev |
* @author Grigor Iliev |
92 |
*/ |
*/ |
93 |
public class MainFrame extends JSMainFrame { |
public class MainFrame extends JSMainFrame { |
94 |
private final static int TITLE_BAR_WIDTH = 420; |
private final StandardBar standardBar = new StandardBar(); |
95 |
private final static int TITLE_BAR_HEIGHT = 29; |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
96 |
|
private final JPanel rootPane = new JPanel(); |
97 |
|
private final MainPane mainPane = new MainPane(); |
98 |
|
private final DevicesPane devicesPane = new DevicesPane(); |
99 |
|
private final JScrollPane spDevicesPane = new JScrollPane(); |
100 |
|
|
101 |
|
private final JMenu recentScriptsMenu = |
102 |
|
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
103 |
|
|
104 |
|
private final JSplitPane hSplitPane; |
105 |
|
|
106 |
|
private final SidePane sidePane = new SidePane(); |
107 |
|
private final JPanel rightPane; |
108 |
|
|
109 |
|
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 cbmiSidePaneVisible = |
117 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane")); |
118 |
|
|
119 |
private final ChannelsPane channelsPane = new ChannelsPane(""); |
private final JCheckBoxMenuItem cbmiDevicesPaneVisible = |
120 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane")); |
121 |
|
|
122 |
/** Creates a new instance of <code>MainFrame</code> */ |
/** Creates a new instance of <code>MainFrame</code> */ |
123 |
public |
public |
124 |
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); |
|
|
} |
|
|
|
|
125 |
setTitle(i18n.getLabel("MainFrame.title")); |
setTitle(i18n.getLabel("MainFrame.title")); |
|
addChannelsPane(channelsPane); |
|
|
add(channelsPane); |
|
|
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; |
|
|
} |
|
|
}; |
|
|
|
|
|
btn.setSelected(true); |
|
|
btn.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
|
|
btn.addActionListener(new ActionListener() { |
|
|
public void |
|
|
actionPerformed(ActionEvent e) { onWindowClose(); } |
|
|
}); |
|
126 |
|
|
127 |
|
if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage()); |
128 |
|
|
129 |
FantasiaTitleBar tb = new FantasiaTitleBar(); |
getContentPane().add(standardBar, BorderLayout.NORTH); |
|
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))); |
|
130 |
|
|
131 |
|
rightPane = createRightPane(); |
132 |
|
|
133 |
|
hSplitPane = new JSplitPane ( |
134 |
|
JSplitPane.HORIZONTAL_SPLIT, |
135 |
|
true, // continuousLayout |
136 |
|
sidePane, rightPane |
137 |
|
); |
138 |
|
hSplitPane.setResizeWeight(0.5); |
139 |
|
|
140 |
tb.add(createVSeparator()); |
rootPane.setLayout(new BorderLayout()); |
141 |
|
rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0)); |
142 |
|
rootPane.setOpaque(false); |
143 |
|
rootPane.add(hSplitPane); |
144 |
|
|
145 |
tb.add(Box.createRigidArea(new Dimension(275, 0))); |
addMenu(); |
146 |
|
|
147 |
tb.add(createVSeparator()); |
addChannelsPane(mainPane.getChannelsPane()); |
148 |
|
|
149 |
tb.add(Box.createRigidArea(new Dimension(29, 0))); |
getContentPane().add(rootPane); |
150 |
|
|
151 |
tb.add(createVSeparator()); |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
152 |
|
hSplitPane.setDividerLocation(i); |
153 |
|
|
154 |
tb.add(Box.createRigidArea(new Dimension(40, 0))); |
setSavedSize(); |
155 |
|
} |
156 |
|
|
157 |
|
private JPanel |
158 |
|
createRightPane() { |
159 |
|
JPanel p = new JPanel(); |
160 |
|
GridBagLayout gridbag = new GridBagLayout(); |
161 |
|
GridBagConstraints c = new GridBagConstraints(); |
162 |
|
|
163 |
tb.add(createVSeparator()); |
p.setLayout(gridbag); |
164 |
|
|
165 |
tb.setPreferredSize(new Dimension(TITLE_BAR_WIDTH, TITLE_BAR_HEIGHT)); |
c.fill = GridBagConstraints.BOTH; |
|
tb.setMinimumSize(tb.getPreferredSize()); |
|
|
tb.setMaximumSize(tb.getPreferredSize()); |
|
|
add(tb, BorderLayout.SOUTH); |
|
166 |
|
|
167 |
getContentPane().setBackground(new java.awt.Color(0x818181)); |
spDevicesPane.setViewportView(devicesPane); |
168 |
getRootPane().setOpaque(false); |
spDevicesPane.setBorder(BorderFactory.createEmptyBorder()); |
169 |
getLayeredPane().setOpaque(false); |
int h = spDevicesPane.getMinimumSize().height; |
170 |
//getContentPane().setVisible(false); |
spDevicesPane.setMinimumSize(new Dimension(200, h)); |
171 |
|
|
172 |
|
c.gridx = 1; |
173 |
|
c.gridy = 0; |
174 |
|
c.weightx = 1.0; |
175 |
|
c.weighty = 1.0; |
176 |
|
c.insets = new Insets(0, 3, 3, 0); |
177 |
|
gridbag.setConstraints(spDevicesPane, c); |
178 |
|
p.add(spDevicesPane); |
179 |
|
|
180 |
|
c.gridx = 0; |
181 |
|
c.gridy = 0; |
182 |
|
c.weightx = 0.0; |
183 |
|
c.weighty = 1.0; |
184 |
|
c.insets = new Insets(0, 3, 3, 3); |
185 |
|
c.fill = GridBagConstraints.VERTICAL; |
186 |
|
gridbag.setConstraints(mainPane, c); |
187 |
|
p.add(mainPane); |
188 |
|
|
189 |
setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop()); |
return p; |
190 |
|
} |
191 |
|
|
192 |
|
private void |
193 |
|
setSavedSize() { |
194 |
|
String s = preferences().getStringProperty("MainFrame.sizeAndLocation"); |
195 |
|
if(s == null) { |
196 |
|
setDefaultSizeAndLocation(); |
197 |
|
return; |
198 |
|
} |
199 |
pack(); |
pack(); |
|
|
|
|
String s = FantasiaPrefs.getWindowLocation(); |
|
|
|
|
200 |
try { |
try { |
201 |
if(s == null) { |
int i = s.indexOf(','); |
202 |
setDefaultLocation(); |
int x = Integer.parseInt(s.substring(0, i)); |
|
} else { |
|
|
int i = s.indexOf(','); |
|
|
int x = Integer.parseInt(s.substring(0, i)); |
|
203 |
|
|
204 |
s = s.substring(i + 1); |
s = s.substring(i + 1); |
205 |
int y = Integer.parseInt(s); |
i = s.indexOf(','); |
206 |
|
int y = Integer.parseInt(s.substring(0, i)); |
207 |
|
|
208 |
setLocation(x, y); |
s = s.substring(i + 1); |
209 |
} |
i = s.indexOf(','); |
210 |
|
int width = Integer.parseInt(s.substring(0, i)); |
211 |
|
|
212 |
|
s = s.substring(i + 1); |
213 |
|
int height = Integer.parseInt(s); |
214 |
|
|
215 |
|
setBounds(x, y, width, height); |
216 |
} catch(Exception x) { |
} catch(Exception x) { |
217 |
String msg = "Parsing of window size and location string failed"; |
String msg = "Parsing of window size and location string failed"; |
218 |
CC.getLogger().log(Level.INFO, msg, x); |
CC.getLogger().log(Level.INFO, msg, x); |
219 |
setDefaultLocation(); |
setDefaultSizeAndLocation(); |
220 |
|
} |
221 |
|
|
222 |
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
223 |
|
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
224 |
} |
} |
225 |
} |
} |
226 |
|
|
227 |
private void |
private void |
228 |
setDefaultLocation() { |
setDefaultSizeAndLocation() { |
229 |
Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
setPreferredSize(new Dimension(900, 600)); |
230 |
setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2); |
pack(); |
231 |
|
setLocationRelativeTo(null); |
232 |
} |
} |
233 |
|
|
234 |
|
|
235 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
236 |
protected void |
protected void |
237 |
onWindowClose() { |
onWindowClose() { |
238 |
FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop()); |
sidePane.savePreferences(); |
239 |
|
|
240 |
|
int i = hSplitPane.getDividerLocation(); |
241 |
|
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
242 |
|
|
243 |
|
preferences().setBoolProperty ( |
244 |
|
"MainFrame.windowMaximized", |
245 |
|
(getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
246 |
|
); |
247 |
|
|
248 |
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
249 |
|
super.onWindowClose(); |
250 |
|
return; |
251 |
|
} |
252 |
|
|
253 |
java.awt.Point p = getLocation(); |
java.awt.Point p = getLocation(); |
254 |
Dimension d = getSize(); |
Dimension d = getSize(); |
255 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |
256 |
sb.append(p.x).append(',').append(p.y + getSize().height - TITLE_BAR_HEIGHT); |
sb.append(p.x).append(',').append(p.y).append(','); |
257 |
FantasiaPrefs.setWindowLocation(sb.toString()); |
sb.append(d.width).append(',').append(d.height); |
258 |
|
preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString()); |
259 |
|
|
260 |
|
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
261 |
|
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
262 |
|
|
263 |
|
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
264 |
|
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
265 |
|
} |
266 |
|
|
267 |
super.onWindowClose(); |
super.onWindowClose(); |
268 |
} |
} |
269 |
|
|
270 |
private JPanel |
private void |
271 |
createVSeparator() { |
addMenu() { |
272 |
JPanel p = new JPanel(); |
JMenu m; |
273 |
p.setName("VSeparator"); |
JMenuItem mi; |
274 |
p.setOpaque(false); |
|
275 |
p.setPreferredSize(new Dimension(2, 29)); |
setJMenuBar(menuBar); |
276 |
p.setMinimumSize(p.getPreferredSize()); |
|
277 |
p.setMaximumSize(p.getPreferredSize()); |
// Actions |
278 |
return p; |
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
279 |
|
|
280 |
|
mi = new JMenuItem(a4n.connect); |
281 |
|
mi.setIcon(null); |
282 |
|
//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); |
283 |
|
m.add(mi); |
284 |
|
|
285 |
|
mi = new JMenuItem(a4n.samplerInfo); |
286 |
|
mi.setIcon(null); |
287 |
|
m.add(mi); |
288 |
|
|
289 |
|
m.addSeparator(); |
290 |
|
|
291 |
|
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
292 |
|
m.add(exportMenu); |
293 |
|
|
294 |
|
mi = new JMenuItem(a4n.exportSamplerConfig); |
295 |
|
mi.setIcon(null); |
296 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
297 |
|
exportMenu.add(mi); |
298 |
|
|
299 |
|
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
300 |
|
mi.setIcon(null); |
301 |
|
exportMenu.add(mi); |
302 |
|
|
303 |
|
m.addSeparator(); |
304 |
|
|
305 |
|
mi = new JMenuItem(a4n.loadScript); |
306 |
|
mi.setIcon(null); |
307 |
|
m.add(mi); |
308 |
|
|
309 |
|
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
310 |
|
for(String s : list) recentScripts.add(s); |
311 |
|
|
312 |
|
updateRecentScriptsMenu(); |
313 |
|
|
314 |
|
m.add(recentScriptsMenu); |
315 |
|
|
316 |
|
m.addSeparator(); |
317 |
|
|
318 |
|
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
319 |
|
m.add(mi); |
320 |
|
mi.addActionListener(new ActionListener() { |
321 |
|
public void |
322 |
|
actionPerformed(ActionEvent e) { onWindowClose(); } |
323 |
|
}); |
324 |
|
|
325 |
|
menuBar.add(m); |
326 |
|
|
327 |
|
|
328 |
|
// Edit |
329 |
|
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
330 |
|
menuBar.add(m); |
331 |
|
|
332 |
|
mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel")); |
333 |
|
m.add(mi); |
334 |
|
mi.addActionListener(new ActionListener() { |
335 |
|
public void |
336 |
|
actionPerformed(ActionEvent e) { |
337 |
|
CC.getSamplerModel().addBackendChannel(); |
338 |
|
} |
339 |
|
}); |
340 |
|
|
341 |
|
m.addSeparator(); |
342 |
|
|
343 |
|
mi = new JMenuItem(a4n.createMidiDevice); |
344 |
|
mi.setIcon(null); |
345 |
|
m.add(mi); |
346 |
|
|
347 |
|
mi = new JMenuItem(a4n.createAudioDevice); |
348 |
|
mi.setIcon(null); |
349 |
|
m.add(mi); |
350 |
|
|
351 |
|
m.addSeparator(); |
352 |
|
|
353 |
|
mi = new JMenuItem(a4n.editPreferences); |
354 |
|
mi.setIcon(null); |
355 |
|
mi.setAccelerator(KeyStroke.getKeyStroke ( |
356 |
|
KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
357 |
|
)); |
358 |
|
m.add(mi); |
359 |
|
|
360 |
|
// View |
361 |
|
m = new FantasiaMenu(i18n.getMenuLabel("view")); |
362 |
|
menuBar.add(m); |
363 |
|
|
364 |
|
m.add(cbmiToolBarVisible); |
365 |
|
|
366 |
|
cbmiToolBarVisible.addActionListener(new ActionListener() { |
367 |
|
public void |
368 |
|
actionPerformed(ActionEvent e) { |
369 |
|
showToolBar(cbmiToolBarVisible.getState()); |
370 |
|
} |
371 |
|
}); |
372 |
|
|
373 |
|
boolean b = preferences().getBoolProperty("toolBar.visible"); |
374 |
|
cbmiToolBarVisible.setSelected(b); |
375 |
|
showToolBar(b); |
376 |
|
|
377 |
|
cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
378 |
|
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
379 |
|
)); |
380 |
|
m.add(cbmiSidePaneVisible); |
381 |
|
|
382 |
|
cbmiSidePaneVisible.addActionListener(new ActionListener() { |
383 |
|
public void |
384 |
|
actionPerformed(ActionEvent e) { |
385 |
|
showSidePane(cbmiSidePaneVisible.getState()); |
386 |
|
} |
387 |
|
}); |
388 |
|
|
389 |
|
b = preferences().getBoolProperty("sidePane.visible"); |
390 |
|
cbmiSidePaneVisible.setSelected(b); |
391 |
|
showSidePane(b); |
392 |
|
|
393 |
|
cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
394 |
|
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
395 |
|
)); |
396 |
|
m.add(cbmiDevicesPaneVisible); |
397 |
|
|
398 |
|
cbmiDevicesPaneVisible.addActionListener(new ActionListener() { |
399 |
|
public void |
400 |
|
actionPerformed(ActionEvent e) { |
401 |
|
showDevicesPane(cbmiDevicesPaneVisible.getState()); |
402 |
|
} |
403 |
|
}); |
404 |
|
|
405 |
|
b = preferences().getBoolProperty("devicesPane.visible"); |
406 |
|
cbmiDevicesPaneVisible.setSelected(b); |
407 |
|
showDevicesPane(b); |
408 |
|
|
409 |
|
|
410 |
|
// Window |
411 |
|
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
412 |
|
menuBar.add(m); |
413 |
|
|
414 |
|
mi = new JMenuItem(a4n.windowLSConsole); |
415 |
|
mi.setIcon(null); |
416 |
|
m.add(mi); |
417 |
|
|
418 |
|
mi = new JMenuItem(a4n.windowInstrumentsDb); |
419 |
|
mi.setIcon(null); |
420 |
|
m.add(mi); |
421 |
|
|
422 |
|
|
423 |
|
// Help |
424 |
|
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
425 |
|
|
426 |
|
mi = new JMenuItem(a4n.helpAbout); |
427 |
|
mi.setIcon(null); |
428 |
|
m.add(mi); |
429 |
|
|
430 |
|
menuBar.add(m); |
431 |
} |
} |
432 |
|
|
433 |
/** |
/** |
436 |
*/ |
*/ |
437 |
public void |
public void |
438 |
insertChannelsPane(JSChannelsPane pane, int idx) { |
insertChannelsPane(JSChannelsPane pane, int idx) { |
439 |
getChannelsPaneList().removeAllElements(); |
|
|
addChannelsPane(pane); |
|
440 |
} |
} |
441 |
|
|
442 |
/** |
/** |
454 |
public void |
public void |
455 |
setSelectedChannelsPane(JSChannelsPane pane) { } |
setSelectedChannelsPane(JSChannelsPane pane) { } |
456 |
|
|
457 |
public static void |
public void |
458 |
repack(JSMainFrame frame) { |
installJSamplerHome() { |
459 |
int y = frame.getLocation().y; |
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
460 |
int height = frame.getSize().height; |
chooser.setVisible(true); |
461 |
y += (height - frame.getPreferredSize().height); |
if(chooser.isCancelled()) return; |
462 |
|
|
463 |
if((height - frame.getPreferredSize().height) > 0) { |
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
|
frame.pack(); |
|
|
frame.setLocation(frame.getLocation().x, y); |
|
|
} else { |
|
|
frame.setLocation(frame.getLocation().x, y); |
|
|
frame.pack(); |
|
|
} |
|
464 |
} |
} |
465 |
|
|
466 |
public void |
public void |
467 |
installJSamplerHome() { } |
showDetailedErrorMessage(Frame owner, String err, String details) { |
468 |
} |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
469 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
470 |
class FantasiaTitleBar extends TitleBar { |
); |
471 |
FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); } |
dlg.setVisible(true); |
472 |
|
} |
473 |
|
|
474 |
|
public void |
475 |
|
showDetailedErrorMessage(Dialog owner, String err, String details) { |
476 |
|
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
477 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
478 |
|
); |
479 |
|
dlg.setVisible(true); |
480 |
|
} |
481 |
|
|
482 |
|
protected LSConsoleModel |
483 |
|
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
484 |
|
|
485 |
|
protected LSConsolePane |
486 |
|
getLSConsolePane() { |
487 |
|
return getLSConsoleFrame().getLSConsolePane(); |
488 |
|
} |
489 |
|
|
490 |
|
protected LSConsoleFrame |
491 |
|
getLSConsoleFrame() { return lsConsoleFrame; } |
492 |
|
|
493 |
class ContextMenu extends MouseAdapter { |
protected void |
494 |
private final JPopupMenu cmenu = new JPopupMenu(); |
runScript() { |
495 |
|
String s = preferences().getStringProperty("lastScriptLocation"); |
496 |
|
JFileChooser fc = new JFileChooser(s); |
497 |
|
fc.setFileFilter(new LscpFileFilter()); |
498 |
|
int result = fc.showOpenDialog(this); |
499 |
|
if(result != JFileChooser.APPROVE_OPTION) return; |
500 |
|
|
501 |
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
502 |
|
preferences().setStringProperty("lastScriptLocation", path); |
503 |
|
|
504 |
|
runScript(fc.getSelectedFile()); |
505 |
|
} |
506 |
|
|
507 |
|
private void |
508 |
|
runScript(String script) { runScript(new File(script)); } |
509 |
|
|
510 |
|
private void |
511 |
|
runScript(File script) { |
512 |
|
FileReader fr; |
513 |
|
try { fr = new FileReader(script); } |
514 |
|
catch(FileNotFoundException e) { |
515 |
|
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
516 |
|
return; |
517 |
|
} |
518 |
|
|
519 |
ContextMenu() { |
BufferedReader br = new BufferedReader(fr); |
520 |
JMenuItem mi; |
|
521 |
|
try { |
522 |
final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem ( |
String s = br.readLine(); |
523 |
i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop") |
while(s != null) { |
524 |
); |
getLSConsoleModel().setCommandLineText(s); |
525 |
cmi.setIcon(null); |
getLSConsoleModel().execCommand(); |
526 |
cmi.setSelected(FantasiaPrefs.isAlwaysOnTop()); |
s = br.readLine(); |
527 |
|
} |
528 |
cmenu.add(cmi); |
} catch(Exception e) { |
529 |
|
HF.showErrorMessage(e); |
530 |
cmi.addActionListener(new ActionListener() { |
return; |
531 |
public void |
} |
532 |
actionPerformed(ActionEvent e) { |
|
533 |
CC.getMainFrame().setAlwaysOnTop(cmi.isSelected()); |
String s = script.getAbsolutePath(); |
534 |
} |
recentScripts.remove(s); |
535 |
}); |
recentScripts.insertElementAt(s, 0); |
536 |
|
|
537 |
|
updateRecentScriptsMenu(); |
538 |
|
} |
539 |
|
|
540 |
|
protected void |
541 |
|
clearRecentScripts() { |
542 |
|
recentScripts.removeAllElements(); |
543 |
|
updateRecentScriptsMenu(); |
544 |
|
} |
545 |
|
|
546 |
|
protected void |
547 |
|
updateRecentScriptsMenu() { |
548 |
|
int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
549 |
|
while(recentScripts.size() > size) { |
550 |
|
recentScripts.removeElementAt(recentScripts.size() - 1); |
551 |
|
} |
552 |
|
|
553 |
|
recentScriptsMenu.removeAll(); |
554 |
|
|
555 |
|
for(String script : recentScripts) { |
556 |
|
JMenuItem mi = new JMenuItem(script); |
557 |
|
recentScriptsMenu.add(mi); |
558 |
|
mi.addActionListener(new RecentScriptHandler(script)); |
559 |
|
} |
560 |
|
|
561 |
|
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
562 |
|
} |
563 |
|
|
564 |
|
private void |
565 |
|
showToolBar(boolean b) { |
566 |
|
preferences().setBoolProperty("toolBar.visible", b); |
567 |
|
standardBar.setVisible(b); |
568 |
|
} |
569 |
|
|
570 |
|
private void |
571 |
|
showSidePane(boolean b) { |
572 |
|
preferences().setBoolProperty("sidePane.visible", b); |
573 |
|
rootPane.remove(rightPane); |
574 |
|
rootPane.remove(hSplitPane); |
575 |
|
|
576 |
|
if(b) { |
577 |
|
hSplitPane.setRightComponent(rightPane); |
578 |
|
rootPane.add(hSplitPane); |
579 |
|
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
580 |
|
|
581 |
/*mi = new JMenuItem(A4n.moveChannelsUp); |
hSplitPane.setDividerLocation(i); |
582 |
mi.setIcon(null); |
hSplitPane.validate(); |
583 |
cmenu.add(mi); |
} else { |
584 |
|
rootPane.add(rightPane); |
585 |
|
|
586 |
cmenu.addSeparator(); |
} |
587 |
|
|
588 |
|
int w = getPreferredSize().width; |
589 |
|
int h = getSize().height; |
590 |
|
setSize(new Dimension(w, h)); |
591 |
|
|
592 |
|
rootPane.revalidate(); |
593 |
|
rootPane.validate(); |
594 |
|
rootPane.repaint(); |
595 |
|
|
596 |
|
SwingUtilities.invokeLater(new Runnable() { |
597 |
|
public void |
598 |
|
run() { sidePanesVisibilityChanged(); } |
599 |
|
}); |
600 |
|
} |
601 |
|
|
602 |
|
private void |
603 |
|
showDevicesPane(boolean b) { |
604 |
|
preferences().setBoolProperty("devicesPane.visible", b); |
605 |
|
|
606 |
|
int width = sidePane.getWidth(); |
607 |
|
int height = sidePane.getPreferredSize().height; |
608 |
|
if(width != 0) sidePane.setPreferredSize(new Dimension(width, height)); |
609 |
|
|
610 |
|
if(b) { |
611 |
|
int w = preferences().getIntProperty("devicesPane.width", 200); |
612 |
|
|
613 |
mi = new JMenuItem(A4n.removeChannels); |
int h = spDevicesPane.getPreferredSize().height; |
614 |
mi.setIcon(null); |
spDevicesPane.setPreferredSize(new Dimension(w, h)); |
615 |
cmenu.add(mi);*/ |
} else { |
616 |
|
int w = spDevicesPane.getWidth(); |
617 |
|
if(w > 0 && w < 200) w = 200; |
618 |
|
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
619 |
} |
} |
620 |
|
|
621 |
public void |
hSplitPane.setResizeWeight(0.0); |
622 |
mousePressed(MouseEvent e) { |
spDevicesPane.setVisible(b); |
623 |
if(e.isPopupTrigger()) show(e); |
hSplitPane.resetToPreferredSizes(); |
624 |
|
|
625 |
|
int w = getPreferredSize().width; |
626 |
|
int h = getSize().height; |
627 |
|
setSize(new Dimension(w, h)); |
628 |
|
|
629 |
|
rootPane.validate(); |
630 |
|
rootPane.repaint(); |
631 |
|
//hSplitPane.validate(); |
632 |
|
|
633 |
|
SwingUtilities.invokeLater(new Runnable() { |
634 |
|
public void |
635 |
|
run() { sidePanesVisibilityChanged(); } |
636 |
|
}); |
637 |
|
} |
638 |
|
|
639 |
|
private void |
640 |
|
sidePanesVisibilityChanged() { |
641 |
|
boolean sidePaneVisible = cbmiSidePaneVisible.isSelected(); |
642 |
|
boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected(); |
643 |
|
|
644 |
|
if(sidePaneVisible && devicesPaneVisible) { |
645 |
|
hSplitPane.setResizeWeight(0.5); |
646 |
|
} else if(sidePaneVisible && !devicesPaneVisible) { |
647 |
|
hSplitPane.setResizeWeight(1.0); |
648 |
|
} |
649 |
|
|
650 |
|
if(!sidePaneVisible && !devicesPaneVisible) { |
651 |
|
standardBar.showFantasiaLogo(false); |
652 |
|
if(isResizable()) setResizable(false); |
653 |
|
} else { |
654 |
|
standardBar.showFantasiaLogo(true); |
655 |
|
if(!isResizable()) setResizable(true); |
656 |
} |
} |
657 |
|
} |
658 |
|
|
659 |
|
private class RecentScriptHandler implements ActionListener { |
660 |
|
private String script; |
661 |
|
|
662 |
|
RecentScriptHandler(String script) { this.script = script; } |
663 |
|
|
664 |
public void |
public void |
665 |
mouseReleased(MouseEvent e) { |
actionPerformed(ActionEvent e) { |
666 |
if(e.isPopupTrigger()) show(e); |
runScript(script); |
667 |
|
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
668 |
|
a4n.windowLSConsole.actionPerformed(null); |
669 |
|
} |
670 |
} |
} |
671 |
|
} |
672 |
|
|
673 |
void |
private static class FantasiaMenu extends JMenu { |
674 |
show(MouseEvent e) { |
FantasiaMenu(String s) { |
675 |
cmenu.show(e.getComponent(), e.getX(), e.getY()); |
super(s); |
676 |
|
setFont(getFont().deriveFont(java.awt.Font.BOLD)); |
677 |
|
setOpaque(false); |
678 |
|
} |
679 |
|
} |
680 |
|
|
681 |
|
private class FantasiaMenuBar extends JMenuBar { |
682 |
|
private Insets pixmapInsets = new Insets(6, 6, 0, 6); |
683 |
|
private Insets pixmapInsets2 = new Insets(6, 6, 6, 6); |
684 |
|
|
685 |
|
FantasiaMenuBar() { |
686 |
|
setOpaque(false); |
687 |
|
} |
688 |
|
|
689 |
|
protected void |
690 |
|
paintComponent(Graphics g) { |
691 |
|
super.paintComponent(g); |
692 |
|
if(standardBar.isVisible()) { |
693 |
|
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
694 |
|
} else { |
695 |
|
PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2); |
696 |
|
} |
697 |
} |
} |
698 |
} |
} |
699 |
} |
} |