/[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 1864 - (show annotations) (download)
Sat Mar 14 20:44:58 2009 UTC (15 years, 1 month ago) by iliev
File size: 16355 byte(s)
* Fixed bug in the parameter table when editing
  string list parameters with no possibilities
* Mac OS integration, work in progress:
* ant: added new target build-fantasia-osx
* Moved the menu bar on top of the screen
* Use custom application icon
* Register LSCP scripts to be opened with Fantasia
* Changed shortcut keys (use command key instead of ctrl key)

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 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 int modKey = CC.getViewConfig().getDefaultModKey();
223 mi = new JMenuItem(mainPane.getInstrumentsTable().cutAction);
224 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, modKey));
225 mi.setIcon(null);
226 m.add(mi);
227
228 mi = new JMenuItem(mainPane.getInstrumentsTable().copyAction);
229 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, modKey));
230 mi.setIcon(null);
231 m.add(mi);
232
233 mi = new JMenuItem(mainPane.getInstrumentsTable().pasteAction);
234 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, modKey));
235 mi.setIcon(null);
236 m.add(mi);
237
238 m.addSeparator();
239
240 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.edit.find"));
241 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, modKey));
242 m.add(mi);
243 mi.addActionListener(new ActionListener() {
244 public void
245 actionPerformed(ActionEvent e) {
246 if(toolbar.btnFind.isSelected()) return;
247
248 String path = instrumentsDbTree.getSelectedDirectoryPath();
249 if(path != null) sidePane.searchPage.setSearchPath(path);
250 toolbar.btnFind.doClick(0);
251 }
252 });
253
254 m.addSeparator();
255
256 mi = new JMenuItem(mainPane.getInstrumentsTable().renameAction);
257 mi.setIcon(null);
258 m.add(mi);
259
260 mi = new JMenuItem(mainPane.getInstrumentsTable().changeDescriptionAction);
261 mi.setIcon(null);
262 m.add(mi);
263
264 m = new JMenu(i18n.getMenuLabel("instrumentsdb.go"));
265 menuBar.add(m);
266
267 instrumentsDbTree.actionGoUp.putValue(Action.SMALL_ICON, Res.iconGoUp22);
268 mi = new JMenuItem(instrumentsDbTree.actionGoUp);
269 mi.setIcon(null);
270 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK));
271 m.add(mi);
272
273 instrumentsDbTree.actionGoBack.putValue(Action.SMALL_ICON, Res.iconGoBack22);
274 mi = new JMenuItem(instrumentsDbTree.actionGoBack);
275 mi.setIcon(null);
276 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK));
277 m.add(mi);
278
279 instrumentsDbTree.actionGoForward.putValue(Action.SMALL_ICON, Res.iconGoForward22);
280 mi = new JMenuItem(instrumentsDbTree.actionGoForward);
281 mi.setIcon(null);
282 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK));
283 m.add(mi);
284 }
285
286 private void
287 installKeyboardListeners() {
288 getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
289 KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
290 "goUp"
291 );
292
293 getRootPane().getActionMap().put ("goUp", new AbstractAction() {
294 public void
295 actionPerformed(ActionEvent e) {
296 if(!instrumentsDbTree.actionGoUp.isEnabled()) return;
297 instrumentsDbTree.actionGoUp.actionPerformed(null);
298 }
299 });
300 }
301
302 /** Invoked when this window is about to close. */
303 private void
304 onWindowClose() {
305 boolean b = (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH;
306 ClassicPrefs.setWindowMaximized("InstrumentsDbFrame", b);
307 if(b) return;
308
309 StdUtils.saveWindowBounds("InstrumentsDbFrame", getBounds());
310 int i = splitPane.getDividerLocation();
311 preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
312
313 mainPane.getInstrumentsTable().saveColumnsVisibleState();
314 mainPane.getInstrumentsTable().saveColumnWidths();
315 }
316
317 @Override
318 public void
319 setVisible(boolean b) {
320 if(b == isVisible()) return;
321
322 super.setVisible(b);
323
324 if(ClassicPrefs.getWindowMaximized("InstrumentsDbFrame")) {
325 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
326 }
327 }
328
329 private void
330 setDefaultSize() {
331 Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
332 double width = dimension.getWidth();
333 double height = dimension.getHeight();
334 setBounds(100, 100, (int) width - 200, (int) height - 200);
335 }
336
337 private void
338 setSavedSize() {
339 Rectangle r = StdUtils.getWindowBounds("InstrumentsDbFrame");
340 if(r == null) {
341 setDefaultSize();
342 return;
343 }
344
345 setBounds(r);
346
347 if(ClassicPrefs.getWindowMaximized("InstrumentsDbFrame"))
348 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
349 }
350
351 private void
352 addSidePane() {
353 getContentPane().remove(mainPane);
354 splitPane.setRightComponent(mainPane);
355 getContentPane().add(splitPane);
356 int i = preferences().getIntProperty("InstrumentsDbFrame.dividerLocation");
357 if(i != 0) splitPane.setDividerLocation(i);
358 }
359
360 private void
361 removeSidePane() {
362 int i = splitPane.getDividerLocation();
363 preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
364 getContentPane().remove(splitPane);
365 getContentPane().add(mainPane);
366 }
367
368 class ToolBar extends JToolBar {
369 private final ToggleButton btnFolders = new ToggleButton();
370 private final ToggleButton btnFind = new ToggleButton();
371
372 private final ToolbarButton btnGoUp = new ToolbarButton(instrumentsDbTree.actionGoUp);
373 private final ToolbarButton btnGoBack = new ToolbarButton(instrumentsDbTree.actionGoBack);
374 private final ToolbarButton btnGoForward = new ToolbarButton(instrumentsDbTree.actionGoForward);
375 private final ToolbarButton btnReload = new ToolbarButton(mainPane.getInstrumentsTable().reloadAction);
376
377 private final ToolbarButton btnPreferences = new ToolbarButton();
378
379 public ToolBar() {
380 super(i18n.getLabel("InstrumentsDbFrame.ToolbarBar.name"));
381 setFloatable(false);
382
383 btnFolders.setIcon(Res.iconFolderOpen22);
384 btnFolders.doClick(0);
385 btnFind.setIcon(Res.iconFind22);
386 btnPreferences.setIcon(Res.iconPreferences22);
387
388 add(btnFolders);
389 add(btnFind);
390 addSeparator();
391 add(btnGoBack);
392 add(btnGoForward);
393 add(btnGoUp);
394 add(btnReload);
395 addSeparator();
396 add(btnPreferences);
397
398
399 btnFolders.addActionListener(new ActionListener() {
400 public void
401 actionPerformed(ActionEvent e) {
402 if(!btnFolders.isSelected() && !btnFind.isSelected()) {
403 removeSidePane();
404 }
405
406 if(!btnFolders.isSelected()) return;
407
408 if(btnFind.isSelected()) btnFind.doClick(0);
409 else addSidePane();
410
411 sidePane.showFoldersPage();
412 }
413 });
414
415 btnFind.addActionListener(new ActionListener() {
416 public void
417 actionPerformed(ActionEvent e) {
418 if(!btnFolders.isSelected() && !btnFind.isSelected()) {
419 removeSidePane();
420 }
421
422 if(!btnFind.isSelected()) return;
423
424 if(btnFolders.isSelected()) btnFolders.doClick(0);
425 else addSidePane();
426
427 sidePane.showSearchPage();
428 }
429 });
430
431 btnPreferences.addActionListener(new ActionListener() {
432 public void
433 actionPerformed(ActionEvent e) {
434 new PreferencesDlg().setVisible(true);
435 }
436 });
437 }
438 }
439
440 class ToggleButton extends JToggleButton {
441 ToggleButton() {
442 setBorderPainted(false);
443 setContentAreaFilled(false);
444 setFocusPainted(false);
445
446 addActionListener(new ActionListener() {
447 public void
448 actionPerformed(ActionEvent e) {
449 setBorderPainted(isSelected());
450 }
451 });
452 }
453 }
454
455 public JSInstrumentsDbTree
456 getInstrumentsDbTree() { return instrumentsDbTree; }
457
458 public void
459 setSearchResults(DbDirectoryInfo[] directories) {
460 setSearchResults(directories, null);
461 }
462
463 public void
464 setSearchResults(DbInstrumentInfo[] instruments) {
465 setSearchResults(null, instruments);
466 }
467
468 public void
469 setSearchResults(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments) {
470 DbDirectoryTreeNode node = mainPane.getSearchResultsNode();
471 node.removeAllDirectories();
472 node.removeAllInstruments();
473
474 if(instruments != null) {
475 for(DbInstrumentInfo i : instruments) i.setShowAbsolutePath(true);
476 node.addInstruments(instruments);
477 }
478
479 if(directories != null) {
480 DbDirectoryTreeNode[] nodeS = new DbDirectoryTreeNode[directories.length];
481 for(int i = 0; i < directories.length; i++) {
482 DbDirectoryInfo d = directories[i];
483 d.setShowAbsolutePath(true);
484 nodeS[i] = new DbDirectoryTreeNode(d);
485
486
487 }
488 node.addDirectories(nodeS);
489 }
490
491 mainPane.showSearchResultsNode();
492 }
493
494 class MainPane extends JPanel {
495 private final JSInstrumentsDbTable instrumentsTable =
496 new JSInstrumentsDbTable(instrumentsDbTree, "InstrumentsDbFrame.");
497
498 private final DbDirectoryTreeNode searchResultsNode = new DbDirectoryTreeNode(null);
499
500 MainPane() {
501 setLayout(new BorderLayout());
502 JScrollPane sp = new JScrollPane(instrumentsTable);
503 add(sp);
504 instrumentsTable.reloadAction.putValue(Action.SMALL_ICON, Res.iconReload22);
505
506 instrumentsTable.createDirectoryAction.putValue (
507 Action.SMALL_ICON, Res.iconNew16
508 );
509
510 instrumentsTable.getParent().setBackground(instrumentsTable.getBackground());
511
512 searchResultsNode.setDetached(true);
513 }
514
515 public JSInstrumentsDbTable
516 getInstrumentsTable() { return instrumentsTable; }
517
518 public DbDirectoryTreeNode
519 getSearchResultsNode() { return searchResultsNode; }
520
521 public void
522 showSearchResultsNode() {
523 instrumentsDbTree.clearSelection();
524 instrumentsTable.setParentDirectoryNode(searchResultsNode);
525 }
526 }
527
528
529 class SidePane extends NavigationPane {
530 private final NavigationPage foldersPage = new NavigationPage();
531 private final DbSearchPage searchPage = new DbSearchPage(InstrumentsDbFrame.this);
532
533 SidePane() {
534 setTitlebarVisiblie(false);
535
536 foldersPage.setTitle(i18n.getLabel("InstrumentsDbFrame.folders"));
537 foldersPage.setLayout(new BorderLayout());
538 foldersPage.add(new JScrollPane(instrumentsDbTree));
539
540 NavigationPage[] pages = { foldersPage, searchPage };
541 setPages(pages);
542 showFoldersPage();
543 }
544
545 /** Shows the folders page in the left pane. */
546 public void
547 showFoldersPage() { getModel().addPage(foldersPage); }
548
549 /** Shows the search page in the left pane. */
550 public void
551 showSearchPage() { getModel().addPage(searchPage); }
552 }
553
554 private final EventHandler eventHandler = new EventHandler();
555
556 private EventHandler
557 getHandler() { return eventHandler; }
558
559 private class EventHandler implements ListSelectionListener {
560 public void
561 valueChanged(ListSelectionEvent e) {
562
563 }
564 }
565
566 class PreferencesDlg extends JSInstrumentsDbColumnPreferencesDlg {
567 PreferencesDlg() {
568 super(InstrumentsDbFrame.this, mainPane.instrumentsTable);
569 }
570 }
571 }

  ViewVC Help
Powered by ViewVC