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 Tuple3i.
38 *
39 * @version $Revision: 1.3 $
40 * @author Masahiro Takatsuka (masa@jbeans.net)
41 * @see EditorSupport
42 */
43
44 public abstract class Tuple3iEditor extends EditorSupport {
45 private JTextField xTF;
46 private JTextField yTF;
47 private JTextField zTF;
48
49 public Tuple3iEditor() {
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 Tuple3i point = (Tuple3i) value;
76 x = Integer.toString(point.x);
77 y = Integer.toString(point.y);
78 z = Integer.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 int x = Integer.parseInt(this.xTF.getText());
87 int y = Integer.parseInt(this.yTF.getText());
88 int z = Integer.parseInt(this.zTF.getText());
89
90 return new Point3i(x, y, z);
91 }
92
93 public String getJavaInitializationString() {
94 Tuple3i point = (Tuple3i) getValue();
95 return "new javax.vecmath.Tuple3i(" + point.x + ", " + point.y + ", " + point.z + ")";
96 }
97 }