summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/TransformEditorDialog.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/scape/TransformEditorDialog.java')
-rw-r--r--NET/worlds/scape/TransformEditorDialog.java367
1 files changed, 367 insertions, 0 deletions
diff --git a/NET/worlds/scape/TransformEditorDialog.java b/NET/worlds/scape/TransformEditorDialog.java
new file mode 100644
index 0000000..5e825ab
--- /dev/null
+++ b/NET/worlds/scape/TransformEditorDialog.java
@@ -0,0 +1,367 @@
+/* */ package NET.worlds.scape;
+/* */
+/* */ import NET.worlds.console.ConfirmDialog;
+/* */ import NET.worlds.console.Console;
+/* */ import NET.worlds.console.DialogReceiver;
+/* */ import NET.worlds.console.PolledDialog;
+/* */ import java.awt.Button;
+/* */ import java.awt.Component;
+/* */ import java.awt.Event;
+/* */ import java.awt.Font;
+/* */ import java.awt.GridBagConstraints;
+/* */ import java.awt.GridBagLayout;
+/* */ import java.awt.Label;
+/* */ import java.awt.TextField;
+/* */ import java.text.MessageFormat;
+/* */ import java.util.StringTokenizer;
+/* */ import java.util.Vector;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ class TransformEditorDialog
+/* */ extends PolledDialog
+/* */ implements DialogReceiver
+/* */ {
+/* */ private static final long serialVersionUID = 1L;
+/* */ Property property;
+/* */ Transform transform;
+/* */ int undoCount;
+/* 55 */ Button undoButton = new Button(Console.message("Undo"));
+/* 56 */ Button okButton = new Button(Console.message("OK"));
+/* 57 */ Button cancelButton = new Button(Console.message("Cancel"));
+/* */
+/* 59 */ Button pitch = new MyButton(Console.message("Pitch-N"), 0, 1);
+/* 60 */ Button roll = new MyButton(Console.message("Roll-N"), 0, 1);
+/* 61 */ Button yaw = new MyButton(Console.message("Yaw-N"), 0, 1);
+/* 62 */ Button spin = new MyButton(Console.message("Spin-by-XYZN"), 3, 1);
+/* 63 */ Button spinTo = new MyButton(Console.message("Spin-to-XYZN"), 3, 1);
+/* */
+/* 65 */ Button moveX = new MyButton(Console.message("Move-x-by-N"), 0, 1);
+/* 66 */ Button moveY = new MyButton(Console.message("Move-y-by-N"), 0, 1);
+/* 67 */ Button moveZ = new MyButton(Console.message("Move-z-by-N"), 0, 1);
+/* 68 */ Button moveBy = new MyButton(Console.message("Move-by-XYZ"), 3, 0);
+/* 69 */ Button moveTo = new MyButton(Console.message("Move-to-XYZ"), 3, 0);
+/* */
+/* 71 */ Button scaleX = new MyButton(Console.message("Scale-x-by-N"), 0, 1);
+/* 72 */ Button scaleY = new MyButton(Console.message("Scale-y-by-N"), 0, 1);
+/* 73 */ Button scaleZ = new MyButton(Console.message("Scale-z-by-N"), 0, 1);
+/* 74 */ Button scaleBy = new MyButton(Console.message("Scale-by-N"), 0, 1);
+/* 75 */ Button scaleTo = new MyButton(Console.message("Scale-to-N"), 0, 1);
+/* */
+/* 77 */ Label position = new Label();
+/* 78 */ Label rotation = new Label();
+/* 79 */ Label scale = new Label();
+/* 80 */ TextField editXYZ = new TextField();
+/* 81 */ TextField editN = new TextField();
+/* 82 */ GridBagLayout gbag = new GridBagLayout();
+/* 83 */ GridBagConstraints c = new GridBagConstraints();
+/* */ Font normalFont;
+/* */ Font selectedFont;
+/* */ Button selectedButton;
+/* */ TextField lastEdit;
+/* */ EditTile parent;
+/* */ Object queuedFunc;
+/* */ private static Object lastPosAndSize;
+/* */
+/* */ TransformEditorDialog(EditTile parent, String title, Property property) {
+/* 93 */ super(Console.getFrame(), parent, title, false);
+/* 94 */ this.property = property;
+/* 95 */ this.parent = parent;
+/* 96 */ ready();
+/* */ }
+/* */
+/* */ protected void build() {
+/* 100 */ this.transform = ((Transform)this.property.get());
+/* 101 */ setLayout(this.gbag);
+/* */
+/* 103 */ add2(new Label("(X,Y,Z):"), this.editXYZ);
+/* 104 */ add2(new Label("(N):"), this.editN);
+/* 105 */ add3(this.moveX, this.pitch, this.scaleX);
+/* 106 */ add3(this.moveY, this.roll, this.scaleY);
+/* 107 */ add3(this.moveZ, this.yaw, this.scaleZ);
+/* 108 */ add3(this.moveBy, this.spin, this.scaleBy);
+/* 109 */ add3(this.moveTo, this.spinTo, this.scaleTo);
+/* 110 */ add2(new Label(Console.message("Position")), this.position);
+/* 111 */ add2(new Label(Console.message("Rotation:")), this.rotation);
+/* 112 */ add2(new Label(Console.message("Scale:")), this.scale);
+/* 113 */ addButtons(this.undoButton, this.okButton, this.cancelButton);
+/* */
+/* 115 */ this.normalFont = this.pitch.getFont();
+/* 116 */ this.selectedFont = new Font(this.normalFont.getName(), this.normalFont.isBold() ? 0 : 1,
+/* 117 */ this.normalFont.getSize());
+/* 118 */ updateInfo();
+/* */ }
+/* */
+/* */ private void add2(Component c1, Component c2) {
+/* 122 */ this.c.fill = 0;
+/* 123 */ this.c.anchor = 13;
+/* 124 */ this.c.gridheight = 1;
+/* 125 */ this.c.weightx = 1.0D;
+/* 126 */ this.c.weighty = 1.0D;
+/* 127 */ this.c.gridwidth = 1;
+/* 128 */ add(this.gbag, c1, this.c);
+/* 129 */ this.c.anchor = 17;
+/* 130 */ this.c.fill = 2;
+/* 131 */ this.c.gridwidth = 0;
+/* 132 */ add(this.gbag, c2, this.c);
+/* */ }
+/* */
+/* */ private void add3(Component c1, Component c2, Component c3) {
+/* 136 */ this.c.fill = 2;
+/* 137 */ this.c.anchor = 17;
+/* 138 */ this.c.gridheight = 1;
+/* 139 */ this.c.gridwidth = 3;
+/* 140 */ this.c.weightx = 1.0D;
+/* 141 */ this.c.weighty = 1.0D;
+/* 142 */ add(this.gbag, c1, this.c);
+/* 143 */ this.c.weightx = 0.0D;
+/* 144 */ this.c.weighty = 0.0D;
+/* 145 */ add(this.gbag, c2, this.c);
+/* 146 */ this.c.gridwidth = 0;
+/* 147 */ add(this.gbag, c3, this.c);
+/* */ }
+/* */
+/* */ private void addButtons(Component c1, Component c2, Component c3) {
+/* 151 */ this.c.fill = 0;
+/* 152 */ this.c.anchor = 13;
+/* 153 */ this.c.gridheight = 1;
+/* 154 */ this.c.gridwidth = 3;
+/* 155 */ this.c.weightx = 1.0D;
+/* 156 */ this.c.weighty = 1.0D;
+/* 157 */ add(this.gbag, c1, this.c);
+/* 158 */ this.c.anchor = 10;
+/* 159 */ add(this.gbag, c2, this.c);
+/* 160 */ this.c.anchor = 17;
+/* 161 */ add(this.gbag, c3, this.c);
+/* */ }
+/* */
+/* */ private void selectButton(Button button) {
+/* 165 */ if (this.selectedButton != null)
+/* 166 */ this.selectedButton.setFont(this.normalFont);
+/* 167 */ this.selectedButton = button;
+/* 168 */ this.selectedButton.setFont(this.selectedFont);
+/* */ }
+/* */
+/* */ private void updateInfo() {
+/* 172 */ this.position.setText(this.transform.getPosition().toString());
+/* 173 */ this.scale.setText(this.transform.getScale().toString());
+/* 174 */ Point3Temp axis = Point3Temp.make();
+/* 175 */ float angle = this.transform.getSpin(axis);
+/* */
+/* 177 */ Object[] arguments = { new String(axis), new String(angle) };
+/* 178 */ this.rotation.setText(MessageFormat.format(Console.message("angle"), arguments));
+/* */
+/* */
+/* 181 */ this.undoButton.setEnabled(this.undoCount != 0);
+/* */ }
+/* */
+/* */ private void set(Transform t) {
+/* 185 */ this.parent.addUndoableSet(this.property, t);
+/* 186 */ this.undoCount += 1;
+/* 187 */ this.transform = ((Transform)this.property.get());
+/* */ }
+/* */
+/* */ protected synchronized void activeCallback() {
+/* 191 */ if (this.queuedFunc == this.undoButton) {
+/* 192 */ if (this.undoCount != 0) {
+/* 193 */ this.parent.undo();
+/* 194 */ this.undoCount -= 1;
+/* 195 */ this.transform = ((Transform)this.property.get());
+/* 196 */ updateInfo();
+/* */ }
+/* 198 */ } else if ((this.queuedFunc instanceof MyButton))
+/* 199 */ apply((MyButton)this.queuedFunc);
+/* 200 */ this.queuedFunc = null;
+/* */ }
+/* */
+/* */ public boolean undoAll() {
+/* 204 */ if (this.undoCount == 0)
+/* 205 */ return done(false);
+/* 206 */ new ConfirmDialog(this, Console.message("Cancel-Transform"), Console.message("undo-changes"));
+/* 207 */ return true;
+/* */ }
+/* */
+/* */ public synchronized void dialogDone(Object who, boolean confirmed) {
+/* 211 */ if (confirmed) {
+/* 212 */ while (this.undoCount != 0) {
+/* 213 */ this.parent.undo();
+/* 214 */ this.undoCount -= 1;
+/* */ }
+/* 216 */ done(false);
+/* */ }
+/* */ }
+/* */
+/* */ @Deprecated
+/* */ public synchronized boolean action(Event event, Object what) {
+/* 222 */ Object target = event.target;
+/* 223 */ if (target == this.okButton)
+/* 224 */ return done(true);
+/* 225 */ if (target == this.cancelButton)
+/* 226 */ return undoAll();
+/* 227 */ if (((target == this.undoButton) || ((target instanceof MyButton))) && (this.queuedFunc == null)) {
+/* 228 */ this.queuedFunc = target;
+/* 229 */ return true;
+/* */ }
+/* 231 */ return false;
+/* */ }
+/* */
+/* */ private float[] parseNumbers(TextField edit)
+/* */ {
+/* 236 */ Vector<Float> vec = new Vector();
+/* 237 */ StringTokenizer e = new StringTokenizer(edit.getText().trim(), ", \t", false);
+/* 238 */ while (e.hasMoreElements())
+/* */ try {
+/* 240 */ vec.addElement(Float.valueOf(e.nextToken()));
+/* */ } catch (NumberFormatException x) {
+/* 242 */ vec.removeAllElements();
+/* 243 */ break;
+/* */ }
+/* 245 */ float[] ret = new float[vec.size()];
+/* 246 */ for (int i = 0; i < ret.length; i++)
+/* 247 */ ret[i] = ((Float)vec.elementAt(i)).floatValue();
+/* 248 */ return ret;
+/* */ }
+/* */
+/* */ private boolean apply(MyButton func)
+/* */ {
+/* 253 */ float[] n = parseNumbers(this.editN);
+/* 254 */ float[] xyz = parseNumbers(this.editXYZ);
+/* 255 */ if ((func.numParamsXYZ != 0) && (func.numParamsXYZ != xyz.length))
+/* 256 */ return setEdit(this.editXYZ);
+/* 257 */ if ((func.numParamsN != 0) && (func.numParamsN != n.length))
+/* 258 */ return setEdit(this.editN);
+/* 259 */ if (func == this.pitch) {
+/* 260 */ this.transform.worldSpin(1.0F, 0.0F, 0.0F, n[0]);
+/* 261 */ } else if (func == this.roll) {
+/* 262 */ this.transform.worldSpin(0.0F, 1.0F, 0.0F, n[0]);
+/* 263 */ } else if (func == this.yaw) {
+/* 264 */ this.transform.worldSpin(0.0F, 0.0F, 1.0F, n[0]);
+/* 265 */ } else if (func == this.spin) {
+/* 266 */ this.transform.worldSpin(xyz[0], xyz[1], xyz[2], n[0]);
+/* 267 */ } else if (func == this.spinTo) {
+/* 268 */ Point3Temp scale = this.transform.getScale();
+/* 269 */ Point3Temp pos = this.transform.getPosition();
+/* 270 */ this.transform.makeIdentity();
+/* 271 */ this.transform.scale(scale);
+/* 272 */ this.transform.worldSpin(xyz[0], xyz[1], xyz[2], n[0]);
+/* 273 */ this.transform.moveTo(pos.x, pos.y, pos.z);
+/* 274 */ } else if (func == this.moveX) {
+/* 275 */ this.transform.moveBy(n[0], 0.0F, 0.0F);
+/* 276 */ } else if (func == this.moveY) {
+/* 277 */ this.transform.moveBy(0.0F, n[0], 0.0F);
+/* 278 */ } else if (func == this.moveZ) {
+/* 279 */ this.transform.moveBy(0.0F, 0.0F, n[0]);
+/* 280 */ } else if (func == this.moveBy) {
+/* 281 */ this.transform.moveBy(xyz[0], xyz[1], xyz[2]);
+/* 282 */ } else if (func == this.moveTo) {
+/* 283 */ this.transform.moveTo(xyz[0], xyz[1], xyz[2]);
+/* 284 */ } else if ((func == this.scaleX) && (n[0] != 0.0F) && (checkScale(n[0], this.transform.getScaleX()))) {
+/* 285 */ this.transform.scale(n[0], 1.0F, 1.0F);
+/* 286 */ } else if ((func == this.scaleY) && (n[0] != 0.0F) && (checkScale(n[0], this.transform.getScaleY()))) {
+/* 287 */ this.transform.scale(1.0F, n[0], 1.0F);
+/* 288 */ } else if ((func == this.scaleZ) && (n[0] != 0.0F) && (checkScale(n[0], this.transform.getScaleZ()))) {
+/* 289 */ this.transform.scale(1.0F, 1.0F, n[0]);
+/* 290 */ } else if ((func == this.scaleBy) && (n[0] != 0.0F) && (checkScale(n[0], this.transform.getScaleX())) &&
+/* 291 */ (checkScale(n[0], this.transform.getScaleY())) && (checkScale(n[0], this.transform.getScaleZ()))) {
+/* 292 */ this.transform.scale(n[0]);
+/* 293 */ } else if ((func == this.scaleTo) && (n[0] != 0.0F)) {
+/* 294 */ Point3Temp scale = this.transform.getScale();
+/* 295 */ this.transform.scale(n[0] / scale.x, n[0] / scale.y, n[0] / scale.z);
+/* */ } else {
+/* 297 */ return true; }
+/* 298 */ set(this.transform);
+/* 299 */ selectButton(func);
+/* 300 */ updateInfo();
+/* 301 */ return setEdit(this.lastEdit);
+/* */ }
+/* */
+/* */ private boolean checkScale(float oldScale, float factor) {
+/* 305 */ double newScale = oldScale * factor;
+/* 306 */ if (newScale < 2.938736052218037E-39D) {
+/* 307 */ Console.println(Console.message("exceed-minimum"));
+/* 308 */ } else if (newScale > 3.4028234663852886E38D) {
+/* 309 */ Console.println(Console.message("exceed-maximum"));
+/* */ } else
+/* 311 */ return true;
+/* 312 */ return false;
+/* */ }
+/* */
+/* */ private boolean toggleEdit() {
+/* 316 */ if (this.lastEdit == this.editN)
+/* 317 */ return setEdit(this.editXYZ);
+/* 318 */ return setEdit(this.editN);
+/* */ }
+/* */
+/* */ private boolean setEdit(TextField edit) {
+/* 322 */ edit.requestFocus();
+/* 323 */ edit.selectAll();
+/* 324 */ this.lastEdit = edit;
+/* 325 */ return true;
+/* */ }
+/* */
+/* */ @Deprecated
+/* */ public boolean keyDown(Event event, int key) {
+/* 330 */ if ((event.target == this.editXYZ) || (event.target == this.editN)) {
+/* 331 */ this.lastEdit = ((TextField)event.target);
+/* */ }
+/* 333 */ if (key == 27)
+/* 334 */ return undoAll();
+/* 335 */ if (key == 10)
+/* 336 */ return done(true);
+/* 337 */ if (key == 9)
+/* 338 */ return toggleEdit();
+/* 339 */ return super.keyDown(event, key);
+/* */ }
+/* */
+/* */
+/* */
+/* */ public void setVisible(boolean visible)
+/* */ {
+/* 346 */ super.setVisible(visible);
+/* 347 */ if (visible) {
+/* 348 */ setEdit(this.editXYZ);
+/* */ }
+/* */ }
+/* */
+/* */
+/* */ public void savePosAndSize(Object state)
+/* */ {
+/* 355 */ lastPosAndSize = state;
+/* */ }
+/* */
+/* */ public Object restorePosAndSize() {
+/* 359 */ return lastPosAndSize;
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\TransformEditorDialog.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file