1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.devaki.nextobjects.ui.workspace.models.styles;
22
23 import java.awt.Dimension;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import javax.swing.JColorChooser;
30 import javax.swing.JDialog;
31 import javax.swing.JPanel;
32 import javax.swing.JTabbedPane;
33 import javax.swing.SwingConstants;
34 import javax.swing.WindowConstants;
35 import org.devaki.nextobjects.NextObjects;
36 import org.devaki.nextobjects.constants.CstGraphics;
37 import org.devaki.nextobjects.ui.components.CustomButton;
38 import org.devaki.nextobjects.workspace.models.graphics.AssociationLinkView;
39 import org.devaki.nextobjects.workspace.models.graphics.ConstraintView;
40 import org.devaki.nextobjects.workspace.models.graphics.ObjectView;
41 import org.devaki.nextobjects.workspace.models.styles.LineStyle;
42
43 /***
44 * This class is responsible for creating the window which manage the style of
45 * all line-like objects
46 *
47 */
48 public class LineStyleEdit extends JDialog
49 {
50 /***
51 * Reference of the style currently edited
52 */
53 private LineStyle myLineStyle;
54
55 /***
56 * Reference of the object currently edited
57 */
58 private ObjectView myObjectView;
59
60 /***
61 * jButtonReset
62 */
63 private CustomButton jButtonReset= new CustomButton("Reset", "Reset to default values", true, false);
64
65 /***
66 * jButtonOK
67 */
68 private CustomButton jButtonOK= new CustomButton("OK", "", true, false);
69
70 /***
71 * jButtonCancel
72 */
73 private CustomButton jButtonCancel= new CustomButton("Cancel", "", true, false);
74
75 /***
76 * jTabbedPane
77 */
78
79 private JTabbedPane jTabbedPane= new JTabbedPane(SwingConstants.TOP);
80
81 /***
82 * l jPanelLine
83 */
84 private JPanel jPanelLine= new JPanel(new GridBagLayout());
85
86 /***
87 * jColorChooserLine
88 */
89 private JColorChooser jColorChooserLine= new JColorChooser();
90
91 /***
92 * Contruct a new window editor for the style of a line-like object
93 * @param pObjectView the context object view
94 */
95 public LineStyleEdit(ObjectView pObjectView)
96 {
97
98 super(NextObjects.getReference());
99 this.myObjectView= pObjectView;
100
101 this.setSize(new Dimension(475, 500));
102
103 this.setLocationRelativeTo(null);
104
105 this.setModal(true);
106
107 this.setResizable(false);
108
109 this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
110
111
112
113 this.getContentPane().setLayout(new GridBagLayout());
114
115
116
117 this.jButtonReset.addActionListener(new ActionListener()
118 {
119 public void actionPerformed(ActionEvent e)
120 {
121 reset();
122 }
123 });
124 this.jButtonOK.addActionListener(new ActionListener()
125 {
126 public void actionPerformed(ActionEvent e)
127 {
128 closingWindow(true);
129 }
130 });
131 this.jButtonCancel.addActionListener(new ActionListener()
132 {
133 public void actionPerformed(ActionEvent e)
134 {
135 closingWindow(false);
136 }
137 });
138
139
140
141 this.jTabbedPane.add(this.jPanelLine, "Line");
142
143 this.jPanelLine.add(
144 jColorChooserLine,
145 new GridBagConstraints(
146 0,
147 0,
148 1,
149 1,
150 1.0,
151 1.0,
152 GridBagConstraints.CENTER,
153 GridBagConstraints.BOTH,
154 new Insets(5, 5, 5, 5),
155 0,
156 0));
157
158 this.getContentPane().add(
159 this.jTabbedPane,
160 new GridBagConstraints(
161 0,
162 0,
163 3,
164 1,
165 1.0,
166 1.0,
167 GridBagConstraints.CENTER,
168 GridBagConstraints.BOTH,
169 new Insets(5, 5, 0, 5),
170 0,
171 0));
172 this.getContentPane().add(
173 this.jButtonReset,
174 new GridBagConstraints(
175 0,
176 1,
177 1,
178 1,
179 1.0,
180 0.0,
181 GridBagConstraints.WEST,
182 GridBagConstraints.NONE,
183 new Insets(5, 5, 5, 5),
184 0,
185 0));
186 this.getContentPane().add(
187 this.jButtonOK,
188 new GridBagConstraints(
189 1,
190 1,
191 1,
192 1,
193 0.0,
194 0.0,
195 GridBagConstraints.CENTER,
196 GridBagConstraints.NONE,
197 new Insets(5, 0, 5, 5),
198 0,
199 0));
200 this.getContentPane().add(
201 this.jButtonCancel,
202 new GridBagConstraints(
203 2,
204 1,
205 1,
206 1,
207 0.0,
208 0.0,
209 GridBagConstraints.CENTER,
210 GridBagConstraints.NONE,
211 new Insets(5, 0, 5, 5),
212 0,
213 0));
214 }
215
216 /***
217 * What to do before closing the window
218 * @param isOK a boolean
219 */
220 private void closingWindow(boolean isOK)
221 {
222
223 if (isOK)
224 {
225 this.saveData();
226 }
227
228
229 this.dispose();
230 }
231
232 /***
233 * Set the informations
234 * @param pLineStyle the context line style
235 */
236 public void setData(LineStyle pLineStyle)
237 {
238
239 this.setTitle(
240 new StringBuffer()
241 .append("Format of '")
242 .append(pLineStyle.getMyObjectView().getBaseObject().getName())
243 .append("' - nextObjects")
244 .toString());
245
246 this.myLineStyle= pLineStyle;
247
248 this.jColorChooserLine.setColor(this.myLineStyle.getLineColor());
249
250
251
252 if (this.jTabbedPane.getTabCount() != 0)
253 {
254 this.jTabbedPane.setSelectedIndex(0);
255 }
256
257
258 this.getRootPane().setDefaultButton(this.jButtonOK);
259
260
261 this.show();
262 }
263
264 /***
265 * Save the information
266 */
267 private void saveData()
268 {
269 this.myLineStyle.setLineColor(this.jColorChooserLine.getColor());
270 }
271
272 /***
273 * Reset format of the object to its default values.
274 */
275 private void reset()
276 {
277 if (this.myObjectView instanceof AssociationLinkView)
278 this.jColorChooserLine.setColor(CstGraphics.DEFAULT_ASSOCIATIONLINK_COLOR);
279 else if (this.myObjectView instanceof ConstraintView)
280 this.jColorChooserLine.setColor(CstGraphics.DEFAULT_CONSTRAINT_COLOR);
281 else
282 this.jColorChooserLine.setColor(CstGraphics.DEFAULT_INHERITANCELINK_COLOR);
283 }
284 }