View Javadoc

1   /* -------------------------------------------------------------------
2    * Java source file for the class Tuple3dEditor
3    * 
4    * Copyright (c), 2003, Masahiro Takatsuka.
5    * All Rights Researved.
6    * 
7    * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8    * $Author: takatsukam $
9    * 
10   * $Date: 2004/03/03 11:53:05 $
11   * 
12   * $Id: Tuple3dEditor.java,v 1.3 2004/03/03 11:53:05 takatsukam Exp $
13   * 
14   * Reference:		Document no:
15   * ___				___
16   * 
17   * To Do:
18   * ___
19   * 
20  ------------------------------------------------------------------- */
21  
22  /* --------------------------- Package ---------------------------- */
23  package net.jbeans.j3d.bean.property.editor;
24  
25  /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26  import java.awt.event.*;
27  import javax.swing.*;
28  import javax.vecmath.*;
29  
30  import net.jbeans.bean.property.editor.*;
31  import net.jbeans.util.text.*;
32  
33  /*====================================================================
34                  Implementation of class Tuple3dEditor                 
35  ====================================================================*/
36  /***
37   * A property editor for editing Tuple3d.
38   * 
39   * @version $Revision: 1.3 $
40   * @author Masahiro Takatsuka (masa@jbeans.net)
41   * @see EditorSupport
42   */
43  
44  public abstract class Tuple3dEditor extends EditorSupport {
45      private JTextField xTF;
46      private JTextField yTF;
47      private JTextField zTF;	
48  
49      public Tuple3dEditor() {
50          this.xTF = new JTextField();
51          this.xTF.setDocument(new NumberDocument());
52          this.yTF = new JTextField();
53          this.yTF.setDocument(new NumberDocument());
54          this.zTF = new JTextField();
55          this.zTF.setDocument(new NumberDocument());
56  
57          JPanel panel = new JPanel();
58          panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
59          panel.add(new JLabel("X: "));
60          panel.add(this.xTF);
61          panel.add(new JLabel("Y: "));
62          panel.add(this.yTF);
63          panel.add(new JLabel("Z: "));
64          panel.add(this.zTF);
65  		setPanel(panel);
66      }
67  
68      public void setValue(Object value)  {
69          super.setValue(value);
70  
71  		String x = "" + 0;
72  		String y = "" + 0;
73  		String z = "" + 0;		
74  		if (value != null) {
75  			Tuple3d point = (Tuple3d) value;
76  			x = Double.toString(point.x);
77  			y = Double.toString(point.y);
78  			z = Double.toString(point.z);			
79  		}
80          this.xTF.setText(x);
81  		this.yTF.setText(y);
82  		this.zTF.setText(z);
83      }
84  
85      public Object getValue()  {
86          double x = Double.parseDouble(this.xTF.getText());
87          double y = Double.parseDouble(this.yTF.getText());
88          double z = Double.parseDouble(this.zTF.getText());		
89          
90          return new Vector3d(x, y, z);
91      }
92  	
93      public String getJavaInitializationString() {
94  		Tuple3d point = (Tuple3d) getValue();
95          return "new javax.vecmath.Tuple3d(" + point.x + ", " + point.y + ", " + point.z + ")";
96      }
97  }