home *** CD-ROM | disk | FTP | other *** search
- // VRML Generator
- // (c) Justin Couch
- //
- // From Chapter 13: Late Night VRML 2.0 and Java
- //
- // The MovieTexture Dialog
-
- package ui.dialogs;
-
- import java.awt.*;
- import java.util.*;
- import ui.dialogs.VrmlBaseDialog;
- import geometry.MovieTexture;
- import ui.VrmlTree;
- import VrmlScene;
- import VrmlTypes;
- import exceptions.NoSelectedNodeException;
-
-
- public class MovieTextureDialog extends VrmlBaseDialog
- {
- private TextField speed;
- private TextField start, stop;
- private TextArea URLs;
- private Checkbox repeatS, repeatT;
- private Checkbox looping;
-
- public MovieTextureDialog(Frame parent, VrmlTree tree, VrmlScene data)
- {
- super(parent, "Edit MovieTexture Node");
-
- vrml_data = data;
- screen_data = tree;
-
- content_panel.setLayout(new BorderLayout(5, 5));
-
- // The URL box
- Panel p1 = new Panel();
- p1.setLayout(new BorderLayout(0, 0));
-
- p1.add("West", new Label("Image URLs:"));
-
- URLs = new TextArea(3, 30);
- p1.add("East", URLs);
- content_panel.add("North", p1);
-
- // Time control section
- Panel p2 = new Panel();
- p2.setLayout(new GridLayout(5, 1));
-
- // loop
- Panel p3 = new Panel();
- p3.setLayout(new BorderLayout());
-
- p3.add("West", new Label("Loop:"));
- looping = new Checkbox("", null, false);
- p3.add("East", looping);
- p2.add(p3);
-
- // speed
- Panel p4 = new Panel();
- p4.setLayout(new BorderLayout(0, 0));
- p4.add("West", new Label("Playing speed"));
- speed = new TextField("1", 5);
- p4.add("East", speed);
- p2.add(p4);
-
- // startTime
- Panel p5 = new Panel();
- p5.setLayout(new BorderLayout(0, 0));
- p5.add("West", new Label("Start time"));
- start = new TextField("0", 5);
- p5.add("East", start);
- p2.add(p5);
-
- // stopTime
- Panel p6 = new Panel();
- p6.setLayout(new BorderLayout(0, 0));
- p6.add("West", new Label("Stop time"));
- stop = new TextField("0", 5);
- p6.add("East", stop);
- p2.add(p6);
-
- // The Texture mapping section
- Panel p7 = new Panel();
- p7.setLayout(new BorderLayout(0, 0));
-
- p7.add("West", new Label("Texture Wrapping"));
-
- Panel p8 = new Panel();
- p8.setLayout(new GridLayout(1, 2));
-
- repeatS = new Checkbox("S ", null, true);
- repeatT = new Checkbox("T ", null, true);
- p8.add(repeatS);
- p8.add(repeatT);
-
- p7.add("East", p8);
-
- p2.add(p7);
- content_panel.add("Center", p2);
-
- pack();
- }
-
- // read all the information back out of the panel and pass it
- // to the appropriate place.
- public boolean applyInformation()
- {
- int i;
- String str;
- StringTokenizer strtok;
- String[] url_strings;
- MovieTexture mt;
- float spd;
- float strt, stp;
-
- // are we creating a default node? This test for a yes
- if(!repeatS.getState() || !repeatT.getState())
- mt = new MovieTexture(browser, repeatS.getState(), repeatT.getState());
- else
- mt = new MovieTexture(browser);
-
- str = name.getText();
-
- if(str.equals(""))
- mt.name = null;
- else
- mt.name = new String(str);
-
- // now put in the URLs The problem is that we need to break up
- // a single line of text into multiple strings. Do this with a
- // stringTokeniser; The delimiters are: comma, space, CR, LF, tab
- strtok = new StringTokenizer(URLs.getText(), ", \n ");
- url_strings = new String[strtok.countTokens()];
-
- for(i = 0; i < strtok.countTokens(); i++)
- url_strings[i] = new String(strtok.nextToken());
-
- mt.set_URL(url_strings);
-
- // and set the rest of the default values
- // loop
- mt.set_loop(looping.getState());
-
- // speed
- spd = Float.valueOf(speed.getText()).floatValue();
- if(spd != 1)
- mt.set_speed(spd);
-
- // startTime
- strt = Float.valueOf(start.getText()).floatValue();
- if(strt != 0)
- mt.set_startTime(strt);
-
- stp = Float.valueOf(stop.getText()).floatValue();
- if(stp != 0)
- mt.set_stopTime(stp);
-
- try
- {
- vrml_data.addNode(VrmlTypes.MovieTexture, mt);
- }
- catch (NoSelectedNodeException e)
- {
- System.out.println("No node selected");
- }
-
- return false;
- }
-
- }