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

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

  ViewVC Help
Powered by ViewVC