/[svn]/jsampler/trunk/src/org/jsampler/view/classic/EditMidiInstrumentDlg.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/classic/EditMidiInstrumentDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1204 - (hide annotations) (download)
Thu May 24 21:43:45 2007 UTC (16 years, 11 months ago) by iliev
File size: 6545 byte(s)
upgrading to version 0.5a

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

  ViewVC Help
Powered by ViewVC