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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1743 - (show annotations) (download)
Sat May 31 23:04:01 2008 UTC (15 years, 10 months ago) by iliev
File size: 27968 byte(s)
* Renamed the column labels in the Channel Routing dialog: The column
  representing the sampler channel's audio channels is "Audio In" and
  the column representing the audio device's channels is "Audio Out"
* Remember the last used tab in the Preferences dialog
* Fantasia: The sampler channels are now referenced by their position
  in the list, not by their ID
* Fantasia: Implemented options to show the channel number and/or the MIDI
  input port/channel on the sampler channel screen when using Small View
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: Migrated to substance 5

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

  ViewVC Help
Powered by ViewVC