home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch12
/
ui
/
dialogs
/
ConeDialog.java
< prev
next >
Wrap
Text File
|
1997-01-02
|
3KB
|
115 lines
// VRML Generator
// (c) Justin Couch
//
// From Chapter 13: Late Night VRML 2.0 and Java
//
// The Cone node dialog.
package ui.dialogs;
import java.awt.*;
import ui.dialogs.VrmlBaseDialog;
import geometry.Cone;
import ui.VrmlTree;
import VrmlScene;
import VrmlTypes;
import exceptions.NoSelectedNodeException;
public class ConeDialog extends VrmlBaseDialog
{
private TextField height;
private TextField radius;
private Checkbox sides;
private Checkbox bottom;
public ConeDialog(Frame parent, VrmlTree tree, VrmlScene data)
{
super(parent, "Edit Group Node");
vrml_data = data;
screen_data = tree;
content_panel.setLayout(new GridLayout(4, 1));
// 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 p1 = new Panel();
p1.setLayout(new BorderLayout(15, 10));
p1.add("West", new Label("Height", Label.LEFT));
height = new TextField("2", 4);
p1.add("East", height);
content_panel.add(p1);
// The second row. Identical to the first with the exception that
// we have changed a label over
Panel p2 = new Panel();
p2.setLayout(new BorderLayout(15, 10));
p2.add("West", new Label("Bottom Radius", Label.LEFT));
radius = new TextField("1", 4);
p2.add("East", radius);
content_panel.add(p2);
// now the labe for the check boxes
content_panel.add(new Label("Show", Label.LEFT));
// check boxes to turn parts of the geometry on and off.
Panel p3 = new Panel();
p3.setLayout(new GridLayout(1, 2));
sides = new Checkbox("Sides", null, true);
bottom = new Checkbox("Bottom", null, true);
p3.add(sides);
p3.add(bottom);
content_panel.add(p3);
pack();
}
// read all the information back out of the panel and pass it
// to the appropriate place.
public boolean applyInformation()
{
String str;
float h;
float r;
Cone cone;
h = Float.valueOf(height.getText()).floatValue();
r = Float.valueOf(radius.getText()).floatValue();
// are we creating a default node? This test for a yes
if((h != 2) || (r != 1) || !sides.getState() || !bottom.getState())
cone = new Cone(browser, r, h, sides.getState(), bottom.getState());
else
cone = new Cone(browser);
str = name.getText();
if(str.equals(""))
cone.name = null;
else
cone.name = new String(str);
try
{
vrml_data.addNode(VrmlTypes.Cone, cone);
}
catch (NoSelectedNodeException e)
{
System.out.println("No node selected");
}
return false;
}
}