1 |
iliev |
1286 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1752 |
* 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 |
iliev |
1752 |
import java.awt.BorderLayout; |
26 |
iliev |
1286 |
import java.awt.Dialog; |
27 |
|
|
import java.awt.Frame; |
28 |
|
|
|
29 |
|
|
import java.awt.event.ActionEvent; |
30 |
iliev |
1752 |
import java.awt.event.ActionListener; |
31 |
iliev |
1286 |
import java.awt.event.KeyEvent; |
32 |
|
|
import java.awt.event.MouseAdapter; |
33 |
|
|
import java.awt.event.MouseEvent; |
34 |
|
|
|
35 |
iliev |
1752 |
import javax.swing.Action; |
36 |
iliev |
1286 |
import javax.swing.AbstractAction; |
37 |
iliev |
1752 |
import javax.swing.JButton; |
38 |
iliev |
1286 |
import javax.swing.JComponent; |
39 |
iliev |
1752 |
import javax.swing.JPanel; |
40 |
iliev |
1286 |
import javax.swing.JScrollPane; |
41 |
|
|
import javax.swing.JSplitPane; |
42 |
iliev |
1752 |
import javax.swing.JToolBar; |
43 |
iliev |
1286 |
import javax.swing.KeyStroke; |
44 |
|
|
import javax.swing.ListSelectionModel; |
45 |
|
|
|
46 |
|
|
import javax.swing.event.ListSelectionEvent; |
47 |
|
|
import javax.swing.event.ListSelectionListener; |
48 |
|
|
|
49 |
|
|
import net.sf.juife.OkCancelDialog; |
50 |
|
|
|
51 |
|
|
import org.jsampler.CC; |
52 |
|
|
|
53 |
|
|
import org.jsampler.view.DbDirectoryTreeNode; |
54 |
|
|
import org.jsampler.view.InstrumentsDbTreeModel; |
55 |
|
|
|
56 |
|
|
import org.linuxsampler.lscp.DbInstrumentInfo; |
57 |
iliev |
1347 |
import org.linuxsampler.lscp.Parser; |
58 |
iliev |
1286 |
|
59 |
|
|
import static org.jsampler.view.std.StdI18n.i18n; |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
/** |
63 |
|
|
* |
64 |
|
|
* @author Grigor Iliev |
65 |
|
|
*/ |
66 |
|
|
public class JSDbInstrumentChooser extends OkCancelDialog implements ListSelectionListener { |
67 |
iliev |
1752 |
protected JSInstrumentsDbTree instrumentsDbTree = |
68 |
|
|
createInstrumentsDbTree(CC.getInstrumentsDbTreeModel()); |
69 |
iliev |
1286 |
|
70 |
iliev |
1752 |
protected JSInstrumentsDbTable instrumentsDbTable = |
71 |
|
|
new JSInstrumentsDbTable(instrumentsDbTree, "DbInstrumentChooser."); |
72 |
|
|
|
73 |
|
|
protected final ToolBar toolBar = new ToolBar(); |
74 |
|
|
|
75 |
|
|
|
76 |
iliev |
1286 |
/** |
77 |
|
|
* Creates a new instance of <code>JSDbInstrumentChooser</code> |
78 |
|
|
*/ |
79 |
|
|
public JSDbInstrumentChooser(Frame owner) { |
80 |
|
|
super(owner, i18n.getLabel("JSDbInstrumentChooser.title")); |
81 |
|
|
initDbInstrumentChooser(); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
/** |
85 |
|
|
* Creates a new instance of <code>JSDbInstrumentChooser</code> |
86 |
|
|
*/ |
87 |
|
|
public JSDbInstrumentChooser(Dialog owner) { |
88 |
|
|
super(owner, i18n.getLabel("JSDbInstrumentChooser.title")); |
89 |
|
|
initDbInstrumentChooser(); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
private void |
93 |
|
|
initDbInstrumentChooser() { |
94 |
|
|
btnOk.setEnabled(false); |
95 |
|
|
JScrollPane sp = new JScrollPane(instrumentsDbTree); |
96 |
|
|
|
97 |
|
|
instrumentsDbTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
98 |
|
|
instrumentsDbTable.getSelectionModel().addListSelectionListener(this); |
99 |
|
|
JScrollPane sp2 = new JScrollPane(instrumentsDbTable); |
100 |
|
|
|
101 |
|
|
JSplitPane splitPane = new JSplitPane ( |
102 |
|
|
JSplitPane.HORIZONTAL_SPLIT, |
103 |
|
|
true, // continuousLayout |
104 |
|
|
sp, |
105 |
|
|
sp2 |
106 |
|
|
); |
107 |
|
|
|
108 |
|
|
splitPane.setDividerSize(3); |
109 |
|
|
splitPane.setDividerLocation(200); |
110 |
|
|
|
111 |
iliev |
1752 |
JPanel p = new JPanel(); |
112 |
|
|
p.setLayout(new BorderLayout()); |
113 |
|
|
p.add(new ToolBar(), BorderLayout.NORTH); |
114 |
|
|
p.add(splitPane); |
115 |
iliev |
1286 |
|
116 |
iliev |
1752 |
setMainPane(p); |
117 |
|
|
|
118 |
iliev |
1286 |
instrumentsDbTable.addMouseListener(new MouseAdapter() { |
119 |
|
|
public void |
120 |
|
|
mouseClicked(MouseEvent e) { |
121 |
|
|
if(e.getButton() != e.BUTTON1 || e.getClickCount() < 2) return; |
122 |
|
|
DbInstrumentInfo infos[]; |
123 |
|
|
infos = instrumentsDbTable.getSelectedInstruments(); |
124 |
|
|
if(infos.length == 0) return; |
125 |
|
|
onOk(); |
126 |
|
|
} |
127 |
|
|
}); |
128 |
|
|
|
129 |
|
|
installKeyboardListeners(); |
130 |
iliev |
1752 |
|
131 |
|
|
setMinimumSize(getPreferredSize()); |
132 |
|
|
setResizable(true); |
133 |
iliev |
1286 |
} |
134 |
|
|
|
135 |
|
|
private void |
136 |
|
|
installKeyboardListeners() { |
137 |
|
|
getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put ( |
138 |
|
|
KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), |
139 |
|
|
"goUp" |
140 |
|
|
); |
141 |
|
|
|
142 |
iliev |
1752 |
getRootPane().getActionMap().put ("goUp", instrumentsDbTree.actionGoUp); |
143 |
iliev |
1286 |
|
144 |
|
|
instrumentsDbTable.getInputMap().put ( |
145 |
|
|
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), |
146 |
|
|
"Select" |
147 |
|
|
); |
148 |
|
|
|
149 |
|
|
instrumentsDbTable.getActionMap().put ("Select", new AbstractAction() { |
150 |
|
|
public void |
151 |
|
|
actionPerformed(ActionEvent e) { |
152 |
|
|
DbDirectoryTreeNode node; |
153 |
|
|
node = instrumentsDbTable.getSelectedDirectoryNode(); |
154 |
|
|
if(node != null) { |
155 |
|
|
instrumentsDbTree.setSelectedDirectoryNode(node); |
156 |
|
|
return; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
if(instrumentsDbTable.getSelectedInstruments().length > 0) { |
160 |
|
|
onOk(); |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
} |
164 |
|
|
}); |
165 |
|
|
} |
166 |
|
|
|
167 |
iliev |
1752 |
protected JSInstrumentsDbTree |
168 |
|
|
createInstrumentsDbTree(InstrumentsDbTreeModel m) { return new JSInstrumentsDbTree(m); } |
169 |
|
|
|
170 |
iliev |
1286 |
public String |
171 |
|
|
getSelectedInstrument() { |
172 |
|
|
DbInstrumentInfo[] infos = instrumentsDbTable.getSelectedInstruments(); |
173 |
|
|
if(infos.length == 0) return null; |
174 |
|
|
return infos[0].getInstrumentPath(); |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
public void |
178 |
|
|
setSelectedInstrument(String instr) { |
179 |
iliev |
1347 |
String parentDir = Parser.getParentDirectory(instr); |
180 |
iliev |
1286 |
if(parentDir == null) return; |
181 |
|
|
instrumentsDbTree.setSelectedDirectory(parentDir); |
182 |
|
|
if(instrumentsDbTable.getParentDirectoryNode() == null) return; |
183 |
|
|
|
184 |
|
|
instr = instr.substring(parentDir.length() + 1, instr.length()); |
185 |
|
|
instrumentsDbTable.setSelectedInstrument(instr); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
public void |
189 |
|
|
setSelectedDirectory(String dir) { |
190 |
|
|
instrumentsDbTree.setSelectedDirectory(dir); |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
protected void |
194 |
|
|
onOk() { |
195 |
|
|
if(!btnOk.isEnabled()) return; |
196 |
iliev |
1752 |
|
197 |
|
|
instrumentsDbTable.saveColumnsVisibleState(); |
198 |
|
|
instrumentsDbTable.saveColumnWidths(); |
199 |
|
|
|
200 |
iliev |
1286 |
setCancelled(false); |
201 |
|
|
setVisible(false); |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
protected void |
205 |
|
|
onCancel() { setVisible(false); } |
206 |
|
|
|
207 |
|
|
public void |
208 |
|
|
valueChanged(ListSelectionEvent e) { |
209 |
|
|
boolean b = instrumentsDbTable.getSelectedInstruments().length > 0; |
210 |
|
|
btnOk.setEnabled(b); |
211 |
|
|
} |
212 |
|
|
|
213 |
iliev |
1752 |
protected JButton |
214 |
|
|
createToolbarButton(Action a) { return new JButton(a); } |
215 |
|
|
|
216 |
|
|
class ToolBar extends JToolBar { |
217 |
|
|
protected final JButton btnGoUp = createToolbarButton(instrumentsDbTree.actionGoUp); |
218 |
|
|
protected final JButton btnGoBack = createToolbarButton(instrumentsDbTree.actionGoBack); |
219 |
|
|
protected final JButton btnGoForward = createToolbarButton(instrumentsDbTree.actionGoForward); |
220 |
|
|
protected final JButton btnReload = createToolbarButton(instrumentsDbTable.reloadAction); |
221 |
|
|
protected final JButton btnPreferences = createToolbarButton(null); |
222 |
iliev |
1286 |
|
223 |
iliev |
1752 |
public ToolBar() { |
224 |
|
|
super(""); |
225 |
|
|
setFloatable(false); |
226 |
|
|
|
227 |
|
|
add(btnGoBack); |
228 |
|
|
add(btnGoForward); |
229 |
|
|
add(btnGoUp); |
230 |
|
|
|
231 |
|
|
javax.swing.Icon i = CC.getViewConfig().getBasicIconSet().getReload16Icon(); |
232 |
|
|
instrumentsDbTable.reloadAction.putValue(Action.SMALL_ICON, i); |
233 |
|
|
add(btnReload); |
234 |
|
|
|
235 |
|
|
addSeparator(); |
236 |
|
|
|
237 |
|
|
i = CC.getViewConfig().getBasicIconSet().getPreferences16Icon(); |
238 |
|
|
btnPreferences.setIcon(i); |
239 |
|
|
add(btnPreferences); |
240 |
|
|
|
241 |
|
|
btnPreferences.addActionListener(new ActionListener() { |
242 |
|
|
public void |
243 |
|
|
actionPerformed(ActionEvent e) { |
244 |
|
|
new PreferencesDlg().setVisible(true); |
245 |
|
|
} |
246 |
|
|
}); |
247 |
iliev |
1286 |
} |
248 |
|
|
} |
249 |
iliev |
1752 |
|
250 |
|
|
class PreferencesDlg extends JSInstrumentsDbColumnPreferencesDlg { |
251 |
|
|
PreferencesDlg() { |
252 |
|
|
super(JSDbInstrumentChooser.this, instrumentsDbTable); |
253 |
|
|
} |
254 |
|
|
} |
255 |
iliev |
1286 |
} |