1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005 Grigor Kirilov Iliev |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
23 |
package org.jsampler.view.classic; |
package org.jsampler.view.classic; |
24 |
|
|
25 |
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
26 |
|
import java.awt.Color; |
27 |
|
import java.awt.Dialog; |
28 |
import java.awt.Dimension; |
import java.awt.Dimension; |
29 |
|
import java.awt.Frame; |
30 |
|
|
31 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
33 |
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
34 |
|
|
35 |
|
import java.io.BufferedReader; |
36 |
|
import java.io.File; |
37 |
|
import java.io.FileNotFoundException; |
38 |
|
import java.io.FileReader; |
39 |
|
|
40 |
|
import java.util.logging.Level; |
41 |
import java.util.Vector; |
import java.util.Vector; |
42 |
|
|
43 |
import javax.swing.Action; |
import javax.swing.Action; |
44 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
45 |
import javax.swing.JCheckBoxMenuItem; |
import javax.swing.JCheckBoxMenuItem; |
46 |
|
import javax.swing.JFileChooser; |
47 |
import javax.swing.JMenu; |
import javax.swing.JMenu; |
48 |
import javax.swing.JMenuBar; |
import javax.swing.JMenuBar; |
49 |
import javax.swing.JMenuItem; |
import javax.swing.JMenuItem; |
58 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
59 |
|
|
60 |
import net.sf.juife.NavigationPage; |
import net.sf.juife.NavigationPage; |
|
import net.sf.juife.NavigationPane; |
|
61 |
|
|
62 |
import org.jsampler.CC; |
import org.jsampler.CC; |
63 |
|
import org.jsampler.HF; |
64 |
|
import org.jsampler.LSConsoleModel; |
65 |
|
import org.jsampler.OrchestraModel; |
66 |
|
import org.jsampler.Server; |
67 |
|
|
68 |
import org.jsampler.view.JSChannel; |
import org.jsampler.view.JSChannel; |
69 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
70 |
|
import org.jsampler.view.LscpFileFilter; |
71 |
|
|
72 |
|
import org.jsampler.view.std.JSConnectDlg; |
73 |
|
import org.jsampler.view.std.JSDetailedErrorDlg; |
74 |
|
import org.jsampler.view.std.JSQuitDlg; |
75 |
|
import org.jsampler.view.std.JSamplerHomeChooser; |
76 |
|
|
77 |
|
import static org.jsampler.view.classic.A4n.a4n; |
78 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
79 |
|
import static org.jsampler.view.classic.ClassicPrefs.preferences; |
80 |
import static org.jsampler.view.classic.LeftPane.getLeftPane; |
import static org.jsampler.view.classic.LeftPane.getLeftPane; |
81 |
|
import static org.jsampler.view.std.StdPrefs.*; |
82 |
|
|
83 |
/** |
/** |
84 |
* |
* |
86 |
*/ |
*/ |
87 |
public class |
public class |
88 |
MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener { |
MainFrame extends org.jsampler.view.JSMainFrame implements ChangeListener, ListSelectionListener { |
89 |
public static ImageIcon applicationIcon = null; |
public static ImageIcon applicationIcon = Res.appIcon; |
|
|
|
|
static { |
|
|
String s = "org/jsampler/view/classic/res/icons/app-icon.png"; |
|
|
java.net.URL url = ClassLoader.getSystemClassLoader().getResource(s); |
|
|
if(url != null) applicationIcon = new ImageIcon(url); |
|
|
} |
|
90 |
|
|
91 |
private final Toolbar toolbar = new Toolbar(); |
private final ChannelsBar channelsBar = new ChannelsBar(); |
92 |
private final Statusbar statusbar = new Statusbar(); |
private final Statusbar statusbar = new Statusbar(); |
93 |
private final JMenuBar menuBar = new JMenuBar(); |
private final JMenuBar menuBar = new JMenuBar(); |
94 |
|
private final JMenu recentScriptsMenu = |
95 |
|
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
96 |
|
private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab")); |
97 |
|
|
98 |
private final JSplitPane splitPane; |
private final JSplitPane vSplitPane; |
99 |
|
private final JSplitPane hSplitPane; |
100 |
|
|
101 |
private final JPanel mainPane = new JPanel(); |
private final JPanel mainPane = new JPanel(); |
102 |
|
private final StandardBar standardBar = new StandardBar(); |
103 |
private final JPanel channelsPane = new JPanel(new BorderLayout()); |
private final JPanel channelsPane = new JPanel(new BorderLayout()); |
104 |
|
private final JPanel rightPane = new JPanel(); |
105 |
|
private final JPanel bottomPane = new JPanel(); |
106 |
|
private final LSConsolePane lsConsolePane = new LSConsolePane(this); |
107 |
|
private LSConsoleDlg lsConsoleDlg = null; |
108 |
|
|
109 |
private final JTabbedPane tabbedPane = |
private final JTabbedPane tabbedPane = |
110 |
new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT); |
new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT); |
|
private final JMenu tabsMenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab")); |
|
111 |
private final Vector<JMenuItem> miList = new Vector<JMenuItem>(); |
private final Vector<JMenuItem> miList = new Vector<JMenuItem>(); |
112 |
|
|
113 |
/** Creates a new instance of JSMainFrame */ |
private final JCheckBoxMenuItem cbmiLeftPaneVisible = |
114 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane")); |
115 |
|
|
116 |
|
private final JCheckBoxMenuItem cbmiStandardBarVisible = |
117 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.standard")); |
118 |
|
|
119 |
|
private final JCheckBoxMenuItem cbmiLSConsoleShown = |
120 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.lsconsole")); |
121 |
|
|
122 |
|
private boolean lsConsolePopOut; |
123 |
|
|
124 |
|
private final Vector<String> recentScripts = new Vector<String>(); |
125 |
|
|
126 |
|
|
127 |
|
/** Creates a new instance of <code>MainFrame</code>. */ |
128 |
public |
public |
129 |
MainFrame() { |
MainFrame() { |
130 |
setTitle(i18n.getLabel("MainFrame.title")); |
setTitle(i18n.getLabel("MainFrame.title")); |
131 |
|
|
132 |
initMainFrame(); |
getContentPane().add(standardBar, BorderLayout.NORTH); |
|
getContentPane().add(toolbar, BorderLayout.NORTH); |
|
133 |
getContentPane().add(mainPane); |
getContentPane().add(mainPane); |
134 |
|
|
135 |
mainPane.setLayout(new BorderLayout()); |
mainPane.setLayout(new BorderLayout()); |
142 |
|
|
143 |
channelsPane.add(getChannelsPane(0)); |
channelsPane.add(getChannelsPane(0)); |
144 |
|
|
145 |
splitPane = new JSplitPane ( |
bottomPane.setLayout(new BorderLayout()); |
146 |
|
|
147 |
|
rightPane.setLayout(new BorderLayout()); |
148 |
|
|
149 |
|
rightPane.add(channelsBar, BorderLayout.NORTH); |
150 |
|
rightPane.add(channelsPane); |
151 |
|
|
152 |
|
hSplitPane = new JSplitPane ( |
153 |
JSplitPane.HORIZONTAL_SPLIT, |
JSplitPane.HORIZONTAL_SPLIT, |
154 |
true, // continuousLayout |
true, // continuousLayout |
155 |
getLeftPane(), |
getLeftPane(), |
156 |
channelsPane |
rightPane |
157 |
|
); |
158 |
|
|
159 |
|
hSplitPane.setOneTouchExpandable(true); |
160 |
|
if(ClassicPrefs.getSaveWindowProperties()) { |
161 |
|
hSplitPane.setDividerLocation(ClassicPrefs.getHSplitDividerLocation()); |
162 |
|
} |
163 |
|
|
164 |
|
mainPane.add(hSplitPane); |
165 |
|
|
166 |
|
|
167 |
|
vSplitPane = new JSplitPane ( |
168 |
|
JSplitPane.VERTICAL_SPLIT, |
169 |
|
true, // continuousLayout |
170 |
|
channelsPane, |
171 |
|
bottomPane |
172 |
); |
); |
173 |
|
|
174 |
splitPane.setOneTouchExpandable(true); |
vSplitPane.setDividerSize(3); |
175 |
|
vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation()); |
176 |
|
|
177 |
mainPane.add(splitPane); |
rightPane.add(vSplitPane); |
178 |
|
|
179 |
if(applicationIcon != null) setIconImage(applicationIcon.getImage()); |
if(applicationIcon != null) setIconImage(applicationIcon.getImage()); |
180 |
|
|
181 |
|
initMainFrame(); |
182 |
|
|
183 |
pack(); |
pack(); |
184 |
|
|
185 |
|
if(ClassicPrefs.getSaveWindowProperties()) setSavedSize(); |
186 |
|
else setDefaultSize(); |
187 |
|
|
188 |
|
if(ClassicPrefs.getSaveLeftPaneState()) { |
189 |
|
NavigationPage page = |
190 |
|
getLeftPane().getPages()[ClassicPrefs.getLeftPanePageIndex()]; |
191 |
|
|
192 |
|
getLeftPane().getModel().addPage(page); |
193 |
|
getLeftPane().getModel().clearHistory(); |
194 |
|
|
195 |
|
int idx = ClassicPrefs.getCurrentOrchestraIndex(); |
196 |
|
if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) { |
197 |
|
OrchestraModel om = CC.getOrchestras().getOrchestra(idx); |
198 |
|
getLeftPane().getOrchestrasPage().setSelectedOrchestra(om); |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
|
//CC.getInstrumentsDbTreeModel(); // used to initialize the db tree model |
203 |
|
} |
204 |
|
|
205 |
|
/** Invoked when this window is about to close. */ |
206 |
|
@Override |
207 |
|
protected void |
208 |
|
onWindowClose() { |
209 |
|
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
210 |
|
if(b && CC.getSamplerModel().isModified()) { |
211 |
|
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
212 |
|
dlg.setVisible(true); |
213 |
|
if(dlg.isCancelled()) return; |
214 |
|
} |
215 |
|
|
216 |
|
if(ClassicPrefs.getSaveWindowProperties()) { |
217 |
|
ClassicPrefs.setWindowMaximized ( |
218 |
|
"Mainframe", (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
219 |
|
); |
220 |
|
|
221 |
|
setVisible(false); |
222 |
|
if(ClassicPrefs.getWindowMaximized("Mainframe")) { |
223 |
|
//setExtendedState(getExtendedState() & ~MAXIMIZED_BOTH); |
224 |
|
CC.cleanExit(); |
225 |
|
return; |
226 |
|
} |
227 |
|
|
228 |
|
java.awt.Point p = getLocation(); |
229 |
|
Dimension d = getSize(); |
230 |
|
StringBuffer sb = new StringBuffer(); |
231 |
|
sb.append(p.x).append(',').append(p.y).append(','); |
232 |
|
sb.append(d.width).append(',').append(d.height); |
233 |
|
ClassicPrefs.setWindowSizeAndLocation("Mainframe", sb.toString()); |
234 |
|
|
235 |
|
ClassicPrefs.setHSplitDividerLocation(hSplitPane.getDividerLocation()); |
236 |
|
} |
237 |
|
|
238 |
|
if(ClassicPrefs.getSaveLeftPaneState()) { |
239 |
|
int idx = 0; |
240 |
|
for(int i = 0; i < getLeftPane().getPages().length; i++) { |
241 |
|
if(getLeftPane().getPages()[i] == getLeftPane().getCurrentPage()) { |
242 |
|
idx = i; |
243 |
|
break; |
244 |
|
} |
245 |
|
} |
246 |
|
|
247 |
|
ClassicPrefs.setLeftPanePageIndex(idx); |
248 |
|
|
249 |
|
idx = getLeftPane().getOrchestrasPage().getCurrentOrchestraIndex(); |
250 |
|
|
251 |
|
if(idx >= 0 && idx < CC.getOrchestras().getOrchestraCount()) |
252 |
|
ClassicPrefs.setCurrentOrchestraIndex(idx); |
253 |
|
} |
254 |
|
|
255 |
|
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
256 |
|
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
257 |
|
|
258 |
|
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
259 |
|
lsConsolePane.saveConsoleHistory(); |
260 |
|
} |
261 |
|
|
262 |
|
ClassicPrefs.setShowLSConsole(isLSConsoleShown()); |
263 |
|
ClassicPrefs.setLSConsolePopOut(isLSConsolePopOut()); |
264 |
|
|
265 |
|
ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation()); |
266 |
|
super.onWindowClose(); |
267 |
|
} |
268 |
|
|
269 |
|
private void |
270 |
|
initMainFrame() { |
271 |
|
addMenu(); |
272 |
|
handleEvents(); |
273 |
|
} |
274 |
|
|
275 |
|
private void |
276 |
|
setDefaultSize() { |
277 |
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); |
278 |
double width = dimension.getWidth(); |
double width = dimension.getWidth(); |
279 |
double height = dimension.getHeight(); |
double height = dimension.getHeight(); |
281 |
} |
} |
282 |
|
|
283 |
private void |
private void |
284 |
initMainFrame() { |
setSavedSize() { |
285 |
addMenu(); |
String s = ClassicPrefs.getWindowSizeAndLocation("Mainframe"); |
286 |
handleEvents(); |
if(s == null) { |
287 |
|
setDefaultSize(); |
288 |
|
return; |
289 |
|
} |
290 |
|
|
291 |
|
try { |
292 |
|
int i = s.indexOf(','); |
293 |
|
int x = Integer.parseInt(s.substring(0, i)); |
294 |
|
|
295 |
|
s = s.substring(i + 1); |
296 |
|
i = s.indexOf(','); |
297 |
|
int y = Integer.parseInt(s.substring(0, i)); |
298 |
|
|
299 |
|
s = s.substring(i + 1); |
300 |
|
i = s.indexOf(','); |
301 |
|
int width = Integer.parseInt(s.substring(0, i)); |
302 |
|
|
303 |
|
s = s.substring(i + 1); |
304 |
|
int height = Integer.parseInt(s); |
305 |
|
|
306 |
|
setBounds(x, y, width, height); |
307 |
|
} catch(Exception x) { |
308 |
|
String msg = "Parsing of window size and location string failed"; |
309 |
|
CC.getLogger().log(Level.INFO, msg, x); |
310 |
|
setDefaultSize(); |
311 |
|
} |
312 |
|
|
313 |
|
if(ClassicPrefs.getWindowMaximized("Mainframe")) |
314 |
|
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
315 |
} |
} |
316 |
|
|
317 |
private void |
private void |
318 |
addMenu() { |
addMenu() { |
319 |
JMenu m; |
JMenu m; |
|
JMenu submenu; |
|
320 |
JMenuItem mi; |
JMenuItem mi; |
321 |
|
|
322 |
setJMenuBar(menuBar); |
setJMenuBar(menuBar); |
325 |
m = new JMenu(i18n.getMenuLabel("actions")); |
m = new JMenu(i18n.getMenuLabel("actions")); |
326 |
menuBar.add(m); |
menuBar.add(m); |
327 |
|
|
328 |
mi = new JMenuItem(A4n.connect); |
mi = new JMenuItem(a4n.refresh); |
329 |
mi.setIcon(null); |
mi.setIcon(null); |
330 |
//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
331 |
m.add(mi); |
m.add(mi); |
332 |
|
|
333 |
mi = new JMenuItem(A4n.refresh); |
mi = new JMenuItem(A4n.samplerInfo); |
334 |
mi.setIcon(null); |
mi.setIcon(null); |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
|
335 |
m.add(mi); |
m.add(mi); |
336 |
|
|
337 |
mi = new JMenuItem(A4n.resetSampler); |
mi = new JMenuItem(a4n.resetSampler); |
338 |
mi.setIcon(null); |
mi.setIcon(null); |
339 |
m.add(mi); |
m.add(mi); |
340 |
|
|
341 |
mi = new JMenuItem(A4n.samplerInfo); |
JMenu midiInstrMenu = new JMenu(i18n.getMenuLabel("actions.midiInstruments")); |
342 |
|
m.add(midiInstrMenu); |
343 |
|
|
344 |
|
mi = new JMenuItem(A4n.addMidiInstrumentMap); |
345 |
|
mi.setIcon(null); |
346 |
|
midiInstrMenu.add(mi); |
347 |
|
|
348 |
|
mi = new JMenuItem(A4n.removeMidiInstrumentMap); |
349 |
|
mi.setIcon(null); |
350 |
|
midiInstrMenu.add(mi); |
351 |
|
|
352 |
|
mi = new JMenuItem(A4n.addMidiInstrumentWizard); |
353 |
|
mi.setIcon(null); |
354 |
|
midiInstrMenu.add(mi); |
355 |
|
|
356 |
|
m.addSeparator(); |
357 |
|
|
358 |
|
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
359 |
|
m.add(exportMenu); |
360 |
|
|
361 |
|
mi = new JMenuItem(a4n.exportSamplerConfig); |
362 |
|
mi.setIcon(null); |
363 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
364 |
|
exportMenu.add(mi); |
365 |
|
|
366 |
|
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
367 |
|
mi.setIcon(null); |
368 |
|
exportMenu.add(mi); |
369 |
|
|
370 |
|
m.addSeparator(); |
371 |
|
|
372 |
|
mi = new JMenuItem(A4n.loadScript); |
373 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
374 |
|
mi.setIcon(null); |
375 |
|
m.add(mi); |
376 |
|
|
377 |
|
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
378 |
|
for(String s : list) recentScripts.add(s); |
379 |
|
|
380 |
|
updateRecentScriptsMenu(); |
381 |
|
|
382 |
|
m.add(recentScriptsMenu); |
383 |
|
|
384 |
|
m.addSeparator(); |
385 |
|
|
386 |
|
mi = new JMenuItem(a4n.changeBackend); |
387 |
mi.setIcon(null); |
mi.setIcon(null); |
388 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
389 |
m.add(mi); |
m.add(mi); |
390 |
|
|
391 |
m.addSeparator(); |
m.addSeparator(); |
394 |
m.add(mi); |
m.add(mi); |
395 |
mi.addActionListener(new ActionListener() { |
mi.addActionListener(new ActionListener() { |
396 |
public void |
public void |
397 |
actionPerformed(ActionEvent e) { CC.cleanExit(); } |
actionPerformed(ActionEvent e) { onWindowClose(); } |
398 |
}); |
}); |
399 |
|
|
400 |
// Edit |
// Edit |
401 |
m = new JMenu(i18n.getMenuLabel("edit")); |
m = new JMenu(i18n.getMenuLabel("edit")); |
402 |
menuBar.add(m); |
menuBar.add(m); |
403 |
|
|
404 |
|
mi = new JMenuItem(i18n.getMenuLabel("edit.audioDevices")); |
405 |
|
m.add(mi); |
406 |
|
mi.addActionListener(new ActionListener() { |
407 |
|
public void |
408 |
|
actionPerformed(ActionEvent e) { |
409 |
|
if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0); |
410 |
|
LeftPane.getLeftPane().showAudioDevicesPage(); |
411 |
|
} |
412 |
|
}); |
413 |
|
|
414 |
|
mi = new JMenuItem(i18n.getMenuLabel("edit.midiDevices")); |
415 |
|
m.add(mi); |
416 |
|
mi.addActionListener(new ActionListener() { |
417 |
|
public void |
418 |
|
actionPerformed(ActionEvent e) { |
419 |
|
if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0); |
420 |
|
LeftPane.getLeftPane().showMidiDevicesPage(); |
421 |
|
} |
422 |
|
}); |
423 |
|
|
424 |
|
mi = new JMenuItem(i18n.getMenuLabel("edit.orchestras")); |
425 |
|
m.add(mi); |
426 |
|
mi.addActionListener(new ActionListener() { |
427 |
|
public void |
428 |
|
actionPerformed(ActionEvent e) { |
429 |
|
if(!isLeftPaneVisible()) cbmiLeftPaneVisible.doClick(0); |
430 |
|
LeftPane.getLeftPane().showManageOrchestrasPage(); |
431 |
|
} |
432 |
|
}); |
433 |
|
|
434 |
m.addSeparator(); |
m.addSeparator(); |
435 |
|
|
436 |
mi = new JMenuItem(A4n.preferences); |
mi = new JMenuItem(A4n.preferences); |
444 |
m = new JMenu(i18n.getMenuLabel("view")); |
m = new JMenu(i18n.getMenuLabel("view")); |
445 |
menuBar.add(m); |
menuBar.add(m); |
446 |
|
|
447 |
final JCheckBoxMenuItem cbmi = |
JMenu toolbarsMenu = new JMenu(i18n.getMenuLabel("view.toolbars")); |
448 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbar")); |
m.add(toolbarsMenu); |
449 |
|
|
450 |
m.add(cbmi); |
toolbarsMenu.add(cbmiStandardBarVisible); |
451 |
cbmi.setState(true); |
cbmiStandardBarVisible.addActionListener(new ActionListener() { |
|
cbmi.addActionListener(new ActionListener() { |
|
452 |
public void |
public void |
453 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
454 |
if(cbmi.getState()) |
showStandardBar(cbmiStandardBarVisible.getState()); |
|
getContentPane().add(toolbar, BorderLayout.NORTH); |
|
|
else getContentPane().remove(toolbar); |
|
|
|
|
|
validate(); |
|
|
repaint(); |
|
455 |
} |
} |
456 |
}); |
}); |
457 |
|
|
458 |
final JCheckBoxMenuItem cbmi1 = |
boolean b = ClassicPrefs.shouldShowStandardBar(); |
459 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftPane")); |
cbmiStandardBarVisible.setSelected(b); |
460 |
|
showStandardBar(b); |
461 |
|
|
462 |
m.add(cbmi1); |
final JCheckBoxMenuItem cbmi = |
463 |
cbmi1.setState(true); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolbars.channels")); |
464 |
cbmi1.addActionListener(new ActionListener() { |
|
465 |
|
toolbarsMenu.add(cbmi); |
466 |
|
cbmi.addActionListener(new ActionListener() { |
467 |
public void |
public void |
468 |
actionPerformed(ActionEvent e) { showLeftPane(cbmi1.getState()); } |
actionPerformed(ActionEvent e) { showChannelsBar(cbmi.getState()); } |
469 |
}); |
}); |
470 |
|
|
471 |
|
b = ClassicPrefs.shouldShowChannelsBar(); |
472 |
|
cbmi.setSelected(b); |
473 |
|
showChannelsBar(b); |
474 |
|
|
475 |
|
m.add(cbmiLeftPaneVisible); |
476 |
|
cbmiLeftPaneVisible.addActionListener(new ActionListener() { |
477 |
|
public void |
478 |
|
actionPerformed(ActionEvent e) { |
479 |
|
showLeftPane(cbmiLeftPaneVisible.getState()); |
480 |
|
} |
481 |
|
}); |
482 |
|
|
483 |
|
b = ClassicPrefs.shouldShowLeftPane(); |
484 |
|
cbmiLeftPaneVisible.setSelected(b); |
485 |
|
showLeftPane(b); |
486 |
|
|
487 |
final JCheckBoxMenuItem cbmi2 = |
final JCheckBoxMenuItem cbmi2 = |
488 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.statusbar")); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.statusbar")); |
489 |
|
|
490 |
m.add(cbmi2); |
m.add(cbmi2); |
|
cbmi2.setState(true); |
|
491 |
cbmi2.addActionListener(new ActionListener() { |
cbmi2.addActionListener(new ActionListener() { |
492 |
public void |
public void |
493 |
|
actionPerformed(ActionEvent e) { showStatusbar(cbmi2.getState()); } |
494 |
|
}); |
495 |
|
b = ClassicPrefs.shouldShowStatusbar(); |
496 |
|
cbmi2.setSelected(b); |
497 |
|
showStatusbar(b); |
498 |
|
|
499 |
|
m.addSeparator(); |
500 |
|
|
501 |
|
setLSConsolePopOut(ClassicPrefs.isLSConsolePopOut()); |
502 |
|
cbmiLSConsoleShown.setSelected(ClassicPrefs.shouldShowLSConsole()); |
503 |
|
showLSConsole(ClassicPrefs.shouldShowLSConsole()); |
504 |
|
|
505 |
|
cbmiLSConsoleShown.addActionListener(new ActionListener() { |
506 |
|
public void |
507 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
508 |
statusbar.setVisible(cbmi2.getState()); |
showLSConsole(cbmiLSConsoleShown.isSelected()); |
509 |
} |
} |
510 |
}); |
}); |
511 |
|
m.add(cbmiLSConsoleShown); |
512 |
|
|
513 |
|
lsConsolePane.updateLSConsoleViewMode(); |
514 |
|
|
515 |
// Channels |
// Channels |
516 |
m = new JMenu(i18n.getMenuLabel("channels")); |
m = new JMenu(i18n.getMenuLabel("channels")); |
631 |
m.add(mi); |
m.add(mi); |
632 |
|
|
633 |
|
|
634 |
|
// Window |
635 |
|
m = new JMenu(i18n.getMenuLabel("window")); |
636 |
|
menuBar.add(m); |
637 |
|
|
638 |
|
mi = new JMenuItem(A4n.windowInstrumentsDb); |
639 |
|
mi.setIcon(null); |
640 |
|
m.add(mi); |
641 |
|
|
642 |
|
|
643 |
// Help |
// Help |
644 |
m = new JMenu(i18n.getMenuLabel("help")); |
m = new JMenu(i18n.getMenuLabel("help")); |
|
menuBar.add(m); |
|
645 |
|
|
646 |
mi = new JMenuItem(A4n.helpAbout); |
mi = new JMenuItem(A4n.helpAbout); |
647 |
mi.setIcon(null); |
mi.setIcon(null); |
648 |
m.add(mi); |
m.add(mi); |
649 |
|
|
650 |
|
m.addSeparator(); |
651 |
|
|
652 |
|
mi = new JMenuItem(a4n.browseOnlineTutorial); |
653 |
|
mi.setIcon(null); |
654 |
|
m.add(mi); |
655 |
|
|
656 |
|
menuBar.add(m); |
657 |
|
} |
658 |
|
|
659 |
|
private class RecentScriptHandler implements ActionListener { |
660 |
|
private String script; |
661 |
|
|
662 |
|
RecentScriptHandler(String script) { this.script = script; } |
663 |
|
|
664 |
|
@Override |
665 |
|
public void |
666 |
|
actionPerformed(ActionEvent e) { runScript(script); } |
667 |
|
} |
668 |
|
|
669 |
|
private void |
670 |
|
handleEvents() { |
671 |
|
tabbedPane.addChangeListener(this); |
672 |
|
} |
673 |
|
|
674 |
|
private void |
675 |
|
showChannelsBar(boolean b) { |
676 |
|
channelsBar.setVisible(b); |
677 |
|
ClassicPrefs.setShowChannelsBar(b); |
678 |
|
|
679 |
|
validate(); |
680 |
|
repaint(); |
681 |
|
} |
682 |
|
|
683 |
|
private void |
684 |
|
showStatusbar(boolean b) { |
685 |
|
ClassicPrefs.setShowStatusbar(b); |
686 |
|
statusbar.setVisible(b); |
687 |
|
} |
688 |
|
|
689 |
|
protected boolean |
690 |
|
isLeftPaneVisible() { return cbmiLeftPaneVisible.isSelected(); } |
691 |
|
|
692 |
|
protected void |
693 |
|
setLeftPaneVisible(boolean b) { |
694 |
|
if(b != cbmiLeftPaneVisible.isSelected()) cbmiLeftPaneVisible.doClick(0); |
695 |
|
} |
696 |
|
|
697 |
|
protected boolean |
698 |
|
isLSConsoleVisible() { return cbmiLSConsoleShown.isSelected(); } |
699 |
|
|
700 |
|
protected void |
701 |
|
setLSConsoleVisible(boolean b) { |
702 |
|
if(b != cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0); |
703 |
} |
} |
704 |
|
|
705 |
private void |
private void |
706 |
showLeftPane(boolean b) { |
showLeftPane(boolean b) { |
707 |
mainPane.remove(splitPane); |
ClassicPrefs.setShowLeftPane(b); |
708 |
mainPane.remove(channelsPane); |
|
709 |
|
mainPane.remove(hSplitPane); |
710 |
|
mainPane.remove(rightPane); |
711 |
|
|
712 |
if(b) { |
if(b) { |
713 |
splitPane.setRightComponent(channelsPane); |
hSplitPane.setRightComponent(rightPane); |
714 |
mainPane.add(splitPane); |
mainPane.add(hSplitPane); |
715 |
|
if(ClassicPrefs.getSaveWindowProperties()) { |
716 |
|
int i = ClassicPrefs.getHSplitDividerLocation(); |
717 |
|
hSplitPane.setDividerLocation(i); |
718 |
|
} |
719 |
} else { |
} else { |
720 |
mainPane.add(channelsPane); |
mainPane.add(rightPane); |
721 |
} |
} |
722 |
|
|
723 |
validate(); |
validate(); |
725 |
} |
} |
726 |
|
|
727 |
private void |
private void |
728 |
handleEvents() { |
showStandardBar(boolean b) { |
729 |
tabbedPane.addChangeListener(this); |
ClassicPrefs.setShowStandardBar(b); |
730 |
|
standardBar.setVisible(b); |
731 |
|
validate(); |
732 |
|
repaint(); |
733 |
} |
} |
734 |
|
|
735 |
|
private void |
736 |
|
showBottomPane(boolean b) { |
737 |
|
if(!b) ClassicPrefs.setVSplitDividerLocation(vSplitPane.getDividerLocation()); |
738 |
|
|
739 |
|
rightPane.remove(vSplitPane); |
740 |
|
rightPane.remove(channelsPane); |
741 |
|
|
742 |
|
if(b) { |
743 |
|
vSplitPane.setTopComponent(channelsPane); |
744 |
|
rightPane.add(vSplitPane); |
745 |
|
vSplitPane.setDividerLocation(ClassicPrefs.getVSplitDividerLocation()); |
746 |
|
} else { |
747 |
|
rightPane.add(channelsPane); |
748 |
|
} |
749 |
|
|
750 |
|
validate(); |
751 |
|
repaint(); |
752 |
|
} |
753 |
|
|
754 |
|
protected void |
755 |
|
setLSConsolePopOut(boolean b) { |
756 |
|
if(b == lsConsolePopOut) return; |
757 |
|
|
758 |
|
lsConsolePopOut = b; |
759 |
|
|
760 |
|
if(isLSConsoleShown()) setLSConsolePopOut0(b); |
761 |
|
} |
762 |
|
|
763 |
|
/** |
764 |
|
* Changes the pop-out state of the LS Console. |
765 |
|
* Invoke this method only when LS Console is shown. |
766 |
|
*/ |
767 |
|
private void |
768 |
|
setLSConsolePopOut0(boolean b) { |
769 |
|
if(b) { |
770 |
|
bottomPane.remove(lsConsolePane); |
771 |
|
showBottomPane(false); |
772 |
|
|
773 |
|
lsConsoleDlg = new LSConsoleDlg(this, lsConsolePane); |
774 |
|
lsConsoleDlg.setVisible(true); |
775 |
|
} else { |
776 |
|
if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false); |
777 |
|
lsConsoleDlg = null; |
778 |
|
bottomPane.add(lsConsolePane); |
779 |
|
showBottomPane(true); |
780 |
|
} |
781 |
|
} |
782 |
|
|
783 |
|
protected boolean |
784 |
|
isLSConsolePopOut() { return lsConsolePopOut; } |
785 |
|
|
786 |
|
protected boolean |
787 |
|
isLSConsoleShown() { return cbmiLSConsoleShown.isSelected(); } |
788 |
|
|
789 |
|
protected void |
790 |
|
setLSConsoleShown(boolean b) { cbmiLSConsoleShown.setSelected(b); } |
791 |
|
|
792 |
|
protected LSConsoleModel |
793 |
|
getLSConsoleModel() { return lsConsolePane.getModel(); } |
794 |
|
|
795 |
|
/** |
796 |
|
* Sets the text color of the LS Console. |
797 |
|
* @param c The text color of the LS Console. |
798 |
|
*/ |
799 |
|
protected void |
800 |
|
setLSConsoleTextColor(Color c) { lsConsolePane.setTextColor(c); } |
801 |
|
|
802 |
|
/** |
803 |
|
* Sets the background color of the LS Console. |
804 |
|
* @param c The background color of the LS Console. |
805 |
|
*/ |
806 |
|
protected void |
807 |
|
setLSConsoleBackgroundColor(Color c) { lsConsolePane.setBackgroundColor(c); } |
808 |
|
|
809 |
|
/** |
810 |
|
* Sets the notification messages' color of the LS Console. |
811 |
|
* @param c The notification messages' color of the LS Console. |
812 |
|
*/ |
813 |
|
protected void |
814 |
|
setLSConsoleNotifyColor(Color c) { lsConsolePane.setNotifyColor(c); } |
815 |
|
|
816 |
|
/** |
817 |
|
* Sets the warning messages' color of the LS Console. |
818 |
|
* @param c The warning messages' color of the LS Console. |
819 |
|
*/ |
820 |
|
protected void |
821 |
|
setLSConsoleWarningColor(Color c) { lsConsolePane.setWarningColor(c); } |
822 |
|
|
823 |
|
/** |
824 |
|
* Sets the error messages' color of the LS Console. |
825 |
|
* @param c The error messages' color of the LS Console. |
826 |
|
*/ |
827 |
|
protected void |
828 |
|
setLSConsoleErrorColor(Color c) { lsConsolePane.setErrorColor(c); } |
829 |
|
|
830 |
|
protected void |
831 |
|
showLSConsole(boolean b) { |
832 |
|
if(!b) { |
833 |
|
showBottomPane(false); |
834 |
|
if(lsConsoleDlg != null) lsConsoleDlg.setVisible(false); |
835 |
|
lsConsolePane.hideAutoCompleteWindow(); |
836 |
|
return; |
837 |
|
} |
838 |
|
|
839 |
|
setLSConsolePopOut0(isLSConsolePopOut()); |
840 |
|
} |
841 |
|
|
842 |
|
/** |
843 |
|
* Adds the specified <code>JSChannelsPane</code> to the view. |
844 |
|
* @param chnPane The <code>JSChannelsPane</code> to be added. |
845 |
|
*/ |
846 |
|
@Override |
847 |
public void |
public void |
848 |
addChannelsPane(JSChannelsPane chnPane) { |
addChannelsPane(JSChannelsPane chnPane) { |
849 |
insertChannelsPane(chnPane, getChannelsPaneCount()); |
insertChannelsPane(chnPane, getChannelsPaneCount()); |
850 |
} |
} |
851 |
|
|
852 |
|
@Override |
853 |
public void |
public void |
854 |
insertChannelsPane(JSChannelsPane chnPane, int idx) { |
insertChannelsPane(JSChannelsPane chnPane, int idx) { |
855 |
chnPane.addListSelectionListener(this); |
chnPane.addListSelectionListener(this); |
870 |
updateTabsMenu(); |
updateTabsMenu(); |
871 |
} |
} |
872 |
|
|
873 |
|
/** |
874 |
|
* Gets the <code>JSChannelsPane</code> that is currently shown. |
875 |
|
* @return The currently shown <code>JSChannelsPane</code>. |
876 |
|
*/ |
877 |
|
@Override |
878 |
public JSChannelsPane |
public JSChannelsPane |
879 |
getSelectedChannelsPane() { |
getSelectedChannelsPane() { |
880 |
if(getChannelsPaneList().size() == 1) return getChannelsPane(0); |
if(getChannelsPaneList().size() == 1) return getChannelsPane(0); |
881 |
return (JSChannelsPane)tabbedPane.getSelectedComponent(); |
return (JSChannelsPane)tabbedPane.getSelectedComponent(); |
882 |
} |
} |
883 |
|
|
884 |
|
/** |
885 |
|
* Sets the <code>JSChannelsPane</code> to be selected. |
886 |
|
* @param pane The <code>JSChannelsPane</code> to be shown. |
887 |
|
*/ |
888 |
|
@Override |
889 |
public void |
public void |
890 |
setSelectedChannelsPane(JSChannelsPane pane) { |
setSelectedChannelsPane(JSChannelsPane pane) { |
891 |
if(getChannelsPaneList().size() == 1) return; |
if(getChannelsPaneList().size() == 1) return; |
892 |
tabbedPane.setSelectedComponent(pane); |
tabbedPane.setSelectedComponent(pane); |
893 |
|
fireChannelsPaneSelectionChanged(); |
894 |
} |
} |
895 |
|
|
896 |
|
/** |
897 |
|
* Removes the specified <code>JSChannelsPane</code> from the view. |
898 |
|
* @param chnPane The <code>JSChannelsPane</code> to be removed. |
899 |
|
* @return <code>true</code> if the specified code>JSChannelsPane</code> |
900 |
|
* is actually removed from the view, <code>false</code> otherwise. |
901 |
|
*/ |
902 |
|
@Override |
903 |
public boolean |
public boolean |
904 |
removeChannelsPane(JSChannelsPane chnPane) { |
removeChannelsPane(JSChannelsPane chnPane) { |
905 |
chnPane.removeListSelectionListener(this); |
chnPane.removeListSelectionListener(this); |
1041 |
public JMenu |
public JMenu |
1042 |
getTabsMenu() { return tabsMenu; } |
getTabsMenu() { return tabsMenu; } |
1043 |
|
|
1044 |
|
@Override |
1045 |
public void |
public void |
1046 |
stateChanged(ChangeEvent e) { |
stateChanged(ChangeEvent e) { |
1047 |
updateTabsMenu(); |
updateTabsMenu(); |
1049 |
checkTabSelection(); |
checkTabSelection(); |
1050 |
} |
} |
1051 |
|
|
1052 |
|
@Override |
1053 |
public void |
public void |
1054 |
valueChanged(ListSelectionEvent e) { |
valueChanged(ListSelectionEvent e) { |
1055 |
if(e.getValueIsAdjusting()) return; |
if(e.getValueIsAdjusting()) return; |
1122 |
addChannelsPane(c); |
addChannelsPane(c); |
1123 |
tabbedPane.setSelectedComponent(c); |
tabbedPane.setSelectedComponent(c); |
1124 |
} |
} |
1125 |
|
|
1126 |
|
protected void |
1127 |
|
runScript() { |
1128 |
|
String s = preferences().getStringProperty("lastScriptLocation"); |
1129 |
|
JFileChooser fc = new JFileChooser(s); |
1130 |
|
fc.setFileFilter(new LscpFileFilter()); |
1131 |
|
int result = fc.showOpenDialog(this); |
1132 |
|
if(result != JFileChooser.APPROVE_OPTION) return; |
1133 |
|
|
1134 |
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
1135 |
|
preferences().setStringProperty("lastScriptLocation", path); |
1136 |
|
|
1137 |
|
runScript(fc.getSelectedFile()); |
1138 |
|
} |
1139 |
|
|
1140 |
|
private void |
1141 |
|
runScript(String script) { runScript(new File(script)); } |
1142 |
|
|
1143 |
|
private void |
1144 |
|
runScript(File script) { |
1145 |
|
FileReader fr; |
1146 |
|
try { fr = new FileReader(script); } |
1147 |
|
catch(FileNotFoundException e) { |
1148 |
|
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
1149 |
|
return; |
1150 |
|
} |
1151 |
|
|
1152 |
|
BufferedReader br = new BufferedReader(fr); |
1153 |
|
|
1154 |
|
try { |
1155 |
|
String s = br.readLine(); |
1156 |
|
while(s != null) { |
1157 |
|
getLSConsoleModel().setCommandLineText(s); |
1158 |
|
getLSConsoleModel().execCommand(); |
1159 |
|
s = br.readLine(); |
1160 |
|
} |
1161 |
|
} catch(Exception e) { |
1162 |
|
HF.showErrorMessage(e); |
1163 |
|
return; |
1164 |
|
} |
1165 |
|
|
1166 |
|
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
1167 |
|
if(!cbmiLSConsoleShown.isSelected()) cbmiLSConsoleShown.doClick(0); |
1168 |
|
} |
1169 |
|
|
1170 |
|
String s = script.getAbsolutePath(); |
1171 |
|
recentScripts.remove(s); |
1172 |
|
recentScripts.insertElementAt(s, 0); |
1173 |
|
|
1174 |
|
updateRecentScriptsMenu(); |
1175 |
|
} |
1176 |
|
|
1177 |
|
protected void |
1178 |
|
clearRecentScripts() { |
1179 |
|
recentScripts.removeAllElements(); |
1180 |
|
updateRecentScriptsMenu(); |
1181 |
|
} |
1182 |
|
|
1183 |
|
protected void |
1184 |
|
updateRecentScriptsMenu() { |
1185 |
|
int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
1186 |
|
while(recentScripts.size() > size) { |
1187 |
|
recentScripts.removeElementAt(recentScripts.size() - 1); |
1188 |
|
} |
1189 |
|
|
1190 |
|
recentScriptsMenu.removeAll(); |
1191 |
|
|
1192 |
|
for(String script : recentScripts) { |
1193 |
|
JMenuItem mi = new JMenuItem(script); |
1194 |
|
recentScriptsMenu.add(mi); |
1195 |
|
mi.addActionListener(new RecentScriptHandler(script)); |
1196 |
|
} |
1197 |
|
|
1198 |
|
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
1199 |
|
} |
1200 |
|
|
1201 |
|
@Override |
1202 |
|
public void |
1203 |
|
installJSamplerHome() { |
1204 |
|
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
1205 |
|
chooser.setVisible(true); |
1206 |
|
if(chooser.isCancelled()) return; |
1207 |
|
|
1208 |
|
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
1209 |
|
} |
1210 |
|
|
1211 |
|
@Override |
1212 |
|
public void |
1213 |
|
showDetailedErrorMessage(Frame owner, String err, String details) { |
1214 |
|
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
1215 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
1216 |
|
); |
1217 |
|
dlg.setVisible(true); |
1218 |
|
} |
1219 |
|
|
1220 |
|
@Override |
1221 |
|
public void |
1222 |
|
showDetailedErrorMessage(Dialog owner, String err, String details) { |
1223 |
|
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
1224 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
1225 |
|
); |
1226 |
|
dlg.setVisible(true); |
1227 |
|
} |
1228 |
|
|
1229 |
|
/** |
1230 |
|
* Gets the server address to which to connect. If the server should be |
1231 |
|
* manually selected, a dialog asking the user to choose a server is displayed. |
1232 |
|
*/ |
1233 |
|
@Override |
1234 |
|
public Server |
1235 |
|
getServer() { |
1236 |
|
boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP); |
1237 |
|
return getServer(b); |
1238 |
|
} |
1239 |
|
|
1240 |
|
/** |
1241 |
|
* Gets the server address to which to connect. If the server should be |
1242 |
|
* manually selected, a dialog asking the user to choose a server is displayed. |
1243 |
|
* @param manualSelect Determines whether the server should be manually selected. |
1244 |
|
*/ |
1245 |
|
@Override |
1246 |
|
public Server |
1247 |
|
getServer(boolean manualSelect) { |
1248 |
|
if(manualSelect) { |
1249 |
|
JSConnectDlg dlg = new JSConnectDlg(); |
1250 |
|
dlg.setVisible(true); |
1251 |
|
return dlg.getSelectedServer(); |
1252 |
|
} |
1253 |
|
|
1254 |
|
int i = preferences().getIntProperty(SERVER_INDEX); |
1255 |
|
int size = CC.getServerList().getServerCount(); |
1256 |
|
if(size == 0) return null; |
1257 |
|
if(i >= size) return CC.getServerList().getServer(0); |
1258 |
|
|
1259 |
|
return CC.getServerList().getServer(i); |
1260 |
|
} |
1261 |
} |
} |