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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (hide annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 11188 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

1 iliev 1313 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2288 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1313 *
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 iliev 1734 import java.awt.GridBagConstraints;
28     import java.awt.GridBagLayout;
29     import java.awt.Insets;
30 iliev 1313
31     import java.awt.event.ActionEvent;
32     import java.awt.event.ActionListener;
33     import java.awt.event.ItemEvent;
34     import java.awt.event.ItemListener;
35    
36     import javax.swing.BorderFactory;
37     import javax.swing.Box;
38     import javax.swing.BoxLayout;
39     import javax.swing.Icon;
40     import javax.swing.JButton;
41     import javax.swing.JCheckBox;
42 iliev 1315 import javax.swing.JComboBox;
43 iliev 1313 import javax.swing.JDialog;
44 iliev 1732 import javax.swing.JLabel;
45 iliev 1313 import javax.swing.JPanel;
46    
47     import org.jsampler.CC;
48     import org.jsampler.JSPrefs;
49    
50 iliev 1315 import org.linuxsampler.lscp.AudioOutputDriver;
51     import org.linuxsampler.lscp.MidiInputDriver;
52    
53 iliev 1313 import static org.jsampler.view.std.StdI18n.i18n;
54 iliev 2288 import static org.jsampler.JSPrefs.*;
55 iliev 1313
56     /**
57     *
58     * @author Grigor Iliev
59     */
60     public class JSDefaultsPropsPane extends JPanel {
61     private final ChannelDefaultsPane channelDefaultsPane;
62 iliev 1315 private final DefaultMidiDriverPane defaultMidiDriverPane = new DefaultMidiDriverPane();
63     private final DefaultAudioDriverPane defaultAudioDriverPane = new DefaultAudioDriverPane();
64 iliev 1313
65    
66     /** Creates a new instance of <code>JSDefaultsPropsPane</code> */
67     public
68     JSDefaultsPropsPane(Dialog owner, Icon iconChangeDefaults) {
69 iliev 1732 this(owner, iconChangeDefaults, false);
70     }
71    
72     /** Creates a new instance of <code>JSDefaultsPropsPane</code> */
73     public
74     JSDefaultsPropsPane(Dialog owner, Icon iconChangeDefaults, boolean showDefaultChannelView) {
75     channelDefaultsPane = new ChannelDefaultsPane(owner, iconChangeDefaults, showDefaultChannelView);
76 iliev 1313
77     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
78     add(channelDefaultsPane);
79 iliev 1315 add(Box.createRigidArea(new Dimension(0, 6)));
80     add(defaultMidiDriverPane);
81     add(Box.createRigidArea(new Dimension(0, 6)));
82     add(defaultAudioDriverPane);
83 iliev 1313 }
84    
85     private static JSPrefs
86     preferences() { return CC.getViewConfig().preferences(); }
87    
88     public void
89     apply() {
90     channelDefaultsPane.apply();
91 iliev 1315 defaultMidiDriverPane.apply();
92     defaultAudioDriverPane.apply();
93 iliev 1313 }
94    
95     public static class ChannelDefaultsPane extends JPanel {
96     private final Dialog owner;
97     private final JCheckBox checkChannelDefaults =
98     new JCheckBox(i18n.getLabel("JSDefaultsPropsPane.checkChannelDefaults"));
99    
100     private final JButton btnChannelDefaults;
101    
102 iliev 1734 private ChannelViewDefaultsPane channelViewDefaultsPane = null;
103 iliev 1732 private final boolean showDefaultView;
104 iliev 1313
105 iliev 1732
106 iliev 1313 public
107     ChannelDefaultsPane(Dialog owner, Icon iconChangeDefaults) {
108 iliev 1732 this(owner, iconChangeDefaults, false);
109     }
110    
111     public
112     ChannelDefaultsPane(Dialog owner, Icon iconChangeDefaults, boolean showDefaultView) {
113 iliev 1313 this.owner = owner;
114 iliev 1732 this.showDefaultView = showDefaultView;
115 iliev 1313 btnChannelDefaults = new JButton(iconChangeDefaults);
116     btnChannelDefaults.setEnabled(false);
117     btnChannelDefaults.setMargin(new java.awt.Insets(0, 0, 0, 0));
118    
119     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
120    
121     JPanel p = new JPanel();
122     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
123    
124     p.add(checkChannelDefaults);
125     p.add(Box.createRigidArea(new Dimension(5, 0)));
126     p.add(btnChannelDefaults);
127     p.setAlignmentX(LEFT_ALIGNMENT);
128     p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
129     add(p);
130    
131     String s = i18n.getLabel("JSDefaultsPropsPane.titleChannels");
132     setBorder(BorderFactory.createTitledBorder(s));
133     setAlignmentX(LEFT_ALIGNMENT);
134    
135     checkChannelDefaults.addItemListener(new ItemListener() {
136     public void
137     itemStateChanged(ItemEvent e) {
138     btnChannelDefaults.setEnabled(checkChannelDefaults.isSelected());
139     }
140     });
141    
142     if(preferences().getBoolProperty(USE_CHANNEL_DEFAULTS)) {
143     checkChannelDefaults.doClick(0);
144     }
145    
146     btnChannelDefaults.addActionListener(new ActionListener() {
147     public void
148     actionPerformed(ActionEvent e) { editChannelDefaults(); }
149     });
150 iliev 1732
151     if(showDefaultView) {
152 iliev 1734 add(Box.createRigidArea(new Dimension(0, 6)));
153     add(new javax.swing.JSeparator());
154     add(Box.createRigidArea(new Dimension(0, 6)));
155 iliev 1732
156 iliev 1734 channelViewDefaultsPane = new ChannelViewDefaultsPane();
157     add(channelViewDefaultsPane);
158 iliev 1732 }
159    
160     setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height));
161 iliev 1313 }
162    
163     public void
164     apply() {
165     boolean b = checkChannelDefaults.isSelected();
166     preferences().setBoolProperty(USE_CHANNEL_DEFAULTS, b);
167 iliev 1732
168     if(showDefaultView) {
169 iliev 1734 channelViewDefaultsPane.apply();
170 iliev 1732 }
171 iliev 1313 }
172    
173     protected void
174     editChannelDefaults() {
175     JDialog dlg = new JSChannelsDefaultSettingsPane().createDialog(owner);
176     dlg.setVisible(true);
177     }
178     }
179 iliev 1315
180 iliev 1734 public static class ChannelViewDefaultsPane extends JPanel {
181     private final ComboBox cbDefaultView = new ComboBox();
182     private final ComboBox cbMouseOverView = new ComboBox();
183    
184     private final JCheckBox checkMouseOverView =
185     new JCheckBox(i18n.getLabel("JSDefaultsPropsPane.checkMouseOverView"));
186    
187     ChannelViewDefaultsPane() {
188     GridBagLayout gridbag = new GridBagLayout();
189     GridBagConstraints c = new GridBagConstraints();
190    
191     setLayout(gridbag);
192    
193     c.fill = GridBagConstraints.NONE;
194    
195     String s = i18n.getLabel("JSDefaultsPropsPane.lDefaultChannelView");
196     JLabel l = new JLabel(s);
197    
198     c.gridx = 0;
199     c.gridy = 0;
200     c.anchor = GridBagConstraints.EAST;
201     c.insets = new Insets(3, 3, 3, 3);
202     gridbag.setConstraints(l, c);
203     add(l);
204    
205    
206    
207     int i = preferences().getIntProperty(DEFAULT_CHANNEL_VIEW);
208     cbDefaultView.setView(i);
209    
210     c.gridx = 1;
211     c.gridy = 0;
212     c.fill = GridBagConstraints.HORIZONTAL;
213     c.anchor = GridBagConstraints.WEST;
214     gridbag.setConstraints(cbDefaultView, c);
215     add(cbDefaultView);
216    
217     c.gridx = 0;
218     c.gridy = 1;
219     c.gridwidth = 2;
220     c.insets = new Insets(9, 3, 3, 3);
221     gridbag.setConstraints(checkMouseOverView, c);
222     add(checkMouseOverView);
223    
224     i = preferences().getIntProperty(CHANNEL_VIEW_ON_MOUSE_OVER);
225     cbMouseOverView.setView(i);
226    
227     c.gridx = 1;
228     c.gridy = 2;
229     c.gridwidth = 1;
230     c.insets = new Insets(0, 3, 5, 3);
231     gridbag.setConstraints(cbMouseOverView, c);
232     add(cbMouseOverView);
233    
234     setAlignmentX(LEFT_ALIGNMENT);
235    
236     checkMouseOverView.addItemListener(new ItemListener() {
237     public void
238     itemStateChanged(ItemEvent e) {
239     cbMouseOverView.setEnabled(checkMouseOverView.isSelected());
240     }
241     });
242    
243     cbMouseOverView.setEnabled(false);
244     if(preferences().getBoolProperty(DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER)) {
245     checkMouseOverView.doClick(0);
246     }
247     }
248    
249     public void
250     apply() {
251     int i = cbDefaultView.getSelectedIndex();
252     preferences().setIntProperty(DEFAULT_CHANNEL_VIEW, i);
253    
254     boolean b = checkMouseOverView.isSelected();
255     preferences().setBoolProperty(DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER, b);
256    
257     i = cbMouseOverView.getSelectedIndex();
258     preferences().setIntProperty(CHANNEL_VIEW_ON_MOUSE_OVER, i);
259     }
260    
261     class ComboBox extends JComboBox {
262     ComboBox() {
263     String s = i18n.getLabel("JSDefaultsPropsPane.lSmallView");
264     addItem(s);
265    
266     s = i18n.getLabel("JSDefaultsPropsPane.lNormalView");
267     addItem(s);
268     }
269    
270     public void
271     setView(int i) {
272     if(i < 0 || i >= getItemCount()) i = 1;
273    
274     setSelectedIndex(i);
275     }
276     }
277     }
278    
279 iliev 1315 public static class DefaultMidiDriverPane extends JPanel {
280     private final JComboBox cbDriver = new JComboBox();
281    
282     public
283     DefaultMidiDriverPane() {
284     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
285    
286     JPanel p = new JPanel();
287     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
288    
289     cbDriver.setAlignmentX(LEFT_ALIGNMENT);
290     int h = cbDriver.getPreferredSize().height;
291     cbDriver.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
292    
293     p.add(cbDriver);
294     p.setAlignmentX(LEFT_ALIGNMENT);
295     p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
296    
297     add(p);
298    
299     String s = i18n.getLabel("JSDefaultsPropsPane.titleMidiDriver");
300     setBorder(BorderFactory.createTitledBorder(s));
301     setAlignmentX(LEFT_ALIGNMENT);
302    
303 iliev 1585 // not connected?
304     if(CC.getSamplerModel().getMidiInputDrivers() == null) return;
305    
306 iliev 1315 for(Object o : CC.getSamplerModel().getMidiInputDrivers()) {
307     cbDriver.addItem(o);
308     }
309    
310     String drv = preferences().getStringProperty(DEFAULT_MIDI_DRIVER);
311     for(MidiInputDriver d : CC.getSamplerModel().getMidiInputDrivers()) {
312     if(d.getName().equals(drv)){
313     cbDriver.setSelectedItem(d);
314     break;
315     }
316     }
317     }
318    
319     public void
320     apply() {
321 iliev 1585 // not connected?
322     if(CC.getSamplerModel().getMidiInputDrivers() == null) return;
323    
324 iliev 1315 Object o = cbDriver.getSelectedItem();
325     if(o == null) {
326     preferences().setStringProperty(DEFAULT_MIDI_DRIVER, null);
327     return;
328     }
329    
330     String drv = ((MidiInputDriver) o).getName();
331     preferences().setStringProperty(DEFAULT_MIDI_DRIVER, drv);
332     }
333     }
334    
335     public static class DefaultAudioDriverPane extends JPanel {
336     private final JComboBox cbDriver = new JComboBox();
337    
338     public
339     DefaultAudioDriverPane() {
340     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
341    
342     JPanel p = new JPanel();
343     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
344    
345     cbDriver.setAlignmentX(LEFT_ALIGNMENT);
346     int h = cbDriver.getPreferredSize().height;
347     cbDriver.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
348    
349     p.add(cbDriver);
350     p.setAlignmentX(LEFT_ALIGNMENT);
351     p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
352    
353     add(p);
354    
355     String s = i18n.getLabel("JSDefaultsPropsPane.titleAudioDriver");
356     setBorder(BorderFactory.createTitledBorder(s));
357     setAlignmentX(LEFT_ALIGNMENT);
358    
359 iliev 1585 // not connected?
360     if(CC.getSamplerModel().getAudioOutputDrivers() == null) return;
361    
362 iliev 1315 for(Object o : CC.getSamplerModel().getAudioOutputDrivers()) {
363     cbDriver.addItem(o);
364     }
365    
366     String drv = preferences().getStringProperty(DEFAULT_AUDIO_DRIVER);
367     for(AudioOutputDriver d : CC.getSamplerModel().getAudioOutputDrivers()) {
368     if(d.getName().equals(drv)){
369     cbDriver.setSelectedItem(d);
370     break;
371     }
372     }
373     }
374    
375     public void
376     apply() {
377 iliev 1585 // not connected?
378     if(CC.getSamplerModel().getAudioOutputDrivers() == null) return;
379    
380 iliev 1315 Object o = cbDriver.getSelectedItem();
381     if(o == null) {
382     preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, null);
383     return;
384     }
385    
386     String drv = ((AudioOutputDriver) o).getName();
387     preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, drv);
388     }
389     }
390 iliev 1313 }

  ViewVC Help
Powered by ViewVC