1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, Joćo E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software 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 GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d.gui;
21
22 import javax.swing.*;
23 import java.awt.*;
24 import camera3d.event.*;
25 import camera3d.*;
26 import java.awt.event.*;
27
28
29
30 /***
31 * Pane for editing VcLaserArray specific parameters.
32 *
33 * @author Carlos da Silva dos Santos
34 * @see camera3d.VcLaserArray
35 */
36 class VcLaserArrayEditionPane extends JPanel implements VcObjectChangeListener,DoubleValueChangeListener,IntValueChangeListener{
37
38 private boolean isListeningDigitalControls = true;
39
40 private JLabel laserLabel = new JLabel();
41 private GUIControl guiControl;
42
43 private VcLaserArray laserArray;
44
45 private DoubleDigitalControl redControl = new DoubleDigitalControl();
46 private DoubleDigitalControl greenControl = new DoubleDigitalControl();
47 private DoubleDigitalControl blueControl = new DoubleDigitalControl();
48 private DoubleDigitalControl sizeControl = new DoubleDigitalControl();
49 private IntDigitalControl xControl = new IntDigitalControl();
50 private IntDigitalControl yControl = new IntDigitalControl();
51 private DoubleDigitalControl dxControl = new DoubleDigitalControl();
52 private DoubleDigitalControl dyControl = new DoubleDigitalControl();
53
54 private JLabel redLabel = new JLabel();
55 private JLabel greenLabel = new JLabel();
56 private JLabel colorLabel = new JLabel();
57 private JLabel blueLabel = new JLabel();
58 private JLabel sizeLabel = new JLabel();
59 private JLabel nbeamsLabel = new JLabel();
60 private JLabel nxLabel = new JLabel();
61 private JLabel nyLabel = new JLabel();
62
63 private int intValue;
64 private double doubleValue;
65 private JLabel distanceLabel = new JLabel();
66 private JLabel dxLabel = new JLabel();
67 private JLabel dyLabel = new JLabel();
68 private JButton gridButton = new JButton();
69 private JCheckBox updatingCheckBox = new JCheckBox();
70 private JLabel gridLabel = new JLabel();
71 private GridBagLayout gridBagLayout1 = new GridBagLayout();
72
73 VcLaserArrayEditionPane() {
74 try {
75 jbInit();
76 }
77 catch(Exception e) {
78 e.printStackTrace();
79 }
80 }
81
82
83
84 private void jbInit() throws Exception {
85 laserLabel.setText("Laser Array");
86 this.setMinimumSize(new Dimension(210, 600));
87 this.setPreferredSize(new Dimension(210, 600));
88 this.setLayout(gridBagLayout1);
89 redLabel.setFont(new java.awt.Font("Dialog", 1, 12));
90 redLabel.setForeground(Color.red);
91 redLabel.setText("R");
92 greenLabel.setFont(new java.awt.Font("Dialog", 1, 12));
93 greenLabel.setForeground(Color.green);
94 greenLabel.setText("G");
95 colorLabel.setText("Color");
96 blueLabel.setFont(new java.awt.Font("Dialog", 1, 12));
97 blueLabel.setForeground(Color.blue);
98 blueLabel.setText("B");
99 sizeLabel.setText("Spot Size");
100 nbeamsLabel.setText("Number of Beams");
101 nxLabel.setFont(new java.awt.Font("Dialog", 1, 12));
102 nxLabel.setForeground(Color.red);
103 nxLabel.setText("X");
104 nyLabel.setFont(new java.awt.Font("Dialog", 1, 12));
105 nyLabel.setForeground(Color.green);
106 nyLabel.setText("Y");
107 distanceLabel.setText("Distance");
108 dxLabel.setFont(new java.awt.Font("Dialog", 1, 12));
109 dxLabel.setForeground(Color.red);
110 dxLabel.setText("X");
111 dyLabel.setFont(new java.awt.Font("Dialog", 1, 12));
112 dyLabel.setForeground(Color.green);
113 dyLabel.setText("Y");
114 gridButton.setText("set Grid");
115 gridButton.addActionListener(new java.awt.event.ActionListener() {
116 public void actionPerformed(ActionEvent e) {
117 gridButton_actionPerformed(e);
118 }
119 });
120 updatingCheckBox.setText("Disable updating");
121 updatingCheckBox.addActionListener(new java.awt.event.ActionListener() {
122 public void actionPerformed(ActionEvent e) {
123 updatingCheckBox_actionPerformed(e);
124 }
125 });
126 gridLabel.setText("Grid");
127 this.add(colorLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
128 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 12, 0, 36), 4, 6));
129 this.add(redLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
130 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(9, 12, 0, 57), 5, 0));
131 this.add(laserLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
132 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 8, 14), 2, 0));
133 this.add(gridLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
134 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 12, 0, 21), 26, 7));
135 this.add(updatingCheckBox, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0
136 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 38), 0, 0));
137 this.add(sizeControl, new GridBagConstraints(0, 5, 1, 1, 1.0, 1.0
138 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 3, 0, 8), 69, 30));
139 this.add(sizeLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
140 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 3, 0, 19), 8, 8));
141 this.add(redControl, new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0
142 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 0, 0), 71, 32));
143 this.add(greenControl, new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0
144 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11, 0, 0, 0), 74, 31));
145 this.add(greenLabel, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
146 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 0, 0, 61), 6, 0));
147 this.add(blueControl, new GridBagConstraints(2, 3, 1, 1, 1.0, 1.0
148 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(12, 0, 0, 11), 72, 30));
149 this.add(blueLabel, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
150 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(11, 0, 0, 70), 6, 0));
151 this.add(dxLabel, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0
152 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 45), 14, 1));
153 this.add(distanceLabel, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0
154 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(19, 14, 0, 13), 6, 11));
155 this.add(nxLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
156 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(16, 15, 0, 45), 14, -1));
157 this.add(nyLabel, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0
158 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(15, 6, 0, 53), 9, 1));
159 this.add(gridButton, new GridBagConstraints(1, 13, 2, 1, 0.0, 0.0
160 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(18, 6, 24, 72), 4, 1));
161 this.add(yControl, new GridBagConstraints(1, 9, 1, 1, 1.0, 1.0
162 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 74, 37));
163 this.add(xControl, new GridBagConstraints(0, 9, 1, 1, 1.0, 1.0
164 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 3, 0, 0), 77, 36));
165 this.add(dxControl, new GridBagConstraints(0, 12, 1, 1, 1.0, 1.0
166 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 10, 0, 7), 64, 40));
167 this.add(dyLabel, new GridBagConstraints(1, 11, 1, 1, 0.0, 0.0
168 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 47), 15, 2));
169 this.add(dyControl, new GridBagConstraints(1, 12, 1, 1, 1.0, 1.0
170 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 9), 65, 39));
171 this.add(nbeamsLabel, new GridBagConstraints(0, 7, 2, 1, 0.0, 0.0
172 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 0, 44), 7, 3));
173 redControl.addValueChangeListener(this);
174 greenControl.addValueChangeListener(this);
175 blueControl.addValueChangeListener(this);
176 sizeControl.addValueChangeListener(this);
177 xControl.addValueChangeListener(this);
178 yControl.addValueChangeListener(this);
179 dxControl.addValueChangeListener(this);
180 dyControl.addValueChangeListener(this);
181 }
182
183 void debugln(String s){
184 if (GUIControl.debugflag){
185 System.out.println(s);
186 }
187 }
188
189
190 void setLaserArray(VcLaserArray array){
191 this.laserArray = array;
192 array.addChangeListener(this);
193 updateData();
194 }
195
196 public void updateData(){
197 /*
198 * During the time data is being updated, we
199 * must stop answering to events of changed digitalControls,
200 * so that we don't generate new actions. We do this because this is tipically
201 * a situation where the VcObjectEditionPane is notified that something has
202 * changed in the listened VcObject, and not a case of changing the VcObject in response to
203 * user's inputs
204 */
205 setDigitalControlsListening(false);
206
207 xControl.setValue(laserArray.getXBeams());
208 yControl.setValue(laserArray.getYBeams());
209 dxControl.setValue(laserArray.getXDelta());
210 dyControl.setValue(laserArray.getYDelta());
211 sizeControl.setValue(laserArray.getTargetScale());
212 redControl.setValue(laserArray.getRed());
213 greenControl.setValue(laserArray.getGreen());
214 blueControl.setValue(laserArray.getBlue());
215
216 setDigitalControlsListening(true);
217 }
218
219 void setGUIControl(GUIControl guiControl){
220 this.guiControl = guiControl;
221 }
222
223
224 public void vcObjectChanged(VcObjectEvent event){
225 if(event.getSource()==laserArray){
226 if(event.getType()==VcObjectEvent.LASER_ARRAY_CHANGED){
227 /*
228 * During the time data is being updated, we
229 * must stop answering to events of changed digitalControls,
230 * so that we don't generate new actions. We do this because this is tipically
231 * a situation where the VcObjectEditionPane is notified that something has
232 * changed in the listened VcObject, and not a case of changing the VcObject in response to
233 * user's inputs
234 */
235 setDigitalControlsListening(false);
236
237 xControl.setValue(laserArray.getXBeams());
238 yControl.setValue(laserArray.getYBeams());
239 dxControl.setValue(laserArray.getXDelta());
240 dyControl.setValue(laserArray.getYDelta());
241 sizeControl.setValue(laserArray.getTargetScale());
242 redControl.setValue(laserArray.getRed());
243 greenControl.setValue(laserArray.getGreen());
244 blueControl.setValue(laserArray.getBlue());
245
246 setDigitalControlsListening(true);
247 }
248 }
249 }
250
251
252 private void setDigitalControlsListening(boolean flag){
253 this.isListeningDigitalControls = flag;
254 }
255
256 public void valueChanged(DoubleChangeEvent ev){
257 if (isListeningDigitalControls){
258 debugln("VcLaserArray Pane: Listening Digital controls");
259 Object src = ev.getSource();
260 if (src ==(Object)dxControl){
261 if(dxControl.getValue()<0.01) dxControl.setValue(0.01d);
262 debugln("updating dx control");
263 } else if (src ==(Object)dyControl){
264 debugln("updating dy control");
265 if(dyControl.getValue()<0.01) dyControl.setValue(0.01d);
266 } else if (src ==(Object)redControl || src ==(Object)greenControl
267 || src ==(Object)blueControl){
268 guiControl.changeLaserArrayColor(laserArray,redControl.getValue(),
269 greenControl.getValue(),
270 blueControl.getValue());
271 } else if (src ==(Object)sizeControl){
272 guiControl.changeLaserSpotSize(laserArray,sizeControl.getValue());
273 }
274 }
275 }
276
277 public void valueChanged(IntChangeEvent ev){
278 if (ev.getSource()==((Object)xControl)){
279 if (xControl.getValue()<1) xControl.setValue(1);
280 } else if (ev.getSource()==((Object)yControl)){
281 if (yControl.getValue()<1) yControl.setValue(1);
282 }
283 }
284
285
286 void gridButton_actionPerformed(ActionEvent e) {
287 if(xControl.getValue()<1) xControl.setValue(1);
288 if(yControl.getValue()<1) yControl.setValue(1);
289 if(dxControl.getValue()<0.01) dxControl.setValue(0.01d);
290 if(dyControl.getValue()<0.01) dyControl.setValue(0.01d);
291 if(guiControl!=null){
292 guiControl.setLaserArrayGrid(laserArray,xControl.getValue(),yControl.getValue(),dxControl.getValue(),dyControl.getValue());
293 }
294 }
295
296 void updatingCheckBox_actionPerformed(ActionEvent e) {
297 if(updatingCheckBox.isSelected()){
298 laserArray.setEnable(false);
299 }else laserArray.setEnable(true);
300 }
301
302
303 }
This page was automatically generated by Maven