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

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSAddMidiInstrumentDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1329 - (show annotations) (download)
Sat Sep 8 18:33:05 2007 UTC (16 years, 7 months ago) by iliev
File size: 7404 byte(s)
* Implemented some UI enhancements for speeding up
  the MIDI instrument mapping process
* some minor bugfixes

1 /*
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.Dimension;
27 import java.awt.Frame;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.Insets;
31
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34
35 import javax.swing.JComboBox;
36 import javax.swing.JLabel;
37 import javax.swing.JPanel;
38 import javax.swing.JSlider;
39 import javax.swing.JSpinner;
40 import javax.swing.JTextField;
41 import javax.swing.SpinnerNumberModel;
42
43 import javax.swing.event.DocumentEvent;
44 import javax.swing.event.DocumentListener;
45
46 import net.sf.juife.OkCancelDialog;
47
48 import org.jsampler.CC;
49 import org.jsampler.JSPrefs;
50
51 import org.linuxsampler.lscp.MidiInstrumentInfo;
52
53 import static org.jsampler.view.std.StdI18n.i18n;
54
55
56 /**
57 *
58 * @author Grigor Iliev
59 */
60 public class JSAddMidiInstrumentDlg extends OkCancelDialog {
61 private final JLabel lName = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lName"));
62 private final JLabel lBank = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lBank"));
63 private final JLabel lProgram = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lProgram"));
64 private final JLabel lVolume = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lVolume"));
65 private final JLabel lLoadMode =
66 new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lLoadMode"));
67
68 private final JTextField tfName = new JTextField();
69 private final JSpinner spinnerBank = new JSpinner(new SpinnerNumberModel(0, 0, 16383, 1));
70 private final JComboBox cbProgram = new JComboBox();
71 private final JSlider slVolume = new JSlider(0, 100, 100);
72 private final JComboBox cbLoadMode = new JComboBox();
73
74 /**
75 * Creates a new instance of <code>JSAddMidiInstrumentDlg</code>
76 */
77 public
78 JSAddMidiInstrumentDlg(Frame owner) {
79 super(owner, i18n.getLabel("JSAddMidiInstrumentDlg.title"));
80 initAddMidiInstrumentDlg();
81 }
82
83 /**
84 * Creates a new instance of <code>JSAddMidiInstrumentDlg</code>
85 */
86 public
87 JSAddMidiInstrumentDlg(Dialog owner) {
88 super(owner, i18n.getLabel("JSAddMidiInstrumentDlg.title"));
89 initAddMidiInstrumentDlg();
90 }
91
92 private void
93 initAddMidiInstrumentDlg() {
94 JPanel mainPane = new JPanel();
95 GridBagLayout gridbag = new GridBagLayout();
96 GridBagConstraints c = new GridBagConstraints();
97
98 mainPane.setLayout(gridbag);
99
100 c.fill = GridBagConstraints.NONE;
101
102 c.gridx = 0;
103 c.gridy = 0;
104 c.anchor = GridBagConstraints.EAST;
105 c.insets = new Insets(3, 3, 3, 3);
106 gridbag.setConstraints(lName, c);
107 mainPane.add(lName);
108
109 c.gridx = 0;
110 c.gridy = 2;
111 gridbag.setConstraints(lBank, c);
112 mainPane.add(lBank);
113
114 c.gridx = 0;
115 c.gridy = 3;
116 gridbag.setConstraints(lProgram, c);
117 mainPane.add(lProgram);
118
119 c.gridx = 0;
120 c.gridy = 4;
121 gridbag.setConstraints(lLoadMode, c);
122 mainPane.add(lLoadMode);
123
124 c.gridx = 0;
125 c.gridy = 1;
126 c.insets = new Insets(3, 3, 24, 3);
127 gridbag.setConstraints(lVolume, c);
128 mainPane.add(lVolume);
129
130 c.fill = GridBagConstraints.HORIZONTAL;
131 c.gridx = 1;
132 c.gridy = 0;
133 c.weightx = 1.0;
134 c.insets = new Insets(3, 3, 3, 3);
135 c.anchor = GridBagConstraints.WEST;
136 gridbag.setConstraints(tfName, c);
137 mainPane.add(tfName);
138
139 c.gridx = 1;
140 c.gridy = 2;
141 gridbag.setConstraints(spinnerBank, c);
142 mainPane.add(spinnerBank);
143
144 c.gridx = 1;
145 c.gridy = 3;
146 gridbag.setConstraints(cbProgram, c);
147 mainPane.add(cbProgram);
148
149 c.gridx = 1;
150 c.gridy = 4;
151 gridbag.setConstraints(cbLoadMode, c);
152 mainPane.add(cbLoadMode);
153
154 c.gridx = 1;
155 c.gridy = 1;
156 c.insets = new Insets(3, 3, 24, 3);
157 gridbag.setConstraints(slVolume, c);
158 mainPane.add(slVolume);
159
160 setMainPane(mainPane);
161
162 setResizable(true);
163 setMinimumSize(getPreferredSize());
164
165 for(int i = 0; i < 128; i++) cbProgram.addItem(new Integer(i));
166
167 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT);
168 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND);
169 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD);
170 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT);
171
172 int i = preferences().getIntProperty("std.midiInstrument.loadMode", 0);
173 if(cbLoadMode.getItemCount() > i) cbLoadMode.setSelectedIndex(i);
174
175 cbLoadMode.addActionListener(new ActionListener() {
176 public void
177 actionPerformed(ActionEvent e) {
178 int j = cbLoadMode.getSelectedIndex();
179 if(j < 0) return;
180 preferences().setIntProperty("std.midiInstrument.loadMode", j);
181 }
182 });
183
184 tfName.getDocument().addDocumentListener(getHandler());
185 }
186
187 protected JSPrefs
188 preferences() { return CC.getViewConfig().preferences(); }
189
190 /**
191 * Gets the selected MIDI bank.
192 */
193 public int
194 getMidiBank() { return Integer.parseInt(spinnerBank.getValue().toString()); }
195
196 /**
197 * Sets the selected MIDI bank.
198 */
199 public void
200 setMidiBank(int bank) { spinnerBank.setValue(bank); }
201
202 /**
203 * Gets the selected MIDI program.
204 */
205 public int
206 getMidiProgram() { return cbProgram.getSelectedIndex(); }
207
208 /**
209 * Sets the selected MIDI program.
210 */
211 public void
212 setMidiProgram(int program) { cbProgram.setSelectedIndex(program); }
213
214 /**
215 * Gets the chosen name for the new MIDI instrument.
216 * @return The chosen name for the new MIDI instrument.
217 */
218 public String
219 getInstrumentName() { return tfName.getText(); }
220
221 /**
222 * Sets the name for the new MIDI instrument.
223 * @param name The name for the new MIDI instrument.
224 */
225 public void
226 setInstrumentName(String name) { tfName.setText(name); }
227
228 /**
229 * Returns the volume level of the new MIDI instrument.
230 * @return The volume level of the new MIDI instrument.
231 */
232 public float
233 getVolume() {
234 float f = slVolume.getValue();
235 f /= 100;
236 return f;
237 }
238
239 /** Gets the selected load mode. */
240 public MidiInstrumentInfo.LoadMode
241 getLoadMode() { return (MidiInstrumentInfo.LoadMode) cbLoadMode.getSelectedItem(); }
242
243 protected void
244 onOk() {
245 if(!btnOk.isEnabled()) return;
246 preferences().setIntProperty("lastUsedMidiBank", getMidiBank());
247 setCancelled(false);
248 setVisible(false);
249 }
250
251 protected void
252 onCancel() { setVisible(false); }
253
254 private void
255 updateState() {
256 boolean b = tfName.getText().length() > 0;
257 b = b && cbProgram.getSelectedItem() != null;
258 btnOk.setEnabled(b);
259 }
260
261 private final Handler eventHandler = new Handler();
262
263 private Handler
264 getHandler() { return eventHandler; }
265
266 private class Handler implements DocumentListener {
267 // DocumentListener
268 public void
269 insertUpdate(DocumentEvent e) { updateState(); }
270
271 public void
272 removeUpdate(DocumentEvent e) { updateState(); }
273
274 public void
275 changedUpdate(DocumentEvent e) { updateState(); }
276 }
277 }

  ViewVC Help
Powered by ViewVC