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