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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 842 - (show annotations) (download)
Thu Mar 16 18:08:34 2006 UTC (18 years ago) by iliev
File size: 4241 byte(s)
Updating to version 0.2a

1 /*
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 btnBrowse.requestFocusInWindow();
117 }
118
119 protected void
120 onOk() {
121 if(tfFilename.getText().length() == 0) {
122 JOptionPane.showMessageDialog (
123 this, i18n.getLabel("InstrumentChooser.selectFile"),
124 "",
125 JOptionPane.INFORMATION_MESSAGE
126 );
127
128 return;
129 }
130
131 setVisible(false);
132 }
133
134 protected void
135 onCancel() { setVisible(false); }
136
137 private void
138 onBrowse() {
139 JFileChooser fc = new JFileChooser();
140 int result = fc.showOpenDialog(this);
141 if(result == JFileChooser.APPROVE_OPTION) {
142 tfFilename.setText(fc.getSelectedFile().getPath());
143 btnOk.requestFocusInWindow();
144 }
145 }
146
147 /**
148 * Gets the name of the selected instrument file.
149 * @return The name of the selected instrument file.
150 */
151 public String
152 getFileName() { return tfFilename.getText(); }
153
154 /**
155 * Gets the index of the instrument in the instrument file.
156 * @return The index of the instrument in the instrument file.
157 */
158 public int
159 getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); }
160 }

  ViewVC Help
Powered by ViewVC