1 |
iliev |
787 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005 Grigor Kirilov Iliev |
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.BorderLayout; |
26 |
|
|
import java.awt.Dimension; |
27 |
|
|
import java.awt.Frame; |
28 |
|
|
|
29 |
|
|
import java.awt.event.ActionEvent; |
30 |
|
|
import java.awt.event.ActionListener; |
31 |
|
|
|
32 |
|
|
import javax.swing.BorderFactory; |
33 |
|
|
import javax.swing.Box; |
34 |
|
|
import javax.swing.BoxLayout; |
35 |
|
|
import javax.swing.JButton; |
36 |
|
|
import javax.swing.JComboBox; |
37 |
|
|
import javax.swing.JLabel; |
38 |
|
|
import javax.swing.JOptionPane; |
39 |
|
|
import javax.swing.JPanel; |
40 |
|
|
import javax.swing.JScrollPane; |
41 |
|
|
|
42 |
|
|
import net.sf.juife.EnhancedDialog; |
43 |
|
|
import net.sf.juife.JuifeUtils; |
44 |
|
|
|
45 |
|
|
import net.sf.juife.event.TaskEvent; |
46 |
|
|
import net.sf.juife.event.TaskListener; |
47 |
|
|
|
48 |
|
|
import org.jsampler.CC; |
49 |
|
|
import org.jsampler.task.CreateAudioDevice; |
50 |
|
|
|
51 |
|
|
import org.linuxsampler.lscp.AudioOutputDriver; |
52 |
|
|
|
53 |
|
|
import static org.jsampler.view.classic.ClassicI18n.i18n; |
54 |
|
|
import org.jsampler.view.ParameterTable; |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* |
59 |
|
|
* @author Grigor Iliev |
60 |
|
|
*/ |
61 |
|
|
public class NewAudioDeviceDlg extends EnhancedDialog { |
62 |
|
|
private final JLabel lDriver = new JLabel(i18n.getLabel("NewAudioDeviceDlg.lDriver")); |
63 |
|
|
private final JComboBox cbDrivers = new JComboBox(); |
64 |
|
|
private final ParameterTable parameterTable = new ParameterTable(); |
65 |
|
|
|
66 |
|
|
private final JButton btnCreate = |
67 |
|
|
new JButton(i18n.getButtonLabel("NewAudioDeviceDlg.btnCreate")); |
68 |
|
|
private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel")); |
69 |
|
|
|
70 |
|
|
/** Creates a new instance of NewMidiDeviceDlg */ |
71 |
|
|
public NewAudioDeviceDlg(Frame owner) { |
72 |
|
|
super(owner, i18n.getLabel("NewAudioDeviceDlg.title")); |
73 |
|
|
|
74 |
|
|
JPanel mainPane = new JPanel(); |
75 |
|
|
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
76 |
|
|
|
77 |
|
|
JPanel p = new JPanel(); |
78 |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
79 |
|
|
p.add(lDriver); |
80 |
|
|
|
81 |
|
|
parameterTable.getModel().setEditFixedParameters(true); |
82 |
|
|
|
83 |
|
|
cbDrivers.addActionListener(new ActionListener() { |
84 |
|
|
public void |
85 |
|
|
actionPerformed(ActionEvent e) { |
86 |
|
|
AudioOutputDriver d = |
87 |
|
|
(AudioOutputDriver)cbDrivers.getSelectedItem(); |
88 |
|
|
if(d == null) return; |
89 |
|
|
cbDrivers.setToolTipText(d.getDescription()); |
90 |
|
|
parameterTable.getModel().setParameters(d.getParameters()); |
91 |
|
|
} |
92 |
|
|
}); |
93 |
|
|
|
94 |
|
|
for(AudioOutputDriver d : CC.getSamplerModel().getAudioOutputDrivers()) { |
95 |
|
|
cbDrivers.addItem(d); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
cbDrivers.setMaximumSize(cbDrivers.getPreferredSize()); |
99 |
|
|
p.add(Box.createRigidArea(new Dimension(5, 0))); |
100 |
|
|
p.add(cbDrivers); |
101 |
|
|
|
102 |
|
|
p.setAlignmentX(LEFT_ALIGNMENT); |
103 |
|
|
mainPane.add(p); |
104 |
|
|
|
105 |
|
|
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
106 |
|
|
|
107 |
|
|
//parameterTable.setModel(new ParameterTableModel(CC.getSamplerModel().)); |
108 |
|
|
JScrollPane sp = new JScrollPane(parameterTable); |
109 |
|
|
sp.setAlignmentX(LEFT_ALIGNMENT); |
110 |
|
|
mainPane.add(sp); |
111 |
|
|
|
112 |
|
|
mainPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 17, 12)); |
113 |
|
|
mainPane.setPreferredSize ( |
114 |
|
|
JuifeUtils.getUnionSize(mainPane.getMinimumSize(), new Dimension(250, 200)) |
115 |
|
|
); |
116 |
|
|
add(mainPane); |
117 |
|
|
|
118 |
|
|
JPanel btnPane = new JPanel(); |
119 |
|
|
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS)); |
120 |
|
|
btnPane.add(Box.createGlue()); |
121 |
|
|
btnPane.add(btnCreate); |
122 |
|
|
btnPane.add(Box.createRigidArea(new Dimension(5, 0))); |
123 |
|
|
btnPane.add(btnCancel); |
124 |
|
|
|
125 |
|
|
btnPane.setBorder(BorderFactory.createEmptyBorder(0, 12, 12, 12)); |
126 |
|
|
add(btnPane, BorderLayout.SOUTH); |
127 |
|
|
|
128 |
|
|
pack(); |
129 |
|
|
|
130 |
|
|
setLocation(JuifeUtils.centerLocation(this, getOwner())); |
131 |
|
|
|
132 |
|
|
btnCancel.addActionListener(new ActionListener() { |
133 |
|
|
public void |
134 |
|
|
actionPerformed(ActionEvent e) { onCancel(); } |
135 |
|
|
}); |
136 |
|
|
|
137 |
|
|
btnCreate.addActionListener(new ActionListener() { |
138 |
|
|
public void |
139 |
|
|
actionPerformed(ActionEvent e) { onOk(); } |
140 |
|
|
}); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
protected void |
144 |
|
|
onOk() { |
145 |
|
|
Object obj = cbDrivers.getSelectedItem(); |
146 |
|
|
if(obj == null) { |
147 |
|
|
JOptionPane.showMessageDialog ( |
148 |
|
|
this, i18n.getMessage("NewAudioDeviceDlg.selectDriver!"), |
149 |
|
|
"", |
150 |
|
|
JOptionPane.INFORMATION_MESSAGE |
151 |
|
|
); |
152 |
|
|
|
153 |
|
|
return; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
btnCreate.setEnabled(false); |
157 |
|
|
|
158 |
|
|
AudioOutputDriver driver = (AudioOutputDriver)obj; |
159 |
|
|
|
160 |
|
|
final CreateAudioDevice cad = |
161 |
|
|
new CreateAudioDevice(driver.getName(), driver.getParameters()); |
162 |
|
|
|
163 |
|
|
cad.addTaskListener(new TaskListener() { |
164 |
|
|
public void |
165 |
|
|
taskPerformed(TaskEvent e) { |
166 |
|
|
btnCreate.setEnabled(true); |
167 |
|
|
setVisible(false); |
168 |
|
|
} |
169 |
|
|
}); |
170 |
|
|
|
171 |
|
|
CC.getTaskQueue().add(cad); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
protected void |
175 |
|
|
onCancel() { setVisible(false); } |
176 |
|
|
} |