/[svn]/jsampler/trunk/src/org/jsampler/view/classic/InstrumentChooser.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/classic/InstrumentChooser.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 787 - (hide annotations) (download)
Mon Oct 10 16:03:12 2005 UTC (18 years, 6 months ago) by iliev
File size: 4034 byte(s)
* The first alpha-release of JSampler

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.Dimension;
26     import java.awt.Frame;
27     import java.awt.GridBagConstraints;
28     import java.awt.GridBagLayout;
29     import java.awt.Insets;
30    
31     import java.awt.event.ActionEvent;
32     import java.awt.event.ActionListener;
33    
34     import javax.swing.JButton;
35     import javax.swing.JFileChooser;
36     import javax.swing.JLabel;
37     import javax.swing.JOptionPane;
38     import javax.swing.JPanel;
39     import javax.swing.JSpinner;
40     import javax.swing.JTextField;
41     import javax.swing.SpinnerNumberModel;
42    
43     import net.sf.juife.OkCancelDialog;
44    
45     import static org.jsampler.view.classic.ClassicI18n.i18n;
46    
47    
48     /**
49     *
50     * @author Grigor Iliev
51     */
52     public class InstrumentChooser extends OkCancelDialog {
53     private final JLabel lFilename = new JLabel(i18n.getLabel("InstrumentChooser.lFilename"));
54     private final JLabel lIndex = new JLabel(i18n.getLabel("InstrumentChooser.lIndex"));
55    
56     private final JTextField tfFilename = new JTextField();
57     private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1));
58    
59     private final JButton btnBrowse =
60     new JButton(i18n.getLabel("InstrumentChooser.btnBrowse"));
61    
62     /** Creates a new instance of InstrumentChooser */
63     public InstrumentChooser(Frame owner) {
64     super(owner, i18n.getLabel("InstrumentChooser.title"));
65    
66     GridBagLayout gridbag = new GridBagLayout();
67     GridBagConstraints c = new GridBagConstraints();
68    
69     JPanel mainPane = new JPanel();
70    
71     mainPane.setLayout(gridbag);
72    
73     c.fill = GridBagConstraints.NONE;
74    
75     c.gridx = 0;
76     c.gridy = 0;
77     c.anchor = GridBagConstraints.EAST;
78     c.insets = new Insets(3, 3, 3, 3);
79     gridbag.setConstraints(lFilename, c);
80     mainPane.add(lFilename);
81    
82     c.gridx = 0;
83     c.gridy = 1;
84     gridbag.setConstraints(lIndex, c);
85     mainPane.add(lIndex);
86    
87     c.gridx = 2;
88     c.gridy = 0;
89     gridbag.setConstraints(btnBrowse, c);
90     mainPane.add(btnBrowse);
91    
92     c.fill = GridBagConstraints.HORIZONTAL;
93     c.gridx = 1;
94     c.gridy = 0;
95     c.weightx = 1.0;
96     c.anchor = GridBagConstraints.WEST;
97     gridbag.setConstraints(tfFilename, c);
98     mainPane.add(tfFilename);
99    
100     c.gridx = 1;
101     c.gridy = 1;
102     gridbag.setConstraints(spinnerIndex, c);
103     mainPane.add(spinnerIndex);
104    
105     tfFilename.setPreferredSize (
106     new Dimension(200, tfFilename.getPreferredSize().height)
107     );
108    
109     setMainPane(mainPane);
110    
111     btnBrowse.addActionListener(new ActionListener() {
112     public void
113     actionPerformed(ActionEvent e) { onBrowse(); }
114     });
115     }
116    
117     protected void
118     onOk() {
119     if(tfFilename.getText().length() == 0) {
120     JOptionPane.showMessageDialog (
121     this, i18n.getLabel("InstrumentChooser.selectFile"),
122     "",
123     JOptionPane.INFORMATION_MESSAGE
124     );
125    
126     return;
127     }
128    
129     setVisible(false);
130     }
131    
132     protected void
133     onCancel() { setVisible(false); }
134    
135     private void
136     onBrowse() {
137     JFileChooser fc = new JFileChooser();
138     int result = fc.showOpenDialog(this);
139     if(result == JFileChooser.APPROVE_OPTION) {
140     tfFilename.setText(fc.getSelectedFile().getPath());
141     }
142     }
143    
144     /**
145     * Gets the name of the selected instrument file.
146     * @return The name of the selected instrument file.
147     */
148     public String
149     getFileName() { return tfFilename.getText(); }
150    
151     public int
152     getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); }
153     }

  ViewVC Help
Powered by ViewVC