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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1315 - (show annotations) (download)
Fri Aug 31 14:25:45 2007 UTC (16 years, 7 months ago) by iliev
File size: 7278 byte(s)
* Added support for assignment of default MIDI/audio drivers to be used
  (choose Edit/Preferences, then click the `Defaults' tab)

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
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 import javax.swing.JComboBox;
40 import javax.swing.JDialog;
41 import javax.swing.JPanel;
42
43 import org.jsampler.CC;
44 import org.jsampler.JSPrefs;
45
46 import org.linuxsampler.lscp.AudioOutputDriver;
47 import org.linuxsampler.lscp.MidiInputDriver;
48
49 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 private final DefaultMidiDriverPane defaultMidiDriverPane = new DefaultMidiDriverPane();
59 private final DefaultAudioDriverPane defaultAudioDriverPane = new DefaultAudioDriverPane();
60
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 add(Box.createRigidArea(new Dimension(0, 6)));
70 add(defaultMidiDriverPane);
71 add(Box.createRigidArea(new Dimension(0, 6)));
72 add(defaultAudioDriverPane);
73 }
74
75 private static JSPrefs
76 preferences() { return CC.getViewConfig().preferences(); }
77
78 public void
79 apply() {
80 channelDefaultsPane.apply();
81 defaultMidiDriverPane.apply();
82 defaultAudioDriverPane.apply();
83 }
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
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 for(Object o : CC.getSamplerModel().getMidiInputDrivers()) {
175 cbDriver.addItem(o);
176 }
177
178 String drv = preferences().getStringProperty(DEFAULT_MIDI_DRIVER);
179 for(MidiInputDriver d : CC.getSamplerModel().getMidiInputDrivers()) {
180 if(d.getName().equals(drv)){
181 cbDriver.setSelectedItem(d);
182 break;
183 }
184 }
185 }
186
187 public void
188 apply() {
189 Object o = cbDriver.getSelectedItem();
190 if(o == null) {
191 preferences().setStringProperty(DEFAULT_MIDI_DRIVER, null);
192 return;
193 }
194
195 String drv = ((MidiInputDriver) o).getName();
196 preferences().setStringProperty(DEFAULT_MIDI_DRIVER, drv);
197 }
198 }
199
200 public static class DefaultAudioDriverPane extends JPanel {
201 private final JComboBox cbDriver = new JComboBox();
202
203 public
204 DefaultAudioDriverPane() {
205 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
206
207 JPanel p = new JPanel();
208 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
209
210 cbDriver.setAlignmentX(LEFT_ALIGNMENT);
211 int h = cbDriver.getPreferredSize().height;
212 cbDriver.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
213
214 p.add(cbDriver);
215 p.setAlignmentX(LEFT_ALIGNMENT);
216 p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
217
218 add(p);
219
220 String s = i18n.getLabel("JSDefaultsPropsPane.titleAudioDriver");
221 setBorder(BorderFactory.createTitledBorder(s));
222 setAlignmentX(LEFT_ALIGNMENT);
223
224 for(Object o : CC.getSamplerModel().getAudioOutputDrivers()) {
225 cbDriver.addItem(o);
226 }
227
228 String drv = preferences().getStringProperty(DEFAULT_AUDIO_DRIVER);
229 for(AudioOutputDriver d : CC.getSamplerModel().getAudioOutputDrivers()) {
230 if(d.getName().equals(drv)){
231 cbDriver.setSelectedItem(d);
232 break;
233 }
234 }
235 }
236
237 public void
238 apply() {
239 Object o = cbDriver.getSelectedItem();
240 if(o == null) {
241 preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, null);
242 return;
243 }
244
245 String drv = ((AudioOutputDriver) o).getName();
246 preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, drv);
247 }
248 }
249 }

  ViewVC Help
Powered by ViewVC