/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSInstrumentsDbTree.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/std/JSInstrumentsDbTree.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1743 - (hide annotations) (download)
Sat May 31 23:04:01 2008 UTC (15 years, 11 months ago) by iliev
File size: 4782 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 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1743 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.view.std;
24    
25     import java.awt.Component;
26    
27     import java.awt.event.ActionEvent;
28     import java.awt.event.ActionListener;
29     import java.awt.event.KeyEvent;
30     import java.awt.event.MouseAdapter;
31     import java.awt.event.MouseEvent;
32    
33     import javax.swing.AbstractAction;
34     import javax.swing.BorderFactory;
35     import javax.swing.JComponent;
36     import javax.swing.JMenuItem;
37     import javax.swing.JPopupMenu;
38     import javax.swing.JTree;
39     import javax.swing.KeyStroke;
40    
41     import javax.swing.tree.DefaultTreeCellRenderer;
42     import javax.swing.tree.TreeSelectionModel;
43    
44     import org.jsampler.view.DbDirectoryTreeNode;
45     import org.jsampler.view.InstrumentsDbTreeModel;
46    
47     import static org.jsampler.view.std.StdI18n.i18n;
48    
49     /**
50     *
51     * @author Grigor Iliev
52     */
53     public class JSInstrumentsDbTree extends org.jsampler.view.AbstractInstrumentsDbTree {
54    
55     /**
56     * Creates a new instance of <code>JSInstrumentsDbTree</code>.
57     */
58     public
59     JSInstrumentsDbTree(InstrumentsDbTreeModel model) {
60     super(model);
61     CellRenderer renderer = new CellRenderer();
62     setCellRenderer(renderer);
63    
64     setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 0));
65    
66     getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
67    
68     addMouseListener(new MouseAdapter() {
69     public void
70     mousePressed(MouseEvent e) {
71     if(e.getButton() != e.BUTTON3) return;
72     setSelectionPath(getClosestPathForLocation(e.getX(), e.getY()));
73     }
74     });
75    
76     ContextMenu contextMenu = new ContextMenu();
77     //addMouseListener(contextMenu);
78     installKeyboardListeners();
79     }
80    
81     private void
82     installKeyboardListeners() {
83     AbstractAction a = new AbstractAction() {
84     public void
85     actionPerformed(ActionEvent e) { }
86     };
87     a.setEnabled(false);
88     getActionMap().put("none", a);
89    
90     getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
91     KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK), "none"
92     );
93    
94     getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
95     KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK), "none"
96     );
97    
98     getInputMap(JComponent.WHEN_FOCUSED).put (
99     KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK), "none"
100     );
101    
102     getInputMap(JComponent.WHEN_FOCUSED).put (
103     KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK), "none"
104     );
105     }
106    
107     private class CellRenderer extends DefaultTreeCellRenderer {
108     CellRenderer() {
109     setOpaque(false);
110     }
111    
112     public Component
113     getTreeCellRendererComponent (
114     JTree tree,
115     Object value,
116     boolean sel,
117     boolean expanded,
118     boolean leaf,
119     int row,
120     boolean hasFocus
121     ) {
122     super.getTreeCellRendererComponent (
123     tree, value, sel,expanded, leaf, row,hasFocus
124     );
125    
126     DbDirectoryTreeNode node = (DbDirectoryTreeNode)value;
127     if(node.getInfo().getName() == "/") setIcon(getView().getRootIcon());
128     else if(leaf) setIcon(getView().getInstrumentIcon());
129     else if(expanded) setIcon(getView().getOpenIcon());
130     else setIcon(getView().getClosedIcon());
131    
132     String s = node.getInfo().getDescription();
133     if(s != null && s.length() > 0) setToolTipText(s);
134     else setToolTipText(null);
135    
136     return this;
137     }
138     }
139    
140     class ContextMenu extends MouseAdapter {
141     private final JPopupMenu cmenu = new JPopupMenu();
142     JMenuItem miEdit = new JMenuItem(i18n.getMenuLabel("ContextMenu.edit"));
143    
144     ContextMenu() {
145     cmenu.add(miEdit);
146     miEdit.addActionListener(new ActionListener() {
147     public void
148     actionPerformed(ActionEvent e) {
149    
150     }
151     });
152    
153     JMenuItem mi = new JMenuItem(i18n.getMenuLabel("ContextMenu.delete"));
154     cmenu.add(mi);
155     mi.addActionListener(new ActionListener() {
156     public void
157     actionPerformed(ActionEvent e) {
158     removeSelectedDirectory();
159     }
160     });
161    
162     }
163    
164     public void
165     mousePressed(MouseEvent e) {
166     if(e.isPopupTrigger()) show(e);
167     }
168    
169     public void
170     mouseReleased(MouseEvent e) {
171     if(e.isPopupTrigger()) show(e);
172     }
173    
174     void
175     show(MouseEvent e) {
176     cmenu.show(e.getComponent(), e.getX(), e.getY());
177     }
178     }
179     }

  ViewVC Help
Powered by ViewVC