home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch12
/
ui
/
dialogs
/
TextureTransformDialog.java
< prev
next >
Wrap
Text File
|
1997-01-02
|
4KB
|
174 lines
// VRML Generator
// (c) Justin Couch
//
// From Chapter 13: Late Night VRML 2.0 and Java
//
// The TextureTransform node dialog.
package ui.dialogs;
import java.awt.*;
import ui.dialogs.VrmlBaseDialog;
import geometry.TextureTransform;
import ui.VrmlTree;
import VrmlScene;
import VrmlTypes;
import exceptions.NoSelectedNodeException;
public class TextureTransformDialog extends VrmlBaseDialog
{
private TextField trans_x, trans_y;
private TextField center_x, center_y;
private TextField rotate;
private TextField scale_x, scale_y;
public TextureTransformDialog(Frame parent, VrmlTree tree, VrmlScene data)
{
super(parent, "Edit TextureTransform Node");
vrml_data = data;
screen_data = tree;
content_panel.setLayout(new GridLayout(4, 1));
// centre fields
Panel p1 = new Panel();
p1.setLayout(new BorderLayout(5, 0));
p1.add("West", new Label("Center:"));
Panel p2 = new Panel();
p2.setLayout(new GridLayout(1, 4));
// the 3 components.
center_x = new TextField("0", 5);
center_y = new TextField("0", 5);
p2.add(new Label("x: ", Label.RIGHT));
p2.add(center_x);
p2.add(new Label("y: ", Label.RIGHT));
p2.add(center_y);
p1.add("East", p2);
content_panel.add(p1);
// rotation
Panel p3 = new Panel();
p3.setLayout(new BorderLayout(15, 10));
rotate = new TextField("0", 5);
p3.add("West", new Label("Rotation:"));
p3.add("East", rotate);
content_panel.add(p3);
// scale fields
Panel p5 = new Panel();
p5.setLayout(new BorderLayout(5, 0));
p5.add("West", new Label("Scale:"));
Panel p6 = new Panel();
p6.setLayout(new GridLayout(1, 4));
// the 3 components.
scale_x = new TextField("1", 5);
scale_y = new TextField("1", 5);
p6.add(new Label("x: ", Label.RIGHT));
p6.add(scale_x);
p6.add(new Label("y: ", Label.RIGHT));
p6.add(scale_y);
p5.add("East", p6);
content_panel.add(p5);
// scale Orientation
Panel p7 = new Panel();
p7.setLayout(new BorderLayout(5, 0));
p7.add("West", new Label("Translation:"));
Panel p8 = new Panel();
p8.setLayout(new GridLayout(1, 8));
// the 3 components.
trans_x = new TextField("0", 5);
trans_y = new TextField("0", 5);
p8.add(new Label("x: ", Label.RIGHT));
p8.add(trans_x);
p8.add(new Label("y: ", Label.RIGHT));
p8.add(trans_y);
p7.add("East", p8);
content_panel.add(p7);
pack();
}
// read all the information back out of the panel and pass it
// to the appropriate place.
public boolean applyInformation()
{
String str;
float tx_x, tx_y;
float c_x, c_y;
float rot;
float sc_x, sc_y;
TextureTransform ttransform;
// first get the basic node constructed
ttransform = new TextureTransform(browser);
str = name.getText();
if(str.equals(""))
ttransform.name = null;
else
ttransform.name = new String(str);
// now we update the fields
// translation
tx_x = Float.valueOf(trans_x.getText()).floatValue();
tx_y = Float.valueOf(trans_y.getText()).floatValue();
if((tx_x != 0) || (tx_y != 0))
ttransform.set_translation(tx_x, tx_y);
// center
c_x = Float.valueOf(center_x.getText()).floatValue();
c_y = Float.valueOf(center_y.getText()).floatValue();
if((c_x != 0) || (c_y != 0))
ttransform.set_center(c_x, c_y);
// rotation
rot = Float.valueOf(rotate.getText()).floatValue();
if(rot != 0)
ttransform.set_rotation(rot);
// scale
sc_x = Float.valueOf(scale_x.getText()).floatValue();
sc_y = Float.valueOf(scale_y.getText()).floatValue();
if((sc_x != 1) || (sc_y != 1))
ttransform.set_scale(sc_x, sc_y);
try
{
vrml_data.addNode(VrmlTypes.TextureTransform, ttransform);
}
catch (NoSelectedNodeException e)
{
System.out.println("No node selected");
}
return false;
}
}