/[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 1752 - (show annotations) (download)
Mon Aug 11 22:51:24 2008 UTC (15 years, 8 months ago) by iliev
File size: 17644 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.classic;
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.JSInstrumentsDbTree;
84 import org.jsampler.view.std.JSLostFilesDlg;
85
86 import org.linuxsampler.lscp.DbDirectoryInfo;
87 import org.linuxsampler.lscp.DbInstrumentInfo;
88 import org.linuxsampler.lscp.DbSearchQuery;
89
90 import static org.jsampler.view.classic.ClassicI18n.i18n;
91 import static org.jsampler.view.classic.ClassicPrefs.preferences;
92 import static org.jsampler.view.fantasia.FantasiaPrefs.INSTRUMENTS_DB_FRAME_SORT_ORDER;
93
94 /**
95 *
96 * @author Grigor Iliev
97 */
98 public class InstrumentsDbFrame extends JFrame {
99 private final ToolBar toolbar;
100 private final JMenuBar menuBar = new JMenuBar();
101 private final JSInstrumentsDbTree instrumentsDbTree;
102 private final SidePane sidePane;
103 private final JSplitPane splitPane;
104 private final MainPane mainPane;
105
106 private JMenu loadInstrumentMenu;
107 private JMenu addToMidiMapMenu;
108 private JMenu addToOrchestraMenu;
109
110 /**
111 * Creates a new instance of <code>InstrumentsDbFrame</code>
112 */
113 public
114 InstrumentsDbFrame() {
115 setTitle(i18n.getLabel("InstrumentsDbFrame.title"));
116 if(Res.appIcon != null) setIconImage(Res.appIcon.getImage());
117
118 instrumentsDbTree = new JSInstrumentsDbTree(CC.getInstrumentsDbTreeModel());
119
120 sidePane = new SidePane();
121 mainPane = new MainPane();
122
123 instrumentsDbTree.setSelectedDirectory("/");
124
125 toolbar = new ToolBar();
126 getContentPane().add(toolbar, BorderLayout.NORTH);
127
128 splitPane = new JSplitPane (
129 JSplitPane.HORIZONTAL_SPLIT,
130 true, // continuousLayout
131 sidePane,
132 mainPane
133 );
134
135 splitPane.setDividerSize(3);
136 splitPane.setDividerLocation(200);
137
138 addMenu();
139
140 pack();
141 setSavedSize();
142
143 getContentPane().add(splitPane);
144 mainPane.getInstrumentsTable().loadColumnWidths();
145
146 addWindowListener(new WindowAdapter() {
147 public void
148 windowClosing(WindowEvent we) { onWindowClose(); }
149 });
150
151 installKeyboardListeners();
152 }
153
154 private void
155 addMenu() {
156 JMenu m;
157 JMenuItem mi;
158
159 setJMenuBar(menuBar);
160
161 // Actions
162 m = new JMenu(i18n.getMenuLabel("instrumentsdb.actions"));
163 menuBar.add(m);
164
165 mi = new JMenuItem(mainPane.getInstrumentsTable().createDirectoryAction);
166 mi.setIcon(null);
167 m.add(mi);
168
169 mi = new JMenuItem(mainPane.getInstrumentsTable().deleteAction);
170 mi.setIcon(null);
171 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
172 m.add(mi);
173
174 JMenu addInstrumentsMenu =
175 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addInstruments"));
176 m.add(addInstrumentsMenu);
177
178 mi = new JMenuItem(mainPane.getInstrumentsTable().addInstrumentsFromFileAction);
179 mi.setIcon(null);
180 addInstrumentsMenu.add(mi);
181
182 mi = new JMenuItem(mainPane.getInstrumentsTable().addInstrumentsFromDirAction);
183 mi.setIcon(null);
184 addInstrumentsMenu.add(mi);
185
186 m.addSeparator();
187
188 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.actions.format"));
189 m.add(mi);
190 mi.addActionListener(new ActionListener() {
191 public void
192 actionPerformed(ActionEvent e) {
193 String s = i18n.getMessage("InstrumentsDbFrame.formatDatabase?");
194 if(!HF.showYesNoDialog(InstrumentsDbFrame.this, s)) return;
195 CC.getTaskQueue().add(new InstrumentsDb.Format());
196 }
197 });
198
199 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.actions.checkForLostFiles"));
200 m.add(mi);
201 mi.addActionListener(new ActionListener() {
202 public void
203 actionPerformed(ActionEvent e) {
204 new JSLostFilesDlg(InstrumentsDbFrame.this).setVisible(true);
205 }
206 });
207
208 m.addSeparator();
209
210 loadInstrumentMenu =
211 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.loadInstrument"));
212 m.add(loadInstrumentMenu);
213 mainPane.getInstrumentsTable().registerLoadInstrumentMenus(loadInstrumentMenu);
214
215 addToMidiMapMenu =
216 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToMidiMap"));
217 m.add(addToMidiMapMenu);
218 mainPane.getInstrumentsTable().registerAddToMidiMapMenu(addToMidiMapMenu);
219
220 addToOrchestraMenu =
221 new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToOrchestra"));
222 m.add(addToOrchestraMenu);
223 mainPane.getInstrumentsTable().registerAddToOrchestraMenu(addToOrchestraMenu);
224
225 m.addSeparator();
226
227 mi = new JMenuItem(mainPane.getInstrumentsTable().reloadAction);
228 mi.setIcon(null);
229 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
230 m.add(mi);
231
232 m.addSeparator();
233
234 mi = new JMenuItem(mainPane.getInstrumentsTable().propertiesAction);
235 mi.setIcon(null);
236 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_MASK));
237 m.add(mi);
238
239 m = new JMenu(i18n.getMenuLabel("instrumentsdb.edit"));
240 menuBar.add(m);
241
242 mi = new JMenuItem(mainPane.getInstrumentsTable().cutAction);
243 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK));
244 mi.setIcon(null);
245 m.add(mi);
246
247 mi = new JMenuItem(mainPane.getInstrumentsTable().copyAction);
248 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
249 mi.setIcon(null);
250 m.add(mi);
251
252 mi = new JMenuItem(mainPane.getInstrumentsTable().pasteAction);
253 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK));
254 mi.setIcon(null);
255 m.add(mi);
256
257 m.addSeparator();
258
259 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.edit.find"));
260 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK));
261 m.add(mi);
262 mi.addActionListener(new ActionListener() {
263 public void
264 actionPerformed(ActionEvent e) {
265 if(toolbar.btnFind.isSelected()) return;
266
267 String path = instrumentsDbTree.getSelectedDirectoryPath();
268 if(path != null) sidePane.searchPage.setSearchPath(path);
269 toolbar.btnFind.doClick(0);
270 }
271 });
272
273 m.addSeparator();
274
275 mi = new JMenuItem(mainPane.getInstrumentsTable().renameAction);
276 mi.setIcon(null);
277 m.add(mi);
278
279 mi = new JMenuItem(mainPane.getInstrumentsTable().changeDescriptionAction);
280 mi.setIcon(null);
281 m.add(mi);
282
283 m = new JMenu(i18n.getMenuLabel("instrumentsdb.go"));
284 menuBar.add(m);
285
286 instrumentsDbTree.actionGoUp.putValue(Action.SMALL_ICON, Res.iconGoUp22);
287 mi = new JMenuItem(instrumentsDbTree.actionGoUp);
288 mi.setIcon(null);
289 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK));
290 m.add(mi);
291
292 instrumentsDbTree.actionGoBack.putValue(Action.SMALL_ICON, Res.iconGoBack22);
293 mi = new JMenuItem(instrumentsDbTree.actionGoBack);
294 mi.setIcon(null);
295 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK));
296 m.add(mi);
297
298 instrumentsDbTree.actionGoForward.putValue(Action.SMALL_ICON, Res.iconGoForward22);
299 mi = new JMenuItem(instrumentsDbTree.actionGoForward);
300 mi.setIcon(null);
301 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK));
302 m.add(mi);
303 }
304
305 private void
306 installKeyboardListeners() {
307 getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
308 KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
309 "goUp"
310 );
311
312 getRootPane().getActionMap().put ("goUp", new AbstractAction() {
313 public void
314 actionPerformed(ActionEvent e) {
315 if(!instrumentsDbTree.actionGoUp.isEnabled()) return;
316 instrumentsDbTree.actionGoUp.actionPerformed(null);
317 }
318 });
319 }
320
321 /** Invoked when this window is about to close. */
322 private void
323 onWindowClose() {
324 boolean b = (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH;
325 ClassicPrefs.setWindowMaximized("InstrumentsDbFrame", b);
326 if(b) return;
327
328 java.awt.Point p = getLocation();
329 Dimension d = getSize();
330 StringBuffer sb = new StringBuffer();
331 sb.append(p.x).append(',').append(p.y).append(',');
332 sb.append(d.width).append(',').append(d.height);
333 ClassicPrefs.setWindowSizeAndLocation("InstrumentsDbFrame", sb.toString());
334 int i = splitPane.getDividerLocation();
335 preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
336
337 mainPane.getInstrumentsTable().saveColumnsVisibleState();
338 mainPane.getInstrumentsTable().saveColumnWidths();
339 }
340
341 private void
342 setDefaultSize() {
343 Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
344 double width = dimension.getWidth();
345 double height = dimension.getHeight();
346 setBounds(100, 100, (int) width - 200, (int) height - 200);
347 }
348
349 private void
350 setSavedSize() {
351 String s = ClassicPrefs.getWindowSizeAndLocation("InstrumentsDbFrame");
352 if(s == null) {
353 setDefaultSize();
354 return;
355 }
356
357 try {
358 int i = s.indexOf(',');
359 int x = Integer.parseInt(s.substring(0, i));
360
361 s = s.substring(i + 1);
362 i = s.indexOf(',');
363 int y = Integer.parseInt(s.substring(0, i));
364
365 s = s.substring(i + 1);
366 i = s.indexOf(',');
367 int width = Integer.parseInt(s.substring(0, i));
368
369 s = s.substring(i + 1);
370 int height = Integer.parseInt(s);
371
372 setBounds(x, y, width, height);
373
374 i = preferences().getIntProperty("InstrumentsDbFrame.dividerLocation");
375 if(i != 0) splitPane.setDividerLocation(i);
376
377 } catch(Exception x) {
378 String msg = "Parsing of window size and location string failed";
379 CC.getLogger().log(Level.INFO, msg, x);
380 setDefaultSize();
381 }
382
383 if(ClassicPrefs.getWindowMaximized("InstrumentsDbFrame"))
384 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
385 }
386
387 private void
388 addSidePane() {
389 getContentPane().remove(mainPane);
390 splitPane.setRightComponent(mainPane);
391 getContentPane().add(splitPane);
392 int i = preferences().getIntProperty("InstrumentsDbFrame.dividerLocation");
393 if(i != 0) splitPane.setDividerLocation(i);
394 }
395
396 private void
397 removeSidePane() {
398 int i = splitPane.getDividerLocation();
399 preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
400 getContentPane().remove(splitPane);
401 getContentPane().add(mainPane);
402 }
403
404 class ToolBar extends JToolBar {
405 private final ToggleButton btnFolders = new ToggleButton();
406 private final ToggleButton btnFind = new ToggleButton();
407
408 private final ToolbarButton btnGoUp = new ToolbarButton(instrumentsDbTree.actionGoUp);
409 private final ToolbarButton btnGoBack = new ToolbarButton(instrumentsDbTree.actionGoBack);
410 private final ToolbarButton btnGoForward = new ToolbarButton(instrumentsDbTree.actionGoForward);
411 private final ToolbarButton btnReload = new ToolbarButton(mainPane.getInstrumentsTable().reloadAction);
412
413 private final ToolbarButton btnPreferences = new ToolbarButton();
414
415 public ToolBar() {
416 super(i18n.getLabel("InstrumentsDbFrame.ToolbarBar.name"));
417 setFloatable(false);
418
419 btnFolders.setIcon(Res.iconFolderOpen22);
420 btnFolders.doClick(0);
421 btnFind.setIcon(Res.iconFind22);
422 btnPreferences.setIcon(Res.iconPreferences22);
423
424 add(btnFolders);
425 add(btnFind);
426 addSeparator();
427 add(btnGoBack);
428 add(btnGoForward);
429 add(btnGoUp);
430 add(btnReload);
431 addSeparator();
432 add(btnPreferences);
433
434
435 btnFolders.addActionListener(new ActionListener() {
436 public void
437 actionPerformed(ActionEvent e) {
438 if(!btnFolders.isSelected() && !btnFind.isSelected()) {
439 removeSidePane();
440 }
441
442 if(!btnFolders.isSelected()) return;
443
444 if(btnFind.isSelected()) btnFind.doClick(0);
445 else addSidePane();
446
447 sidePane.showFoldersPage();
448 }
449 });
450
451 btnFind.addActionListener(new ActionListener() {
452 public void
453 actionPerformed(ActionEvent e) {
454 if(!btnFolders.isSelected() && !btnFind.isSelected()) {
455 removeSidePane();
456 }
457
458 if(!btnFind.isSelected()) return;
459
460 if(btnFolders.isSelected()) btnFolders.doClick(0);
461 else addSidePane();
462
463 sidePane.showSearchPage();
464 }
465 });
466
467 btnPreferences.addActionListener(new ActionListener() {
468 public void
469 actionPerformed(ActionEvent e) {
470 new PreferencesDlg().setVisible(true);
471 }
472 });
473 }
474 }
475
476 class ToggleButton extends JToggleButton {
477 ToggleButton() {
478 setBorderPainted(false);
479 setContentAreaFilled(false);
480 setFocusPainted(false);
481
482 addActionListener(new ActionListener() {
483 public void
484 actionPerformed(ActionEvent e) {
485 setBorderPainted(isSelected());
486 }
487 });
488 }
489 }
490
491 public JSInstrumentsDbTree
492 getInstrumentsDbTree() { return instrumentsDbTree; }
493
494 public void
495 setSearchResults(DbDirectoryInfo[] directories) {
496 setSearchResults(directories, null);
497 }
498
499 public void
500 setSearchResults(DbInstrumentInfo[] instruments) {
501 setSearchResults(null, instruments);
502 }
503
504 public void
505 setSearchResults(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments) {
506 DbDirectoryTreeNode node = mainPane.getSearchResultsNode();
507 node.removeAllDirectories();
508 node.removeAllInstruments();
509
510 if(instruments != null) {
511 for(DbInstrumentInfo i : instruments) i.setShowAbsolutePath(true);
512 node.addInstruments(instruments);
513 }
514
515 if(directories != null) {
516 DbDirectoryTreeNode[] nodeS = new DbDirectoryTreeNode[directories.length];
517 for(int i = 0; i < directories.length; i++) {
518 DbDirectoryInfo d = directories[i];
519 d.setShowAbsolutePath(true);
520 nodeS[i] = new DbDirectoryTreeNode(d);
521
522
523 }
524 node.addDirectories(nodeS);
525 }
526
527 mainPane.showSearchResultsNode();
528 }
529
530 class MainPane extends JPanel {
531 private final JSInstrumentsDbTable instrumentsTable =
532 new JSInstrumentsDbTable(instrumentsDbTree, "InstrumentsDbFrame.");
533
534 private final DbDirectoryTreeNode searchResultsNode = new DbDirectoryTreeNode(null);
535
536 MainPane() {
537 setLayout(new BorderLayout());
538 JScrollPane sp = new JScrollPane(instrumentsTable);
539 add(sp);
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