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

  1. // VRML Generator
  2. // (c) Justin Couch
  3. //
  4. // From Chapter 13: Late Night VRML 2.0 and Java
  5. //
  6. // The MovieTexture Dialog
  7.  
  8. package ui.dialogs;
  9.  
  10. import java.awt.*;
  11. import java.util.*;
  12. import ui.dialogs.VrmlBaseDialog;
  13. import geometry.MovieTexture;
  14. import ui.VrmlTree;
  15. import VrmlScene;
  16. import VrmlTypes;
  17. import exceptions.NoSelectedNodeException;
  18.  
  19.  
  20. public class MovieTextureDialog extends VrmlBaseDialog
  21. {
  22.     private    TextField    speed;
  23.     private TextField    start, stop;
  24.     private TextArea    URLs;
  25.     private Checkbox    repeatS, repeatT;
  26.     private Checkbox    looping;
  27.  
  28.     public MovieTextureDialog(Frame parent, VrmlTree tree, VrmlScene data)
  29.     {
  30.         super(parent, "Edit MovieTexture Node");
  31.  
  32.         vrml_data = data;
  33.         screen_data = tree;
  34.  
  35.         content_panel.setLayout(new BorderLayout(5, 5));
  36.  
  37.         // The URL box
  38.         Panel p1 = new Panel();
  39.         p1.setLayout(new BorderLayout(0, 0));
  40.  
  41.         p1.add("West", new Label("Image URLs:"));
  42.  
  43.         URLs = new TextArea(3, 30);
  44.         p1.add("East", URLs);
  45.         content_panel.add("North", p1);
  46.  
  47.         // Time control section
  48.         Panel p2 = new Panel();
  49.         p2.setLayout(new GridLayout(5, 1));
  50.  
  51.         // loop
  52.         Panel p3 = new Panel();
  53.         p3.setLayout(new BorderLayout());
  54.  
  55.         p3.add("West", new Label("Loop:"));
  56.         looping = new Checkbox("", null, false);
  57.         p3.add("East", looping);
  58.         p2.add(p3);
  59.  
  60.         // speed
  61.         Panel p4 = new Panel();
  62.         p4.setLayout(new BorderLayout(0, 0));
  63.         p4.add("West", new Label("Playing speed"));
  64.         speed = new TextField("1", 5);
  65.         p4.add("East", speed);
  66.         p2.add(p4);
  67.  
  68.         // startTime
  69.         Panel p5 = new Panel();
  70.         p5.setLayout(new BorderLayout(0, 0));
  71.         p5.add("West", new Label("Start time"));
  72.         start = new TextField("0", 5);
  73.         p5.add("East", start);
  74.         p2.add(p5);
  75.  
  76.         // stopTime
  77.         Panel p6 = new Panel();
  78.         p6.setLayout(new BorderLayout(0, 0));
  79.         p6.add("West", new Label("Stop time"));
  80.         stop = new TextField("0", 5);
  81.         p6.add("East", stop);
  82.         p2.add(p6);
  83.  
  84.         // The Texture mapping section
  85.         Panel p7 = new Panel();
  86.         p7.setLayout(new BorderLayout(0, 0));
  87.  
  88.         p7.add("West", new Label("Texture Wrapping"));
  89.  
  90.         Panel p8 = new Panel();
  91.         p8.setLayout(new GridLayout(1, 2));
  92.  
  93.         repeatS = new Checkbox("S  ", null, true);
  94.         repeatT = new Checkbox("T  ", null, true);
  95.         p8.add(repeatS);
  96.         p8.add(repeatT);
  97.  
  98.         p7.add("East", p8);
  99.  
  100.         p2.add(p7);
  101.         content_panel.add("Center", p2);
  102.  
  103.         pack();
  104.     }
  105.  
  106.     // read all the information back out of the panel and pass it
  107.     // to the appropriate place.
  108.     public boolean applyInformation()
  109.     {
  110.         int        i;
  111.         String    str;
  112.         StringTokenizer strtok;
  113.         String[] url_strings;
  114.         MovieTexture mt;
  115.         float    spd;
  116.         float    strt, stp;
  117.  
  118.         // are we creating a default node? This test for a yes
  119.         if(!repeatS.getState() ||  !repeatT.getState())
  120.             mt = new MovieTexture(browser, repeatS.getState(), repeatT.getState());
  121.         else
  122.             mt = new MovieTexture(browser);
  123.  
  124.         str = name.getText();
  125.  
  126.         if(str.equals(""))
  127.             mt.name = null;
  128.         else
  129.             mt.name = new String(str);
  130.  
  131.         // now put in the URLs The problem is that we need to break up
  132.         // a single line of text into multiple strings. Do this with a
  133.         // stringTokeniser; The delimiters are: comma, space, CR, LF, tab
  134.         strtok = new StringTokenizer(URLs.getText(), ", \n    ");
  135.         url_strings = new String[strtok.countTokens()];
  136.  
  137.         for(i = 0; i < strtok.countTokens(); i++)
  138.             url_strings[i] = new String(strtok.nextToken());
  139.  
  140.         mt.set_URL(url_strings);
  141.  
  142.         // and set the rest of the default values
  143.         // loop
  144.         mt.set_loop(looping.getState());
  145.  
  146.         // speed
  147.         spd = Float.valueOf(speed.getText()).floatValue();
  148.         if(spd != 1)
  149.             mt.set_speed(spd);
  150.  
  151.         // startTime
  152.         strt = Float.valueOf(start.getText()).floatValue();
  153.         if(strt != 0)
  154.             mt.set_startTime(strt);
  155.  
  156.         stp = Float.valueOf(stop.getText()).floatValue();
  157.         if(stp != 0)
  158.             mt.set_stopTime(stp);
  159.  
  160.         try
  161.         {
  162.             vrml_data.addNode(VrmlTypes.MovieTexture, mt);
  163.         }
  164.         catch (NoSelectedNodeException e)
  165.         {
  166.             System.out.println("No node selected");
  167.         }
  168.  
  169.         return false;
  170.     }
  171.  
  172. }