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