home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch12 / ui / dialogs / CylinderDialog.java < prev    next >
Text File  |  1997-01-02  |  3KB  |  124 lines

  1. // VRML Generator
  2. // (c) Justin Couch
  3. //
  4. // From Chapter 13: Late Night VRML 2.0 and Java
  5. //
  6. // The Cylinder node dialog.
  7.  
  8. package ui.dialogs;
  9.  
  10. import java.awt.*;
  11. import ui.dialogs.VrmlBaseDialog;
  12. import geometry.Cylinder;
  13. import ui.VrmlTree;
  14. import VrmlScene;
  15. import VrmlTypes;
  16. import exceptions.NoSelectedNodeException;
  17.  
  18.  
  19. public class CylinderDialog extends VrmlBaseDialog
  20. {
  21.     private TextField    height;
  22.     private TextField    radius;
  23.     private Checkbox    sides;
  24.     private Checkbox    bottom;
  25.     private Checkbox    top;
  26.  
  27.     public CylinderDialog(Frame parent, VrmlTree tree, VrmlScene data)
  28.     {
  29.         super(parent, "Edit Cylinder Node");
  30.  
  31.         vrml_data = data;
  32.         screen_data = tree;
  33.  
  34.         content_panel.setLayout(new GridLayout(4, 1));
  35.  
  36.         // now the first row. On the left is the Label and on the right is
  37.         // the 3 boxes for x, y and z, indicated by appropriate labels.
  38.         Panel p1 = new Panel();
  39.         p1.setLayout(new BorderLayout(15, 10));
  40.  
  41.         p1.add("West", new Label("Height", Label.LEFT));
  42.  
  43.         height = new TextField("2", 4);
  44.         p1.add("East", height);
  45.  
  46.         content_panel.add(p1);
  47.  
  48.         // The second row. Identical to the first with the exception that
  49.         // we have changed a label over
  50.         Panel p2 = new Panel();
  51.         p2.setLayout(new BorderLayout(15, 10));
  52.  
  53.         p2.add("West", new Label("Radius", Label.LEFT));
  54.  
  55.         radius = new TextField("1", 4);
  56.         p2.add("East", radius);
  57.  
  58.         content_panel.add(p2);
  59.  
  60.         // now the labe for the check boxes
  61.         content_panel.add(new Label("Show", Label.LEFT));
  62.  
  63.         // check boxes to turn parts of the geometry on and off.
  64.         Panel p3 = new Panel();
  65.         p3.setLayout(new GridLayout(1, 3));
  66.  
  67.         sides = new Checkbox("Sides", null, true);
  68.         top = new Checkbox("Top", null, true);
  69.         bottom = new Checkbox("Bottom", null, true);
  70.         p3.add(top);
  71.         p3.add(bottom);
  72.         p3.add(sides);
  73.  
  74.         content_panel.add(p3);
  75.  
  76.         pack();
  77.     }
  78.  
  79.     // read all the information back out of the panel and pass it
  80.     // to the appropriate place.
  81.     public boolean applyInformation()
  82.     {
  83.         String str;
  84.  
  85.         float h;
  86.         float r;
  87.  
  88.         Cylinder cyl;
  89.  
  90.         h = Float.valueOf(height.getText()).floatValue();
  91.         r = Float.valueOf(radius.getText()).floatValue();
  92.  
  93.         // are we creating a default node? This test for a yes
  94.         if((h != 2) || (r != 1) ||
  95.            !sides.getState() || !bottom.getState() || !top.getState())
  96.             cyl = new Cylinder(browser,
  97.                                r,
  98.                                h,
  99.                                sides.getState(),
  100.                                top.getState(),
  101.                                bottom.getState());
  102.         else
  103.             cyl = new Cylinder(browser);
  104.  
  105.         str = name.getText();
  106.  
  107.         if(str.equals(""))
  108.             cyl.name = null;
  109.         else
  110.             cyl.name = new String(str);
  111.  
  112.         try
  113.         {
  114.             vrml_data.addNode(VrmlTypes.Cylinder, cyl);
  115.         }
  116.         catch (NoSelectedNodeException e)
  117.         {
  118.             System.out.println("No node selected");
  119.         }
  120.  
  121.         return false;
  122.     }
  123.  
  124. }