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
23 import camera3d.*;
24 import camera3d.event.*;
25 import javax.swing.*;
26 import java.awt.*;
27 import java.awt.event.*;
28 import javax.media.j3d.*;
29 import javax.vecmath.*;
30 import camera3d.action.TransformAction;
31
32 /***
33 * Pane for editing VcObject parameters.
34 *
35 * @author Fábio Roberto de Miranda
36 * @version 1.0
37 * @see camera3d.VcObject
38 */
39 class VcObjectEditionPane extends JPanel implements VcObjectChangeListener, DoubleValueChangeListener {
40 private VcObject vcObject;
41 private GUIControl guiControl;
42 private JLabel positionLabel = new JLabel();
43 private DoubleDigitalControl xPosControl = new DoubleDigitalControl();
44 private DoubleDigitalControl yPosControl = new DoubleDigitalControl();
45 private DoubleDigitalControl zPosControl = new DoubleDigitalControl();
46 private JLabel xPosLabel = new JLabel();
47 private JLabel yPosLabel = new JLabel();
48 private JLabel zPosLabel = new JLabel();
49 private JLabel rotLabel = new JLabel();
50 private DoubleDigitalControl xAngleControl = new DoubleDigitalControl();
51 private DoubleDigitalControl yAngleControl = new DoubleDigitalControl();
52 private DoubleDigitalControl zAngleControl = new DoubleDigitalControl();
53 private JLabel xPosLabel1 = new JLabel();
54 private JLabel yPosLabel1 = new JLabel();
55 private JLabel zPosLabel1 = new JLabel();
56 private JLabel scalLabel = new JLabel();
57 private JLabel xPosLabel2 = new JLabel();
58 private JLabel yPosLabel2 = new JLabel();
59 private JLabel zPosLabel2 = new JLabel();
60 private DoubleDigitalControl xScaleControl = new DoubleDigitalControl();
61 private DoubleDigitalControl yScaleControl = new DoubleDigitalControl();
62 private DoubleDigitalControl zScaleControl = new DoubleDigitalControl();
63 private JLabel titleLabel = new JLabel();
64 private JLabel nameLabel = new JLabel();
65 private JTextField nameTxt = new JTextField();
66
67 private boolean isListeningDigitalControls = true;
68
69 private JCheckBox jScaleCheckBox = new JCheckBox();
70 private JCheckBox relativeCheckBox = new JCheckBox();
71
72 VcObjectEditionPane(GUIControl guiControl) {
73 this();
74 this.guiControl = guiControl;
75 }
76
77 /*
78 * Sets the object this VcObjectEditionPane will edit
79 */
80 void setVcObject(VcObject vcObject){
81 releaseObjects();
82 this.vcObject = vcObject;
83 vcObject.addChangeListener(this);
84 updateTranslationControlsIncrement();
85 updateData();
86 }
87
88 void updateData(){
89 /*
90 * During the time data is being updated, we
91 * must stop answering to events of changed digitalControls,
92 * so that we don't generate new actions. We do this because this is tipically
93 * a situation where the VcObjectEditionPane is notified that something has
94 * changed in the listened VcObject, and not a case of changing the VcObject in response to
95 * user's inputs
96 */
97 setDigitalControlsListening(false);
98 nameTxt.setText(vcObject.getLabel());
99 debugln("VcObjectEditionPane.updateData():Positional info extracted from VcObject {");
100 xPosControl.setValue(vcObject.getXTranslation());
101 yPosControl.setValue(vcObject.getYTranslation());
102 zPosControl.setValue(vcObject.getZTranslation());
103 // change to deg methods
104 xAngleControl.setValue(vcObject.getXAngleDeg());
105 yAngleControl.setValue(vcObject.getYAngleDeg());
106 zAngleControl.setValue(vcObject.getZAngleDeg());
107 ///
108 xScaleControl.setValue(vcObject.getXScale());
109 yScaleControl.setValue(vcObject.getYScale());
110 zScaleControl.setValue(vcObject.getZScale());
111 /*
112 debugln(vcObject.getXTranslation()+",");
113 debugln(vcObject.getYTranslation()+",");
114 debugln(vcObject.getZTranslation()+",");
115 debugln(vcObject.getXAngle()+",");
116 debugln(vcObject.getYAngle()+",");
117 debugln(vcObject.getZAngle()+",");
118 debugln(vcObject.getXScale()+",");
119 debugln(vcObject.getYScale()+",");
120 debugln(vcObject.getZScale()+"}");
121 */
122 setDigitalControlsListening(true);
123
124 if (relativeCheckBox.isSelected()){
125 vcObject.setOngoingTransformationMode(TransformMode.RELATIVE);
126 } else {
127 vcObject.setOngoingTransformationMode(TransformMode.ABSOLUTE);
128 }
129
130
131 }
132
133 private void setDigitalControlsListening(boolean flag){
134 this.isListeningDigitalControls = flag;
135 }
136
137
138 VcObjectEditionPane() {
139 try {
140 jbInit();
141 }
142 catch(Exception e) {
143 e.printStackTrace();
144 }
145 }
146 private void jbInit() throws Exception {
147 positionLabel.setText("Position");
148 positionLabel.setBounds(new Rectangle(13, 165, 48, 19));
149 this.setLayout(null);
150 xPosLabel.setForeground(Color.red);
151 xPosLabel.setText("X");
152 xPosLabel.setBounds(new Rectangle(7, 184, 22, 23));
153 yPosLabel.setForeground(new Color(0, 150, 0));
154 yPosLabel.setText("Y");
155 yPosLabel.setBounds(new Rectangle(7, 246, 20, 17));
156 zPosLabel.setForeground(Color.blue);
157 zPosLabel.setText("Z");
158 zPosLabel.setBounds(new Rectangle(7, 298, 20, 17));
159 rotLabel.setText("Rotation ");
160 rotLabel.setBounds(new Rectangle(112, 166, 59, 17));
161 xPosLabel1.setForeground(Color.red);
162 xPosLabel1.setText("X");
163 xPosLabel1.setBounds(new Rectangle(112, 184, 22, 23));
164 yPosLabel1.setForeground(new Color(0, 150, 0));
165 yPosLabel1.setText("Y");
166 yPosLabel1.setBounds(new Rectangle(112, 246, 20, 17));
167 zPosLabel1.setForeground(Color.blue);
168 zPosLabel1.setText("Z");
169 zPosLabel1.setBounds(new Rectangle(112, 298, 20, 17));
170 scalLabel.setText("Scale");
171 scalLabel.setBounds(new Rectangle(7, 377, 69, 24));
172 xPosLabel2.setForeground(Color.red);
173 xPosLabel2.setText("X");
174 xPosLabel2.setBounds(new Rectangle(7, 414, 16, 23));
175 yPosLabel2.setForeground(new Color(0, 150, 0));
176 yPosLabel2.setText("Y");
177 yPosLabel2.setBounds(new Rectangle(7, 451, 17, 17));
178 zPosLabel2.setForeground(Color.blue);
179 zPosLabel2.setText("Z");
180 zPosLabel2.setBounds(new Rectangle(7, 488, 16, 17));
181 titleLabel.setText("Basic parameters");
182 titleLabel.setBounds(new Rectangle(16, 16, 172, 25));
183 nameLabel.setText("Name");
184 nameLabel.setBounds(new Rectangle(15, 53, 50, 22));
185 this.setName("");
186 this.setBorder(BorderFactory.createEtchedBorder());
187 this.setMinimumSize(new Dimension(150, 525));
188 this.setPreferredSize(new Dimension(150, 525));
189
190 zScaleControl.setBounds(new Rectangle(29, 475, 72, 41));
191 yScaleControl.setBounds(new Rectangle(29, 437, 71, 38));
192 xScaleControl.setBounds(new Rectangle(29, 401, 72, 36));
193 zAngleControl.setBounds(new Rectangle(112, 315, 66, 35));
194 zPosControl.setBounds(new Rectangle(7, 315, 78, 35));
195 yAngleControl.setBounds(new Rectangle(112, 263, 67, 35));
196 yPosControl.setBounds(new Rectangle(7, 263, 78, 35));
197 xAngleControl.setBounds(new Rectangle(112, 207, 68, 39));
198 xPosControl.setBounds(new Rectangle(7, 207, 78, 39));
199 nameTxt.setBounds(new Rectangle(14, 76, 153, 26));
200 nameTxt.addActionListener(new java.awt.event.ActionListener() {
201 public void actionPerformed(ActionEvent e) {
202 nameTxt_actionPerformed(e);
203 }
204 });
205 jScaleCheckBox.setSelected(true);
206 jScaleCheckBox.setText("Uniform scale");
207 jScaleCheckBox.setBounds(new Rectangle(52, 381, 121, 18));
208 relativeCheckBox.setText("Relative transformations");
209 relativeCheckBox.setFont(new java.awt.Font("Dialog", 1, 10));
210 relativeCheckBox.setBounds(new Rectangle(11, 130, 159, 25));
211 relativeCheckBox.addActionListener(new java.awt.event.ActionListener() {
212 public void actionPerformed(ActionEvent e) {
213 relativeCheckBox_actionPerformed(e);
214 }
215 });
216 this.add(titleLabel, null);
217 this.add(nameTxt, null);
218 this.add(nameLabel, null);
219 this.add(xScaleControl, null);
220 this.add(yScaleControl, null);
221 this.add(zScaleControl, null);
222 this.add(zPosLabel2, null);
223 this.add(yPosLabel2, null);
224 this.add(xPosLabel2, null);
225 this.add(scalLabel, null);
226 this.add(jScaleCheckBox, null);
227 this.add(zAngleControl, null);
228 this.add(yAngleControl, null);
229 this.add(zPosLabel, null);
230 this.add(zPosControl, null);
231 this.add(xPosLabel, null);
232 this.add(rotLabel, null);
233 this.add(xAngleControl, null);
234 this.add(yPosLabel, null);
235 this.add(yPosLabel1, null);
236 this.add(xPosControl, null);
237 this.add(positionLabel, null);
238 this.add(yPosControl, null);
239 this.add(zPosLabel1, null);
240 this.add(xPosLabel1, null);
241 this.add(relativeCheckBox, null);
242 addListenerToControls();
243 }
244
245 void nameTxt_actionPerformed(ActionEvent e) {
246 /* Put here the code that renames the object as necessary*/
247 String oldName = vcObject.getLabel();
248 String newName = nameTxt.getText();
249 guiControl.renameVcObject(oldName, newName);
250 }
251
252 void setGUIControl(GUIControl guiControl){
253 this.guiControl = guiControl;
254 }
255
256 /***
257 * Removes this from all objects whose listeners constains this object
258 */
259 private void releaseObjects(){
260 if (vcObject != null){
261 vcObject.removeChangeListener(this);
262 }
263 }
264
265
266 public void vcObjectChanged(VcObjectEvent event){
267 if(event.getSource()==this.vcObject){
268 /*
269 * During the time data is being updated, we
270 * must stop answering to events of changed digitalControls,
271 * so that we don't generate new actions. We do this because this is tipically
272 * a situation where the VcObjectEditionPane is notified that something has
273 * changed in the listened VcObject, and not a case of changing the VcObject in response to
274 * user's inputs
275 */
276 setDigitalControlsListening(false);
277 switch(event.getType()){
278 case VcObjectEvent.LABEL_CHANGED:
279 nameTxt.setText(vcObject.getLabel());
280 break;
281 case VcObjectEvent.TRANSLATION_CHANGED:
282 xPosControl.setValue(vcObject.getXTranslation());
283 yPosControl.setValue(vcObject.getYTranslation());
284 zPosControl.setValue(vcObject.getZTranslation());
285 break;
286 case VcObjectEvent.ROTATION_CHANGED:
287 if(!relativeCheckBox.isSelected()&&vcObject.isInvalidData()){
288 xAngleControl.setValue(vcObject.getXAngleDeg());
289 yAngleControl.setValue(vcObject.getYAngleDeg());
290 zAngleControl.setValue(vcObject.getZAngleDeg());
291 }
292 break;
293 case VcObjectEvent.SCALE_CHANGED:
294 xScaleControl.setValue(vcObject.getXScale());
295 yScaleControl.setValue(vcObject.getYScale());
296 zScaleControl.setValue(vcObject.getZScale());
297 break;
298 case VcObjectEvent.TRANSFORM_CHANGED:
299 updateData();
300 break;
301 }
302 setDigitalControlsListening(true);
303 }
304 }
305
306 public void valueChanged(DoubleChangeEvent ev){
307 TransformMode mode = TransformMode.ABSOLUTE;
308 if (relativeCheckBox.isSelected()){
309 mode = TransformMode.RELATIVE;
310 }
311 if (isListeningDigitalControls){
312 if (((DoubleDigitalControl)ev.getSource()).equals(xPosControl)){
313 // fire change in x coordinate
314 double value = findValue(xPosControl);
315 guiControl.translateX(mode, vcObject, value);
316 }
317
318 if (((DoubleDigitalControl)ev.getSource()).equals(yPosControl)){
319 // fire change in y coordinate
320 double value = findValue(yPosControl);
321 guiControl.translateY(mode, vcObject, value);
322 }
323
324 if (((DoubleDigitalControl)ev.getSource()).equals(zPosControl)){
325 // fire change in y coordinate
326 double value = findValue(zPosControl);
327 guiControl.translateZ(mode, vcObject, value);
328
329 }
330
331 if (((DoubleDigitalControl)ev.getSource()).equals(xAngleControl)){
332 // fire change in x coordinate
333 double value = findValue(xAngleControl);
334 guiControl.rotateX(mode, vcObject, Math.toRadians(value));
335 }
336
337 if (((DoubleDigitalControl)ev.getSource()).equals(yAngleControl)){
338 // fire change in y coordinate
339 double value = findValue(yAngleControl);
340 guiControl.rotateY(mode, vcObject, Math.toRadians(value));
341 }
342
343 if (((DoubleDigitalControl)ev.getSource()).equals(zAngleControl)){
344 // fire change in z coordinate
345 double value = findValue(zAngleControl);
346 guiControl.rotateZ(mode, vcObject, Math.toRadians(value));
347 }
348
349 if (((DoubleDigitalControl)ev.getSource()).equals(xScaleControl)){
350 // fire change in x coordinate
351 double value = xScaleControl.getValue();
352 if (jScaleCheckBox.isSelected()){
353 guiControl.scale(mode, vcObject, value);
354 } else {
355 guiControl.scaleX(mode, vcObject, value);
356 }
357 }
358
359 if (((DoubleDigitalControl)ev.getSource()).equals(yScaleControl)){
360 // fire change in y coordinate
361 double value = yScaleControl.getValue();
362 if (jScaleCheckBox.isSelected()){
363 guiControl.scale(mode, vcObject, value);
364 } else {
365 guiControl.scaleY(mode, vcObject, value);
366 }
367 }
368
369 if (((DoubleDigitalControl)ev.getSource()).equals(zScaleControl)){
370 // fire change in z coordinate
371 double value = zScaleControl.getValue();
372 if (jScaleCheckBox.isSelected()){
373 guiControl.scale(mode, vcObject, value);
374 } else {
375 guiControl.scaleZ(mode, vcObject, value);
376 }
377 }
378
379
380 }
381 }
382
383 void debugln(String s){
384 if (GUIControl.debugflag){
385 System.out.println(s);
386 }
387 }
388
389 private void addListenerToControls(){
390 xAngleControl.setIncrementStep(1.0);
391 yAngleControl.setIncrementStep(1.0);
392 zAngleControl.setIncrementStep(1.0);
393 xScaleControl.setIncrementStep(0.5);
394 yScaleControl.setIncrementStep(0.5);
395 zScaleControl.setIncrementStep(0.5);
396 xPosControl.addValueChangeListener(this);
397 yPosControl.addValueChangeListener(this);
398 zPosControl.addValueChangeListener(this);
399 xAngleControl.addValueChangeListener(this);
400 yAngleControl.addValueChangeListener(this);
401 zAngleControl.addValueChangeListener(this);
402 xScaleControl.addValueChangeListener(this);
403 yScaleControl.addValueChangeListener(this);
404 zScaleControl.addValueChangeListener(this);
405 }
406
407 void relativeCheckBox_actionPerformed(ActionEvent e) {
408 if (relativeCheckBox.isSelected()){
409 debugln("relative selected");
410 updateData(); // Chamado só para mandar os objetos redesenharem seus eixos
411 /***
412 * Como o updateData parou de funcionar, mandarei o objeto desenhar seus eixos na mão
413 */
414 resetControls();
415 } else {
416 debugln("relative not selected");
417 resetControls();
418 updateData();
419 }
420
421 if (relativeCheckBox.isSelected()){
422 vcObject.setOngoingTransformationMode(TransformMode.RELATIVE);
423 } else {
424 vcObject.setOngoingTransformationMode(TransformMode.ABSOLUTE);
425 }
426
427 }
428
429 void resetControls(){
430 boolean tempBoolean = this.isListeningDigitalControls;
431 this.isListeningDigitalControls = false;
432
433 xPosControl.setValue(0.0);
434 xPosControl.resetDelta();
435
436 yPosControl.setValue(0.0);
437 yPosControl.resetDelta();
438
439 zPosControl.setValue(0.0);
440 zPosControl.resetDelta();
441
442 xAngleControl.setValue(0.0);
443 xAngleControl.resetDelta();
444
445 yAngleControl.setValue(0.0);
446 yAngleControl.resetDelta();
447
448 zAngleControl.setValue(0.0);
449 zAngleControl.resetDelta();
450
451 xScaleControl.setValue(1.0);
452 xScaleControl.resetDelta();
453
454 yScaleControl.setValue(1.0);
455 yScaleControl.resetDelta();
456
457 zScaleControl.setValue(1.0);
458 zScaleControl.resetDelta();
459
460 this.isListeningDigitalControls = tempBoolean;
461 }
462
463 /*
464 * Based on the length of the diagonal of the bounding box of an object,
465 * sets the increment step for the translation controls
466 */
467 void updateTranslationControlsIncrement(){
468 DimensionsManager.getDimensionsManager().computeTranslationControlsIncrement(vcObject);
469 double incrementFactor = DimensionsManager.getDimensionsManager().getTranslationIncrement();
470 xPosControl.setIncrementStep(incrementFactor);
471 yPosControl.setIncrementStep(incrementFactor);
472 zPosControl.setIncrementStep(incrementFactor);
473 }
474
475 double findValue(DoubleDigitalControl control){
476 if (relativeCheckBox.isSelected()){
477 return control.getDelta();
478 } else {
479 return control.getValue();
480 }
481 }
482 }
This page was automatically generated by Maven