home *** CD-ROM | disk | FTP | other *** search
- // VRML Generator
- // (c) Justin Couch
- //
- // From Chapter 13: Late Night VRML 2.0 and Java
- //
- // The Cylinder node dialog.
-
- package ui.dialogs;
-
- import java.awt.*;
- import ui.dialogs.VrmlBaseDialog;
- import geometry.Cylinder;
- import ui.VrmlTree;
- import VrmlScene;
- import VrmlTypes;
- import exceptions.NoSelectedNodeException;
-
-
- public class CylinderDialog extends VrmlBaseDialog
- {
- private TextField height;
- private TextField radius;
- private Checkbox sides;
- private Checkbox bottom;
- private Checkbox top;
-
- public CylinderDialog(Frame parent, VrmlTree tree, VrmlScene data)
- {
- super(parent, "Edit Cylinder 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("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, 3));
-
- sides = new Checkbox("Sides", null, true);
- top = new Checkbox("Top", null, true);
- bottom = new Checkbox("Bottom", null, true);
- p3.add(top);
- p3.add(bottom);
- p3.add(sides);
-
- 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;
-
- Cylinder cyl;
-
- 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() || !top.getState())
- cyl = new Cylinder(browser,
- r,
- h,
- sides.getState(),
- top.getState(),
- bottom.getState());
- else
- cyl = new Cylinder(browser);
-
- str = name.getText();
-
- if(str.equals(""))
- cyl.name = null;
- else
- cyl.name = new String(str);
-
- try
- {
- vrml_data.addNode(VrmlTypes.Cylinder, cyl);
- }
- catch (NoSelectedNodeException e)
- {
- System.out.println("No node selected");
- }
-
- return false;
- }
-
- }