/Users/lyon/j4p/src/ip/raul/ObjectInfo.java
|
1 package ip.raul;
2
3 import ip.gui.dialog.MessLog;
4
5 import java.awt.*;
6 import java.awt.event.*;
7
8
9 public class ObjectInfo extends
10 Dialog implements ActionListener, ItemListener, WindowListener {
11
12 private TextField fields[];
13 private Label labels[];
14 public Choice names = new Choice();
15 private Choice texture = new Choice();
16 public Button cancelButton = new Button("Cancel");
17 public Button setButton = new Button("Set");
18 private String userInput;
19 private int fieldSize;
20 public Object3D objects[] = null;
21 public int maxTextures;
22
23 private static int colSpace = 5;
24 private static int rowSpace = 10;
25 private Panel inputPanel = new Panel();
26
27 public ObjectInfo(
28 String title,
29 Object3D _objects[], int maxObjects, int _maxTextures) {
30 super(new Frame(), title, false);
31 objects = _objects;
32 maxTextures = _maxTextures;
33 initialize(maxObjects);
34 pack();
35 show();
36 }
37
38 private void initialize(int maxObjects) {
39 fieldSize = 6;
40 fields = new TextField[12];
41
42 names.removeAll();
43 if (maxObjects >= 0) {
44 for (int i = 0; i <= maxObjects; i++)
45 names.addItem(objects[i].name);
46 names.select(names.getItem(0));
47 }
48 texture.removeAll();
49 texture.addItem("none");
50 if (maxTextures >= 0) {
51 for (int i = 0; i <= maxTextures; i++)
52 texture.addItem("Texture " + (i + 1));
53 }
54 texture.select(names.getItem(0));
55
56 if (maxObjects >= 0) {
57 fields[0] = new TextField("" + objects[0].Pos.x, fieldSize);
58 fields[1] = new TextField("" + objects[0].Pos.y, fieldSize);
59 fields[2] = new TextField("" + objects[0].Pos.z, fieldSize);
60 fields[3] = new TextField("" + objects[0].Rot.x, fieldSize);
61 fields[4] = new TextField("" + objects[0].Rot.y, fieldSize);
62 fields[5] = new TextField("" + objects[0].Rot.z, fieldSize);
63 fields[6] = new TextField("" + objects[0].Sca.x, fieldSize);
64 fields[7] = new TextField("" + objects[0].Sca.y, fieldSize);
65 fields[8] = new TextField("" + objects[0].Sca.z, fieldSize);
66 fields[9] = new TextField("" + objects[0].Cen.x, fieldSize);
67 fields[10] = new TextField("" + objects[0].Cen.y, fieldSize);
68 fields[11] = new TextField("" + objects[0].Cen.z, fieldSize);
69 texture.select(objects[0].textureIndex + 1);
70 } else
71 for (int i = 0; i < 12; i++)
72 fields[i] = new TextField("0.00", fieldSize);
73 inputPanel.setLayout(new GridLayout(5, 5, colSpace, rowSpace));
74 inputPanel.add(new Label("Names:"));
75 inputPanel.add(names);
76 inputPanel.add(new Label("Texture:"));
77 inputPanel.add(texture);
78 // inputPanel.add(new Label(" "));
79 inputPanel.add(new Label(" "));
80
81 inputPanel.add(new Label(" "));
82 inputPanel.add(new Label("Position"));
83 inputPanel.add(new Label("Rotation"));
84 inputPanel.add(new Label("Scale"));
85 inputPanel.add(new Label("Center"));
86 inputPanel.add(new Label(" X "));
87 inputPanel.add(fields[0]);
88 inputPanel.add(fields[3]);
89 inputPanel.add(fields[6]);
90 inputPanel.add(fields[9]);
91 inputPanel.add(new Label(" Y "));
92 inputPanel.add(fields[1]);
93 inputPanel.add(fields[4]);
94 inputPanel.add(fields[7]);
95 inputPanel.add(fields[10]);
96 inputPanel.add(new Label(" Z "));
97 inputPanel.add(fields[2]);
98 inputPanel.add(fields[5]);
99 inputPanel.add(fields[8]);
100 inputPanel.add(fields[11]);
101 add("Center", inputPanel);
102 buttonPanel();
103 addWindowListener(this);
104 }
105
106
107 private void buttonPanel() {
108 Panel p2 = new Panel();
109 p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
110 p2.add(cancelButton);
111 p2.add(setButton);
112 cancelButton.addActionListener(this);
113 setButton.addActionListener(this);
114 names.addItemListener(this);
115 add("South", p2);
116 pack();
117 show();
118 }
119
120
121 private void Names_Click() {
122 try {
123 int i1 = 0;
124 i1 = names.getSelectedIndex();
125 fields[0].setText("" + objects[i1].Pos.x);
126 fields[1].setText("" + objects[i1].Pos.y);
127 fields[2].setText("" + objects[i1].Pos.z);
128 fields[3].setText("" + objects[i1].Rot.x);
129 fields[4].setText("" + objects[i1].Rot.y);
130 fields[5].setText("" + objects[i1].Rot.z);
131 fields[6].setText("" + objects[i1].Sca.x);
132 fields[7].setText("" + objects[i1].Sca.y);
133 fields[8].setText("" + objects[i1].Sca.z);
134 fields[9].setText("" + objects[i1].Cen.x);
135 fields[10].setText("" + objects[i1].Cen.y);
136 fields[11].setText("" + objects[i1].Cen.z);
137 texture.select(objects[i1].textureIndex + 1);
138 } catch (Exception ex) {
139 }
140 }
141
142
143 private void setThem() {
144 String txt = new String();
145 int i1 = 0;
146 int j1 = 0;
147
148 Float f;
149 try {
150 i1 = names.getSelectedIndex();
151 j1 = texture.getSelectedIndex();
152 } catch (Exception ex) {
153 }
154
155 try {
156 f = Float.valueOf(fields[0].getText());
157 objects[i1].Pos.x = f.floatValue();
158 f = Float.valueOf(fields[1].getText());
159 objects[i1].Pos.y = f.floatValue();
160 f = Float.valueOf(fields[2].getText());
161 objects[i1].Pos.z = f.floatValue();
162 f = Float.valueOf(fields[3].getText());
163 objects[i1].Rot.x = f.floatValue();
164 f = Float.valueOf(fields[4].getText());
165 objects[i1].Rot.y = f.floatValue();
166 f = Float.valueOf(fields[5].getText());
167 objects[i1].Rot.z = f.floatValue();
168 f = Float.valueOf(fields[6].getText());
169 objects[i1].Sca.x = f.floatValue();
170 f = Float.valueOf(fields[7].getText());
171 objects[i1].Sca.y = f.floatValue();
172 f = Float.valueOf(fields[8].getText());
173 objects[i1].Sca.z = f.floatValue();
174 f = Float.valueOf(fields[9].getText());
175 objects[i1].Cen.x = f.floatValue();
176 f = Float.valueOf(fields[10].getText());
177 objects[i1].Cen.y = f.floatValue();
178 f = Float.valueOf(fields[11].getText());
179 objects[i1].Cen.z = f.floatValue();
180 objects[i1].textureIndex = j1 - 1;
181 } catch (NumberFormatException e) {
182 MessLog ml =
183 new MessLog(
184 new Frame(),
185 "Input Error:",
186 "Could not convert to Float");
187 }
188
189 }
190
191
192 public void itemStateChanged(ItemEvent e) {
193 if (e.getSource() == names) {
194 Names_Click();
195 return;
196 }
197 }
198
199 public void actionPerformed(ActionEvent e) {
200 Button b = (Button) e.getSource();
201 if (b == cancelButton) setVisible(false);
202 if (b == setButton) setThem();
203 }
204
205 public void windowClosing(WindowEvent e) {
206 dispose();
207 }
208
209 public void windowClosed(WindowEvent e) {
210 };
211 public void windowDeiconified(WindowEvent e) {
212 };
213 public void windowIconified(WindowEvent e) {
214 };
215 public void windowActivated(WindowEvent e) {
216 };
217 public void windowDeactivated(WindowEvent e) {
218 };
219 public void windowOpened(WindowEvent e) {
220 };
221
222 }
223
224
225
226
227
228
229
230
231