/[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 1585 - (hide annotations) (download)
Mon Dec 10 15:44:15 2007 UTC (16 years, 4 months ago) by iliev
File size: 7646 byte(s)
* fixed bug #66

1 iliev 1313 /*
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    
28     import java.awt.event.ActionEvent;
29     import java.awt.event.ActionListener;
30     import java.awt.event.ItemEvent;
31     import java.awt.event.ItemListener;
32    
33     import javax.swing.BorderFactory;
34     import javax.swing.Box;
35     import javax.swing.BoxLayout;
36     import javax.swing.Icon;
37     import javax.swing.JButton;
38     import javax.swing.JCheckBox;
39 iliev 1315 import javax.swing.JComboBox;
40 iliev 1313 import javax.swing.JDialog;
41     import javax.swing.JPanel;
42    
43     import org.jsampler.CC;
44     import org.jsampler.JSPrefs;
45    
46 iliev 1315 import org.linuxsampler.lscp.AudioOutputDriver;
47     import org.linuxsampler.lscp.MidiInputDriver;
48    
49 iliev 1313 import static org.jsampler.view.std.StdI18n.i18n;
50     import static org.jsampler.view.std.StdPrefs.*;
51    
52     /**
53     *
54     * @author Grigor Iliev
55     */
56     public class JSDefaultsPropsPane extends JPanel {
57     private final ChannelDefaultsPane channelDefaultsPane;
58 iliev 1315 private final DefaultMidiDriverPane defaultMidiDriverPane = new DefaultMidiDriverPane();
59     private final DefaultAudioDriverPane defaultAudioDriverPane = new DefaultAudioDriverPane();
60 iliev 1313
61    
62     /** Creates a new instance of <code>JSDefaultsPropsPane</code> */
63     public
64     JSDefaultsPropsPane(Dialog owner, Icon iconChangeDefaults) {
65     channelDefaultsPane = new ChannelDefaultsPane(owner, iconChangeDefaults);
66    
67     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
68     add(channelDefaultsPane);
69 iliev 1315 add(Box.createRigidArea(new Dimension(0, 6)));
70     add(defaultMidiDriverPane);
71     add(Box.createRigidArea(new Dimension(0, 6)));
72     add(defaultAudioDriverPane);
73 iliev 1313 }
74    
75     private static JSPrefs
76     preferences() { return CC.getViewConfig().preferences(); }
77    
78     public void
79     apply() {
80     channelDefaultsPane.apply();
81 iliev 1315 defaultMidiDriverPane.apply();
82     defaultAudioDriverPane.apply();
83 iliev 1313 }
84    
85     public static class ChannelDefaultsPane extends JPanel {
86     private final Dialog owner;
87     private final JCheckBox checkChannelDefaults =
88     new JCheckBox(i18n.getLabel("JSDefaultsPropsPane.checkChannelDefaults"));
89    
90     private final JButton btnChannelDefaults;
91    
92    
93     public
94     ChannelDefaultsPane(Dialog owner, Icon iconChangeDefaults) {
95     this.owner = owner;
96     btnChannelDefaults = new JButton(iconChangeDefaults);
97     btnChannelDefaults.setEnabled(false);
98     btnChannelDefaults.setMargin(new java.awt.Insets(0, 0, 0, 0));
99    
100     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
101    
102     JPanel p = new JPanel();
103     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
104    
105     p.add(checkChannelDefaults);
106     p.add(Box.createRigidArea(new Dimension(5, 0)));
107     p.add(btnChannelDefaults);
108     p.setAlignmentX(LEFT_ALIGNMENT);
109     p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
110     add(p);
111    
112     setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
113    
114     String s = i18n.getLabel("JSDefaultsPropsPane.titleChannels");
115     setBorder(BorderFactory.createTitledBorder(s));
116     setAlignmentX(LEFT_ALIGNMENT);
117    
118     checkChannelDefaults.addItemListener(new ItemListener() {
119     public void
120     itemStateChanged(ItemEvent e) {
121     btnChannelDefaults.setEnabled(checkChannelDefaults.isSelected());
122     }
123     });
124    
125     setMaximumSize(new Dimension(Short.MAX_VALUE, getMaximumSize().height));
126    
127     if(preferences().getBoolProperty(USE_CHANNEL_DEFAULTS)) {
128     checkChannelDefaults.doClick(0);
129     }
130    
131     btnChannelDefaults.addActionListener(new ActionListener() {
132     public void
133     actionPerformed(ActionEvent e) { editChannelDefaults(); }
134     });
135     }
136    
137     public void
138     apply() {
139     boolean b = checkChannelDefaults.isSelected();
140     preferences().setBoolProperty(USE_CHANNEL_DEFAULTS, b);
141     }
142    
143     protected void
144     editChannelDefaults() {
145     JDialog dlg = new JSChannelsDefaultSettingsPane().createDialog(owner);
146     dlg.setVisible(true);
147     }
148     }
149 iliev 1315
150     public static class DefaultMidiDriverPane extends JPanel {
151     private final JComboBox cbDriver = new JComboBox();
152    
153     public
154     DefaultMidiDriverPane() {
155     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
156    
157     JPanel p = new JPanel();
158     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
159    
160     cbDriver.setAlignmentX(LEFT_ALIGNMENT);
161     int h = cbDriver.getPreferredSize().height;
162     cbDriver.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
163    
164     p.add(cbDriver);
165     p.setAlignmentX(LEFT_ALIGNMENT);
166     p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
167    
168     add(p);
169    
170     String s = i18n.getLabel("JSDefaultsPropsPane.titleMidiDriver");
171     setBorder(BorderFactory.createTitledBorder(s));
172     setAlignmentX(LEFT_ALIGNMENT);
173    
174 iliev 1585 // not connected?
175     if(CC.getSamplerModel().getMidiInputDrivers() == null) return;
176    
177 iliev 1315 for(Object o : CC.getSamplerModel().getMidiInputDrivers()) {
178     cbDriver.addItem(o);
179     }
180    
181     String drv = preferences().getStringProperty(DEFAULT_MIDI_DRIVER);
182     for(MidiInputDriver d : CC.getSamplerModel().getMidiInputDrivers()) {
183     if(d.getName().equals(drv)){
184     cbDriver.setSelectedItem(d);
185     break;
186     }
187     }
188     }
189    
190     public void
191     apply() {
192 iliev 1585 // not connected?
193     if(CC.getSamplerModel().getMidiInputDrivers() == null) return;
194    
195 iliev 1315 Object o = cbDriver.getSelectedItem();
196     if(o == null) {
197     preferences().setStringProperty(DEFAULT_MIDI_DRIVER, null);
198     return;
199     }
200    
201     String drv = ((MidiInputDriver) o).getName();
202     preferences().setStringProperty(DEFAULT_MIDI_DRIVER, drv);
203     }
204     }
205    
206     public static class DefaultAudioDriverPane extends JPanel {
207     private final JComboBox cbDriver = new JComboBox();
208    
209     public
210     DefaultAudioDriverPane() {
211     setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
212    
213     JPanel p = new JPanel();
214     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
215    
216     cbDriver.setAlignmentX(LEFT_ALIGNMENT);
217     int h = cbDriver.getPreferredSize().height;
218     cbDriver.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
219    
220     p.add(cbDriver);
221     p.setAlignmentX(LEFT_ALIGNMENT);
222     p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
223    
224     add(p);
225    
226     String s = i18n.getLabel("JSDefaultsPropsPane.titleAudioDriver");
227     setBorder(BorderFactory.createTitledBorder(s));
228     setAlignmentX(LEFT_ALIGNMENT);
229    
230 iliev 1585 // not connected?
231     if(CC.getSamplerModel().getAudioOutputDrivers() == null) return;
232    
233 iliev 1315 for(Object o : CC.getSamplerModel().getAudioOutputDrivers()) {
234     cbDriver.addItem(o);
235     }
236    
237     String drv = preferences().getStringProperty(DEFAULT_AUDIO_DRIVER);
238     for(AudioOutputDriver d : CC.getSamplerModel().getAudioOutputDrivers()) {
239     if(d.getName().equals(drv)){
240     cbDriver.setSelectedItem(d);
241     break;
242     }
243     }
244     }
245    
246     public void
247     apply() {
248 iliev 1585 // not connected?
249     if(CC.getSamplerModel().getAudioOutputDrivers() == null) return;
250    
251 iliev 1315 Object o = cbDriver.getSelectedItem();
252     if(o == null) {
253     preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, null);
254     return;
255     }
256    
257     String drv = ((AudioOutputDriver) o).getName();
258     preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, drv);
259     }
260     }
261 iliev 1313 }

  ViewVC Help
Powered by ViewVC