/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSAddOrEditOrchestraDlg.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSAddOrEditOrchestraDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1286 - (show annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 9 months ago) by iliev
File size: 4416 byte(s)
- Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

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.std;
24
25 import java.awt.Dimension;
26 import java.awt.GridBagConstraints;
27 import java.awt.GridBagLayout;
28 import java.awt.Insets;
29
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
33
34 import javax.swing.event.DocumentEvent;
35 import javax.swing.event.DocumentListener;
36
37 import net.sf.juife.OkCancelDialog;
38
39 import org.jsampler.CC;
40 import org.jsampler.DefaultOrchestraModel;
41 import org.jsampler.OrchestraModel;
42
43 import static org.jsampler.view.std.StdI18n.i18n;
44
45
46 /**
47 *
48 * @author Grigor Iliev
49 */
50 public class JSAddOrEditOrchestraDlg extends OkCancelDialog {
51 private final JLabel lName = new JLabel(i18n.getLabel("JSAddOrEditOrchestraDlg.lName"));
52 private final JLabel lDesc = new JLabel(i18n.getLabel("JSAddOrEditOrchestraDlg.lDesc"));
53
54 private final JTextField tfName = new JTextField();
55 private final JTextField tfDesc = new JTextField();
56
57 private OrchestraModel orchestraModel;
58
59
60 /**
61 * Creates a new instance of <code>JSAddOrEditOrchestraDlg</code>.
62 */
63 public JSAddOrEditOrchestraDlg() { this(new DefaultOrchestraModel()); }
64
65 /**
66 * Creates a new instance of <code>JSAddOrEditOrchestraDlg</code>.
67 *
68 * @param orchestra The orchestra model to modify.
69 */
70 public JSAddOrEditOrchestraDlg(OrchestraModel orchestra) {
71 super(CC.getMainFrame(), i18n.getLabel("JSAddOrEditOrchestraDlg.title"));
72
73 orchestraModel = orchestra;
74
75 JPanel p = new JPanel();
76
77 GridBagLayout gridbag = new GridBagLayout();
78 GridBagConstraints c = new GridBagConstraints();
79
80 p.setLayout(gridbag);
81
82 c.fill = GridBagConstraints.NONE;
83
84 c.gridx = 0;
85 c.gridy = 0;
86 c.anchor = GridBagConstraints.EAST;
87 c.insets = new Insets(3, 3, 3, 3);
88 gridbag.setConstraints(lName, c);
89 p.add(lName);
90
91 c.gridx = 0;
92 c.gridy = 1;
93 gridbag.setConstraints(lDesc, c);
94 p.add(lDesc);
95
96 c.fill = GridBagConstraints.HORIZONTAL;
97 c.gridx = 1;
98 c.gridy = 0;
99 c.weightx = 1.0;
100 c.anchor = GridBagConstraints.WEST;
101 gridbag.setConstraints(tfName, c);
102 p.add(tfName);
103
104 c.gridx = 1;
105 c.gridy = 1;
106 gridbag.setConstraints(tfDesc, c);
107 p.add(tfDesc);
108
109 setMainPane(p);
110
111 int w = getPreferredSize().width;
112 Dimension d = new Dimension(w > 400 ? w : 400, getPreferredSize().height);
113 setPreferredSize(d);
114 pack();
115
116 setLocationRelativeTo(getOwner());
117
118 btnOk.setEnabled(false);
119 tfName.getDocument().addDocumentListener(getHandler());
120
121 updateInfo();
122 updateState();
123 }
124
125 private void
126 updateInfo() {
127 tfName.setText(getOrchestra().getName());
128 tfDesc.setText(getOrchestra().getDescription());
129 }
130
131 private void
132 updateState() {
133 boolean b = true;
134 if(tfName.getText().length() == 0) b = false;
135
136 btnOk.setEnabled(b);
137 }
138
139 protected void
140 onOk() {
141 if(!btnOk.isEnabled()) return;
142
143 orchestraModel.setName(tfName.getText());
144 orchestraModel.setDescription(tfDesc.getText());
145 setVisible(false);
146
147 setCancelled(false);
148 }
149
150 protected void
151 onCancel() {
152 setVisible(false);
153 }
154
155 /**
156 * Gets the newly created orchestra.
157 * @return The newly created orchestra or <code>null</code> if
158 * the Cancel button is pressed.
159 */
160 public OrchestraModel
161 getOrchestra() { return orchestraModel; }
162
163 private final Handler eventHandler = new Handler();
164
165 private Handler
166 getHandler() { return eventHandler; }
167
168 private class Handler implements DocumentListener {
169 // DocumentListener
170 public void
171 insertUpdate(DocumentEvent e) { updateState(); }
172
173 public void
174 removeUpdate(DocumentEvent e) { updateState(); }
175
176 public void
177 changedUpdate(DocumentEvent e) { updateState(); }
178 }
179 }

  ViewVC Help
Powered by ViewVC