/[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 1143 - (show annotations) (download)
Mon Apr 2 21:18:31 2007 UTC (17 years, 1 month ago) by iliev
File size: 4379 byte(s)
* upgrading to version 0.4a

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

  ViewVC Help
Powered by ViewVC