home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch12
/
ui
/
dialogs
/
TransformDialog.bak
< prev
next >
Wrap
Text File
|
1997-01-05
|
9KB
|
321 lines
// VRML Generator
// (c) Justin Couch
//
// From Chapter 13: Late Night VRML 2.0 and Java
//
// The Transform node dialog.
package ui.dialogs;
import java.awt.*;
import ui.dialogs.VrmlBaseDialog;
import geometry.Transform;
import ui.VrmlTree;
import VrmlScene;
import VrmlTypes;
import exceptions.NoSelectedNodeException;
public class TransformDialog extends VrmlBaseDialog
{
private TextField trans_x, trans_y, trans_z;
private TextField center_x, center_y, center_z;
private TextField rot_x, rot_y, rot_z, rot_a;
private TextField scale_x, scale_y, scale_z;
private TextField scaleO_x, scaleO_y, scaleO_z, scaleO_a;
private TextField bbcenter_x, bbcenter_y, bbcenter_z;
private TextField bbsize_x, bbsize_y, bbsize_z;
public TransformDialog(Frame parent, VrmlTree tree, VrmlScene data)
{
super(parent, "Edit Transform Node");
vrml_data = data;
screen_data = tree;
content_panel.setLayout(new GridLayout(8, 1));
// translation fields
Panel p1 = new Panel();
p1.setLayout(new BorderLayout(5, 0));
p1.add("West", new Label("Translation", Label.LEFT));
Panel p2 = new Panel();
p2.setLayout(new GridLayout(1, 8));
// the 3 components.
trans_x = new TextField("0", 5);
trans_y = new TextField("0", 5);
trans_z = new TextField("0", 5);
p2.add(new Label("x: ", Label.RIGHT));
p2.add(trans_x);
p2.add(new Label("y: ", Label.RIGHT));
p2.add(trans_y);
p2.add(new Label("z: ", Label.RIGHT));
p2.add(trans_z);
p1.add("East", p2);
content_panel.add(p1);
// center fields
Panel p3 = new Panel();
p3.setLayout(new BorderLayout(15, 10));
p3.add("West", new Label("Center", Label.LEFT));
Panel p4 = new Panel();
p4.setLayout(new GridLayout(1, 8));
// the 3 components.
center_x = new TextField("0", 5);
center_y = new TextField("0", 5);
center_z = new TextField("0", 5);
p4.add(new Label("x: ", Label.RIGHT));
p4.add(center_x);
p4.add(new Label("y: ", Label.RIGHT));
p4.add(center_y);
p4.add(new Label("z: ", Label.RIGHT));
p4.add(center_z);
p3.add("East", p4);
content_panel.add(p3);
// rotation fields
Panel p5 = new Panel();
p5.setLayout(new BorderLayout(5, 0));
p5.add("West", new Label("Rotation", Label.LEFT));
Panel p6 = new Panel();
p6.setLayout(new GridLayout(1, 8));
// the 4 components.
rot_x = new TextField("0", 5);
rot_y = new TextField("0", 5);
rot_z = new TextField("1", 5);
rot_a = new TextField("0", 5);
p6.add(new Label("x: ", Label.RIGHT));
p6.add(rot_x);
p6.add(new Label("y: ", Label.RIGHT));
p6.add(rot_y);
p6.add(new Label("z: ", Label.RIGHT));
p6.add(rot_z);
p6.add(new Label("angle: ", Label.RIGHT));
p6.add(rot_a);
p5.add("East", p6);
content_panel.add(p5);
// scale fields
Panel p7 = new Panel();
p7.setLayout(new BorderLayout(5, 0));
p7.add("West", new Label("Scale", Label.LEFT));
Panel p8 = new Panel();
p8.setLayout(new GridLayout(1, 8));
// the 3 components.
scale_x = new TextField("1", 5);
scale_y = new TextField("1", 5);
scale_z = new TextField("1", 5);
p8.add(new Label("x: ", Label.RIGHT));
p8.add(scale_x);
p8.add(new Label("y: ", Label.RIGHT));
p8.add(scale_y);
p8.add(new Label("z: ", Label.RIGHT));
p8.add(scale_z);
p7.add("East", p8);
content_panel.add(p7);
// scale Orientation
Panel p9 = new Panel();
p9.setLayout(new BorderLayout(5, 0));
p9.add("West", new Label("ScaleOrientation"));
Panel p10 = new Panel();
p10.setLayout(new GridLayout(1, 8));
// the 3 components.
scaleO_x = new TextField("0", 5);
scaleO_y = new TextField("0", 5);
scaleO_z = new TextField("1", 5);
scaleO_a = new TextField("0", 5);
p10.add(new Label("x: ", Label.RIGHT));
p10.add(scaleO_x);
p10.add(new Label("y: ", Label.RIGHT));
p10.add(scaleO_y);
p10.add(new Label("z: ", Label.RIGHT));
p10.add(scaleO_z);
p10.add(new Label("angle: ", Label.RIGHT));
p10.add(scaleO_a);
p9.add("East", p10);
content_panel.add(p9);
// Bounding Box Stuff
content_panel.add(new Label("Bounding Box"));
// now the first row. On the left is the Label and on the right is
// the 3 boxes for x, y and z, indicated by appropriate labels.
Panel p11 = new Panel();
p11.setLayout(new BorderLayout(5, 0));
p11.add("West", new Label("Center"));
Panel p12 = new Panel();
p12.setLayout(new GridLayout(1, 8));
// the 3 components.
bbcenter_x = new TextField("0", 5);
bbcenter_y = new TextField("0", 5);
bbcenter_z = new TextField("0", 5);
p12.add(new Label("x: ", Label.RIGHT));
p12.add(bbcenter_x);
p12.add(new Label("y: ", Label.RIGHT));
p12.add(bbcenter_y);
p12.add(new Label("z: ", Label.RIGHT));
p12.add(bbcenter_z);
p11.add("East", p12);
content_panel.add(p11);
// The second row. Identical to the first with the exception that
// we have changed a label over
Panel p13 = new Panel();
p13.setLayout(new BorderLayout(5, 0));
p13.add("West", new Label("Size"));
Panel p14 = new Panel();
p14.setLayout(new GridLayout(1, 8));
// the 3 components.
bbsize_x = new TextField("-1", 5);
bbsize_y = new TextField("-1", 5);
bbsize_z = new TextField("-1", 5);
p14.add(new Label("x: ", Label.RIGHT));
p14.add(bbsize_x);
p14.add(new Label("y: ", Label.RIGHT));
p14.add(bbsize_y);
p14.add(new Label("z: ", Label.RIGHT));
p14.add(bbsize_z);
p13.add("East", p14);
content_panel.add(p13);
pack();
}
// read all the information back out of the panel and pass it
// to the appropriate place.
public boolean applyInformation()
{
String str;
float[] bbcenter = new float[3];
float[] bbsize = new float[3];
float[] tx = new float[3];
float[] center = new float[3];
float[] rot = new float[4];
float[] scale = new float[3];
float[] scaleO = new float[4];
Transform transform;
// first get the basic node constructed
bbcenter[0] = Float.valueOf(bbcenter_x.getText()).floatValue();
bbcenter[1] = Float.valueOf(bbcenter_y.getText()).floatValue();
bbcenter[2] = Float.valueOf(bbcenter_z.getText()).floatValue();
bbsize[0] = Float.valueOf(bbsize_x.getText()).floatValue();
bbsize[1] = Float.valueOf(bbsize_y.getText()).floatValue();
bbsize[2] = Float.valueOf(bbsize_z.getText()).floatValue();
// are we creating a default node? This test for a yes
if((bbcenter[0] != 0) || (bbcenter[1] != 0) || (bbcenter[2] != 0) ||
(bbsize[0] != -1) || (bbsize[1] != -1) || (bbsize[2] != -1))
transform = new Transform(browser, bbcenter, bbsize);
else
transform = new Transform(browser);
System.out.println("Node created");
str = name.getText();
if(str.equals(""))
transform.name = null;
else
transform.name = new String();
// now we update the fields
// translation
tx[0] = Float.valueOf(trans_x.getText()).floatValue();
tx[1] = Float.valueOf(trans_y.getText()).floatValue();
tx[2] = Float.valueOf(trans_z.getText()).floatValue();
if((tx[0] != 0) || (tx[1] != 0) || (tx[2] != 0))
transform.set_translation(tx);
// center
center[0] = Float.valueOf(center_x.getText()).floatValue();
center[1] = Float.valueOf(center_y.getText()).floatValue();
center[2] = Float.valueOf(center_z.getText()).floatValue();
if((center[0] != 0) || (center[1] != 0) || (center[2] != 0))
transform.set_center(center);
// rotation
rot[0] = Float.valueOf(rot_x.getText()).floatValue();
rot[1] = Float.valueOf(rot_y.getText()).floatValue();
rot[2] = Float.valueOf(rot_z.getText()).floatValue();
rot[3] = Float.valueOf(rot_a.getText()).floatValue();
if((rot[0] != 0) || (rot[1] != 0) || (rot[2] != 1) || (rot[3] != 0))
transform.set_rotation(rot);
// scale
scale[0] = Float.valueOf(scale_x.getText()).floatValue();
scale[1] = Float.valueOf(scale_y.getText()).floatValue();
scale[2] = Float.valueOf(scale_z.getText()).floatValue();
if((scale[0] != 1) || (scale[1] != 1) || (scale[2] != 1))
transform.set_scale(scale);
// scaleOrientation
scaleO[0] = Float.valueOf(scaleO_x.getText()).floatValue();
scaleO[1] = Float.valueOf(scaleO_y.getText()).floatValue();
scaleO[2] = Float.valueOf(scaleO_z.getText()).floatValue();
scaleO[3] = Float.valueOf(scaleO_a.getText()).floatValue();
if((scaleO[0] != 0) || (scaleO[1] != 0) ||
(scaleO[2] != 1) || (scaleO[3] != 0))
transform.set_scaleOrientation(scaleO);
try
{
System.out.println("About to add");
vrml_data.addNode(VrmlTypes.Transform, transform);
System.out.println("done adding");
}
catch (NoSelectedNodeException e)
{
System.out.println("No node was selected");
}
return false;
}
}