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.java341
1 files changed, 341 insertions, 0 deletions
diff --git a/NET/worlds/scape/TransformEditorDialog.java b/NET/worlds/scape/TransformEditorDialog.java
new file mode 100644
index 0000000..d7b5a21
--- /dev/null
+++ b/NET/worlds/scape/TransformEditorDialog.java
@@ -0,0 +1,341 @@
+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.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 {
+ Property property;
+ Transform transform;
+ int undoCount;
+ Button undoButton = new Button(Console.message("Undo"));
+ Button okButton = new Button(Console.message("OK"));
+ Button cancelButton = new Button(Console.message("Cancel"));
+ Button pitch = new MyButton(Console.message("Pitch-N"), 0, 1);
+ Button roll = new MyButton(Console.message("Roll-N"), 0, 1);
+ Button yaw = new MyButton(Console.message("Yaw-N"), 0, 1);
+ Button spin = new MyButton(Console.message("Spin-by-XYZN"), 3, 1);
+ Button spinTo = new MyButton(Console.message("Spin-to-XYZN"), 3, 1);
+ Button moveX = new MyButton(Console.message("Move-x-by-N"), 0, 1);
+ Button moveY = new MyButton(Console.message("Move-y-by-N"), 0, 1);
+ Button moveZ = new MyButton(Console.message("Move-z-by-N"), 0, 1);
+ Button moveBy = new MyButton(Console.message("Move-by-XYZ"), 3, 0);
+ Button moveTo = new MyButton(Console.message("Move-to-XYZ"), 3, 0);
+ Button scaleX = new MyButton(Console.message("Scale-x-by-N"), 0, 1);
+ Button scaleY = new MyButton(Console.message("Scale-y-by-N"), 0, 1);
+ Button scaleZ = new MyButton(Console.message("Scale-z-by-N"), 0, 1);
+ Button scaleBy = new MyButton(Console.message("Scale-by-N"), 0, 1);
+ Button scaleTo = new MyButton(Console.message("Scale-to-N"), 0, 1);
+ Label position = new Label();
+ Label rotation = new Label();
+ Label scale = new Label();
+ TextField editXYZ = new TextField();
+ TextField editN = new TextField();
+ GridBagLayout gbag = new GridBagLayout();
+ 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) {
+ super(Console.getFrame(), parent, title, false);
+ this.property = property;
+ this.parent = parent;
+ this.ready();
+ }
+
+ @Override
+ protected void build() {
+ this.transform = (Transform)this.property.get();
+ this.setLayout(this.gbag);
+ this.add2(new Label("(X,Y,Z):"), this.editXYZ);
+ this.add2(new Label("(N):"), this.editN);
+ this.add3(this.moveX, this.pitch, this.scaleX);
+ this.add3(this.moveY, this.roll, this.scaleY);
+ this.add3(this.moveZ, this.yaw, this.scaleZ);
+ this.add3(this.moveBy, this.spin, this.scaleBy);
+ this.add3(this.moveTo, this.spinTo, this.scaleTo);
+ this.add2(new Label(Console.message("Position")), this.position);
+ this.add2(new Label(Console.message("Rotation:")), this.rotation);
+ this.add2(new Label(Console.message("Scale:")), this.scale);
+ this.addButtons(this.undoButton, this.okButton, this.cancelButton);
+ this.normalFont = this.pitch.getFont();
+ this.selectedFont = new Font(this.normalFont.getName(), this.normalFont.isBold() ? 0 : 1, this.normalFont.getSize());
+ this.updateInfo();
+ }
+
+ private void add2(Component c1, Component c2) {
+ this.c.fill = 0;
+ this.c.anchor = 13;
+ this.c.gridheight = 1;
+ this.c.weightx = 1.0;
+ this.c.weighty = 1.0;
+ this.c.gridwidth = 1;
+ this.add(this.gbag, c1, this.c);
+ this.c.anchor = 17;
+ this.c.fill = 2;
+ this.c.gridwidth = 0;
+ this.add(this.gbag, c2, this.c);
+ }
+
+ private void add3(Component c1, Component c2, Component c3) {
+ this.c.fill = 2;
+ this.c.anchor = 17;
+ this.c.gridheight = 1;
+ this.c.gridwidth = 3;
+ this.c.weightx = 1.0;
+ this.c.weighty = 1.0;
+ this.add(this.gbag, c1, this.c);
+ this.c.weightx = 0.0;
+ this.c.weighty = 0.0;
+ this.add(this.gbag, c2, this.c);
+ this.c.gridwidth = 0;
+ this.add(this.gbag, c3, this.c);
+ }
+
+ private void addButtons(Component c1, Component c2, Component c3) {
+ this.c.fill = 0;
+ this.c.anchor = 13;
+ this.c.gridheight = 1;
+ this.c.gridwidth = 3;
+ this.c.weightx = 1.0;
+ this.c.weighty = 1.0;
+ this.add(this.gbag, c1, this.c);
+ this.c.anchor = 10;
+ this.add(this.gbag, c2, this.c);
+ this.c.anchor = 17;
+ this.add(this.gbag, c3, this.c);
+ }
+
+ private void selectButton(Button button) {
+ if (this.selectedButton != null) {
+ this.selectedButton.setFont(this.normalFont);
+ }
+
+ this.selectedButton = button;
+ this.selectedButton.setFont(this.selectedFont);
+ }
+
+ private void updateInfo() {
+ this.position.setText(this.transform.getPosition().toString());
+ this.scale.setText(this.transform.getScale().toString());
+ Point3Temp axis = Point3Temp.make();
+ float angle = this.transform.getSpin(axis);
+ Object[] arguments = new Object[]{new String("" + axis), new String("" + angle)};
+ this.rotation.setText(MessageFormat.format(Console.message("angle"), arguments));
+ this.undoButton.enable(this.undoCount != 0);
+ }
+
+ private void set(Transform t) {
+ this.parent.addUndoableSet(this.property, t);
+ this.undoCount++;
+ this.transform = (Transform)this.property.get();
+ }
+
+ @Override
+ protected synchronized void activeCallback() {
+ if (this.queuedFunc == this.undoButton) {
+ if (this.undoCount != 0) {
+ this.parent.undo();
+ this.undoCount--;
+ this.transform = (Transform)this.property.get();
+ this.updateInfo();
+ }
+ } else if (this.queuedFunc instanceof MyButton) {
+ this.apply((MyButton)this.queuedFunc);
+ }
+
+ this.queuedFunc = null;
+ }
+
+ public boolean undoAll() {
+ if (this.undoCount == 0) {
+ return this.done(false);
+ } else {
+ new ConfirmDialog(this, Console.message("Cancel-Transform"), Console.message("undo-changes"));
+ return true;
+ }
+ }
+
+ @Override
+ public synchronized void dialogDone(Object who, boolean confirmed) {
+ if (confirmed) {
+ while (this.undoCount != 0) {
+ this.parent.undo();
+ this.undoCount--;
+ }
+
+ this.done(false);
+ }
+ }
+
+ @Override
+ public synchronized boolean action(java.awt.Event event, Object what) {
+ Object target = event.target;
+ if (target == this.okButton) {
+ return this.done(true);
+ } else if (target == this.cancelButton) {
+ return this.undoAll();
+ } else if ((target == this.undoButton || target instanceof MyButton) && this.queuedFunc == null) {
+ this.queuedFunc = target;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private float[] parseNumbers(TextField edit) {
+ Vector vec = new Vector();
+ StringTokenizer e = new StringTokenizer(edit.getText().trim(), ", \t", false);
+
+ while (e.hasMoreElements()) {
+ try {
+ vec.addElement(Float.valueOf(e.nextToken()));
+ } catch (NumberFormatException var6) {
+ vec.removeAllElements();
+ break;
+ }
+ }
+
+ float[] ret = new float[vec.size()];
+
+ for (int i = 0; i < ret.length; i++) {
+ ret[i] = (Float)vec.elementAt(i);
+ }
+
+ return ret;
+ }
+
+ private boolean apply(MyButton func) {
+ float[] n = this.parseNumbers(this.editN);
+ float[] xyz = this.parseNumbers(this.editXYZ);
+ if (func.numParamsXYZ != 0 && func.numParamsXYZ != xyz.length) {
+ return this.setEdit(this.editXYZ);
+ } else if (func.numParamsN != 0 && func.numParamsN != n.length) {
+ return this.setEdit(this.editN);
+ } else {
+ if (func == this.pitch) {
+ this.transform.worldSpin(1.0F, 0.0F, 0.0F, n[0]);
+ } else if (func == this.roll) {
+ this.transform.worldSpin(0.0F, 1.0F, 0.0F, n[0]);
+ } else if (func == this.yaw) {
+ this.transform.worldSpin(0.0F, 0.0F, 1.0F, n[0]);
+ } else if (func == this.spin) {
+ this.transform.worldSpin(xyz[0], xyz[1], xyz[2], n[0]);
+ } else if (func == this.spinTo) {
+ Point3Temp scale = this.transform.getScale();
+ Point3Temp pos = this.transform.getPosition();
+ this.transform.makeIdentity();
+ this.transform.scale(scale);
+ this.transform.worldSpin(xyz[0], xyz[1], xyz[2], n[0]);
+ this.transform.moveTo(pos.x, pos.y, pos.z);
+ } else if (func == this.moveX) {
+ this.transform.moveBy(n[0], 0.0F, 0.0F);
+ } else if (func == this.moveY) {
+ this.transform.moveBy(0.0F, n[0], 0.0F);
+ } else if (func == this.moveZ) {
+ this.transform.moveBy(0.0F, 0.0F, n[0]);
+ } else if (func == this.moveBy) {
+ this.transform.moveBy(xyz[0], xyz[1], xyz[2]);
+ } else if (func == this.moveTo) {
+ this.transform.moveTo(xyz[0], xyz[1], xyz[2]);
+ } else if (func == this.scaleX && n[0] != 0.0F && this.checkScale(n[0], this.transform.getScaleX())) {
+ this.transform.scale(n[0], 1.0F, 1.0F);
+ } else if (func == this.scaleY && n[0] != 0.0F && this.checkScale(n[0], this.transform.getScaleY())) {
+ this.transform.scale(1.0F, n[0], 1.0F);
+ } else if (func == this.scaleZ && n[0] != 0.0F && this.checkScale(n[0], this.transform.getScaleZ())) {
+ this.transform.scale(1.0F, 1.0F, n[0]);
+ } else if (func == this.scaleBy
+ && n[0] != 0.0F
+ && this.checkScale(n[0], this.transform.getScaleX())
+ && this.checkScale(n[0], this.transform.getScaleY())
+ && this.checkScale(n[0], this.transform.getScaleZ())) {
+ this.transform.scale(n[0]);
+ } else {
+ if (func != this.scaleTo || n[0] == 0.0F) {
+ return true;
+ }
+
+ Point3Temp scale = this.transform.getScale();
+ this.transform.scale(n[0] / scale.x, n[0] / scale.y, n[0] / scale.z);
+ }
+
+ this.set(this.transform);
+ this.selectButton(func);
+ this.updateInfo();
+ return this.setEdit(this.lastEdit);
+ }
+ }
+
+ private boolean checkScale(float oldScale, float factor) {
+ double newScale = (double)oldScale * factor;
+ if (newScale < 2.938736052218037E-39) {
+ Console.println(Console.message("exceed-minimum"));
+ } else {
+ if (!(newScale > Float.MAX_VALUE)) {
+ return true;
+ }
+
+ Console.println(Console.message("exceed-maximum"));
+ }
+
+ return false;
+ }
+
+ private boolean toggleEdit() {
+ return this.lastEdit == this.editN ? this.setEdit(this.editXYZ) : this.setEdit(this.editN);
+ }
+
+ private boolean setEdit(TextField edit) {
+ edit.requestFocus();
+ edit.selectAll();
+ this.lastEdit = edit;
+ return true;
+ }
+
+ @Override
+ public boolean keyDown(java.awt.Event event, int key) {
+ if (event.target == this.editXYZ || event.target == this.editN) {
+ this.lastEdit = (TextField)event.target;
+ }
+
+ if (key == 27) {
+ return this.undoAll();
+ } else if (key == 10) {
+ return this.done(true);
+ } else {
+ return key == 9 ? this.toggleEdit() : super.keyDown(event, key);
+ }
+ }
+
+ @Override
+ public void show() {
+ super.show();
+ this.setEdit(this.editXYZ);
+ }
+
+ @Override
+ public void savePosAndSize(Object state) {
+ lastPosAndSize = state;
+ }
+
+ @Override
+ public Object restorePosAndSize() {
+ return lastPosAndSize;
+ }
+}