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 >
Text File  |  1997-01-02  |  4KB  |  174 lines

  1. // VRML Generator
  2. // (c) Justin Couch
  3. //
  4. // From Chapter 13: Late Night VRML 2.0 and Java
  5. //
  6. // The TextureTransform node dialog.
  7.  
  8. package ui.dialogs;
  9.  
  10. import java.awt.*;
  11. import ui.dialogs.VrmlBaseDialog;
  12. import geometry.TextureTransform;
  13. import ui.VrmlTree;
  14. import VrmlScene;
  15. import VrmlTypes;
  16. import exceptions.NoSelectedNodeException;
  17.  
  18.  
  19. public class TextureTransformDialog extends VrmlBaseDialog
  20. {
  21.  
  22.     private TextField    trans_x, trans_y;
  23.     private TextField    center_x, center_y;
  24.     private TextField    rotate;
  25.     private TextField    scale_x, scale_y;
  26.  
  27.     public TextureTransformDialog(Frame parent, VrmlTree tree, VrmlScene data)
  28.     {
  29.         super(parent, "Edit TextureTransform Node");
  30.  
  31.         vrml_data = data;
  32.         screen_data = tree;
  33.  
  34.         content_panel.setLayout(new GridLayout(4, 1));
  35.  
  36.         // centre fields
  37.         Panel p1 = new Panel();
  38.         p1.setLayout(new BorderLayout(5, 0));
  39.  
  40.         p1.add("West", new Label("Center:"));
  41.  
  42.         Panel p2 = new Panel();
  43.         p2.setLayout(new GridLayout(1, 4));
  44.  
  45.         // the 3 components.
  46.         center_x = new TextField("0", 5);
  47.         center_y = new TextField("0", 5);
  48.  
  49.         p2.add(new Label("x: ", Label.RIGHT));
  50.         p2.add(center_x);
  51.         p2.add(new Label("y: ", Label.RIGHT));
  52.         p2.add(center_y);
  53.  
  54.         p1.add("East", p2);
  55.         content_panel.add(p1);
  56.  
  57.         // rotation
  58.         Panel p3 = new Panel();
  59.         p3.setLayout(new BorderLayout(15, 10));
  60.  
  61.         rotate = new TextField("0", 5);
  62.         p3.add("West", new Label("Rotation:"));
  63.         p3.add("East", rotate);
  64.         content_panel.add(p3);
  65.  
  66.         // scale fields
  67.         Panel p5 = new Panel();
  68.         p5.setLayout(new BorderLayout(5, 0));
  69.  
  70.         p5.add("West", new Label("Scale:"));
  71.  
  72.         Panel p6 = new Panel();
  73.         p6.setLayout(new GridLayout(1, 4));
  74.  
  75.         // the 3 components.
  76.         scale_x = new TextField("1", 5);
  77.         scale_y = new TextField("1", 5);
  78.  
  79.         p6.add(new Label("x: ", Label.RIGHT));
  80.         p6.add(scale_x);
  81.         p6.add(new Label("y: ", Label.RIGHT));
  82.         p6.add(scale_y);
  83.  
  84.         p5.add("East", p6);
  85.         content_panel.add(p5);
  86.  
  87.         // scale Orientation
  88.         Panel p7 = new Panel();
  89.         p7.setLayout(new BorderLayout(5, 0));
  90.  
  91.         p7.add("West", new Label("Translation:"));
  92.  
  93.         Panel p8 = new Panel();
  94.         p8.setLayout(new GridLayout(1, 8));
  95.  
  96.         // the 3 components.
  97.         trans_x = new TextField("0", 5);
  98.         trans_y = new TextField("0", 5);
  99.  
  100.         p8.add(new Label("x: ", Label.RIGHT));
  101.         p8.add(trans_x);
  102.         p8.add(new Label("y: ", Label.RIGHT));
  103.         p8.add(trans_y);
  104.  
  105.         p7.add("East", p8);
  106.         content_panel.add(p7);
  107.  
  108.         pack();
  109.     }
  110.  
  111.     // read all the information back out of the panel and pass it
  112.     // to the appropriate place.
  113.     public boolean applyInformation()
  114.     {
  115.         String str;
  116.  
  117.         float tx_x, tx_y;
  118.         float c_x, c_y;
  119.         float rot;
  120.         float sc_x, sc_y;
  121.  
  122.         TextureTransform ttransform;
  123.  
  124.         // first get the basic node constructed
  125.         ttransform = new TextureTransform(browser);
  126.  
  127.         str = name.getText();
  128.  
  129.         if(str.equals(""))
  130.             ttransform.name = null;
  131.         else
  132.             ttransform.name = new String(str);
  133.  
  134.         // now we update the fields
  135.         // translation
  136.         tx_x = Float.valueOf(trans_x.getText()).floatValue();
  137.         tx_y = Float.valueOf(trans_y.getText()).floatValue();
  138.  
  139.         if((tx_x != 0) || (tx_y != 0))
  140.             ttransform.set_translation(tx_x, tx_y);
  141.  
  142.         // center
  143.         c_x = Float.valueOf(center_x.getText()).floatValue();
  144.         c_y = Float.valueOf(center_y.getText()).floatValue();
  145.  
  146.         if((c_x != 0) || (c_y != 0))
  147.             ttransform.set_center(c_x, c_y);
  148.  
  149.         // rotation
  150.         rot = Float.valueOf(rotate.getText()).floatValue();
  151.  
  152.         if(rot != 0)
  153.             ttransform.set_rotation(rot);
  154.  
  155.         // scale
  156.         sc_x = Float.valueOf(scale_x.getText()).floatValue();
  157.         sc_y = Float.valueOf(scale_y.getText()).floatValue();
  158.  
  159.         if((sc_x != 1) || (sc_y != 1))
  160.             ttransform.set_scale(sc_x, sc_y);
  161.  
  162.         try
  163.         {
  164.             vrml_data.addNode(VrmlTypes.TextureTransform, ttransform);
  165.         }
  166.         catch (NoSelectedNodeException e)
  167.         {
  168.             System.out.println("No node selected");
  169.         }
  170.  
  171.         return false;
  172.     }
  173.  
  174. }