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

  1. // VRML Generator
  2. // (c) Justin Couch
  3. //
  4. // From Chapter 13: Late Night VRML 2.0 and Java
  5. //
  6. // The Group node dialog. Only needs to get the bounding box size
  7. // and center as well as a DEF name.
  8.  
  9. package ui.dialogs;
  10.  
  11. import java.awt.*;
  12. import java.util.*;
  13. import ui.dialogs.VrmlBaseDialog;
  14. import geometry.ImageTexture;
  15. import ui.VrmlTree;
  16. import VrmlScene;
  17. import VrmlTypes;
  18. import exceptions.NoSelectedNodeException;
  19.  
  20.  
  21. public class ImageTextureDialog extends VrmlBaseDialog
  22. {
  23.     private TextArea    URLs;
  24.     private Checkbox    repeatS, repeatT;
  25.  
  26.     public ImageTextureDialog(Frame parent, VrmlTree tree, VrmlScene data)
  27.     {
  28.         super(parent, "Edit ImageTexture Node");
  29.  
  30.         vrml_data = data;
  31.         screen_data = tree;
  32.  
  33.         content_panel.setLayout(new BorderLayout(5, 5));
  34.  
  35.         // The URL box
  36.         Panel p1 = new Panel();
  37.         p1.setLayout(new BorderLayout(0, 0));
  38.  
  39.         p1.add("West", new Label("Image URLs:"));
  40.  
  41.         URLs = new TextArea(3, 30);
  42.         p1.add("East", URLs);
  43.         content_panel.add("North", p1);
  44.  
  45.         // The Texture mapping section
  46.         Panel p2 = new Panel();
  47.         p2.setLayout(new GridLayout(2, 1));
  48.  
  49.         p2.add(new Label("Texture Wrapping"));
  50.  
  51.         Panel p3 = new Panel();
  52.         p3.setLayout(new GridLayout(1, 2));
  53.  
  54.         repeatS = new Checkbox(" S", null, true);
  55.         repeatT = new Checkbox(" T", null, true);
  56.         p3.add(repeatS);
  57.         p3.add(repeatT);
  58.  
  59.         p2.add(p3);
  60.         content_panel.add("South", p2);
  61.  
  62.         pack();
  63.     }
  64.  
  65.     // read all the information back out of the panel and pass it
  66.     // to the appropriate place.
  67.     public boolean applyInformation()
  68.     {
  69.         int        i;
  70.         String    str;
  71.         StringTokenizer strtok;
  72.         String[] url_strings;
  73.         ImageTexture it;
  74.  
  75.         // are we creating a default node? This test for a yes
  76.         if(!repeatS.getState() ||  !repeatT.getState())
  77.             it = new ImageTexture(browser, repeatS.getState(), repeatT.getState());
  78.         else
  79.             it = new ImageTexture(browser);
  80.  
  81.         str = name.getText();
  82.  
  83.         if(str.equals(""))
  84.             it.name = null;
  85.         else
  86.             it.name = new String(str);
  87.  
  88.         // now put in the URLs The problem is that we need to break up
  89.         // a single line of text into multiple strings. Do this with a
  90.         // stringTokeniser; The delimiters are: comma, space, CR, LF, tab
  91.         strtok = new StringTokenizer(URLs.getText());
  92.         url_strings = new String[strtok.countTokens()];
  93.  
  94.         for(i = 0; i < strtok.countTokens(); i++)
  95.             url_strings[i] = new String(strtok.nextToken());
  96.             
  97.         it.set_URL(url_strings);
  98.         
  99.         try
  100.         {
  101.             vrml_data.addNode(VrmlTypes.ImageTexture, it);
  102.         }
  103.         catch (NoSelectedNodeException e)
  104.         {
  105.             System.out.println("No node selected");
  106.         }
  107.  
  108.         return false;
  109.     }
  110.  
  111. }