GED: Arc Properties
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / ged / graphic_objects / properties / Arc.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2013 - Marcos CARDINOT
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12 package org.scilab.modules.gui.ged.graphic_objects.properties;
13
14 import java.awt.Color;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
17 import java.awt.event.FocusAdapter;
18 import java.awt.event.FocusEvent;
19
20 import javax.swing.JButton;
21 import javax.swing.JCheckBox;
22 import javax.swing.JColorChooser;
23 import javax.swing.JComboBox;
24 import javax.swing.JDialog;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27 import javax.swing.JTextField;
28 import javax.swing.JToggleButton;
29
30 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
31 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
32 import org.scilab.modules.gui.ged.ColorMapHandler;
33 import org.scilab.modules.gui.ged.ContentLayout;
34 import org.scilab.modules.gui.ged.MessagesGED;
35
36 /**
37 * Camera properties:
38 * ArcDrawingMethod
39 *
40 * @author Marcos CARDINOT <mcardinot@gmail.com>
41 */
42 public class Arc extends ContentLayout {
43     private JTextField cULP;
44     private JTextField cULPx;
45     private JTextField cULPy;
46     private JTextField cULPz;
47
48     /**
49      * Components of the property: Arc Drawing Method
50      * @param panel
51      * @param ROW
52      * @param COLUMN
53      * @param LEFTMARGIN
54      * @param UID objectID
55      */
56     public void arcDrawingMethod(JPanel panel, int ROW, int COLUMN, int LEFTMARGIN, final String UID) {
57         JLabel lArcDrawingMethod = new JLabel();
58         final JComboBox cArcDrawingMethod = new JComboBox();
59         addLabelComboBox(panel, lArcDrawingMethod, MessagesGED.arc_drawing_method,
60                                 cArcDrawingMethod, new String[] {MessagesGED.nurbs , MessagesGED.lines},
61                                 LEFTMARGIN, COLUMN, ROW++);
62         cArcDrawingMethod.addActionListener(new ActionListener() {
63             @Override
64             public void actionPerformed(ActionEvent evt) {
65                 GraphicController.getController().setProperty(
66                         UID, GraphicObjectProperties.__GO_ARC_DRAWING_METHOD__,
67                         cArcDrawingMethod.getSelectedIndex());
68             }
69         });
70         // Get the current status of the property: Arc Drawing Method
71         cArcDrawingMethod.setSelectedIndex((Integer) GraphicController.getController()
72                 .getProperty(UID, GraphicObjectProperties.__GO_ARC_DRAWING_METHOD__));
73     }
74
75     /**
76      * Components of the property: Upper Left Point
77      * @param panel
78      * @param ROW
79      * @param COLUMN
80      * @param LEFTMARGIN
81      * @param UID 
82      */
83     public void upperLeftPoint(JPanel panel, int ROW, int COLUMN, int LEFTMARGIN, final String UID) {
84         int LEFTMARGINIP = 0; //left margin - inner panel
85         int COLUMNIP = 0; //left column - inner panel
86         final JPanel pULP = new JPanel();
87         final JToggleButton bULP = new JToggleButton();
88         JLabel lULP = new JLabel();
89         JLabel lULPx = new JLabel();
90         JLabel lULPy = new JLabel();
91         JLabel lULPz = new JLabel();
92         cULP = new JTextField();
93         cULPx = new JTextField();
94         cULPy = new JTextField();
95         cULPz = new JTextField();
96
97         addInnerPanel(panel, pULP, bULP, lULP, cULP, MessagesGED.upper_left_point, ROW);
98         bULP.addActionListener(new ActionListener() {
99             @Override
100             public void actionPerformed(ActionEvent evt) {
101                 pULP.setVisible(!bULP.isSelected());
102             }
103         });
104         int rowULP = 0;
105         //ULP - X
106         addLabelTextField(pULP, lULPx, "X",
107                           cULPx, true, LEFTMARGINIP, COLUMNIP, rowULP++);
108         cULPx.addActionListener(new ActionListener() {
109             @Override
110             public void actionPerformed(ActionEvent evt) {
111                 updateULP(UID);
112             }
113         });
114         cULPx.addFocusListener(new FocusAdapter() {
115             @Override
116             public void focusLost(FocusEvent evt) {
117                 updateULP(UID);
118             }
119         });
120         //ULP - Y
121         addLabelTextField(pULP, lULPy, "Y",
122                           cULPy, true, LEFTMARGINIP, COLUMNIP, rowULP++);
123         cULPy.addActionListener(new ActionListener() {
124             @Override
125             public void actionPerformed(ActionEvent evt) {
126                 updateULP(UID);
127             }
128         });
129         cULPy.addFocusListener(new FocusAdapter() {
130             @Override
131             public void focusLost(FocusEvent evt) {
132                 updateULP(UID);
133             }
134         });
135         //ULP - Z
136         addLabelTextField(pULP, lULPz, "Z",
137                           cULPz, true, LEFTMARGINIP, COLUMNIP, rowULP++);
138         cULPz.addActionListener(new ActionListener() {
139             @Override
140             public void actionPerformed(ActionEvent evt) {
141                 updateULP(UID);
142             }
143         });
144         cULPz.addFocusListener(new FocusAdapter() {
145             @Override
146             public void focusLost(FocusEvent evt) {
147                 updateULP(UID);
148             }
149         });
150         getULP(UID);
151     }
152
153     /**
154     * Inserts the current situation of the upper left point.
155     */
156     private void titleULP() {
157         cULP.setText(" [" + cULPx.getText() + " , " + cULPy.getText()  + " , " + cULPz.getText() + "]");
158     }
159
160     /**
161     * Get status of the property: upper left point.
162     */
163     private void getULP(String UID) {
164         Double[] currentULP = (Double []) GraphicController.getController()
165                     .getProperty(UID, GraphicObjectProperties.__GO_UPPER_LEFT_POINT__);
166         cULPx.setText(currentULP[0].toString());
167         cULPy.setText(currentULP[1].toString());
168         cULPz.setText(currentULP[2].toString());
169         titleULP();
170     }
171
172     /**
173     * Updates the property: upper left point.
174     */
175     private void updateULP(String UID) {
176         try {
177             Double[] value = new Double[3];
178             value[0] = Double.parseDouble(cULPx.getText());
179             value[1] = Double.parseDouble(cULPy.getText());
180             value[2] = Double.parseDouble(cULPz.getText());
181             GraphicController.getController()
182                        .setProperty(UID, GraphicObjectProperties.__GO_UPPER_LEFT_POINT__, value);
183             titleULP();
184         } catch (NumberFormatException e) {
185             getULP(UID);
186         }
187     }
188
189     /**
190      * Components of the property: Width
191      * @param panel
192      * @param ROW
193      * @param COLUMN
194      * @param LEFTMARGIN
195      * @param UID objectID.
196      */
197     public void width(JPanel panel, int ROW, int COLUMN, int LEFTMARGIN, final String UID) {
198         JLabel lWidth = new JLabel();
199         final JTextField cWidth = new JTextField();
200
201         addLabelTextField(panel, lWidth, MessagesGED.width,
202                                  cWidth, true, LEFTMARGIN, COLUMN, ROW++);
203         cWidth.addActionListener(new ActionListener() {
204             @Override
205             public void actionPerformed(ActionEvent evt) {
206                 setWidth(cWidth, UID);
207             }
208         });
209         cWidth.addFocusListener(new FocusAdapter() {
210             @Override
211             public void focusLost(FocusEvent evt) {
212                 setWidth(cWidth, UID);
213             }
214         });
215         // Get the current status of the property: Width
216         cWidth.setText(Double.toString((Double) GraphicController.getController()
217                     .getProperty(UID, GraphicObjectProperties.__GO_WIDTH__)));
218
219     }
220
221     /**
222     * Set Width
223     * @param cWidth JTextField
224     * @param UID id
225     */
226     private void setWidth(JTextField cWidth, String UID) {
227         try {
228             GraphicController.getController().setProperty(
229                     UID,
230                     GraphicObjectProperties.__GO_WIDTH__,
231                     Double.parseDouble(cWidth.getText()));
232         } catch (NumberFormatException e) {
233             cWidth.setText(Double.toString((Double) GraphicController.getController()
234                     .getProperty(UID, GraphicObjectProperties.__GO_WIDTH__)));
235         }
236     }
237
238     /**
239      * Components of the property: Height
240      * @param panel
241      * @param ROW
242      * @param COLUMN
243      * @param LEFTMARGIN
244      * @param UID objectID.
245      */
246     public void height(JPanel panel, int ROW, int COLUMN, int LEFTMARGIN, final String UID) {
247         JLabel lHeight = new JLabel();
248         final JTextField cHeight = new JTextField();
249
250         addLabelTextField(panel, lHeight, MessagesGED.height,
251                                  cHeight, true, LEFTMARGIN, COLUMN, ROW++);
252         cHeight.addActionListener(new ActionListener() {
253             @Override
254             public void actionPerformed(ActionEvent evt) {
255                 setHeight(cHeight, UID);
256             }
257         });
258         cHeight.addFocusListener(new FocusAdapter() {
259             @Override
260             public void focusLost(FocusEvent evt) {
261                 setHeight(cHeight, UID);
262             }
263         });
264         // Get the current status of the property: Height
265         cHeight.setText(Double.toString((Double) GraphicController.getController()
266                     .getProperty(UID, GraphicObjectProperties.__GO_HEIGHT__)));
267
268     }
269
270     /**
271     * Set Width
272     * @param cHeight JTextField
273     * @param UID id
274     */
275     private void setHeight(JTextField cHeight, String UID) {
276         try {
277             GraphicController.getController().setProperty(
278                     UID,
279                     GraphicObjectProperties.__GO_HEIGHT__,
280                     Double.parseDouble(cHeight.getText()));
281         } catch (NumberFormatException e) {
282             cHeight.setText(Double.toString((Double) GraphicController.getController()
283                     .getProperty(UID, GraphicObjectProperties.__GO_HEIGHT__)));
284         }
285     }
286
287     /**
288      * Components of the property: Start Angle
289      * @param panel
290      * @param ROW
291      * @param COLUMN
292      * @param LEFTMARGIN
293      * @param UID objectID.
294      */
295     public void startAngle(JPanel panel, int ROW, int COLUMN, int LEFTMARGIN, final String UID) {
296         JLabel lStartAngle = new JLabel();
297         final JTextField cStartAngle = new JTextField();
298
299         addLabelTextField(panel, lStartAngle, MessagesGED.start_angle,
300                                  cStartAngle, true, LEFTMARGIN, COLUMN, ROW++);
301         cStartAngle.addActionListener(new ActionListener() {
302             @Override
303             public void actionPerformed(ActionEvent evt) {
304                 setStartAngle(cStartAngle, UID);
305             }
306         });
307         cStartAngle.addFocusListener(new FocusAdapter() {
308             @Override
309             public void focusLost(FocusEvent evt) {
310                 setStartAngle(cStartAngle, UID);
311             }
312         });
313         // Get the current status of the property: Start Angle
314         cStartAngle.setText(Double.toString((Double) GraphicController.getController()
315                     .getProperty(UID, GraphicObjectProperties.__GO_START_ANGLE__)));
316
317     }
318
319     /**
320     * Set Start Angle
321     * @param cStartAngle JTextField
322     * @param UID id
323     */
324     private void setStartAngle(JTextField cStartAngle, String UID) {
325         try {
326             GraphicController.getController().setProperty(
327                     UID,
328                     GraphicObjectProperties.__GO_START_ANGLE__,
329                     Double.parseDouble(cStartAngle.getText()));
330         } catch (NumberFormatException e) {
331             cStartAngle.setText(Double.toString((Double) GraphicController.getController()
332                     .getProperty(UID, GraphicObjectProperties.__GO_START_ANGLE__)));
333         }
334     }
335
336     /**
337      * Components of the property: End Angle
338      * @param panel
339      * @param ROW
340      * @param COLUMN
341      * @param LEFTMARGIN
342      * @param UID objectID.
343      */
344     public void endAngle(JPanel panel, int ROW, int COLUMN, int LEFTMARGIN, final String UID) {
345         JLabel lEndAngle = new JLabel();
346         final JTextField cEndAngle = new JTextField();
347
348         addLabelTextField(panel, lEndAngle, MessagesGED.end_angle,
349                                  cEndAngle, true, LEFTMARGIN, COLUMN, ROW++);
350         cEndAngle.addActionListener(new ActionListener() {
351             @Override
352             public void actionPerformed(ActionEvent evt) {
353                 setEndAngle(cEndAngle, UID);
354             }
355         });
356         cEndAngle.addFocusListener(new FocusAdapter() {
357             @Override
358             public void focusLost(FocusEvent evt) {
359                 setEndAngle(cEndAngle, UID);
360             }
361         });
362         // Get the current status of the property: End Angle
363         cEndAngle.setText(Double.toString((Double) GraphicController.getController()
364                     .getProperty(UID, GraphicObjectProperties.__GO_END_ANGLE__)));
365
366     }
367
368     /**
369     * Set End Angle
370     * @param cEndAngle JTextField
371     * @param UID id
372     */
373     private void setEndAngle(JTextField cEndAngle, String UID) {
374         try {
375             GraphicController.getController().setProperty(
376                     UID,
377                     GraphicObjectProperties.__GO_END_ANGLE__,
378                     Double.parseDouble(cEndAngle.getText()));
379         } catch (NumberFormatException e) {
380             cEndAngle.setText(Double.toString((Double) GraphicController.getController()
381                     .getProperty(UID, GraphicObjectProperties.__GO_END_ANGLE__)));
382         }
383     }
384 }