1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
35
36 /***
37 * A property editor for editing Tuple2f.
38 *
39 * @version $Revision: 1.3 $
40 * @author Masahiro Takatsuka (masa@jbeans.net)
41 * @see EditorSupport
42 */
43
44 public abstract class Tuple2fEditor extends EditorSupport {
45 private JTextField xTF;
46 private JTextField yTF;
47 private JTextField zTF;
48
49 public Tuple2fEditor() {
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 setPanel(panel);
64 }
65
66 public void setValue(Object value) {
67 super.setValue(value);
68
69 String x = "" + 0;
70 String y = "" + 0;
71 if (value != null) {
72 Tuple2f point = (Tuple2f) value;
73 x = Float.toString(point.x);
74 y = Float.toString(point.y);
75 }
76 this.xTF.setText(x);
77 this.yTF.setText(y);
78 }
79
80 public Object getValue() {
81 float x = Float.parseFloat(this.xTF.getText());
82 float y = Float.parseFloat(this.yTF.getText());
83
84 return new Vector2f(x, y);
85 }
86
87 public String getJavaInitializationString() {
88 Tuple2f point = (Tuple2f) getValue();
89 return "new javax.vecmath.Tuple2f(" + point.x + ", " + point.y + ")";
90 }
91 }