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

Annotation of /jsampler/trunk/src/org/jsampler/view/std/JSPianoRollPrefsDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1776 - (hide annotations) (download)
Thu Sep 11 18:48:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 3593 byte(s)
* Implemented virtual MIDI keyboard

1 iliev 1776 /*
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 JSpinner spinnerFirstKey;
80     private final JSpinner spinnerLastKey;
81    
82     public
83     MainPane() {
84     spinnerFirstKey = new JSpinner(new SpinnerNumberModel(0, 0, 127, 1));
85     spinnerLastKey = new JSpinner(new SpinnerNumberModel(0, 0, 127, 1));
86    
87     int i = CC.preferences().getIntProperty("midiKeyboard.firstKey");
88     spinnerFirstKey.setValue(i);
89    
90     i = CC.preferences().getIntProperty("midiKeyboard.lastKey");
91     spinnerLastKey.setValue(i);
92    
93     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
94     add(lFromKey);
95     add(Box.createRigidArea(new Dimension(6, 0)));
96     add(spinnerFirstKey);
97     add(Box.createRigidArea(new Dimension(6, 0)));
98     add(lToKey);
99     add(Box.createRigidArea(new Dimension(6, 0)));
100     add(spinnerLastKey);
101    
102     String s = i18n.getLabel("JSPianoRollPrefsDlg.keyRange");
103     setBorder(BorderFactory.createTitledBorder(s));
104     }
105    
106     public void
107     apply() throws Exception {
108     int i = Integer.parseInt(spinnerFirstKey.getValue().toString());
109     int j = Integer.parseInt(spinnerLastKey.getValue().toString());
110    
111     if(i < 0 || i > 127 || j < 0 || j > 127 || i >= j) {
112     String s = i18n.getError("JSPianoRollPrefsDlg.invalidKeyRange!");
113     throw new Exception(s);
114     }
115    
116     if(j - i < 31) {
117     int k = j - i + 1;
118     String s = i18n.getError("JSPianoRollPrefsDlg.tooSmallKeyRange!", k);
119     throw new Exception(s);
120     }
121    
122     CC.preferences().setIntProperty("midiKeyboard.firstKey", i);
123     CC.preferences().setIntProperty("midiKeyboard.lastKey", j);
124     }
125     }
126     }

  ViewVC Help
Powered by ViewVC