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 |
* |
* |
26 |
import java.awt.Dialog; |
import java.awt.Dialog; |
27 |
import java.awt.Dimension; |
import java.awt.Dimension; |
28 |
import java.awt.Frame; |
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 |
|
import java.io.StringReader; |
46 |
|
|
47 |
|
import java.util.Vector; |
48 |
import java.util.logging.Level; |
import java.util.logging.Level; |
49 |
|
|
50 |
|
import javax.swing.BorderFactory; |
51 |
import javax.swing.Box; |
import javax.swing.Box; |
52 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
53 |
import javax.swing.JCheckBoxMenuItem; |
import javax.swing.JCheckBoxMenuItem; |
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.JSamplerHomeChooser; |
81 |
|
|
82 |
|
import static org.jsampler.view.fantasia.A4n.a4n; |
83 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
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 |
/** |
/** |
90 |
* @author Grigor Iliev |
* @author Grigor Iliev |
91 |
*/ |
*/ |
92 |
public class MainFrame extends JSMainFrame { |
public class MainFrame extends JSMainFrame { |
93 |
private final static int TITLE_BAR_WIDTH = 420; |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
94 |
private final static int TITLE_BAR_HEIGHT = 29; |
private final StandardBar standardBar = new StandardBar(); |
95 |
|
private final MainPane mainPane = new MainPane(); |
96 |
|
private final DevicesPane devicesPane = new DevicesPane(); |
97 |
|
|
98 |
|
private final JMenu recentScriptsMenu = |
99 |
|
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
100 |
|
|
101 |
private final ChannelsPane channelsPane = new ChannelsPane(""); |
private final JSplitPane hSplitPane; |
102 |
|
|
103 |
|
private final SidePane sidePane = new SidePane(); |
104 |
|
|
105 |
|
private LSConsoleFrame lsConsoleFrame = null; |
106 |
|
private final Vector<String> recentScripts = new Vector<String>(); |
107 |
|
|
108 |
|
|
109 |
/** Creates a new instance of <code>MainFrame</code> */ |
/** Creates a new instance of <code>MainFrame</code> */ |
110 |
public |
public |
111 |
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); |
|
|
} |
|
|
|
|
112 |
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(); } |
|
|
}); |
|
113 |
|
|
114 |
|
if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage()); |
115 |
|
|
116 |
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))); |
|
117 |
|
|
118 |
|
addMenu(); |
119 |
|
|
120 |
|
addChannelsPane(mainPane.getChannelsPane()); |
121 |
|
|
122 |
tb.add(createVSeparator()); |
JScrollPane sp = new JScrollPane(createRightPane()); |
123 |
|
sp.setBorder(BorderFactory.createEmptyBorder()); |
124 |
|
|
125 |
tb.add(Box.createRigidArea(new Dimension(275, 0))); |
hSplitPane = new JSplitPane ( |
126 |
|
JSplitPane.HORIZONTAL_SPLIT, |
127 |
|
true, // continuousLayout |
128 |
|
sidePane, sp |
129 |
|
); |
130 |
|
|
131 |
tb.add(createVSeparator()); |
getContentPane().add(hSplitPane); |
132 |
|
|
133 |
tb.add(Box.createRigidArea(new Dimension(29, 0))); |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
134 |
|
hSplitPane.setDividerLocation(i); |
135 |
|
|
136 |
tb.add(createVSeparator()); |
setSavedSize(); |
137 |
|
} |
138 |
tb.add(Box.createRigidArea(new Dimension(40, 0))); |
|
139 |
|
private JPanel |
140 |
|
createRightPane() { |
141 |
|
JPanel p = new JPanel(); |
142 |
|
GridBagLayout gridbag = new GridBagLayout(); |
143 |
|
GridBagConstraints c = new GridBagConstraints(); |
144 |
|
|
145 |
tb.add(createVSeparator()); |
p.setLayout(gridbag); |
146 |
|
|
147 |
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); |
|
148 |
|
|
149 |
getContentPane().setBackground(new java.awt.Color(0x818181)); |
c.gridx = 1; |
150 |
getRootPane().setOpaque(false); |
c.gridy = 0; |
151 |
getLayeredPane().setOpaque(false); |
c.weightx = 1.0; |
152 |
//getContentPane().setVisible(false); |
c.weighty = 1.0; |
153 |
|
c.insets = new Insets(0, 3, 3, 0); |
154 |
|
gridbag.setConstraints(devicesPane, c); |
155 |
|
p.add(devicesPane); |
156 |
|
|
157 |
|
c.gridx = 0; |
158 |
|
c.gridy = 0; |
159 |
|
c.weightx = 0.0; |
160 |
|
c.weighty = 1.0; |
161 |
|
c.insets = new Insets(0, 3, 3, 3); |
162 |
|
c.fill = GridBagConstraints.VERTICAL; |
163 |
|
gridbag.setConstraints(mainPane, c); |
164 |
|
p.add(mainPane); |
165 |
|
|
166 |
setAlwaysOnTop(FantasiaPrefs.isAlwaysOnTop()); |
return p; |
167 |
|
} |
168 |
|
|
169 |
|
private void |
170 |
|
setSavedSize() { |
171 |
|
String s = preferences().getStringProperty("MainFrame.sizeAndLocation"); |
172 |
|
if(s == null) { |
173 |
|
setDefaultSizeAndLocation(); |
174 |
|
return; |
175 |
|
} |
176 |
pack(); |
pack(); |
|
|
|
|
String s = FantasiaPrefs.getWindowLocation(); |
|
|
|
|
177 |
try { |
try { |
178 |
if(s == null) { |
int i = s.indexOf(','); |
179 |
setDefaultLocation(); |
int x = Integer.parseInt(s.substring(0, i)); |
|
} else { |
|
|
int i = s.indexOf(','); |
|
|
int x = Integer.parseInt(s.substring(0, i)); |
|
180 |
|
|
181 |
s = s.substring(i + 1); |
s = s.substring(i + 1); |
182 |
int y = Integer.parseInt(s); |
i = s.indexOf(','); |
183 |
|
int y = Integer.parseInt(s.substring(0, i)); |
184 |
|
|
185 |
setLocation(x, y); |
s = s.substring(i + 1); |
186 |
} |
i = s.indexOf(','); |
187 |
|
int width = Integer.parseInt(s.substring(0, i)); |
188 |
|
|
189 |
|
s = s.substring(i + 1); |
190 |
|
int height = Integer.parseInt(s); |
191 |
|
|
192 |
|
setBounds(x, y, width, height); |
193 |
} catch(Exception x) { |
} catch(Exception x) { |
194 |
String msg = "Parsing of window size and location string failed"; |
String msg = "Parsing of window size and location string failed"; |
195 |
CC.getLogger().log(Level.INFO, msg, x); |
CC.getLogger().log(Level.INFO, msg, x); |
196 |
setDefaultLocation(); |
setDefaultSizeAndLocation(); |
197 |
|
} |
198 |
|
|
199 |
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
200 |
|
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
201 |
} |
} |
202 |
} |
} |
203 |
|
|
204 |
private void |
private void |
205 |
setDefaultLocation() { |
setDefaultSizeAndLocation() { |
206 |
Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
setPreferredSize(new Dimension(900, 600)); |
207 |
setLocation((d.width - TITLE_BAR_WIDTH) / 2, (d.height - TITLE_BAR_HEIGHT) / 2); |
pack(); |
208 |
|
setLocationRelativeTo(null); |
209 |
} |
} |
210 |
|
|
211 |
|
|
212 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
213 |
protected void |
protected void |
214 |
onWindowClose() { |
onWindowClose() { |
215 |
FantasiaPrefs.setAlwaysOnTop(isAlwaysOnTop()); |
sidePane.savePreferences(); |
216 |
|
|
217 |
|
int i = hSplitPane.getDividerLocation(); |
218 |
|
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
219 |
|
|
220 |
|
preferences().setBoolProperty ( |
221 |
|
"MainFrame.windowMaximized", |
222 |
|
(getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
223 |
|
); |
224 |
|
|
225 |
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
226 |
|
super.onWindowClose(); |
227 |
|
return; |
228 |
|
} |
229 |
|
|
230 |
java.awt.Point p = getLocation(); |
java.awt.Point p = getLocation(); |
231 |
Dimension d = getSize(); |
Dimension d = getSize(); |
232 |
StringBuffer sb = new StringBuffer(); |
StringBuffer sb = new StringBuffer(); |
233 |
sb.append(p.x).append(',').append(p.y + getSize().height - TITLE_BAR_HEIGHT); |
sb.append(p.x).append(',').append(p.y).append(','); |
234 |
FantasiaPrefs.setWindowLocation(sb.toString()); |
sb.append(d.width).append(',').append(d.height); |
235 |
|
preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString()); |
236 |
|
|
237 |
|
sb = new StringBuffer(); |
238 |
|
for(String s : recentScripts) sb.append(s).append("\n"); |
239 |
|
preferences().setStringProperty(RECENT_LSCP_SCRIPTS, sb.toString()); |
240 |
|
|
241 |
|
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
242 |
|
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
243 |
|
} |
244 |
|
|
245 |
super.onWindowClose(); |
super.onWindowClose(); |
246 |
} |
} |
247 |
|
|
248 |
private JPanel |
private void |
249 |
createVSeparator() { |
addMenu() { |
250 |
JPanel p = new JPanel(); |
JMenu m; |
251 |
p.setName("VSeparator"); |
JMenuItem mi; |
252 |
p.setOpaque(false); |
|
253 |
p.setPreferredSize(new Dimension(2, 29)); |
setJMenuBar(menuBar); |
254 |
p.setMinimumSize(p.getPreferredSize()); |
|
255 |
p.setMaximumSize(p.getPreferredSize()); |
// Actions |
256 |
return p; |
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
257 |
|
|
258 |
|
mi = new JMenuItem(a4n.connect); |
259 |
|
mi.setIcon(null); |
260 |
|
//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); |
261 |
|
m.add(mi); |
262 |
|
|
263 |
|
mi = new JMenuItem(a4n.samplerInfo); |
264 |
|
mi.setIcon(null); |
265 |
|
m.add(mi); |
266 |
|
|
267 |
|
m.addSeparator(); |
268 |
|
|
269 |
|
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
270 |
|
m.add(exportMenu); |
271 |
|
|
272 |
|
mi = new JMenuItem(a4n.exportSamplerConfig); |
273 |
|
mi.setIcon(null); |
274 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
275 |
|
exportMenu.add(mi); |
276 |
|
|
277 |
|
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
278 |
|
mi.setIcon(null); |
279 |
|
exportMenu.add(mi); |
280 |
|
|
281 |
|
m.addSeparator(); |
282 |
|
|
283 |
|
mi = new JMenuItem(a4n.loadScript); |
284 |
|
mi.setIcon(null); |
285 |
|
m.add(mi); |
286 |
|
|
287 |
|
String s = preferences().getStringProperty(RECENT_LSCP_SCRIPTS); |
288 |
|
BufferedReader br = new BufferedReader(new StringReader(s)); |
289 |
|
|
290 |
|
try { |
291 |
|
s = br.readLine(); |
292 |
|
while(s != null) { |
293 |
|
recentScripts.add(s); |
294 |
|
s = br.readLine(); |
295 |
|
} |
296 |
|
} catch(Exception x) { |
297 |
|
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
298 |
|
} |
299 |
|
|
300 |
|
updateRecentScriptsMenu(); |
301 |
|
|
302 |
|
m.add(recentScriptsMenu); |
303 |
|
|
304 |
|
m.addSeparator(); |
305 |
|
|
306 |
|
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
307 |
|
m.add(mi); |
308 |
|
mi.addActionListener(new ActionListener() { |
309 |
|
public void |
310 |
|
actionPerformed(ActionEvent e) { onWindowClose(); } |
311 |
|
}); |
312 |
|
|
313 |
|
menuBar.add(m); |
314 |
|
|
315 |
|
|
316 |
|
// Edit |
317 |
|
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
318 |
|
menuBar.add(m); |
319 |
|
|
320 |
|
mi = new JMenuItem(a4n.editPreferences); |
321 |
|
mi.setIcon(null); |
322 |
|
mi.setAccelerator(KeyStroke.getKeyStroke ( |
323 |
|
KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
324 |
|
)); |
325 |
|
m.add(mi); |
326 |
|
|
327 |
|
|
328 |
|
// Window |
329 |
|
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
330 |
|
menuBar.add(m); |
331 |
|
|
332 |
|
mi = new JMenuItem(a4n.windowLSConsole); |
333 |
|
mi.setIcon(null); |
334 |
|
m.add(mi); |
335 |
|
|
336 |
|
mi = new JMenuItem(a4n.windowInstrumentsDb); |
337 |
|
mi.setIcon(null); |
338 |
|
m.add(mi); |
339 |
|
|
340 |
|
|
341 |
|
// Help |
342 |
|
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
343 |
|
|
344 |
|
mi = new JMenuItem(a4n.helpAbout); |
345 |
|
mi.setIcon(null); |
346 |
|
m.add(mi); |
347 |
|
|
348 |
|
menuBar.add(m); |
349 |
} |
} |
350 |
|
|
351 |
/** |
/** |
354 |
*/ |
*/ |
355 |
public void |
public void |
356 |
insertChannelsPane(JSChannelsPane pane, int idx) { |
insertChannelsPane(JSChannelsPane pane, int idx) { |
357 |
getChannelsPaneList().removeAllElements(); |
|
|
addChannelsPane(pane); |
|
358 |
} |
} |
359 |
|
|
360 |
/** |
/** |
372 |
public void |
public void |
373 |
setSelectedChannelsPane(JSChannelsPane pane) { } |
setSelectedChannelsPane(JSChannelsPane pane) { } |
374 |
|
|
|
public static void |
|
|
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(); |
|
|
} |
|
|
} |
|
|
|
|
375 |
public void |
public void |
376 |
installJSamplerHome() { } |
installJSamplerHome() { |
377 |
|
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
378 |
|
chooser.setVisible(true); |
379 |
|
if(chooser.isCancelled()) return; |
380 |
|
|
381 |
|
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
382 |
|
} |
383 |
|
|
384 |
public void |
public void |
385 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
showDetailedErrorMessage(Frame owner, String err, String details) { |
390 |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
391 |
// TODO: |
// TODO: |
392 |
} |
} |
|
} |
|
|
|
|
|
class FantasiaTitleBar extends TitleBar { |
|
|
FantasiaTitleBar() { this.addMouseListener(new ContextMenu()); } |
|
393 |
|
|
394 |
class ContextMenu extends MouseAdapter { |
protected LSConsoleModel |
395 |
private final JPopupMenu cmenu = new JPopupMenu(); |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
396 |
|
|
397 |
|
protected LSConsolePane |
398 |
|
getLSConsolePane() { |
399 |
|
return getLSConsoleFrame().getLSConsolePane(); |
400 |
|
} |
401 |
|
|
402 |
|
protected LSConsoleFrame |
403 |
|
getLSConsoleFrame() { |
404 |
|
if(lsConsoleFrame == null) lsConsoleFrame = new LSConsoleFrame(); |
405 |
|
return lsConsoleFrame; |
406 |
|
} |
407 |
|
|
408 |
|
protected void |
409 |
|
runScript() { |
410 |
|
String s = preferences().getStringProperty("lastScriptLocation"); |
411 |
|
JFileChooser fc = new JFileChooser(s); |
412 |
|
fc.setFileFilter(new LscpFileFilter()); |
413 |
|
int result = fc.showOpenDialog(this); |
414 |
|
if(result != JFileChooser.APPROVE_OPTION) return; |
415 |
|
|
416 |
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
417 |
|
preferences().setStringProperty("lastScriptLocation", path); |
418 |
|
|
419 |
|
runScript(fc.getSelectedFile()); |
420 |
|
} |
421 |
|
|
422 |
|
private void |
423 |
|
runScript(String script) { runScript(new File(script)); } |
424 |
|
|
425 |
|
private void |
426 |
|
runScript(File script) { |
427 |
|
FileReader fr; |
428 |
|
try { fr = new FileReader(script); } |
429 |
|
catch(FileNotFoundException e) { |
430 |
|
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
431 |
|
return; |
432 |
|
} |
433 |
|
|
434 |
ContextMenu() { |
BufferedReader br = new BufferedReader(fr); |
435 |
JMenuItem mi; |
|
436 |
|
try { |
437 |
final JCheckBoxMenuItem cmi = new JCheckBoxMenuItem ( |
String s = br.readLine(); |
438 |
i18n.getMenuLabel("FantasiaTitleBar.AlwaysOnTop") |
while(s != null) { |
439 |
); |
getLSConsoleModel().setCommandLineText(s); |
440 |
cmi.setIcon(null); |
getLSConsoleModel().execCommand(); |
441 |
cmi.setSelected(FantasiaPrefs.isAlwaysOnTop()); |
s = br.readLine(); |
442 |
|
} |
443 |
cmenu.add(cmi); |
} catch(Exception e) { |
444 |
|
HF.showErrorMessage(e); |
445 |
cmi.addActionListener(new ActionListener() { |
return; |
|
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);*/ |
|
446 |
} |
} |
447 |
|
|
448 |
public void |
String s = script.getAbsolutePath(); |
449 |
mousePressed(MouseEvent e) { |
recentScripts.remove(s); |
450 |
if(e.isPopupTrigger()) show(e); |
recentScripts.insertElementAt(s, 0); |
451 |
|
|
452 |
|
updateRecentScriptsMenu(); |
453 |
|
} |
454 |
|
|
455 |
|
protected void |
456 |
|
clearRecentScripts() { |
457 |
|
recentScripts.removeAllElements(); |
458 |
|
updateRecentScriptsMenu(); |
459 |
|
} |
460 |
|
|
461 |
|
protected void |
462 |
|
updateRecentScriptsMenu() { |
463 |
|
int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
464 |
|
while(recentScripts.size() > size) { |
465 |
|
recentScripts.removeElementAt(recentScripts.size() - 1); |
466 |
} |
} |
467 |
|
|
468 |
|
recentScriptsMenu.removeAll(); |
469 |
|
|
470 |
|
for(String script : recentScripts) { |
471 |
|
JMenuItem mi = new JMenuItem(script); |
472 |
|
recentScriptsMenu.add(mi); |
473 |
|
mi.addActionListener(new RecentScriptHandler(script)); |
474 |
|
} |
475 |
|
|
476 |
|
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
477 |
|
} |
478 |
|
|
479 |
|
private class RecentScriptHandler implements ActionListener { |
480 |
|
private String script; |
481 |
|
|
482 |
|
RecentScriptHandler(String script) { this.script = script; } |
483 |
|
|
484 |
public void |
public void |
485 |
mouseReleased(MouseEvent e) { |
actionPerformed(ActionEvent e) { |
486 |
if(e.isPopupTrigger()) show(e); |
runScript(script); |
487 |
|
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
488 |
|
a4n.windowLSConsole.actionPerformed(null); |
489 |
|
} |
490 |
} |
} |
491 |
|
} |
492 |
|
|
493 |
void |
private static class FantasiaMenu extends JMenu { |
494 |
show(MouseEvent e) { |
FantasiaMenu(String s) { |
495 |
cmenu.show(e.getComponent(), e.getX(), e.getY()); |
super(s); |
496 |
|
setFont(getFont().deriveFont(java.awt.Font.BOLD)); |
497 |
|
setOpaque(false); |
498 |
|
} |
499 |
|
} |
500 |
|
|
501 |
|
private static class FantasiaMenuBar extends JMenuBar { |
502 |
|
private static Insets pixmapInsets = new Insets(6, 6, 0, 6); |
503 |
|
|
504 |
|
FantasiaMenuBar() { |
505 |
|
setOpaque(false); |
506 |
|
} |
507 |
|
|
508 |
|
protected void |
509 |
|
paintComponent(Graphics g) { |
510 |
|
super.paintComponent(g); |
511 |
|
|
512 |
|
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
513 |
} |
} |
514 |
} |
} |
515 |
} |
} |