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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1347 - (hide annotations) (download)
Thu Sep 13 22:20:38 2007 UTC (16 years, 7 months ago) by iliev
File size: 5515 byte(s)
* added support for escape sequences to the instruments database

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.std;
24    
25     import java.awt.Dialog;
26     import java.awt.Frame;
27    
28     import java.awt.event.ActionEvent;
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.JComponent;
35     import javax.swing.JScrollPane;
36     import javax.swing.JSplitPane;
37     import javax.swing.KeyStroke;
38     import javax.swing.ListSelectionModel;
39    
40     import javax.swing.event.ListSelectionEvent;
41     import javax.swing.event.ListSelectionListener;
42    
43     import net.sf.juife.OkCancelDialog;
44    
45     import org.jsampler.CC;
46    
47     import org.jsampler.view.DbDirectoryTreeNode;
48     import org.jsampler.view.InstrumentsDbTreeModel;
49    
50     import org.linuxsampler.lscp.DbInstrumentInfo;
51 iliev 1347 import org.linuxsampler.lscp.Parser;
52 iliev 1286
53     import static org.jsampler.view.std.StdI18n.i18n;
54    
55    
56     /**
57     *
58     * @author Grigor Iliev
59     */
60     public class JSDbInstrumentChooser extends OkCancelDialog implements ListSelectionListener {
61     protected JSInstrumentsDbTree instrumentsDbTree;
62     protected JSInstrumentsDbTable instrumentsDbTable;
63    
64     /**
65     * Creates a new instance of <code>JSDbInstrumentChooser</code>
66     */
67     public JSDbInstrumentChooser(Frame owner) {
68     super(owner, i18n.getLabel("JSDbInstrumentChooser.title"));
69     initDbInstrumentChooser();
70     }
71    
72     /**
73     * Creates a new instance of <code>JSDbInstrumentChooser</code>
74     */
75     public JSDbInstrumentChooser(Dialog owner) {
76     super(owner, i18n.getLabel("JSDbInstrumentChooser.title"));
77     initDbInstrumentChooser();
78     }
79    
80     private void
81     initDbInstrumentChooser() {
82     btnOk.setEnabled(false);
83     instrumentsDbTree = new JSInstrumentsDbTree(CC.getInstrumentsDbTreeModel());
84     JScrollPane sp = new JScrollPane(instrumentsDbTree);
85    
86     instrumentsDbTable = new JSInstrumentsDbTable(instrumentsDbTree);
87     instrumentsDbTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
88     instrumentsDbTable.getSelectionModel().addListSelectionListener(this);
89     instrumentsDbTable.loadColumnWidths();
90     JScrollPane sp2 = new JScrollPane(instrumentsDbTable);
91    
92     JSplitPane splitPane = new JSplitPane (
93     JSplitPane.HORIZONTAL_SPLIT,
94     true, // continuousLayout
95     sp,
96     sp2
97     );
98    
99     splitPane.setDividerSize(3);
100     splitPane.setDividerLocation(200);
101    
102     setMainPane(splitPane);
103    
104     instrumentsDbTable.addMouseListener(new MouseAdapter() {
105     public void
106     mouseClicked(MouseEvent e) {
107     if(e.getButton() != e.BUTTON1 || e.getClickCount() < 2) return;
108     DbInstrumentInfo infos[];
109     infos = instrumentsDbTable.getSelectedInstruments();
110     if(infos.length == 0) return;
111     onOk();
112     }
113     });
114    
115     installKeyboardListeners();
116     }
117    
118     private void
119     installKeyboardListeners() {
120     getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put (
121     KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
122     "goUp"
123     );
124    
125     getRootPane().getActionMap().put ("goUp", new GoUp());
126    
127     instrumentsDbTable.getInputMap().put (
128     KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
129     "Select"
130     );
131    
132     instrumentsDbTable.getActionMap().put ("Select", new AbstractAction() {
133     public void
134     actionPerformed(ActionEvent e) {
135     DbDirectoryTreeNode node;
136     node = instrumentsDbTable.getSelectedDirectoryNode();
137     if(node != null) {
138     instrumentsDbTree.setSelectedDirectoryNode(node);
139     return;
140     }
141    
142     if(instrumentsDbTable.getSelectedInstruments().length > 0) {
143     onOk();
144     }
145    
146     }
147     });
148     }
149    
150     public String
151     getSelectedInstrument() {
152     DbInstrumentInfo[] infos = instrumentsDbTable.getSelectedInstruments();
153     if(infos.length == 0) return null;
154     return infos[0].getInstrumentPath();
155     }
156    
157     public void
158     setSelectedInstrument(String instr) {
159 iliev 1347 String parentDir = Parser.getParentDirectory(instr);
160 iliev 1286 if(parentDir == null) return;
161     instrumentsDbTree.setSelectedDirectory(parentDir);
162     if(instrumentsDbTable.getParentDirectoryNode() == null) return;
163    
164     instr = instr.substring(parentDir.length() + 1, instr.length());
165     instrumentsDbTable.setSelectedInstrument(instr);
166     }
167    
168     public void
169     setSelectedDirectory(String dir) {
170     instrumentsDbTree.setSelectedDirectory(dir);
171     }
172    
173     protected void
174     onOk() {
175     if(!btnOk.isEnabled()) return;
176     setCancelled(false);
177     setVisible(false);
178     }
179    
180     protected void
181     onCancel() { setVisible(false); }
182    
183     public void
184     valueChanged(ListSelectionEvent e) {
185     boolean b = instrumentsDbTable.getSelectedInstruments().length > 0;
186     btnOk.setEnabled(b);
187     }
188    
189     private class GoUp extends AbstractAction {
190     GoUp() { }
191    
192     public void
193     actionPerformed(ActionEvent e) {
194     DbDirectoryTreeNode node = instrumentsDbTree.getSelectedDirectoryNode();
195     if(node == null) return;
196     if(node.getParent() == null) return;
197     instrumentsDbTree.setSelectedDirectoryNode(node.getParent());
198     }
199     }
200     }

  ViewVC Help
Powered by ViewVC