1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2011 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 |
package org.jsampler.view.std; |
23 |
|
24 |
import java.awt.Dimension; |
25 |
import javax.swing.Box; |
26 |
import javax.swing.BoxLayout; |
27 |
import javax.swing.JComboBox; |
28 |
import javax.swing.JFrame; |
29 |
import javax.swing.JLabel; |
30 |
import javax.swing.JPanel; |
31 |
import javax.swing.JSpinner; |
32 |
import javax.swing.SpinnerNumberModel; |
33 |
import net.sf.juife.OkCancelDialog; |
34 |
import org.jsampler.CC; |
35 |
import org.linuxsampler.lscp.EffectParameter; |
36 |
import org.linuxsampler.lscp.FloatParameter; |
37 |
|
38 |
/** |
39 |
* |
40 |
* @author Grigor IlievJSSetParameterDlg |
41 |
*/ |
42 |
public class JSSetParameterDlg extends OkCancelDialog { |
43 |
private FloatValuePanel pane; |
44 |
|
45 |
public |
46 |
JSSetParameterDlg(EffectParameter param) { |
47 |
this(CC.getMainFrame(), param); |
48 |
} |
49 |
|
50 |
public |
51 |
JSSetParameterDlg(JFrame owner, EffectParameter param) { |
52 |
super(owner); |
53 |
pane = new FloatValuePanel(param, param.getDescription()); |
54 |
|
55 |
if(pane.spValue != null) pane.spValue.requestFocusInWindow(); |
56 |
|
57 |
setMainPane(pane); |
58 |
} |
59 |
|
60 |
protected void |
61 |
onOk() { |
62 |
if(!btnOk.isEnabled()) return; |
63 |
|
64 |
setVisible(false); |
65 |
setCancelled(false); |
66 |
} |
67 |
|
68 |
protected void |
69 |
onCancel() { setVisible(false); } |
70 |
|
71 |
public float |
72 |
getNewValue() { return pane.getValue(); } |
73 |
|
74 |
public static class FloatValuePanel extends JPanel { |
75 |
private final FloatParameter param; |
76 |
private final JLabel lName = new JLabel(); |
77 |
|
78 |
private JComboBox cbValue = null; |
79 |
private JSpinner spValue = null; |
80 |
|
81 |
public FloatValuePanel(FloatParameter p, String name) { |
82 |
this.param = p; |
83 |
lName.setText(name); |
84 |
|
85 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
86 |
add(lName); |
87 |
add(Box.createRigidArea(new Dimension(6, 0))); |
88 |
|
89 |
// TODO: uncomment when fixed on back-end |
90 |
/*if(param.hasPossibilities()) { |
91 |
cbValue = new JComboBox(); |
92 |
|
93 |
for(Float f : param.getPossibilities()) { |
94 |
cbValue.addItem(f); |
95 |
} |
96 |
|
97 |
add(cbValue); |
98 |
} else*/ { |
99 |
double val, min, max; |
100 |
val = p.getValue().floatValue(); |
101 |
min = p.hasRangeMin() ? p.getRangeMin().floatValue() : Float.MIN_VALUE; |
102 |
max = p.hasRangeMax() ? p.getRangeMax().floatValue() : Float.MAX_VALUE; |
103 |
|
104 |
spValue = new JSpinner(new SpinnerNumberModel(val, min, max, 1.0)); |
105 |
int w = spValue.getPreferredSize().width; |
106 |
if(w > 200) { |
107 |
int h = spValue.getPreferredSize().height; |
108 |
spValue.setPreferredSize(new Dimension(200, h)); |
109 |
} |
110 |
add(spValue); |
111 |
} |
112 |
} |
113 |
|
114 |
public float |
115 |
getValue() { |
116 |
if(cbValue != null) return (Float)cbValue.getSelectedItem(); |
117 |
|
118 |
return ((Double)spValue.getValue()).floatValue(); |
119 |
} |
120 |
} |
121 |
} |