View Javadoc

1   /* -------------------------------------------------------------------
2    * Java source file for the class Tuple4fEditor
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: Tuple4fEditor.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 Tuple4fEditor                 
35  ====================================================================*/
36  /***
37   * A property editor for editing Tuple4f.
38   * 
39   * @version $Revision: 1.3 $
40   * @author Masahiro Takatsuka (masa@jbeans.net)
41   * @see EditorSupport
42   */
43  
44  public abstract class Tuple4fEditor extends EditorSupport {
45      private JTextField xTF;
46      private JTextField yTF;
47      private JTextField zTF;
48      private JTextField wTF;		
49  
50      public Tuple4fEditor() {
51          this.xTF = new JTextField();
52          this.xTF.setDocument(new NumberDocument());
53          this.yTF = new JTextField();
54          this.yTF.setDocument(new NumberDocument());
55          this.zTF = new JTextField();
56          this.zTF.setDocument(new NumberDocument());
57          this.wTF = new JTextField();
58          this.wTF.setDocument(new NumberDocument());
59  
60          JPanel panel = new JPanel();
61          panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
62          panel.add(new JLabel("X: "));
63          panel.add(this.xTF);
64          panel.add(new JLabel("Y: "));
65          panel.add(this.yTF);
66          panel.add(new JLabel("Z: "));
67          panel.add(this.zTF);
68          panel.add(new JLabel("W: "));
69          panel.add(this.wTF);
70  		setPanel(panel);
71      }
72  
73      public void setValue(Object value)  {
74          super.setValue(value);
75  
76  		String x = "" + 0;
77  		String y = "" + 0;
78  		String z = "" + 0;
79  		String w = "" + 0;		
80  		if (value != null) {
81  			Tuple4f point = (Tuple4f) value;
82  			x = Float.toString(point.x);
83  			y = Float.toString(point.y);
84  			z = Float.toString(point.z);
85  			w = Float.toString(point.w);						
86  		}
87          this.xTF.setText(x);
88  		this.yTF.setText(y);
89  		this.zTF.setText(z);
90  		this.zTF.setText(w);		
91      }
92  
93      public Object getValue()  {
94          float x = Float.parseFloat(this.xTF.getText());
95          float y = Float.parseFloat(this.yTF.getText());
96          float z = Float.parseFloat(this.zTF.getText());
97  		float w = Float.parseFloat(this.wTF.getText());		
98          
99          return new Vector4f(x, y, z, w);
100     }
101 	
102     public String getJavaInitializationString() {
103 		Tuple4f point = (Tuple4f) getValue();
104         return "new javax.vecmath.Tuple4f(" + point.x + ", " + point.y + ", " + point.z + ", " + point.w + ")";
105     }
106 }