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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 912 - (hide annotations) (download)
Mon Aug 7 18:34:40 2006 UTC (17 years, 8 months ago) by iliev
File size: 4240 byte(s)
* updating to JSampler 0.3a

1 iliev 912 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005, 2006 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.fantasia;
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.fantasia.FantasiaI18n.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 JTextField tfIndex = new JTextField("0");
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     tfIndex.setHorizontalAlignment(JTextField.RIGHT);
101     c.gridx = 1;
102     c.gridy = 1;
103     gridbag.setConstraints(tfIndex, c);
104     mainPane.add(tfIndex);
105    
106     tfFilename.setPreferredSize (
107     new Dimension(200, tfFilename.getPreferredSize().height)
108     );
109    
110     setMainPane(mainPane);
111    
112     btnBrowse.addActionListener(new ActionListener() {
113     public void
114     actionPerformed(ActionEvent e) { onBrowse(); }
115     });
116    
117     btnBrowse.requestFocusInWindow();
118     }
119    
120     protected void
121     onOk() {
122     if(tfFilename.getText().length() == 0) {
123     JOptionPane.showMessageDialog (
124     this, i18n.getLabel("InstrumentChooser.selectFile"),
125     "",
126     JOptionPane.INFORMATION_MESSAGE
127     );
128    
129     return;
130     }
131    
132     setVisible(false);
133     }
134    
135     protected void
136     onCancel() { setVisible(false); }
137    
138     private void
139     onBrowse() {
140     JFileChooser fc = new JFileChooser();
141     int result = fc.showOpenDialog(this);
142     if(result == JFileChooser.APPROVE_OPTION) {
143     tfFilename.setText(fc.getSelectedFile().getPath());
144     btnOk.requestFocusInWindow();
145     }
146     }
147    
148     /**
149     * Gets the name of the selected instrument file.
150     * @return The name of the selected instrument file.
151     */
152     public String
153     getFileName() { return tfFilename.getText(); }
154    
155     /**
156     * Gets the index of the instrument in the instrument file.
157     * @return The index of the instrument in the instrument file.
158     */
159     public int
160     getInstrumentIndex() { return Integer.parseInt(tfIndex.getText()); }
161     }

  ViewVC Help
Powered by ViewVC