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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1286 - (show annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 9 months ago) by iliev
File size: 6558 byte(s)
- Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

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.Dimension;
26 import java.awt.GridBagConstraints;
27 import java.awt.GridBagLayout;
28 import java.awt.Insets;
29
30 import javax.swing.JComboBox;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.JSlider;
34 import javax.swing.JSpinner;
35 import javax.swing.JTextField;
36 import javax.swing.SpinnerNumberModel;
37
38 import javax.swing.event.DocumentEvent;
39 import javax.swing.event.DocumentListener;
40
41 import net.sf.juife.OkCancelDialog;
42
43 import org.jsampler.CC;
44
45 import org.linuxsampler.lscp.MidiInstrumentInfo;
46 import org.linuxsampler.lscp.SamplerEngine;
47
48 import static org.jsampler.view.std.StdI18n.i18n;
49
50
51 /**
52 *
53 * @author Grigor Iliev
54 */
55 public class JSEditMidiInstrumentDlg extends OkCancelDialog {
56 private final JLabel lName = new JLabel(i18n.getLabel("JSEditMidiInstrumentDlg.lName"));
57
58 private final JLabel lFilename =
59 new JLabel(i18n.getLabel("JSEditMidiInstrumentDlg.lFilename"));
60
61 private final JLabel lIndex = new JLabel(i18n.getLabel("JSEditMidiInstrumentDlg.lIndex"));
62
63 private final JLabel lEngine = new JLabel(i18n.getLabel("JSEditMidiInstrumentDlg.lEngine"));
64
65 private final JLabel lLoadMode =
66 new JLabel(i18n.getLabel("JSEditMidiInstrumentDlg.lLoadMode"));
67
68 private final JLabel lVolume =
69 new JLabel(i18n.getLabel("JSEditMidiInstrumentDlg.lVolume"));
70
71 private final JTextField tfName = new JTextField();
72 private final JTextField tfFilename = new JTextField();
73 private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1));
74 private final JComboBox cbEngine = new JComboBox();
75 private final JComboBox cbLoadMode = new JComboBox();
76 private final JSlider slVolume = new JSlider(0, 100, 100);
77
78 private final MidiInstrumentInfo instrument;
79
80 /**
81 * Creates a new instance of <code>JSEditMidiInstrumentDlg</code>.
82 *
83 * @param instr The instrument whose settings should be edited.
84 */
85 public JSEditMidiInstrumentDlg(MidiInstrumentInfo instr) {
86 super(CC.getMainFrame(), i18n.getLabel("JSEditMidiInstrumentDlg.title"));
87
88 this.instrument = instr;
89
90 GridBagLayout gridbag = new GridBagLayout();
91 GridBagConstraints c = new GridBagConstraints();
92
93 JPanel p = new JPanel();
94 p.setLayout(gridbag);
95
96 c.fill = GridBagConstraints.NONE;
97
98 c.gridx = 0;
99 c.gridy = 0;
100 c.anchor = GridBagConstraints.EAST;
101 c.insets = new Insets(3, 3, 3, 3);
102 gridbag.setConstraints(lName, c);
103 p.add(lName);
104
105 c.gridx = 0;
106 c.gridy = 1;
107 gridbag.setConstraints(lFilename, c);
108 p.add(lFilename);
109
110 c.gridx = 0;
111 c.gridy = 2;
112 gridbag.setConstraints(lIndex, c);
113 p.add(lIndex);
114
115 c.gridx = 0;
116 c.gridy = 3;
117 c.insets = new Insets(12, 3, 3, 3);
118 gridbag.setConstraints(lEngine, c);
119 p.add(lEngine);
120
121 c.gridx = 0;
122 c.gridy = 4;
123 c.insets = new Insets(3, 3, 3, 3);
124 gridbag.setConstraints(lLoadMode, c);
125 p.add(lLoadMode);
126
127 c.gridx = 0;
128 c.gridy = 5;
129 gridbag.setConstraints(lVolume, c);
130 p.add(lVolume);
131
132 c.fill = GridBagConstraints.HORIZONTAL;
133 c.gridx = 1;
134 c.gridy = 0;
135 c.weightx = 1.0;
136 c.insets = new Insets(3, 12, 3, 3);
137 c.anchor = GridBagConstraints.WEST;
138 gridbag.setConstraints(tfName, c);
139 p.add(tfName);
140
141 c.gridx = 1;
142 c.gridy = 1;
143 c.anchor = GridBagConstraints.WEST;
144 gridbag.setConstraints(tfFilename, c);
145 p.add(tfFilename);
146
147 c.gridx = 1;
148 c.gridy = 2;
149 gridbag.setConstraints(spinnerIndex, c);
150 p.add(spinnerIndex);
151
152 c.gridx = 1;
153 c.gridy = 3;
154 c.insets = new Insets(12, 12, 3, 64);
155 gridbag.setConstraints(cbEngine, c);
156 p.add(cbEngine);
157
158 c.gridx = 1;
159 c.gridy = 4;
160 c.insets = new Insets(3, 12, 3, 64);
161 gridbag.setConstraints(cbLoadMode, c);
162 p.add(cbLoadMode);
163
164 c.gridx = 1;
165 c.gridy = 5;
166 gridbag.setConstraints(slVolume, c);
167 p.add(slVolume);
168
169 setMainPane(p);
170
171 tfName.setText(instr.getName());
172 tfFilename.setText(instr.getFilePath());
173 spinnerIndex.setValue(instr.getInstrumentIndex());
174 slVolume.setValue((int)(instr.getVolume() * 100));
175
176 for(SamplerEngine e : CC.getSamplerModel().getEngines()) {
177 cbEngine.addItem(e);
178 if(e.getName().equals(instr.getEngine())) cbEngine.setSelectedItem(e);
179 }
180
181 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT);
182 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND);
183 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD);
184 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT);
185 cbLoadMode.setSelectedItem(instr.getLoadMode());
186
187 tfName.getDocument().addDocumentListener(getHandler());
188 tfFilename.getDocument().addDocumentListener(getHandler());
189 }
190
191 public MidiInstrumentInfo
192 getInstrument() { return instrument; }
193
194 public void
195 onOk() {
196 instrument.setName(tfName.getText());
197 instrument.setFilePath(tfFilename.getText());
198 instrument.setInstrumentIndex(Integer.parseInt(spinnerIndex.getValue().toString()));
199 String s = ((SamplerEngine)cbEngine.getSelectedItem()).getName();
200 instrument.setEngine(s);
201 instrument.setLoadMode((MidiInstrumentInfo.LoadMode)cbLoadMode.getSelectedItem());
202 float f = slVolume.getValue();
203 f /= 100;
204 instrument.setVolume(f);
205
206 setCancelled(false);
207 setVisible(false);
208 }
209
210 public void
211 onCancel() { setVisible(false); }
212
213 private void
214 updateState() {
215 boolean b = tfName.getText().length() != 0 && tfFilename.getText().length() != 0;
216 btnOk.setEnabled(b);
217 }
218
219 private final Handler eventHandler = new Handler();
220
221 private Handler
222 getHandler() { return eventHandler; }
223
224 private class Handler implements DocumentListener {
225 // DocumentListener
226 public void
227 insertUpdate(DocumentEvent e) { updateState(); }
228
229 public void
230 removeUpdate(DocumentEvent e) { updateState(); }
231
232 public void
233 changedUpdate(DocumentEvent e) { updateState(); }
234 }
235 }

  ViewVC Help
Powered by ViewVC