/[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 2288 - (hide annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 6 months ago) by iliev
File size: 4554 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

1 iliev 1776 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2288 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1776 *
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 iliev 2288 import net.sf.juife.swing.OkCancelDialog;
36 iliev 1776
37     import org.jsampler.CC;
38 iliev 2288 import org.jsampler.view.swing.SHF;
39 iliev 1776
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 iliev 2288 super(SHF.getMainFrame(), i18n.getLabel("JSPianoRollPrefsDlg.title"));
52 iliev 1776 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 iliev 2288 catch(Exception x) { SHF.showErrorMessage(x); return; }
64 iliev 1776
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 iliev 1778 private final JLabel lHeight =
80     new JLabel(i18n.getLabel("JSPianoRollPrefsDlg.lHeight"));
81    
82 iliev 1776 private final JSpinner spinnerFirstKey;
83     private final JSpinner spinnerLastKey;
84    
85 iliev 1778 private final JSpinner spinnerHeight;
86    
87 iliev 1776 public
88     MainPane() {
89     spinnerFirstKey = new JSpinner(new SpinnerNumberModel(0, 0, 127, 1));
90     spinnerLastKey = new JSpinner(new SpinnerNumberModel(0, 0, 127, 1));
91 iliev 1778 spinnerHeight = new JSpinner(new SpinnerNumberModel(80, 80, 300, 1));
92 iliev 1776
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 iliev 1778 i = CC.preferences().getIntProperty("midiKeyboard.height");
100     spinnerHeight.setValue(i);
101 iliev 1776
102 iliev 1778 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 iliev 1776 String s = i18n.getLabel("JSPianoRollPrefsDlg.keyRange");
117 iliev 1778 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 iliev 1776 }
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 iliev 1778
150     i = Integer.parseInt(spinnerHeight.getValue().toString());
151     CC.preferences().setIntProperty("midiKeyboard.height", i);
152 iliev 1776 }
153     }
154     }

  ViewVC Help
Powered by ViewVC