1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2008 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.Dimension; |
26 |
|
27 |
import javax.swing.BorderFactory; |
28 |
import javax.swing.Box; |
29 |
import javax.swing.BoxLayout; |
30 |
import javax.swing.JLabel; |
31 |
import javax.swing.JPanel; |
32 |
import javax.swing.JSpinner; |
33 |
import javax.swing.SpinnerNumberModel; |
34 |
|
35 |
import net.sf.juife.OkCancelDialog; |
36 |
|
37 |
import org.jsampler.CC; |
38 |
import org.jsampler.HF; |
39 |
|
40 |
import static org.jsampler.view.std.StdI18n.i18n; |
41 |
|
42 |
/** |
43 |
* |
44 |
* @author Grigor Iliev |
45 |
*/ |
46 |
public class JSPianoRollPrefsDlg extends OkCancelDialog { |
47 |
private final MainPane mainPane = new MainPane(); |
48 |
|
49 |
public |
50 |
JSPianoRollPrefsDlg() { |
51 |
super(CC.getMainFrame(), i18n.getLabel("JSPianoRollPrefsDlg.title")); |
52 |
btnOk.setText(i18n.getButtonLabel("apply")); |
53 |
|
54 |
setMainPane(mainPane); |
55 |
btnOk.requestFocus(); |
56 |
} |
57 |
|
58 |
protected void |
59 |
onOk() { |
60 |
if(!btnOk.isEnabled()) return; |
61 |
|
62 |
try { mainPane.apply(); } |
63 |
catch(Exception x) { HF.showErrorMessage(x); return; } |
64 |
|
65 |
setVisible(false); |
66 |
setCancelled(false); |
67 |
} |
68 |
|
69 |
protected void |
70 |
onCancel() { setVisible(false); } |
71 |
|
72 |
public static class MainPane extends JPanel { |
73 |
private final JLabel lFromKey = |
74 |
new JLabel(i18n.getLabel("JSPianoRollPrefsDlg.lFromKey")); |
75 |
|
76 |
private final JLabel lToKey = |
77 |
new JLabel(i18n.getLabel("JSPianoRollPrefsDlg.lToKey")); |
78 |
|
79 |
private final JLabel lHeight = |
80 |
new JLabel(i18n.getLabel("JSPianoRollPrefsDlg.lHeight")); |
81 |
|
82 |
private final JSpinner spinnerFirstKey; |
83 |
private final JSpinner spinnerLastKey; |
84 |
|
85 |
private final JSpinner spinnerHeight; |
86 |
|
87 |
public |
88 |
MainPane() { |
89 |
spinnerFirstKey = new JSpinner(new SpinnerNumberModel(0, 0, 127, 1)); |
90 |
spinnerLastKey = new JSpinner(new SpinnerNumberModel(0, 0, 127, 1)); |
91 |
spinnerHeight = new JSpinner(new SpinnerNumberModel(80, 80, 300, 1)); |
92 |
|
93 |
int i = CC.preferences().getIntProperty("midiKeyboard.firstKey"); |
94 |
spinnerFirstKey.setValue(i); |
95 |
|
96 |
i = CC.preferences().getIntProperty("midiKeyboard.lastKey"); |
97 |
spinnerLastKey.setValue(i); |
98 |
|
99 |
i = CC.preferences().getIntProperty("midiKeyboard.height"); |
100 |
spinnerHeight.setValue(i); |
101 |
|
102 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
103 |
|
104 |
JPanel p = new JPanel(); |
105 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
106 |
p.add(lFromKey); |
107 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
108 |
p.add(spinnerFirstKey); |
109 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
110 |
p.add(lToKey); |
111 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
112 |
p.add(spinnerLastKey); |
113 |
p.setAlignmentX(LEFT_ALIGNMENT); |
114 |
add(p); |
115 |
|
116 |
String s = i18n.getLabel("JSPianoRollPrefsDlg.keyRange"); |
117 |
p.setBorder(BorderFactory.createTitledBorder(s)); |
118 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, p.getPreferredSize().height)); |
119 |
|
120 |
add(Box.createRigidArea(new Dimension(0, 6))); |
121 |
|
122 |
p = new JPanel(); |
123 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
124 |
p.add(lHeight); |
125 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
126 |
p.add(spinnerHeight); |
127 |
p.setAlignmentX(LEFT_ALIGNMENT); |
128 |
add(p); |
129 |
} |
130 |
|
131 |
public void |
132 |
apply() throws Exception { |
133 |
int i = Integer.parseInt(spinnerFirstKey.getValue().toString()); |
134 |
int j = Integer.parseInt(spinnerLastKey.getValue().toString()); |
135 |
|
136 |
if(i < 0 || i > 127 || j < 0 || j > 127 || i >= j) { |
137 |
String s = i18n.getError("JSPianoRollPrefsDlg.invalidKeyRange!"); |
138 |
throw new Exception(s); |
139 |
} |
140 |
|
141 |
if(j - i < 31) { |
142 |
int k = j - i + 1; |
143 |
String s = i18n.getError("JSPianoRollPrefsDlg.tooSmallKeyRange!", k); |
144 |
throw new Exception(s); |
145 |
} |
146 |
|
147 |
CC.preferences().setIntProperty("midiKeyboard.firstKey", i); |
148 |
CC.preferences().setIntProperty("midiKeyboard.lastKey", j); |
149 |
|
150 |
i = Integer.parseInt(spinnerHeight.getValue().toString()); |
151 |
CC.preferences().setIntProperty("midiKeyboard.height", i); |
152 |
} |
153 |
} |
154 |
} |