/[svn]/jsampler/trunk/src/org/jsampler/view/classic/InstrumentsDbFrame.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/InstrumentsDbFrame.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1786 - (show annotations) (download)
Wed Oct 8 22:38:15 2008 UTC (15 years, 6 months ago) by iliev
File size: 16351 byte(s)
* Implemented option to launch the backend if it is not yet started
  (choose Edit/Preferences, then click the `Backend' tab)
* LSCP scripts can now be run by passing them to jsampler
  as command-line arguments
* The scripts in the `scripts' directory now pass the command-line
  arguments to the respective jsampler distribution
* ant: the default target is now build-fantasia
* bugfix: backend address was always set to 127.0.0.1 when adding
  backend to the backend list

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.classic;
24
25 import java.awt.BorderLayout;
26 import java.awt.Dimension;
27
28 import java.awt.Rectangle;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.awt.event.KeyEvent;
32 import java.awt.event.WindowAdapter;
33 import java.awt.event.WindowEvent;
34
35 import javax.swing.AbstractAction;
36 import javax.swing.Action;
37 import javax.swing.JComponent;
38 import javax.swing.JFrame;
39 import javax.swing.JMenu;
40 import javax.swing.JMenuBar;
41 import javax.swing.JMenuItem;
42 import javax.swing.JPanel;
43 import javax.swing.JScrollPane;
44 import javax.swing.JSplitPane;
45 import javax.swing.JToggleButton;
46 import javax.swing.JToolBar;
47 import javax.swing.KeyStroke;
48
49 import javax.swing.event.ListSelectionEvent;
50 import javax.swing.event.ListSelectionListener;
51
52 import net.sf.juife.NavigationPage;
53 import net.sf.juife.NavigationPane;
54
55 import org.jsampler.CC;
56 import org.jsampler.HF;
57
58 import org.jsampler.task.InstrumentsDb;
59
60 import org.jsampler.view.DbDirectoryTreeNode;
61
62 import org.jsampler.view.std.JSInstrumentsDbColumnPreferencesDlg;
63 import org.jsampler.view.std.JSInstrumentsDbTable;
64 import org.jsampler.view.std.JSInstrumentsDbTree;
65 import org.jsampler.view.std.JSLostFilesDlg;
66 import org.jsampler.view.std.StdUtils;
67
68 import org.linuxsampler.lscp.DbDirectoryInfo;
69 import org.linuxsampler.lscp.DbInstrumentInfo;
70
71 import static org.jsampler.view.classic.ClassicI18n.i18n;
72 import static org.jsampler.view.classic.ClassicPrefs.preferences;
73
74 /**
75 *
76 * @author Grigor Iliev
77 */
78 public class InstrumentsDbFrame extends JFrame {
79 private final ToolBar toolbar;
80 private final JMenuBar menuBar = new JMenuBar();
81 private final JSInstrumentsDbTree instrumentsDbTree;
82 private final SidePane sidePane;
83 private final JSplitPane splitPane;
84 private final MainPane mainPane;
85
86 private JMenu loadInstrumentMenu;
87 private JMenu addToMidiMapMenu;
88 private JMenu addToOrchestraMenu;
89
90 /**
91 * Creates a new instance of <code>InstrumentsDbFrame</code>
92 */
93 public
94 InstrumentsDbFrame() {
95 setTitle(i18n.getLabel("InstrumentsDbFrame.title"));
96 if(Res.appIcon != null) setIconImage(Res.appIcon.getImage());
97
98 instrumentsDbTree = new JSInstrumentsDbTree(CC.getInstrumentsDbTreeModel());
99
100 sidePane = new SidePane();
101 mainPane = new MainPane();
102
103 instrumentsDbTree.setSelectedDirectory("/");
104
105 toolbar = new ToolBar();
106 getContentPane().add(toolbar, BorderLayout.NORTH);
107
108 splitPane = new JSplitPane (
109 JSplitPane.HORIZONTAL_SPLIT,
110 true, // continuousLayout
111 sidePane,
112 mainPane
113 );
114
115 splitPane.setDividerSize(3);
116 splitPane.setDividerLocation(200);
117
118 addMenu();
119
120 pack();
121 setSavedSize();
122
123 getContentPane().add(splitPane);
124 mainPane.getInstrumentsTable().loadColumnWidths();
125
126 addWindowListener(new WindowAdapter() {
127 public void
128 windowClosing(WindowEvent we) { onWindowClose(); }
129 });
130
131 installKeyboardListeners();
132 }
133
134 private void
135 addMenu() {
136 JMenu m;
137 JMenuItem mi;
138
139 setJMenuBar(menuBar);
140
141 // Actions
142 m = new JMenu(i18n.getMenuLabel("instrumentsdb.actions"));
143 menuBar.add(m);
144
145 mi = new JMenuItem(mainPane.getInstrumentsTable().createDirectoryAction);
146 mi.setIcon(null);
147 m.add(mi);
148
149 mi = new JMenuItem(mainPane.getInstrumentsTable().deleteAction);
150 mi.setIcon(null);
151 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
152 m.add(mi);
153
154 JMenu addInstrumentsMenu =
155 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addInstruments"));
156 m.add(addInstrumentsMenu);
157
158 mi = new JMenuItem(mainPane.getInstrumentsTable().addInstrumentsFromFileAction);
159 mi.setIcon(null);
160 addInstrumentsMenu.add(mi);
161
162 mi = new JMenuItem(mainPane.getInstrumentsTable().addInstrumentsFromDirAction);
163 mi.setIcon(null);
164 addInstrumentsMenu.add(mi);
165
166 m.addSeparator();
167
168 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.actions.format"));
169 m.add(mi);
170 mi.addActionListener(new ActionListener() {
171 public void
172 actionPerformed(ActionEvent e) {
173 String s = i18n.getMessage("InstrumentsDbFrame.formatDatabase?");
174 if(!HF.showYesNoDialog(InstrumentsDbFrame.this, s)) return;
175 CC.getTaskQueue().add(new InstrumentsDb.Format());
176 }
177 });
178
179 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.actions.checkForLostFiles"));
180 m.add(mi);
181 mi.addActionListener(new ActionListener() {
182 public void
183 actionPerformed(ActionEvent e) {
184 new JSLostFilesDlg(InstrumentsDbFrame.this).setVisible(true);
185 }
186 });
187
188 m.addSeparator();
189
190 loadInstrumentMenu =
191 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.loadInstrument"));
192 m.add(loadInstrumentMenu);
193 mainPane.getInstrumentsTable().registerLoadInstrumentMenus(loadInstrumentMenu);
194
195 addToMidiMapMenu =
196 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToMidiMap"));
197 m.add(addToMidiMapMenu);
198 mainPane.getInstrumentsTable().registerAddToMidiMapMenu(addToMidiMapMenu);
199
200 addToOrchestraMenu =
201 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToOrchestra"));
202 m.add(addToOrchestraMenu);
203 mainPane.getInstrumentsTable().registerAddToOrchestraMenu(addToOrchestraMenu);
204
205 m.addSeparator();
206
207 mi = new JMenuItem(mainPane.getInstrumentsTable().reloadAction);
208 mi.setIcon(null);
209 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
210 m.add(mi);
211
212 m.addSeparator();
213
214 mi = new JMenuItem(mainPane.getInstrumentsTable().propertiesAction);
215 mi.setIcon(null);
216 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_MASK));
217 m.add(mi);
218
219 m = new JMenu(i18n.getMenuLabel("instrumentsdb.edit"));
220 menuBar.add(m);
221
222 mi = new JMenuItem(mainPane.getInstrumentsTable().cutAction);
223 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK));
224 mi.setIcon(null);
225 m.add(mi);
226
227 mi = new JMenuItem(mainPane.getInstrumentsTable().copyAction);
228 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
229 mi.setIcon(null);
230 m.add(mi);
231
232 mi = new JMenuItem(mainPane.getInstrumentsTable().pasteAction);
233 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK));
234 mi.setIcon(null);
235 m.add(mi);
236
237 m.addSeparator();
238
239 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.edit.find"));
240 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK));
241 m.add(mi);
242 mi.addActionListener(new ActionListener() {
243 public void
244 actionPerformed(ActionEvent e) {
245 if(toolbar.btnFind.isSelected()) return;
246
247 String path = instrumentsDbTree.getSelectedDirectoryPath();
248 if(path != null) sidePane.searchPage.setSearchPath(path);
249 toolbar.btnFind.doClick(0);
250 }
251 });
252
253 m.addSeparator();
254
255 mi = new JMenuItem(mainPane.getInstrumentsTable().renameAction);
256 mi.setIcon(null);
257 m.add(mi);
258
259 mi = new JMenuItem(mainPane.getInstrumentsTable().changeDescriptionAction);
260 mi.setIcon(null);
261 m.add(mi);
262
263 m = new JMenu(i18n.getMenuLabel("instrumentsdb.go"));
264 menuBar.add(m);
265
266 instrumentsDbTree.actionGoUp.putValue(Action.SMALL_ICON, Res.iconGoUp22);
267 mi = new JMenuItem(instrumentsDbTree.actionGoUp);
268 mi.setIcon(null);
269 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK));
270 m.add(mi);
271
272 instrumentsDbTree.actionGoBack.putValue(Action.SMALL_ICON, Res.iconGoBack22);
273 mi = new JMenuItem(instrumentsDbTree.actionGoBack);
274 mi.setIcon(null);
275 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK));
276 m.add(mi);
277
278 instrumentsDbTree.actionGoForward.putValue(Action.SMALL_ICON, Res.iconGoForward22);
279 mi = new JMenuItem(instrumentsDbTree.actionGoForward);
280 mi.setIcon(null);
281 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK));
282 m.add(mi);
283 }
284
285 private void
286 installKeyboardListeners() {
287 getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
288 KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
289 "goUp"
290 );
291
292 getRootPane().getActionMap().put ("goUp", new AbstractAction() {
293 public void
294 actionPerformed(ActionEvent e) {
295 if(!instrumentsDbTree.actionGoUp.isEnabled()) return;
296 instrumentsDbTree.actionGoUp.actionPerformed(null);
297 }
298 });
299 }
300
301 /** Invoked when this window is about to close. */
302 private void
303 onWindowClose() {
304 boolean b = (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH;
305 ClassicPrefs.setWindowMaximized("InstrumentsDbFrame", b);
306 if(b) return;
307
308 StdUtils.saveWindowBounds("InstrumentsDbFrame", getBounds());
309 int i = splitPane.getDividerLocation();
310 preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
311
312 mainPane.getInstrumentsTable().saveColumnsVisibleState();
313 mainPane.getInstrumentsTable().saveColumnWidths();
314 }
315
316 @Override
317 public void
318 setVisible(boolean b) {
319 if(b == isVisible()) return;
320
321 super.setVisible(b);
322
323 if(ClassicPrefs.getWindowMaximized("InstrumentsDbFrame")) {
324 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
325 }
326 }
327
328 private void
329 setDefaultSize() {
330 Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
331 double width = dimension.getWidth();
332 double height = dimension.getHeight();
333 setBounds(100, 100, (int) width - 200, (int) height - 200);
334 }
335
336 private void
337 setSavedSize() {
338 Rectangle r = StdUtils.getWindowBounds("InstrumentsDbFrame");
339 if(r == null) {
340 setDefaultSize();
341 return;
342 }
343
344 setBounds(r);
345
346 if(ClassicPrefs.getWindowMaximized("InstrumentsDbFrame"))
347 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
348 }
349
350 private void
351 addSidePane() {
352 getContentPane().remove(mainPane);
353 splitPane.setRightComponent(mainPane);
354 getContentPane().add(splitPane);
355 int i = preferences().getIntProperty("InstrumentsDbFrame.dividerLocation");
356 if(i != 0) splitPane.setDividerLocation(i);
357 }
358
359 private void
360 removeSidePane() {
361 int i = splitPane.getDividerLocation();
362 preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
363 getContentPane().remove(splitPane);
364 getContentPane().add(mainPane);
365 }
366
367 class ToolBar extends JToolBar {
368 private final ToggleButton btnFolders = new ToggleButton();
369 private final ToggleButton btnFind = new ToggleButton();
370
371 private final ToolbarButton btnGoUp = new ToolbarButton(instrumentsDbTree.actionGoUp);
372 private final ToolbarButton btnGoBack = new ToolbarButton(instrumentsDbTree.actionGoBack);
373 private final ToolbarButton btnGoForward = new ToolbarButton(instrumentsDbTree.actionGoForward);
374 private final ToolbarButton btnReload = new ToolbarButton(mainPane.getInstrumentsTable().reloadAction);
375
376 private final ToolbarButton btnPreferences = new ToolbarButton();
377
378 public ToolBar() {
379 super(i18n.getLabel("InstrumentsDbFrame.ToolbarBar.name"));
380 setFloatable(false);
381
382 btnFolders.setIcon(Res.iconFolderOpen22);
383 btnFolders.doClick(0);
384 btnFind.setIcon(Res.iconFind22);
385 btnPreferences.setIcon(Res.iconPreferences22);
386
387 add(btnFolders);
388 add(btnFind);
389 addSeparator();
390 add(btnGoBack);
391 add(btnGoForward);
392 add(btnGoUp);
393 add(btnReload);
394 addSeparator();
395 add(btnPreferences);
396
397
398 btnFolders.addActionListener(new ActionListener() {
399 public void
400 actionPerformed(ActionEvent e) {
401 if(!btnFolders.isSelected() && !btnFind.isSelected()) {
402 removeSidePane();
403 }
404
405 if(!btnFolders.isSelected()) return;
406
407 if(btnFind.isSelected()) btnFind.doClick(0);
408 else addSidePane();
409
410 sidePane.showFoldersPage();
411 }
412 });
413
414 btnFind.addActionListener(new ActionListener() {
415 public void
416 actionPerformed(ActionEvent e) {
417 if(!btnFolders.isSelected() && !btnFind.isSelected()) {
418 removeSidePane();
419 }
420
421 if(!btnFind.isSelected()) return;
422
423 if(btnFolders.isSelected()) btnFolders.doClick(0);
424 else addSidePane();
425
426 sidePane.showSearchPage();
427 }
428 });
429
430 btnPreferences.addActionListener(new ActionListener() {
431 public void
432 actionPerformed(ActionEvent e) {
433 new PreferencesDlg().setVisible(true);
434 }
435 });
436 }
437 }
438
439 class ToggleButton extends JToggleButton {
440 ToggleButton() {
441 setBorderPainted(false);
442 setContentAreaFilled(false);
443 setFocusPainted(false);
444
445 addActionListener(new ActionListener() {
446 public void
447 actionPerformed(ActionEvent e) {
448 setBorderPainted(isSelected());
449 }
450 });
451 }
452 }
453
454 public JSInstrumentsDbTree
455 getInstrumentsDbTree() { return instrumentsDbTree; }
456
457 public void
458 setSearchResults(DbDirectoryInfo[] directories) {
459 setSearchResults(directories, null);
460 }
461
462 public void
463 setSearchResults(DbInstrumentInfo[] instruments) {
464 setSearchResults(null, instruments);
465 }
466
467 public void
468 setSearchResults(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments) {
469 DbDirectoryTreeNode node = mainPane.getSearchResultsNode();
470 node.removeAllDirectories();
471 node.removeAllInstruments();
472
473 if(instruments != null) {
474 for(DbInstrumentInfo i : instruments) i.setShowAbsolutePath(true);
475 node.addInstruments(instruments);
476 }
477
478 if(directories != null) {
479 DbDirectoryTreeNode[] nodeS = new DbDirectoryTreeNode[directories.length];
480 for(int i = 0; i < directories.length; i++) {
481 DbDirectoryInfo d = directories[i];
482 d.setShowAbsolutePath(true);
483 nodeS[i] = new DbDirectoryTreeNode(d);
484
485
486 }
487 node.addDirectories(nodeS);
488 }
489
490 mainPane.showSearchResultsNode();
491 }
492
493 class MainPane extends JPanel {
494 private final JSInstrumentsDbTable instrumentsTable =
495 new JSInstrumentsDbTable(instrumentsDbTree, "InstrumentsDbFrame.");
496
497 private final DbDirectoryTreeNode searchResultsNode = new DbDirectoryTreeNode(null);
498
499 MainPane() {
500 setLayout(new BorderLayout());
501 JScrollPane sp = new JScrollPane(instrumentsTable);
502 add(sp);
503 instrumentsTable.reloadAction.putValue(Action.SMALL_ICON, Res.iconReload22);
504
505 instrumentsTable.createDirectoryAction.putValue (
506 Action.SMALL_ICON, Res.iconNew16
507 );
508
509 instrumentsTable.getParent().setBackground(instrumentsTable.getBackground());
510
511 searchResultsNode.setDetached(true);
512 }
513
514 public JSInstrumentsDbTable
515 getInstrumentsTable() { return instrumentsTable; }
516
517 public DbDirectoryTreeNode
518 getSearchResultsNode() { return searchResultsNode; }
519
520 public void
521 showSearchResultsNode() {
522 instrumentsDbTree.clearSelection();
523 instrumentsTable.setParentDirectoryNode(searchResultsNode);
524 }
525 }
526
527
528 class SidePane extends NavigationPane {
529 private final NavigationPage foldersPage = new NavigationPage();
530 private final DbSearchPage searchPage = new DbSearchPage(InstrumentsDbFrame.this);
531
532 SidePane() {
533 setTitlebarVisiblie(false);
534
535 foldersPage.setTitle(i18n.getLabel("InstrumentsDbFrame.folders"));
536 foldersPage.setLayout(new BorderLayout());
537 foldersPage.add(new JScrollPane(instrumentsDbTree));
538
539 NavigationPage[] pages = { foldersPage, searchPage };
540 setPages(pages);
541 showFoldersPage();
542 }
543
544 /** Shows the folders page in the left pane. */
545 public void
546 showFoldersPage() { getModel().addPage(foldersPage); }
547
548 /** Shows the search page in the left pane. */
549 public void
550 showSearchPage() { getModel().addPage(searchPage); }
551 }
552
553 private final EventHandler eventHandler = new EventHandler();
554
555 private EventHandler
556 getHandler() { return eventHandler; }
557
558 private class EventHandler implements ListSelectionListener {
559 public void
560 valueChanged(ListSelectionEvent e) {
561
562 }
563 }
564
565 class PreferencesDlg extends JSInstrumentsDbColumnPreferencesDlg {
566 PreferencesDlg() {
567 super(InstrumentsDbFrame.this, mainPane.instrumentsTable);
568 }
569 }
570 }

  ViewVC Help
Powered by ViewVC