1 |
iliev |
912 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1729 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
912 |
* |
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 |
iliev |
1204 |
import java.awt.Dialog; |
27 |
iliev |
912 |
import java.awt.Dimension; |
28 |
iliev |
1204 |
import java.awt.Frame; |
29 |
iliev |
1285 |
import java.awt.Graphics; |
30 |
|
|
import java.awt.GridBagConstraints; |
31 |
|
|
import java.awt.GridBagLayout; |
32 |
|
|
import java.awt.Insets; |
33 |
iliev |
912 |
import java.awt.Point; |
34 |
|
|
|
35 |
|
|
import java.awt.event.ActionEvent; |
36 |
|
|
import java.awt.event.ActionListener; |
37 |
iliev |
1285 |
import java.awt.event.KeyEvent; |
38 |
iliev |
912 |
import java.awt.event.MouseAdapter; |
39 |
|
|
import java.awt.event.MouseEvent; |
40 |
|
|
|
41 |
iliev |
1285 |
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 |
iliev |
912 |
import java.util.logging.Level; |
48 |
|
|
|
49 |
iliev |
1285 |
import javax.swing.BorderFactory; |
50 |
iliev |
912 |
import javax.swing.Box; |
51 |
|
|
import javax.swing.BoxLayout; |
52 |
|
|
import javax.swing.JCheckBoxMenuItem; |
53 |
iliev |
1323 |
import javax.swing.JComponent; |
54 |
iliev |
1285 |
import javax.swing.JDialog; |
55 |
|
|
import javax.swing.JFileChooser; |
56 |
|
|
import javax.swing.JFrame; |
57 |
iliev |
912 |
import javax.swing.JMenu; |
58 |
iliev |
1285 |
import javax.swing.JMenuBar; |
59 |
iliev |
912 |
import javax.swing.JMenuItem; |
60 |
|
|
import javax.swing.JPanel; |
61 |
|
|
import javax.swing.JPopupMenu; |
62 |
iliev |
1285 |
import javax.swing.JScrollPane; |
63 |
|
|
import javax.swing.JSplitPane; |
64 |
iliev |
912 |
import javax.swing.JToggleButton; |
65 |
iliev |
1285 |
import javax.swing.KeyStroke; |
66 |
|
|
import javax.swing.SwingUtilities; |
67 |
iliev |
1734 |
import javax.swing.Timer; |
68 |
iliev |
912 |
import javax.swing.UIManager; |
69 |
|
|
|
70 |
|
|
import net.sf.juife.TitleBar; |
71 |
|
|
|
72 |
|
|
import org.jsampler.CC; |
73 |
|
|
import org.jsampler.HF; |
74 |
iliev |
1285 |
import org.jsampler.LSConsoleModel; |
75 |
iliev |
1688 |
import org.jsampler.Server; |
76 |
iliev |
912 |
|
77 |
|
|
import org.jsampler.view.JSChannel; |
78 |
|
|
import org.jsampler.view.JSChannelsPane; |
79 |
|
|
import org.jsampler.view.JSMainFrame; |
80 |
iliev |
1285 |
import org.jsampler.view.LscpFileFilter; |
81 |
iliev |
912 |
|
82 |
iliev |
1688 |
import org.jsampler.view.std.JSConnectDlg; |
83 |
iliev |
1355 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
84 |
iliev |
1567 |
import org.jsampler.view.std.JSQuitDlg; |
85 |
iliev |
1285 |
import org.jsampler.view.std.JSamplerHomeChooser; |
86 |
|
|
|
87 |
|
|
import static org.jsampler.view.fantasia.A4n.a4n; |
88 |
iliev |
912 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
89 |
iliev |
1285 |
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
90 |
|
|
import static org.jsampler.view.std.StdPrefs.*; |
91 |
iliev |
912 |
|
92 |
|
|
|
93 |
|
|
/** |
94 |
|
|
* |
95 |
|
|
* @author Grigor Iliev |
96 |
|
|
*/ |
97 |
|
|
public class MainFrame extends JSMainFrame { |
98 |
iliev |
1323 |
private final StandardBar standardBar = new StandardBar(); |
99 |
iliev |
1285 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
100 |
iliev |
1323 |
private final JPanel rootPane = new JPanel(); |
101 |
iliev |
1285 |
private final MainPane mainPane = new MainPane(); |
102 |
iliev |
912 |
|
103 |
iliev |
1285 |
private final JMenu recentScriptsMenu = |
104 |
|
|
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
105 |
iliev |
912 |
|
106 |
iliev |
1285 |
private final JSplitPane hSplitPane; |
107 |
|
|
|
108 |
iliev |
1729 |
private final LeftSidePane leftSidePane = new LeftSidePane(); |
109 |
|
|
private final RightSidePane rightSidePane = new RightSidePane(); |
110 |
iliev |
1323 |
private final JPanel rightPane; |
111 |
iliev |
1285 |
|
112 |
iliev |
1767 |
//private final StatusBar statusBar = new StatusBar(); |
113 |
|
|
|
114 |
iliev |
1311 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
115 |
iliev |
1285 |
private final Vector<String> recentScripts = new Vector<String>(); |
116 |
|
|
|
117 |
|
|
|
118 |
iliev |
1323 |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
119 |
|
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
120 |
|
|
|
121 |
iliev |
1729 |
private final JCheckBoxMenuItem cbmiLeftSidePaneVisible = |
122 |
|
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane")); |
123 |
iliev |
1323 |
|
124 |
iliev |
1729 |
private final JCheckBoxMenuItem cbmiRightSidePaneVisible = |
125 |
|
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane")); |
126 |
iliev |
1323 |
|
127 |
iliev |
1734 |
private final Timer guiTimer = new Timer(1000, null); |
128 |
|
|
|
129 |
iliev |
912 |
/** Creates a new instance of <code>MainFrame</code> */ |
130 |
|
|
public |
131 |
|
|
MainFrame() { |
132 |
|
|
setTitle(i18n.getLabel("MainFrame.title")); |
133 |
|
|
|
134 |
iliev |
1285 |
if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage()); |
135 |
iliev |
912 |
|
136 |
iliev |
1285 |
getContentPane().add(standardBar, BorderLayout.NORTH); |
137 |
iliev |
1767 |
//getContentPane().add(statusBar, BorderLayout.SOUTH); |
138 |
iliev |
912 |
|
139 |
iliev |
1323 |
rightPane = createRightPane(); |
140 |
iliev |
912 |
|
141 |
iliev |
1285 |
hSplitPane = new JSplitPane ( |
142 |
|
|
JSplitPane.HORIZONTAL_SPLIT, |
143 |
|
|
true, // continuousLayout |
144 |
iliev |
1729 |
leftSidePane, rightPane |
145 |
iliev |
1285 |
); |
146 |
iliev |
1323 |
hSplitPane.setResizeWeight(0.5); |
147 |
iliev |
912 |
|
148 |
iliev |
1323 |
rootPane.setLayout(new BorderLayout()); |
149 |
|
|
rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0)); |
150 |
|
|
rootPane.setOpaque(false); |
151 |
|
|
rootPane.add(hSplitPane); |
152 |
iliev |
912 |
|
153 |
iliev |
1323 |
addMenu(); |
154 |
|
|
|
155 |
|
|
addChannelsPane(mainPane.getChannelsPane()); |
156 |
|
|
|
157 |
|
|
getContentPane().add(rootPane); |
158 |
|
|
|
159 |
iliev |
1285 |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
160 |
|
|
hSplitPane.setDividerLocation(i); |
161 |
iliev |
912 |
|
162 |
iliev |
1285 |
setSavedSize(); |
163 |
iliev |
1734 |
|
164 |
|
|
guiTimer.start(); |
165 |
iliev |
1285 |
} |
166 |
|
|
|
167 |
|
|
private JPanel |
168 |
|
|
createRightPane() { |
169 |
|
|
JPanel p = new JPanel(); |
170 |
|
|
GridBagLayout gridbag = new GridBagLayout(); |
171 |
|
|
GridBagConstraints c = new GridBagConstraints(); |
172 |
iliev |
912 |
|
173 |
iliev |
1285 |
p.setLayout(gridbag); |
174 |
iliev |
912 |
|
175 |
iliev |
1285 |
c.fill = GridBagConstraints.BOTH; |
176 |
iliev |
912 |
|
177 |
iliev |
1285 |
c.gridx = 1; |
178 |
|
|
c.gridy = 0; |
179 |
|
|
c.weightx = 1.0; |
180 |
|
|
c.weighty = 1.0; |
181 |
iliev |
1729 |
c.insets = new Insets(0, 3, 0, 0); |
182 |
|
|
gridbag.setConstraints(rightSidePane, c); |
183 |
|
|
p.add(rightSidePane); |
184 |
iliev |
912 |
|
185 |
iliev |
1285 |
c.gridx = 0; |
186 |
|
|
c.gridy = 0; |
187 |
|
|
c.weightx = 0.0; |
188 |
|
|
c.weighty = 1.0; |
189 |
iliev |
1729 |
c.insets = new Insets(0, 3, 0, 3); |
190 |
iliev |
1285 |
c.fill = GridBagConstraints.VERTICAL; |
191 |
|
|
gridbag.setConstraints(mainPane, c); |
192 |
|
|
p.add(mainPane); |
193 |
iliev |
912 |
|
194 |
iliev |
1285 |
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 |
iliev |
912 |
pack(); |
205 |
|
|
try { |
206 |
iliev |
1285 |
int i = s.indexOf(','); |
207 |
|
|
int x = Integer.parseInt(s.substring(0, i)); |
208 |
iliev |
912 |
|
209 |
iliev |
1285 |
s = s.substring(i + 1); |
210 |
|
|
i = s.indexOf(','); |
211 |
|
|
int y = Integer.parseInt(s.substring(0, i)); |
212 |
iliev |
912 |
|
213 |
iliev |
1285 |
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 |
iliev |
912 |
} catch(Exception x) { |
222 |
|
|
String msg = "Parsing of window size and location string failed"; |
223 |
|
|
CC.getLogger().log(Level.INFO, msg, x); |
224 |
iliev |
1285 |
setDefaultSizeAndLocation(); |
225 |
iliev |
912 |
} |
226 |
iliev |
1285 |
|
227 |
|
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
228 |
|
|
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
229 |
|
|
} |
230 |
iliev |
912 |
} |
231 |
|
|
|
232 |
|
|
private void |
233 |
iliev |
1285 |
setDefaultSizeAndLocation() { |
234 |
|
|
setPreferredSize(new Dimension(900, 600)); |
235 |
|
|
pack(); |
236 |
|
|
setLocationRelativeTo(null); |
237 |
iliev |
912 |
} |
238 |
|
|
|
239 |
|
|
|
240 |
|
|
/** Invoked when this window is about to close. */ |
241 |
|
|
protected void |
242 |
|
|
onWindowClose() { |
243 |
iliev |
1688 |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
244 |
|
|
if(b && CC.getSamplerModel().isModified()) { |
245 |
iliev |
1567 |
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
246 |
|
|
dlg.setVisible(true); |
247 |
|
|
if(dlg.isCancelled()) return; |
248 |
|
|
} |
249 |
|
|
|
250 |
iliev |
1729 |
leftSidePane.savePreferences(); |
251 |
|
|
rightSidePane.savePreferences(); |
252 |
iliev |
912 |
|
253 |
iliev |
1285 |
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 |
iliev |
912 |
java.awt.Point p = getLocation(); |
267 |
|
|
Dimension d = getSize(); |
268 |
|
|
StringBuffer sb = new StringBuffer(); |
269 |
iliev |
1285 |
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 |
iliev |
912 |
|
273 |
iliev |
1308 |
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
274 |
|
|
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
275 |
iliev |
1285 |
|
276 |
|
|
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
277 |
|
|
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
278 |
|
|
} |
279 |
|
|
|
280 |
iliev |
912 |
super.onWindowClose(); |
281 |
|
|
} |
282 |
|
|
|
283 |
iliev |
1285 |
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 |
iliev |
1688 |
mi = new JMenuItem(a4n.refresh); |
294 |
iliev |
1285 |
mi.setIcon(null); |
295 |
iliev |
1688 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
296 |
iliev |
1285 |
m.add(mi); |
297 |
|
|
|
298 |
|
|
mi = new JMenuItem(a4n.samplerInfo); |
299 |
|
|
mi.setIcon(null); |
300 |
|
|
m.add(mi); |
301 |
|
|
|
302 |
iliev |
1688 |
mi = new JMenuItem(a4n.resetSampler); |
303 |
|
|
mi.setIcon(null); |
304 |
|
|
m.add(mi); |
305 |
|
|
|
306 |
iliev |
1285 |
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 |
iliev |
1688 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
325 |
iliev |
1285 |
m.add(mi); |
326 |
|
|
|
327 |
iliev |
1308 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
328 |
|
|
for(String s : list) recentScripts.add(s); |
329 |
iliev |
1285 |
|
330 |
|
|
updateRecentScriptsMenu(); |
331 |
|
|
|
332 |
|
|
m.add(recentScriptsMenu); |
333 |
|
|
|
334 |
|
|
m.addSeparator(); |
335 |
|
|
|
336 |
iliev |
1688 |
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 |
iliev |
1285 |
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 |
iliev |
1323 |
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 |
iliev |
1285 |
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 |
iliev |
1323 |
// View |
386 |
|
|
m = new FantasiaMenu(i18n.getMenuLabel("view")); |
387 |
|
|
menuBar.add(m); |
388 |
iliev |
1285 |
|
389 |
iliev |
1323 |
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 |
iliev |
1729 |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
403 |
iliev |
1323 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
404 |
|
|
)); |
405 |
iliev |
1729 |
m.add(cbmiLeftSidePaneVisible); |
406 |
iliev |
1323 |
|
407 |
iliev |
1729 |
cbmiLeftSidePaneVisible.addActionListener(new ActionListener() { |
408 |
iliev |
1323 |
public void |
409 |
|
|
actionPerformed(ActionEvent e) { |
410 |
iliev |
1729 |
showSidePane(cbmiLeftSidePaneVisible.getState()); |
411 |
iliev |
1323 |
} |
412 |
|
|
}); |
413 |
|
|
|
414 |
iliev |
1729 |
b = preferences().getBoolProperty("leftSidePane.visible"); |
415 |
|
|
cbmiLeftSidePaneVisible.setSelected(b); |
416 |
iliev |
1323 |
showSidePane(b); |
417 |
|
|
|
418 |
iliev |
1729 |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
419 |
iliev |
1323 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
420 |
|
|
)); |
421 |
iliev |
1729 |
m.add(cbmiRightSidePaneVisible); |
422 |
iliev |
1323 |
|
423 |
iliev |
1729 |
cbmiRightSidePaneVisible.addActionListener(new ActionListener() { |
424 |
iliev |
1323 |
public void |
425 |
|
|
actionPerformed(ActionEvent e) { |
426 |
iliev |
1729 |
showDevicesPane(cbmiRightSidePaneVisible.getState()); |
427 |
iliev |
1323 |
} |
428 |
|
|
}); |
429 |
|
|
|
430 |
iliev |
1729 |
b = preferences().getBoolProperty("rightSidePane.visible"); |
431 |
|
|
cbmiRightSidePaneVisible.setSelected(b); |
432 |
iliev |
1323 |
showDevicesPane(b); |
433 |
|
|
|
434 |
|
|
|
435 |
iliev |
1285 |
// 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 |
iliev |
1496 |
mi = new JMenuItem(a4n.browseOnlineTutorial); |
452 |
|
|
mi.setIcon(null); |
453 |
|
|
m.add(mi); |
454 |
|
|
|
455 |
|
|
m.addSeparator(); |
456 |
|
|
|
457 |
iliev |
1285 |
mi = new JMenuItem(a4n.helpAbout); |
458 |
|
|
mi.setIcon(null); |
459 |
|
|
m.add(mi); |
460 |
|
|
|
461 |
|
|
menuBar.add(m); |
462 |
iliev |
912 |
} |
463 |
|
|
|
464 |
iliev |
1767 |
public RightSidePane |
465 |
|
|
getRightSidePane() { return rightSidePane; } |
466 |
|
|
|
467 |
iliev |
912 |
/** |
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 |
iliev |
1285 |
|
474 |
iliev |
912 |
} |
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 |
iliev |
1285 |
public void |
492 |
|
|
installJSamplerHome() { |
493 |
|
|
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
494 |
|
|
chooser.setVisible(true); |
495 |
|
|
if(chooser.isCancelled()) return; |
496 |
iliev |
912 |
|
497 |
iliev |
1285 |
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
498 |
iliev |
912 |
} |
499 |
|
|
|
500 |
iliev |
1143 |
public void |
501 |
iliev |
1204 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
502 |
iliev |
1355 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
503 |
|
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
504 |
|
|
); |
505 |
|
|
dlg.setVisible(true); |
506 |
iliev |
1204 |
} |
507 |
|
|
|
508 |
|
|
public void |
509 |
|
|
showDetailedErrorMessage(Dialog owner, String err, String details) { |
510 |
iliev |
1355 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
511 |
|
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
512 |
|
|
); |
513 |
|
|
dlg.setVisible(true); |
514 |
iliev |
1204 |
} |
515 |
iliev |
912 |
|
516 |
iliev |
1688 |
/** |
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 |
iliev |
1734 |
public Timer |
548 |
|
|
getGuiTimer() { return guiTimer; } |
549 |
|
|
|
550 |
iliev |
1285 |
protected LSConsoleModel |
551 |
|
|
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
552 |
|
|
|
553 |
|
|
protected LSConsolePane |
554 |
|
|
getLSConsolePane() { |
555 |
|
|
return getLSConsoleFrame().getLSConsolePane(); |
556 |
|
|
} |
557 |
|
|
|
558 |
|
|
protected LSConsoleFrame |
559 |
iliev |
1311 |
getLSConsoleFrame() { return lsConsoleFrame; } |
560 |
iliev |
1285 |
|
561 |
iliev |
1688 |
protected boolean |
562 |
iliev |
1285 |
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 |
iliev |
1688 |
if(result != JFileChooser.APPROVE_OPTION) return false; |
568 |
iliev |
912 |
|
569 |
iliev |
1285 |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
570 |
|
|
preferences().setStringProperty("lastScriptLocation", path); |
571 |
|
|
|
572 |
|
|
runScript(fc.getSelectedFile()); |
573 |
iliev |
1688 |
|
574 |
|
|
return true; |
575 |
iliev |
1285 |
} |
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 |
iliev |
912 |
} |
588 |
|
|
|
589 |
iliev |
1285 |
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 |
iliev |
912 |
} |
602 |
iliev |
1285 |
|
603 |
|
|
String s = script.getAbsolutePath(); |
604 |
|
|
recentScripts.remove(s); |
605 |
|
|
recentScripts.insertElementAt(s, 0); |
606 |
|
|
|
607 |
|
|
updateRecentScriptsMenu(); |
608 |
|
|
} |
609 |
iliev |
912 |
|
610 |
iliev |
1285 |
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 |
iliev |
1323 |
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 |
iliev |
1729 |
preferences().setBoolProperty("leftSidePane.visible", b); |
643 |
iliev |
1323 |
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 |
iliev |
1729 |
preferences().setBoolProperty("rightSidePane.visible", b); |
675 |
iliev |
1323 |
|
676 |
iliev |
1729 |
int width = leftSidePane.getWidth(); |
677 |
|
|
int height = leftSidePane.getPreferredSize().height; |
678 |
|
|
if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height)); |
679 |
iliev |
1323 |
|
680 |
|
|
if(b) { |
681 |
|
|
int w = preferences().getIntProperty("devicesPane.width", 200); |
682 |
|
|
|
683 |
iliev |
1729 |
int h = rightSidePane.getPreferredSize().height; |
684 |
|
|
rightSidePane.setPreferredSize(new Dimension(w, h)); |
685 |
iliev |
1323 |
} else { |
686 |
iliev |
1729 |
int w = rightSidePane.getWidth(); |
687 |
iliev |
1323 |
if(w > 0 && w < 200) w = 200; |
688 |
|
|
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
689 |
|
|
} |
690 |
|
|
|
691 |
|
|
hSplitPane.setResizeWeight(0.0); |
692 |
iliev |
1729 |
rightSidePane.setVisible(b); |
693 |
iliev |
1323 |
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 |
iliev |
1729 |
boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected(); |
712 |
|
|
boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected(); |
713 |
iliev |
1323 |
|
714 |
iliev |
1729 |
if(leftSidePaneVisible && rightSidePaneVisible) { |
715 |
iliev |
1323 |
hSplitPane.setResizeWeight(0.5); |
716 |
iliev |
1729 |
} else if(leftSidePaneVisible && !rightSidePaneVisible) { |
717 |
iliev |
1323 |
hSplitPane.setResizeWeight(1.0); |
718 |
|
|
} |
719 |
|
|
|
720 |
iliev |
1729 |
if(!leftSidePaneVisible && !rightSidePaneVisible) { |
721 |
iliev |
1323 |
standardBar.showFantasiaLogo(false); |
722 |
|
|
if(isResizable()) setResizable(false); |
723 |
|
|
} else { |
724 |
|
|
standardBar.showFantasiaLogo(true); |
725 |
|
|
if(!isResizable()) setResizable(true); |
726 |
|
|
} |
727 |
|
|
} |
728 |
|
|
|
729 |
iliev |
1285 |
private class RecentScriptHandler implements ActionListener { |
730 |
|
|
private String script; |
731 |
|
|
|
732 |
|
|
RecentScriptHandler(String script) { this.script = script; } |
733 |
|
|
|
734 |
iliev |
912 |
public void |
735 |
iliev |
1285 |
actionPerformed(ActionEvent e) { |
736 |
|
|
runScript(script); |
737 |
|
|
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
738 |
|
|
a4n.windowLSConsole.actionPerformed(null); |
739 |
|
|
} |
740 |
iliev |
912 |
} |
741 |
iliev |
1285 |
} |
742 |
iliev |
912 |
|
743 |
iliev |
1285 |
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 |
iliev |
912 |
} |
749 |
|
|
} |
750 |
iliev |
1285 |
|
751 |
iliev |
1323 |
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 |
iliev |
1285 |
|
755 |
|
|
FantasiaMenuBar() { |
756 |
|
|
setOpaque(false); |
757 |
|
|
} |
758 |
|
|
|
759 |
|
|
protected void |
760 |
|
|
paintComponent(Graphics g) { |
761 |
|
|
super.paintComponent(g); |
762 |
iliev |
1323 |
if(standardBar.isVisible()) { |
763 |
|
|
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
764 |
|
|
} else { |
765 |
|
|
PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2); |
766 |
|
|
} |
767 |
iliev |
1285 |
} |
768 |
|
|
} |
769 |
iliev |
912 |
} |