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

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/InstrumentsDbFrame.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1729 - (hide annotations) (download)
Tue Apr 29 22:22:40 2008 UTC (16 years, 1 month ago) by iliev
File size: 27888 byte(s)
* Added support for handling lost files in the Instruments Database
  (In the Instruments Database window choose Actions/Check For Lost Files)
* Fantasia: Added option to show the Instruments Database
  on the Right-Side Pane of the Fantasia's main window
  (choose Edit/Preferences, then click the `View' tab)
* Added new menu item in the Instruments Database window: Edit/Find
* Some minor bugfixes and enhancements

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1729 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
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 iliev 1705 import java.util.List;
37 iliev 1286 import java.util.logging.Level;
38    
39     import javax.swing.AbstractAction;
40     import javax.swing.Action;
41     import javax.swing.BorderFactory;
42     import javax.swing.BoxLayout;
43     import javax.swing.Icon;
44     import javax.swing.JCheckBox;
45     import javax.swing.JComponent;
46     import javax.swing.JFrame;
47     import javax.swing.JMenu;
48     import javax.swing.JMenuBar;
49     import javax.swing.JMenuItem;
50     import javax.swing.JPanel;
51     import javax.swing.JScrollPane;
52     import javax.swing.JSplitPane;
53     import javax.swing.JTextField;
54     import javax.swing.JToggleButton;
55     import javax.swing.JToolBar;
56     import javax.swing.KeyStroke;
57 iliev 1705 import javax.swing.RowSorter.SortKey;
58     import javax.swing.SortOrder;
59 iliev 1286
60 iliev 1688 import javax.swing.event.ChangeEvent;
61     import javax.swing.event.ChangeListener;
62 iliev 1286 import javax.swing.event.ListSelectionEvent;
63     import javax.swing.event.ListSelectionListener;
64 iliev 1705 import javax.swing.event.RowSorterEvent;
65     import javax.swing.event.RowSorterListener;
66 iliev 1286 import javax.swing.event.TreeSelectionEvent;
67     import javax.swing.event.TreeSelectionListener;
68    
69     import javax.swing.plaf.ToolBarUI;
70    
71     import net.sf.juife.InformationDialog;
72     import net.sf.juife.NavigationPage;
73     import net.sf.juife.NavigationPane;
74    
75     import net.sf.juife.DefaultNavigationHistoryModel;
76     import net.sf.juife.Task;
77    
78     import net.sf.juife.event.TaskEvent;
79     import net.sf.juife.event.TaskListener;
80    
81     import org.jsampler.CC;
82     import org.jsampler.HF;
83     import org.jsampler.JSI18n;
84    
85     import org.jsampler.task.InstrumentsDb;
86    
87     import org.jsampler.view.DbDirectoryTreeNode;
88     import org.jsampler.view.InstrumentsDbTableModel;
89     import org.jsampler.view.InstrumentsDbTableView;
90     import org.jsampler.view.std.JSInstrumentsDbTable;
91     import org.jsampler.view.std.JSInstrumentsDbTree;
92 iliev 1729 import org.jsampler.view.std.JSLostFilesDlg;
93 iliev 1286
94     import org.linuxsampler.lscp.DbDirectoryInfo;
95     import org.linuxsampler.lscp.DbInstrumentInfo;
96     import org.linuxsampler.lscp.DbSearchQuery;
97    
98 iliev 1705 import static javax.swing.event.RowSorterEvent.Type.SORT_ORDER_CHANGED;
99 iliev 1286 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
100     import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
101 iliev 1705 import static org.jsampler.view.fantasia.FantasiaPrefs.INSTRUMENTS_DB_FRAME_SORT_ORDER;
102 iliev 1286
103     /**
104     *
105     * @author Grigor Iliev
106     */
107     public class InstrumentsDbFrame extends JFrame {
108 iliev 1729 private final ToolBar toolbar;
109 iliev 1286 private final JMenuBar menuBar = new JMenuBar();
110     private final JSInstrumentsDbTree instrumentsDbTree;
111     private final SidePane sidePane;
112     private final JSplitPane splitPane;
113     private final MainPane mainPane;
114    
115     private final GoUp goUp = new GoUp();
116     private final GoBack goBack = new GoBack();
117     private final GoForward goForward = new GoForward();
118    
119     private final NavigationHistoryModel navigationHistoryModel = new NavigationHistoryModel();
120    
121     private JMenu loadInstrumentMenu;
122     private JMenu addToMidiMapMenu;
123     private JMenu addToOrchestraMenu;
124    
125     /**
126     * Creates a new instance of <code>InstrumentsDbFrame</code>
127     */
128     public
129     InstrumentsDbFrame() {
130     setTitle(i18n.getLabel("InstrumentsDbFrame.title"));
131     if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
132    
133     instrumentsDbTree = new JSInstrumentsDbTree(CC.getInstrumentsDbTreeModel());
134 iliev 1688 CC.addInstrumentsDbChangeListener(new ChangeListener() {
135     public void
136     stateChanged(ChangeEvent e) {
137     instrumentsDbTree.setModel(CC.getInstrumentsDbTreeModel());
138    
139     CC.scheduleInTaskQueue(new Runnable() {
140     public void
141     run() {
142     instrumentsDbTree.setSelectedDirectory("/");
143     navigationHistoryModel.clearHistory();
144     }
145     });
146     }
147     });
148 iliev 1286
149     sidePane = new SidePane();
150     mainPane = new MainPane();
151    
152     instrumentsDbTree.setSelectedDirectory("/");
153    
154 iliev 1729 toolbar = new ToolBar();
155     getContentPane().add(toolbar, BorderLayout.NORTH);
156 iliev 1286
157     splitPane = new JSplitPane (
158     JSplitPane.HORIZONTAL_SPLIT,
159     true, // continuousLayout
160     sidePane,
161     mainPane
162     );
163    
164     splitPane.setDividerSize(3);
165     splitPane.setDividerLocation(200);
166    
167     addMenu();
168    
169     pack();
170     setSavedSize();
171    
172     getContentPane().add(splitPane);
173     mainPane.getInstrumentsTable().loadColumnWidths();
174    
175     addWindowListener(new WindowAdapter() {
176     public void
177     windowClosing(WindowEvent we) { onWindowClose(); }
178     });
179    
180     instrumentsDbTree.addTreeSelectionListener(goUp);
181     instrumentsDbTree.addTreeSelectionListener(navigationHistoryModel);
182     installKeyboardListeners();
183     }
184    
185     private void
186     addMenu() {
187     JMenu m;
188     JMenuItem mi;
189    
190     setJMenuBar(menuBar);
191    
192     // Actions
193     m = new JMenu(i18n.getMenuLabel("instrumentsdb.actions"));
194     menuBar.add(m);
195    
196     mi = new JMenuItem(mainPane.getInstrumentsTable().createDirectoryAction);
197     mi.setIcon(null);
198     m.add(mi);
199    
200     mi = new JMenuItem(mainPane.getInstrumentsTable().deleteAction);
201     mi.setIcon(null);
202     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
203     m.add(mi);
204    
205     JMenu addInstrumentsMenu =
206     new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addInstruments"));
207     m.add(addInstrumentsMenu);
208    
209     mi = new JMenuItem(mainPane.getInstrumentsTable().addInstrumentsFromFileAction);
210     mi.setIcon(null);
211     addInstrumentsMenu.add(mi);
212    
213     mi = new JMenuItem(mainPane.getInstrumentsTable().addInstrumentsFromDirAction);
214     mi.setIcon(null);
215     addInstrumentsMenu.add(mi);
216    
217     m.addSeparator();
218    
219 iliev 1355 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.actions.format"));
220     m.add(mi);
221     mi.addActionListener(new ActionListener() {
222     public void
223     actionPerformed(ActionEvent e) {
224     String s = i18n.getMessage("InstrumentsDbFrame.formatDatabase?");
225     if(!HF.showYesNoDialog(InstrumentsDbFrame.this, s)) return;
226     CC.getTaskQueue().add(new InstrumentsDb.Format());
227     }
228     });
229    
230 iliev 1729 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.actions.checkForLostFiles"));
231     m.add(mi);
232     mi.addActionListener(new ActionListener() {
233     public void
234     actionPerformed(ActionEvent e) {
235     new JSLostFilesDlg(InstrumentsDbFrame.this).setVisible(true);
236     }
237     });
238    
239 iliev 1355 m.addSeparator();
240    
241 iliev 1286 loadInstrumentMenu =
242     new JMenu(i18n.getMenuLabel("instrumentsdb.actions.loadInstrument"));
243     m.add(loadInstrumentMenu);
244     mainPane.getInstrumentsTable().registerLoadInstrumentMenus(loadInstrumentMenu);
245    
246     addToMidiMapMenu =
247     new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToMidiMap"));
248     m.add(addToMidiMapMenu);
249     mainPane.getInstrumentsTable().registerAddToMidiMapMenu(addToMidiMapMenu);
250    
251     addToOrchestraMenu =
252     new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToOrchestra"));
253     m.add(addToOrchestraMenu);
254     mainPane.getInstrumentsTable().registerAddToOrchestraMenu(addToOrchestraMenu);
255    
256     m.addSeparator();
257    
258     mi = new JMenuItem(mainPane.getInstrumentsTable().reloadAction);
259     mi.setIcon(null);
260     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
261     m.add(mi);
262    
263     m.addSeparator();
264    
265     mi = new JMenuItem(mainPane.getInstrumentsTable().propertiesAction);
266     mi.setIcon(null);
267     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_MASK));
268     m.add(mi);
269    
270     m = new JMenu(i18n.getMenuLabel("instrumentsdb.edit"));
271     menuBar.add(m);
272    
273     mi = new JMenuItem(mainPane.getInstrumentsTable().cutAction);
274     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK));
275     mi.setIcon(null);
276     m.add(mi);
277    
278     mi = new JMenuItem(mainPane.getInstrumentsTable().copyAction);
279     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
280     mi.setIcon(null);
281     m.add(mi);
282    
283     mi = new JMenuItem(mainPane.getInstrumentsTable().pasteAction);
284     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK));
285     mi.setIcon(null);
286     m.add(mi);
287    
288     m.addSeparator();
289    
290 iliev 1729 mi = new JMenuItem(i18n.getMenuLabel("instrumentsdb.edit.find"));
291     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK));
292     m.add(mi);
293     mi.addActionListener(new ActionListener() {
294     public void
295     actionPerformed(ActionEvent e) {
296     if(toolbar.btnFind.isSelected()) return;
297    
298     String path = instrumentsDbTree.getSelectedDirectoryPath();
299     if(path != null) sidePane.searchPage.setSearchPath(path);
300     toolbar.btnFind.doClick(0);
301     }
302     });
303    
304     m.addSeparator();
305    
306 iliev 1286 mi = new JMenuItem(mainPane.getInstrumentsTable().renameAction);
307     mi.setIcon(null);
308     m.add(mi);
309    
310     mi = new JMenuItem(mainPane.getInstrumentsTable().changeDescriptionAction);
311     mi.setIcon(null);
312     m.add(mi);
313    
314     m = new JMenu(i18n.getMenuLabel("instrumentsdb.go"));
315     menuBar.add(m);
316    
317     mi = new JMenuItem(goUp);
318     mi.setIcon(null);
319     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_MASK));
320     m.add(mi);
321    
322     mi = new JMenuItem(goBack);
323     mi.setIcon(null);
324     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_MASK));
325     m.add(mi);
326    
327     mi = new JMenuItem(goForward);
328     mi.setIcon(null);
329     mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_MASK));
330     m.add(mi);
331     }
332    
333     private void
334     installKeyboardListeners() {
335     getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
336     KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
337     "goUp"
338     );
339    
340     getRootPane().getActionMap().put ("goUp", new AbstractAction() {
341     public void
342     actionPerformed(ActionEvent e) {
343     if(!goUp.isEnabled()) return;
344     goUp.actionPerformed(null);
345     }
346     });
347     }
348    
349     /** Invoked when this window is about to close. */
350     private void
351     onWindowClose() {
352     boolean b = (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH;
353     preferences().setBoolProperty("InstrumentsDbFrame.windowMaximized", b);
354     if(b) return;
355    
356     java.awt.Point p = getLocation();
357     Dimension d = getSize();
358     StringBuffer sb = new StringBuffer();
359     sb.append(p.x).append(',').append(p.y).append(',');
360     sb.append(d.width).append(',').append(d.height);
361     String s = "InstrumentsDbFrame.windowSizeAndLocation";
362     preferences().setStringProperty(s, sb.toString());
363     int i = splitPane.getDividerLocation();
364     preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
365    
366     mainPane.getInstrumentsTable().saveColumnsVisibleState();
367     mainPane.getInstrumentsTable().saveColumnWidths();
368     }
369    
370     private void
371     setDefaultSize() {
372     Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
373     double width = dimension.getWidth();
374     double height = dimension.getHeight();
375     setBounds(100, 100, (int) width - 200, (int) height - 200);
376     }
377    
378     private void
379     setSavedSize() {
380     String sp = "InstrumentsDbFrame.windowSizeAndLocation";
381     String s = preferences().getStringProperty(sp, null);
382     if(s == null) {
383     setDefaultSize();
384     return;
385     }
386    
387     try {
388     int i = s.indexOf(',');
389     int x = Integer.parseInt(s.substring(0, i));
390    
391     s = s.substring(i + 1);
392     i = s.indexOf(',');
393     int y = Integer.parseInt(s.substring(0, i));
394    
395     s = s.substring(i + 1);
396     i = s.indexOf(',');
397     int width = Integer.parseInt(s.substring(0, i));
398    
399     s = s.substring(i + 1);
400     int height = Integer.parseInt(s);
401    
402     setBounds(x, y, width, height);
403    
404     i = preferences().getIntProperty("InstrumentsDbFrame.dividerLocation");
405     if(i != 0) splitPane.setDividerLocation(i);
406    
407     } catch(Exception x) {
408     String msg = "Parsing of window size and location string failed";
409     CC.getLogger().log(Level.INFO, msg, x);
410     setDefaultSize();
411     }
412    
413     if(preferences().getBoolProperty("InstrumentsDbFrame.windowMaximized")) {
414     setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
415     }
416     }
417    
418     private void
419     addSidePane() {
420     getContentPane().remove(mainPane);
421     splitPane.setRightComponent(mainPane);
422     getContentPane().add(splitPane);
423     int i = preferences().getIntProperty("InstrumentsDbFrame.dividerLocation");
424     if(i != 0) splitPane.setDividerLocation(i);
425     }
426    
427     private void
428     removeSidePane() {
429     int i = splitPane.getDividerLocation();
430     preferences().setIntProperty("InstrumentsDbFrame.dividerLocation", i);
431     getContentPane().remove(splitPane);
432     getContentPane().add(mainPane);
433     }
434    
435     private class GoUp extends AbstractAction implements TreeSelectionListener {
436     GoUp() {
437     super(i18n.getMenuLabel("instrumentsdb.go.up"));
438    
439     String s = i18n.getMenuLabel("instrumentsdb.go.up.tt");
440     putValue(SHORT_DESCRIPTION, s);
441     putValue(Action.SMALL_ICON, Res.iconGoUp22);
442     setEnabled(false);
443     }
444    
445     public void
446     actionPerformed(ActionEvent e) {
447     DbDirectoryTreeNode node = instrumentsDbTree.getSelectedDirectoryNode();
448     if(node == null) return;
449     instrumentsDbTree.setSelectedDirectoryNode(node.getParent());
450     }
451    
452     public void
453     valueChanged(TreeSelectionEvent e) {
454     DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode();
455     if(n == null) {
456     setEnabled(false);
457     return;
458     }
459    
460     setEnabled(n.getParent() != null);
461     }
462     }
463    
464     private class GoBack extends AbstractAction {
465     GoBack() {
466     super(i18n.getMenuLabel("instrumentsdb.go.back"));
467    
468     String s = i18n.getMenuLabel("instrumentsdb.go.back.tt");
469     putValue(SHORT_DESCRIPTION, s);
470     putValue(Action.SMALL_ICON, Res.iconGoBack22);
471     setEnabled(false);
472     }
473    
474     public void
475     actionPerformed(ActionEvent e) {
476     navigationHistoryModel.goBack();
477     }
478     }
479    
480     private class GoForward extends AbstractAction {
481     GoForward() {
482     super(i18n.getMenuLabel("instrumentsdb.go.forward"));
483    
484     String s = i18n.getMenuLabel("instrumentsdb.go.forward.tt");
485     putValue(SHORT_DESCRIPTION, s);
486     putValue(Action.SMALL_ICON, Res.iconGoForward22);
487     setEnabled(false);
488     }
489    
490     public void
491     actionPerformed(ActionEvent e) {
492     navigationHistoryModel.goForward();
493     }
494     }
495    
496 iliev 1729 class ToolBar extends JToolBar {
497 iliev 1286 private final ToggleButton btnFolders = new ToggleButton();
498     private final ToggleButton btnFind = new ToggleButton();
499    
500     private final ToolbarButton btnGoUp = new ToolbarButton(goUp);
501     private final ToolbarButton btnGoBack = new ToolbarButton(goBack);
502     private final ToolbarButton btnGoForward = new ToolbarButton(goForward);
503     private final ToolbarButton btnReload =
504     new ToolbarButton(mainPane.getInstrumentsTable().reloadAction);
505    
506     private final ToolbarButton btnPreferences = new ToolbarButton();
507    
508 iliev 1729 public ToolBar() {
509 iliev 1286 super(i18n.getLabel("InstrumentsDbFrame.ToolbarBar.name"));
510     setFloatable(false);
511    
512     btnFolders.setIcon(Res.iconFolderOpen22);
513     btnFolders.doClick(0);
514     btnFind.setIcon(Res.iconFind22);
515     btnPreferences.setIcon(Res.iconPreferences22);
516    
517     add(btnFolders);
518     add(btnFind);
519     addSeparator();
520     add(btnGoBack);
521     add(btnGoForward);
522     add(btnGoUp);
523     add(btnReload);
524     addSeparator();
525     add(btnPreferences);
526    
527    
528     btnFolders.addActionListener(new ActionListener() {
529     public void
530     actionPerformed(ActionEvent e) {
531     if(!btnFolders.isSelected() && !btnFind.isSelected()) {
532     removeSidePane();
533     }
534    
535     if(!btnFolders.isSelected()) return;
536    
537     if(btnFind.isSelected()) btnFind.doClick(0);
538     else addSidePane();
539    
540     sidePane.showFoldersPage();
541     }
542     });
543    
544     btnFind.addActionListener(new ActionListener() {
545     public void
546     actionPerformed(ActionEvent e) {
547     if(!btnFolders.isSelected() && !btnFind.isSelected()) {
548     removeSidePane();
549     }
550    
551     if(!btnFind.isSelected()) return;
552    
553     if(btnFolders.isSelected()) btnFolders.doClick(0);
554     else addSidePane();
555    
556     sidePane.showSearchPage();
557     }
558     });
559    
560     btnPreferences.addActionListener(new ActionListener() {
561     public void
562     actionPerformed(ActionEvent e) {
563     new PreferencesDlg().setVisible(true);
564     }
565     });
566     }
567     }
568    
569     class ToggleButton extends JToggleButton {
570     ToggleButton() {
571     setFocusPainted(false);
572     }
573     }
574    
575     private class NavigationHistoryModel
576     extends DefaultNavigationHistoryModel<DbDirectoryTreeNode>
577     implements TreeSelectionListener, ActionListener {
578    
579     private boolean lock = false;
580    
581     NavigationHistoryModel() {
582     addActionListener(this);
583     }
584    
585     public DbDirectoryTreeNode
586     goBack() {
587     lock = true;
588     DbDirectoryTreeNode node = selectDirectory(super.goBack());
589     lock = false;
590     return node;
591     }
592    
593     public DbDirectoryTreeNode
594     goForward() {
595     lock = true;
596     DbDirectoryTreeNode node = selectDirectory(super.goForward());
597     lock = false;
598     return node;
599     }
600    
601     private DbDirectoryTreeNode
602     selectDirectory(DbDirectoryTreeNode node) {
603     if(node == null) return null;
604    
605     if(node == mainPane.getSearchResultsNode()) {
606     mainPane.showSearchResultsNode();
607     return node;
608     }
609    
610     String path = node.getInfo().getDirectoryPath();
611     if(CC.getInstrumentsDbTreeModel().getNodeByPath(path) != null) {
612     getInstrumentsDbTree().setSelectedDirectory(path);
613     return node;
614     }
615    
616     removePage();
617     fireActionPerformed();
618     String s = i18n.getMessage("InstrumentsDbFrame.unknownDirectory!", path);
619     HF.showErrorMessage(s, InstrumentsDbFrame.this);
620     return node;
621     }
622    
623     public void
624     addPage(DbDirectoryTreeNode node) {
625     if(lock) return;
626     if(node == null) return;
627     super.addPage(node);
628     }
629    
630     public void
631     valueChanged(TreeSelectionEvent e) {
632     addPage(instrumentsDbTree.getSelectedDirectoryNode());
633     }
634    
635     public void
636     actionPerformed(ActionEvent e) {
637     goBack.setEnabled(hasBack());
638     goForward.setEnabled(hasForward());
639     }
640     }
641    
642     public JSInstrumentsDbTree
643     getInstrumentsDbTree() { return instrumentsDbTree; }
644    
645     public void
646     setSearchResults(DbDirectoryInfo[] directories) {
647     setSearchResults(directories, null);
648     }
649    
650     public void
651     setSearchResults(DbInstrumentInfo[] instruments) {
652     setSearchResults(null, instruments);
653     }
654    
655     public void
656     setSearchResults(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments) {
657     DbDirectoryTreeNode node = mainPane.getSearchResultsNode();
658     node.removeAllDirectories();
659     node.removeAllInstruments();
660    
661     if(instruments != null) {
662     for(DbInstrumentInfo i : instruments) i.setShowAbsolutePath(true);
663     node.addInstruments(instruments);
664     }
665    
666     if(directories != null) {
667     DbDirectoryTreeNode[] nodeS = new DbDirectoryTreeNode[directories.length];
668     for(int i = 0; i < directories.length; i++) {
669     DbDirectoryInfo d = directories[i];
670     d.setShowAbsolutePath(true);
671     nodeS[i] = new DbDirectoryTreeNode(d);
672    
673    
674     }
675     node.addDirectories(nodeS);
676     }
677    
678     mainPane.showSearchResultsNode();
679     }
680    
681     class MainPane extends JPanel {
682     private final JSInstrumentsDbTable instrumentsTable =
683     new JSInstrumentsDbTable(instrumentsDbTree);
684    
685     private final DbDirectoryTreeNode searchResultsNode = new DbDirectoryTreeNode(null);
686    
687     MainPane() {
688     setLayout(new BorderLayout());
689     JScrollPane sp = new JScrollPane(instrumentsTable);
690     add(sp);
691    
692     //instrumentsTable.setBackground(new java.awt.Color(0x626262));
693     instrumentsTable.getModel().setShowDummyColumn(false);
694     instrumentsTable.reloadAction.putValue(Action.SMALL_ICON, Res.iconReload22);
695    
696     instrumentsTable.createDirectoryAction.putValue (
697     Action.SMALL_ICON, Res.iconNew16
698     );
699    
700     instrumentsTable.getParent().setBackground(instrumentsTable.getBackground());
701 iliev 1705
702     int i = preferences().getIntProperty(INSTRUMENTS_DB_FRAME_SORT_ORDER);
703     boolean descending = i < 0;
704     if(i < 0) i *= -1;
705 iliev 1729 i--;
706 iliev 1705
707 iliev 1729 if(i < 0 || i >= instrumentsTable.getModel().getColumnCount()) {
708     instrumentsTable.getRowSorter().toggleSortOrder(0);
709     CC.getLogger().warning("Unknown table column: " + i);
710     } else {
711     instrumentsTable.getRowSorter().toggleSortOrder(i);
712     if(descending) instrumentsTable.getRowSorter().toggleSortOrder(i);
713     }
714    
715 iliev 1286 searchResultsNode.setDetached(true);
716 iliev 1705
717     RowSorterListener l = new RowSorterListener() {
718     public void
719     sorterChanged(RowSorterEvent e) {
720     if(e.getType() != SORT_ORDER_CHANGED) return;
721     rowSorterChanged();
722     }
723     };
724    
725     instrumentsTable.getRowSorter().addRowSorterListener(l);
726 iliev 1286 }
727    
728 iliev 1705 private void
729     rowSorterChanged() {
730     List<? extends SortKey> list = instrumentsTable.getRowSorter().getSortKeys();
731     if(list.isEmpty()) return;
732     SortKey k = list.get(0);
733     int i = k.getColumn() + 1;
734     if(k.getSortOrder() == SortOrder.UNSORTED) return;
735     if(k.getSortOrder() == SortOrder.DESCENDING) i *= -1;
736     preferences().setIntProperty(INSTRUMENTS_DB_FRAME_SORT_ORDER, i);
737     }
738    
739 iliev 1286 public JSInstrumentsDbTable
740     getInstrumentsTable() { return instrumentsTable; }
741    
742     public DbDirectoryTreeNode
743     getSearchResultsNode() { return searchResultsNode; }
744    
745     public void
746     showSearchResultsNode() {
747     instrumentsDbTree.clearSelection();
748     instrumentsTable.setParentDirectoryNode(searchResultsNode);
749     navigationHistoryModel.addPage(searchResultsNode);
750     }
751     }
752    
753    
754     class SidePane extends NavigationPane {
755     private final NavigationPage foldersPage = new NavigationPage();
756     private final DbSearchPage searchPage = new DbSearchPage(InstrumentsDbFrame.this);
757    
758     SidePane() {
759     setTitlebarVisiblie(false);
760    
761     foldersPage.setTitle(i18n.getLabel("InstrumentsDbFrame.folders"));
762     foldersPage.setLayout(new BorderLayout());
763     foldersPage.add(new JScrollPane(instrumentsDbTree));
764    
765     NavigationPage[] pages = { foldersPage, searchPage };
766     setPages(pages);
767     showFoldersPage();
768     }
769    
770     /** Shows the folders page in the left pane. */
771     public void
772     showFoldersPage() { getModel().addPage(foldersPage); }
773    
774     /** Shows the search page in the left pane. */
775     public void
776     showSearchPage() { getModel().addPage(searchPage); }
777     }
778    
779     private final EventHandler eventHandler = new EventHandler();
780    
781     private EventHandler
782     getHandler() { return eventHandler; }
783    
784     private class EventHandler implements ListSelectionListener {
785     public void
786     valueChanged(ListSelectionEvent e) {
787    
788     }
789     }
790    
791     class PreferencesDlg extends InformationDialog implements ItemListener {
792     private final JCheckBox checkShowSizeColumn =
793     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.SIZE"));
794    
795     private final JCheckBox checkShowFormatFamilyColumn =
796     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.FORMAT_FAMILY"));
797    
798     private final JCheckBox checkShowFormatVersionColumn =
799     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.FORMAT_VERSION"));
800    
801     private final JCheckBox checkShowIsDrumColumn =
802     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.IS_DRUM"));
803    
804     private final JCheckBox checkShowCreatedColumn =
805     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.CREATED"));
806    
807     private final JCheckBox checkShowModifiedColumn =
808     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.MODIFIED"));
809    
810     private final JCheckBox checkShowProductColumn =
811     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.PRODUCT"));
812    
813     private final JCheckBox checkShowArtistsColumn =
814     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.ARTISTS"));
815    
816     private final JCheckBox checkShowInstrumentFileColumn
817     = new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.INSTRUMENT_FILE"));
818    
819     private final JCheckBox checkShowInstrumentNrColumn =
820     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.INSTRUMENT_NR"));
821    
822     private final JCheckBox checkShowKeywordsColumn =
823     new JCheckBox(JSI18n.i18n.getLabel("InstrumentsDbTableModel.KEYWORDS"));
824    
825     PreferencesDlg() {
826     super(InstrumentsDbFrame.this);
827     InstrumentsDbTableModel m = mainPane.instrumentsTable.getModel();
828    
829     checkShowSizeColumn.setSelected(m.getShowSizeColumn());
830     checkShowFormatFamilyColumn.setSelected(m.getShowFormatFamilyColumn());
831     checkShowFormatVersionColumn.setSelected(m.getShowFormatVersionColumn());
832     checkShowIsDrumColumn.setSelected(m.getShowIsDrumColumn());
833     checkShowCreatedColumn.setSelected(m.getShowCreatedColumn());
834     checkShowModifiedColumn.setSelected(m.getShowModifiedColumn());
835     checkShowProductColumn.setSelected(m.getShowProductColumn());
836     checkShowArtistsColumn.setSelected(m.getShowArtistsColumn());
837     checkShowInstrumentFileColumn.setSelected(m.getShowInstrumentFileColumn());
838     checkShowInstrumentNrColumn.setSelected(m.getShowInstrumentNrColumn());
839     checkShowKeywordsColumn.setSelected(m.getShowKeywordsColumn());
840    
841     checkShowSizeColumn.addItemListener(this);
842     checkShowFormatFamilyColumn.addItemListener(this);
843     checkShowFormatVersionColumn.addItemListener(this);
844     checkShowIsDrumColumn.addItemListener(this);
845     checkShowCreatedColumn.addItemListener(this);
846     checkShowModifiedColumn.addItemListener(this);
847     checkShowProductColumn.addItemListener(this);
848     checkShowArtistsColumn.addItemListener(this);
849     checkShowInstrumentFileColumn.addItemListener(this);
850     checkShowInstrumentNrColumn.addItemListener(this);
851     checkShowKeywordsColumn.addItemListener(this);
852    
853     JPanel p = new JPanel();
854     p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
855     p.add(checkShowSizeColumn);
856     p.add(checkShowFormatFamilyColumn);
857     p.add(checkShowFormatVersionColumn);
858     p.add(checkShowIsDrumColumn);
859     p.add(checkShowCreatedColumn);
860     p.add(checkShowModifiedColumn);
861     p.add(checkShowProductColumn);
862     p.add(checkShowArtistsColumn);
863     p.add(checkShowInstrumentFileColumn);
864     p.add(checkShowInstrumentNrColumn);
865     p.add(checkShowKeywordsColumn);
866     String s = i18n.getLabel("InstrumentsDbFrame.columns");
867     p.setBorder(BorderFactory.createTitledBorder(s));
868    
869     setMainPane(p);
870     }
871    
872     public void
873     itemStateChanged(ItemEvent e) {
874     mainPane.getInstrumentsTable().saveColumnWidths();
875    
876     InstrumentsDbTableModel m = mainPane.instrumentsTable.getModel();
877    
878     Object source = e.getItemSelectable();
879     if(source == checkShowSizeColumn) {
880     m.setShowSizeColumn(checkShowSizeColumn.isSelected());
881     } else if(source == checkShowFormatFamilyColumn) {
882     boolean b = checkShowFormatFamilyColumn.isSelected();
883     m.setShowFormatFamilyColumn(b);
884     } else if(source == checkShowFormatVersionColumn) {
885     boolean b = checkShowFormatVersionColumn.isSelected();
886     m.setShowFormatVersionColumn(b);
887     } else if(source == checkShowIsDrumColumn) {
888     m.setShowIsDrumColumn(checkShowIsDrumColumn.isSelected());
889     } else if(source == checkShowCreatedColumn) {
890     m.setShowCreatedColumn(checkShowCreatedColumn.isSelected());
891     } else if(source == checkShowModifiedColumn) {
892     m.setShowModifiedColumn(checkShowModifiedColumn.isSelected());
893     } else if(source == checkShowProductColumn) {
894     m.setShowProductColumn(checkShowProductColumn.isSelected());
895     } else if(source == checkShowArtistsColumn) {
896     m.setShowArtistsColumn(checkShowArtistsColumn.isSelected());
897     } else if(source == checkShowInstrumentFileColumn) {
898     boolean b = checkShowInstrumentFileColumn.isSelected();
899     m.setShowInstrumentFileColumn(b);
900     } else if(source == checkShowInstrumentNrColumn) {
901     boolean b = checkShowInstrumentNrColumn.isSelected();
902     m.setShowInstrumentNrColumn(b);
903     } else if(source == checkShowKeywordsColumn) {
904     m.setShowKeywordsColumn(checkShowKeywordsColumn.isSelected());
905     }
906    
907     mainPane.getInstrumentsTable().loadColumnWidths();
908     mainPane.getInstrumentsTable().getRowSorter().toggleSortOrder(0);
909     }
910     }
911     }

  ViewVC Help
Powered by ViewVC