/[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 1752 - (show annotations) (download)
Mon Aug 11 22:51:24 2008 UTC (15 years, 8 months ago) by iliev
File size: 17761 byte(s)
* Added toolbar to the Database Instrument Chooser dialog
* Instrument Chooser and Database Instrument Chooser dialogs
  are now resizable
* Fantasia: Added toolbar to the Right-Side Pane's Instruments Database

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

  ViewVC Help
Powered by ViewVC