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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 913 - (show annotations) (download)
Mon Aug 7 18:45:48 2006 UTC (17 years, 8 months ago) by iliev
File size: 4337 byte(s)
updating to JSampler 0.3a

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

  ViewVC Help
Powered by ViewVC