/[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 1705 - (hide annotations) (download)
Tue Feb 19 16:32:36 2008 UTC (16 years, 2 months ago) by iliev
File size: 26811 byte(s)
* The column sort order in the Instruments Database
  window is now saved for the next session

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

  ViewVC Help
Powered by ViewVC