/[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 1688 - (hide annotations) (download)
Thu Feb 14 16:52:36 2008 UTC (16 years, 3 months ago) by iliev
File size: 25613 byte(s)
* Implemented a backend list with option to manually choose a backend
  to connect on startup(Edit/Preferences, then click the `Backend' tab)
  and option to change the backend without restarting JSampler
  (Actions/Change Backend or Ctrl + B)

* Added confirmation messages for removing sampler channels and
  audio/MIDI devices (Edit/Preferences, then click the `View' tab)

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

  ViewVC Help
Powered by ViewVC