1 package org.devaki.nextobjects.ui.workspace.models.objects;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.awt.Dimension;
22 import java.awt.GridBagConstraints;
23 import java.awt.GridBagLayout;
24 import java.awt.Insets;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.FocusAdapter;
28 import java.awt.event.FocusEvent;
29 import javax.swing.JDialog;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.JTabbedPane;
34 import javax.swing.SwingConstants;
35 import javax.swing.WindowConstants;
36 import org.devaki.nextobjects.NextObjects;
37 import org.devaki.nextobjects.ui.components.CustomButton;
38 import org.devaki.nextobjects.ui.components.CustomTextArea;
39 import org.devaki.nextobjects.ui.components.CustomTextField;
40 import org.devaki.nextobjects.workspace.models.objects.Label;
41 /***
42 * Edit a note on the models
43 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
44 */
45 public class LabelEdit extends JDialog
46 {
47 /***
48 * the label
49 */
50 private Label myLabel;
51 /***
52 * the ok button
53 */
54 private CustomButton jButtonOK = new CustomButton("OK", "", true, false);
55 /***
56 * the cancel button
57 */
58 private CustomButton jButtonCancel =
59 new CustomButton("Cancel", "", true, false);
60 /***
61 * jlabel name
62 */
63 private JLabel jLabelName = new JLabel("Name");
64 /***
65 * jlabel description
66 */
67 private JLabel jLabelDescription = new JLabel("Description");
68 /***
69 * jtextfield name
70 */
71 private CustomTextField jTextFieldName =
72 new CustomTextField("", "Name of the association in the schema", true);
73 /***
74 * jtextarea description
75 */
76 private CustomTextArea jTextAreaDescription =
77 new CustomTextArea("", "Description of the association", true, true);
78 /***
79 * the tablbed pane
80 */
81 private JTabbedPane jTabbedPane = new JTabbedPane(SwingConstants.TOP);
82 /***
83 * the unique panel
84 */
85 private JPanel jPanelNotes = new JPanel(new GridBagLayout());
86 /***
87 * Create a new 'LabelEdit' object
88 */
89 public LabelEdit()
90 {
91 super(NextObjects.getReference());
92 this.jLabelDescription.setBorder(null);
93 this.jLabelName.setBorder(null);
94
95
96 this.setSize(new Dimension(475, 500));
97
98 this.setLocationRelativeTo(null);
99
100 this.setModal(true);
101
102 this.setResizable(false);
103
104 this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
105
106
107
108 this.getContentPane().setLayout(new GridBagLayout());
109
110
111
112 this.jTextFieldName.addFocusListener(new FocusAdapter()
113 {
114
115 public final void focusGained(final FocusEvent e)
116 {
117 jTextFieldName.selectAll();
118 }
119 });
120 this.jButtonOK.addActionListener(new ActionListener()
121 {
122
123 public final void actionPerformed(final ActionEvent e)
124 {
125 closingWindow(true);
126 }
127 });
128 this.jButtonCancel.addActionListener(new ActionListener()
129 {
130
131 public final void actionPerformed(final ActionEvent e)
132 {
133 closingWindow(false);
134 }
135 });
136
137 this.jPanelNotes.add(
138 this.jLabelName,
139 new GridBagConstraints(
140 0,
141 0,
142 1,
143 1,
144 0.0,
145 0.0,
146 GridBagConstraints.NORTH,
147 GridBagConstraints.BOTH,
148 new Insets(5, 5, 5, 5),
149 0,
150 0));
151 this.jPanelNotes.add(
152 this.jTextFieldName,
153 new GridBagConstraints(
154 1,
155 0,
156 1,
157 1,
158 0.0,
159 0.0,
160 GridBagConstraints.NORTH,
161 GridBagConstraints.BOTH,
162 new Insets(5, 5, 5, 5),
163 0,
164 0));
165
166 jTextAreaDescription.setLineWrap(true);
167 jTextAreaDescription.setWrapStyleWord(true);
168 this.jPanelNotes.add(
169 new JScrollPane(
170 this.jTextAreaDescription,
171 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
172 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER),
173 new GridBagConstraints(
174 0,
175 1,
176 2,
177 2,
178 1.0,
179 1.0,
180 GridBagConstraints.CENTER,
181 GridBagConstraints.BOTH,
182 new Insets(5, 5, 5, 5),
183 0,
184 0));
185 this.jTabbedPane.add(this.jPanelNotes, "Notes");
186
187 this.getContentPane().add(
188 this.jTabbedPane,
189 new GridBagConstraints(
190 0,
191 0,
192 2,
193 1,
194 1.0,
195 1.0,
196 GridBagConstraints.CENTER,
197 GridBagConstraints.BOTH,
198 new Insets(5, 5, 0, 5),
199 0,
200 0));
201 this.getContentPane().add(
202 this.jButtonOK,
203 new GridBagConstraints(
204 0,
205 1,
206 1,
207 1,
208 1.0,
209 0.0,
210 GridBagConstraints.EAST,
211 GridBagConstraints.NONE,
212 new Insets(5, 5, 5, 5),
213 0,
214 0));
215 this.getContentPane().add(
216 this.jButtonCancel,
217 new GridBagConstraints(
218 1,
219 1,
220 1,
221 1,
222 0.0,
223 0.0,
224 GridBagConstraints.CENTER,
225 GridBagConstraints.NONE,
226 new Insets(5, 0, 5, 5),
227 0,
228 0));
229 }
230 /***
231 * What to do before closing the window
232 * @param isOK can save
233 */
234 private void closingWindow(final boolean isOK)
235 {
236
237 if (isOK)
238 {
239 this.saveData();
240 }
241
242
243 this.dispose();
244 }
245 /***
246 * Initialize window components with the data of the object given as
247 * parameter of the constructor
248 * @param pLabel the context label
249 */
250 public final void setData(final Label pLabel)
251 {
252
253 this.setTitle(
254 new StringBuffer()
255 .append("Properties of '")
256 .append(pLabel.getName())
257 .append("' - devaki-nextobjects")
258 .toString());
259
260 this.myLabel = pLabel;
261 this.jTextFieldName.setText(pLabel.getName());
262 this.jTextAreaDescription.setText(pLabel.getNotes());
263
264 this.jTabbedPane.setSelectedIndex(0);
265
266 this.getRootPane().setDefaultButton(this.jButtonOK);
267
268 this.show();
269 }
270 /***
271 * Save the informations into the edited object
272 */
273 private void saveData()
274 {
275 this.myLabel.setName(this.jTextFieldName.getText());
276 this.myLabel.setNotes(this.jTextAreaDescription.getText());
277
278 myLabel.getMyModel().getModelView().setFullRefresh(true);
279 myLabel.getMyModel().getModelView().drawingArea.repaint();
280 }
281 }