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

  ViewVC Help
Powered by ViewVC