home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / Image3D / lgimage3d.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-01-03  |  9.4 KB  |  494 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.Event;
  8. import java.awt.Font;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.LayoutManager;
  12. import java.awt.MediaTracker;
  13. import java.awt.image.ColorModel;
  14. import java.awt.image.MemoryImageSource;
  15. import java.awt.image.PixelGrabber;
  16. import java.net.URL;
  17.  
  18. public class lgimage3d extends Applet implements Runnable {
  19.    private Thread m_image3d;
  20.    private String m_image = "";
  21.    private int m_delay = 20;
  22.    private int m_pause;
  23.    private String m_background = "black";
  24.    private String m_link;
  25.    private String m_target;
  26.    private String m_info = "";
  27.    private String m_quality = "high";
  28.    private String m_axis = "y";
  29.    private boolean m_clockwise = true;
  30.    private final String PARAM_image = "image";
  31.    private final String PARAM_delay = "delay";
  32.    private final String PARAM_pause = "pause";
  33.    private final String PARAM_background = "background";
  34.    private final String PARAM_link = "link";
  35.    private final String PARAM_target = "target";
  36.    private final String PARAM_info = "info";
  37.    private final String PARAM_quality = "quality";
  38.    private final String PARAM_axis = "axis";
  39.    private final String PARAM_clockwise = "clockwise";
  40.    private Image[] images;
  41.    private Image image;
  42.    private PixelGrabber grabber;
  43.    private int[] pixels1;
  44.    private int[] pixels2;
  45.    // $FF: renamed from: w int
  46.    private int field_0;
  47.    // $FF: renamed from: h int
  48.    private int field_1;
  49.    private double degree;
  50.    private int centerx;
  51.    private int centery;
  52.    private Image offImage;
  53.    private Graphics offGraphics;
  54.    private Image ZoffImage;
  55.    private Graphics ZoffGraphics;
  56.    // $FF: renamed from: d java.awt.Dimension
  57.    private Dimension field_2;
  58.    // $FF: renamed from: i int
  59.    private int field_3;
  60.    private boolean drawable;
  61.    private boolean drawn;
  62.    private boolean firsttime = true;
  63.    private boolean mouseIn;
  64.    private String address = "http://www.lawrencegoetz.com/lgimage3dvisitor.html";
  65.    private URL mySite;
  66.    private double cos;
  67.    private double sin;
  68.    private Button site;
  69.    private boolean active;
  70.    private URL link;
  71.  
  72.    public boolean mouseEnter(Event var1, int var2, int var3) {
  73.       if (!this.mouseIn && this.site != null && this.field_2 != null) {
  74.          this.site.reshape(this.field_2.width - 70, this.field_2.height - 30, 70, 30);
  75.       }
  76.  
  77.       this.mouseIn = true;
  78.       if (this.m_info != null) {
  79.          ((Applet)this).getAppletContext().showStatus(this.m_info);
  80.       }
  81.  
  82.       return true;
  83.    }
  84.  
  85.    public void stop() {
  86.       if (this.m_image3d != null) {
  87.          this.m_image3d.stop();
  88.          this.m_image3d = null;
  89.       }
  90.  
  91.    }
  92.  
  93.    public void rotatez(int var1, int var2) {
  94.       int var5 = var1 - this.centerx;
  95.       int var6 = var2 - this.centery;
  96.       int var3 = (int)((double)var5 * this.cos + (double)var6 * this.sin);
  97.       int var4 = (int)((double)var6 * this.cos - (double)var5 * this.sin);
  98.       var3 += this.centerx;
  99.       var4 += this.centery;
  100.       if (var3 >= 0 && var3 <= this.field_0 - 1 && var4 >= 0 && var4 <= this.field_1 - 1) {
  101.          try {
  102.             this.pixels2[var2 * this.field_0 + var1] = this.pixels1[var4 * this.field_0 + var3];
  103.          } catch (Exception var7) {
  104.          }
  105.       }
  106.    }
  107.  
  108.    public void makeImages() {
  109.       this.degree = (double)0.1875F;
  110.       if (this.m_quality.equalsIgnoreCase("low")) {
  111.          this.degree = (double)0.375F;
  112.       }
  113.  
  114.       int var1 = 0;
  115.  
  116.       for(double var2 = (double)0.0F; var2 < (Math.PI * 2D); var2 += this.degree) {
  117.          ++var1;
  118.       }
  119.  
  120.       this.images = new Image[var1];
  121.       double var4 = this.degree;
  122.       this.field_3 = 0;
  123.  
  124.       for(this.degree = (double)0.0F; this.degree < (Math.PI * 2D); this.degree += var4) {
  125.          this.cos = Math.cos(this.degree);
  126.          if (this.m_axis.equalsIgnoreCase("z")) {
  127.             this.sin = Math.sin(this.degree);
  128.          }
  129.  
  130.          this.loading("Calculating frame", this.field_3 + 1 + " of " + var1);
  131.          this.animation(this.field_3);
  132.          ++this.field_3;
  133.       }
  134.  
  135.    }
  136.  
  137.    public void animation(int var1) {
  138.       this.field_0 = this.image.getWidth(this);
  139.       this.field_1 = this.image.getHeight(this);
  140.       this.pixels1 = new int[this.field_0 * this.field_1];
  141.       this.pixels2 = new int[this.field_0 * this.field_1];
  142.       this.grabber = new PixelGrabber(this.image, 0, 0, this.field_0, this.field_1, this.pixels1, 0, this.field_0);
  143.  
  144.       try {
  145.          this.grabber.grabPixels();
  146.       } catch (InterruptedException var4) {
  147.          ((Applet)this).getAppletContext().showStatus("Interruption");
  148.       }
  149.  
  150.       if (this.m_axis.equalsIgnoreCase("x")) {
  151.          for(int var2 = 0; var2 < this.field_1; ++var2) {
  152.             for(int var3 = 0; var3 < this.field_0; ++var3) {
  153.                this.rotatex(var3, var2, this.pixels1[var2 * this.field_0 + var3]);
  154.             }
  155.          }
  156.       } else if (this.m_axis.equalsIgnoreCase("z")) {
  157.          for(int var5 = 0; var5 < this.field_1; ++var5) {
  158.             for(int var7 = 0; var7 < this.field_0; ++var7) {
  159.                this.rotatez(var7, var5);
  160.             }
  161.          }
  162.       } else {
  163.          for(int var6 = 0; var6 < this.field_1; ++var6) {
  164.             for(int var8 = 0; var8 < this.field_0; ++var8) {
  165.                this.rotatey(var8, var6, this.pixels1[var6 * this.field_0 + var8]);
  166.             }
  167.          }
  168.       }
  169.  
  170.       this.images[var1] = ((Component)this).createImage(new MemoryImageSource(this.field_0, this.field_1, ColorModel.getRGBdefault(), this.pixels2, 0, this.field_0));
  171.    }
  172.  
  173.    public boolean mouseExit(Event var1, int var2, int var3) {
  174.       if (this.field_2 != null) {
  175.          if (var2 > 0 && var2 < this.field_2.width && var3 > 0 && var3 < this.field_2.height) {
  176.             return true;
  177.          }
  178.  
  179.          if (this.mouseIn && this.site != null) {
  180.             this.site.reshape(this.field_2.width - 70, this.field_2.height - 30, 0, 0);
  181.          }
  182.       }
  183.  
  184.       ((Applet)this).getAppletContext().showStatus("");
  185.       this.mouseIn = false;
  186.       return true;
  187.    }
  188.  
  189.    public void loading(String var1, String var2) {
  190.       this.offGraphics.setColor(Color.white);
  191.       this.offGraphics.fillRect(0, 0, this.field_2.width, this.field_2.height);
  192.       this.offGraphics.setColor(Color.black);
  193.       this.offGraphics.drawString(var1, 5, 15);
  194.       this.offGraphics.drawString(var2, 5, 35);
  195.       this.drawn = false;
  196.       this.drawable = true;
  197.       ((Component)this).repaint();
  198.  
  199.       while(!this.drawn) {
  200.          try {
  201.             Thread.sleep(10L);
  202.          } catch (Exception var3) {
  203.          }
  204.       }
  205.  
  206.       this.drawable = false;
  207.    }
  208.  
  209.    public void paint(Graphics var1) {
  210.       if (this.drawable) {
  211.          if (!this.active) {
  212.             var1.drawImage(this.offImage, 0, 0, this);
  213.             this.drawn = true;
  214.          } else {
  215.             if (this.images[this.field_3] != null) {
  216.                int var2 = (this.field_2.width - this.images[this.field_3].getWidth(this)) / 2;
  217.                int var3 = (this.field_2.height - this.images[this.field_3].getHeight(this)) / 2;
  218.                this.setMyColor(this.offGraphics, this.m_background);
  219.                this.offGraphics.fillRect(0, 0, this.field_2.width, this.field_2.height);
  220.                this.offGraphics.drawImage(this.images[this.field_3], var2, var3, this);
  221.                var1.drawImage(this.offImage, 0, 0, this);
  222.             }
  223.  
  224.             this.drawn = true;
  225.          }
  226.       }
  227.    }
  228.  
  229.    public void create() {
  230.       if (this.firsttime) {
  231.          this.degree = (double)0.0F;
  232.          this.field_2 = ((Component)this).size();
  233.          if (this.offImage == null) {
  234.             this.offImage = ((Component)this).createImage(this.field_2.width, this.field_2.height);
  235.             this.offGraphics = this.offImage.getGraphics();
  236.             Object var1 = null;
  237.             Font var5 = new Font("Helvetica", 0, 12);
  238.             this.offGraphics.getFontMetrics(var5);
  239.             this.offGraphics.setFont(var5);
  240.          }
  241.  
  242.          this.loading("Loading image...", "");
  243.          this.image = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_image);
  244.          MediaTracker var6 = new MediaTracker(this);
  245.          var6.addImage(this.image, 0);
  246.  
  247.          try {
  248.             var6.waitForID(0);
  249.          } catch (InterruptedException var4) {
  250.          }
  251.  
  252.          if (this.m_axis.equalsIgnoreCase("z")) {
  253.             int var2 = (this.field_2.width - this.image.getWidth(this)) / 2;
  254.             int var3 = (this.field_2.height - this.image.getHeight(this)) / 2;
  255.             this.ZoffImage = ((Component)this).createImage(this.field_2.width, this.field_2.height);
  256.             this.ZoffGraphics = this.ZoffImage.getGraphics();
  257.             this.setMyColor(this.ZoffGraphics, this.m_background);
  258.             this.ZoffGraphics.fillRect(0, 0, this.field_2.width, this.field_2.height);
  259.             this.ZoffGraphics.drawImage(this.image, var2, var3, this);
  260.             this.image = this.ZoffImage;
  261.          }
  262.  
  263.          this.field_0 = this.image.getWidth(this);
  264.          this.field_1 = this.image.getHeight(this);
  265.          this.centerx = this.field_0 / 2;
  266.          this.centery = this.field_1 / 2;
  267.          this.makeImages();
  268.       }
  269.    }
  270.  
  271.    public String[][] getParameterInfo() {
  272.       String[][] var1 = new String[][]{{"image", "String", "Image Name"}, {"delay", "String", "Delay between frames"}, {"pause", "String", "Pause after front image"}, {"background", "String", "Background color"}, {"link", "String", "Link for applet"}, {"target", "String", "Target for link"}, {"info", "String", "Info for link"}, {"quality", "String", "Rotation quality"}, {"axis", "String", "Rotation axis"}, {"clockwise", "String", "Rotation direction"}};
  273.       return var1;
  274.    }
  275.  
  276.    public void destroy() {
  277.       if (this.m_image3d != null) {
  278.          this.m_image3d.stop();
  279.          this.m_image3d = null;
  280.       }
  281.  
  282.       this.images = null;
  283.    }
  284.  
  285.    public void update(Graphics var1) {
  286.       this.paint(var1);
  287.    }
  288.  
  289.    public void rotatex(int var1, int var2, int var3) {
  290.       int var5 = var2 - this.centery;
  291.       int var4 = (int)((double)var5 * this.cos);
  292.       var4 += this.centery;
  293.  
  294.       try {
  295.          this.pixels2[var4 * this.field_0 + var1] = var3;
  296.       } catch (Exception var6) {
  297.       }
  298.    }
  299.  
  300.    public void start() {
  301.       if (this.m_image3d == null) {
  302.          this.m_image3d = new Thread(this);
  303.          this.m_image3d.start();
  304.       }
  305.  
  306.    }
  307.  
  308.    public String getAppletInfo() {
  309.       return "Name: lgimage3d\r\n" + "Author: Lawrence Goetz\r\n" + "E-mail: goetz@lawrencegoetz.com\r\n" + "Website: http://www.lawrencegoetz.com/\r\n" + "Created with Microsoft Visual J++ Version 1.1";
  310.    }
  311.  
  312.    public boolean mouseDown(Event var1, int var2, int var3) {
  313.       if (this.field_2 != null && (var2 < this.field_2.width - 70 || var3 < this.field_2.height - 30) && this.link != null) {
  314.          if (this.m_target != null) {
  315.             ((Applet)this).getAppletContext().showDocument(this.link, this.m_target);
  316.          } else {
  317.             ((Applet)this).getAppletContext().showDocument(this.link);
  318.          }
  319.       }
  320.  
  321.       return true;
  322.    }
  323.  
  324.    public boolean action(Event var1, Object var2) {
  325.       if ((String)var2 == "About") {
  326.          if (this.site != null) {
  327.             this.site.reshape(this.field_2.width - 70, this.field_2.height - 30, 0, 0);
  328.          }
  329.  
  330.          ((Applet)this).getAppletContext().showDocument(this.mySite, "_blank");
  331.          return true;
  332.       } else {
  333.          return super.handleEvent(var1);
  334.       }
  335.    }
  336.  
  337.    public void rotatey(int var1, int var2, int var3) {
  338.       int var5 = var1 - this.centerx;
  339.       int var4 = (int)((double)var5 * this.cos);
  340.       var4 += this.centerx;
  341.  
  342.       try {
  343.          this.pixels2[var2 * this.field_0 + var4] = var3;
  344.       } catch (Exception var6) {
  345.       }
  346.    }
  347.  
  348.    public void run() {
  349.       try {
  350.          this.create();
  351.       } catch (Exception var4) {
  352.       }
  353.  
  354.       this.firsttime = false;
  355.       this.field_3 = 0;
  356.       this.active = true;
  357.  
  358.       while(true) {
  359.          this.drawn = false;
  360.          this.drawable = true;
  361.          ((Component)this).repaint();
  362.  
  363.          while(!this.drawn) {
  364.             try {
  365.                Thread.sleep(20L);
  366.             } catch (Exception var2) {
  367.             }
  368.          }
  369.  
  370.          if (this.field_3 == 0 && this.m_pause > 0) {
  371.             try {
  372.                Thread.sleep((long)this.m_pause);
  373.             } catch (Exception var1) {
  374.             }
  375.          } else {
  376.             try {
  377.                Thread.sleep((long)this.m_delay);
  378.             } catch (Exception var3) {
  379.             }
  380.          }
  381.  
  382.          this.drawable = false;
  383.          if (this.m_clockwise) {
  384.             ++this.field_3;
  385.             if (this.field_3 == this.images.length) {
  386.                this.field_3 = 0;
  387.             }
  388.          } else {
  389.             this.field_3 += -1;
  390.             if (this.field_3 == -1) {
  391.                this.field_3 = this.images.length - 1;
  392.             }
  393.          }
  394.       }
  395.    }
  396.  
  397.    public void init() {
  398.       String var1 = ((Applet)this).getParameter("image");
  399.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  400.          this.m_image = var1;
  401.       }
  402.  
  403.       var1 = ((Applet)this).getParameter("delay");
  404.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  405.          this.m_delay = new Integer(var1);
  406.       }
  407.  
  408.       var1 = ((Applet)this).getParameter("pause");
  409.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  410.          this.m_pause = new Integer(var1);
  411.       }
  412.  
  413.       var1 = ((Applet)this).getParameter("background");
  414.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  415.          this.m_background = var1;
  416.       }
  417.  
  418.       var1 = ((Applet)this).getParameter("link");
  419.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  420.          this.m_link = var1;
  421.  
  422.          try {
  423.             this.link = new URL(((Applet)this).getDocumentBase(), this.m_link);
  424.          } catch (Exception var3) {
  425.          }
  426.       }
  427.  
  428.       var1 = ((Applet)this).getParameter("target");
  429.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  430.          this.m_target = var1;
  431.       }
  432.  
  433.       var1 = ((Applet)this).getParameter("info");
  434.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  435.          this.m_info = var1;
  436.       }
  437.  
  438.       var1 = ((Applet)this).getParameter("quality");
  439.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  440.          this.m_quality = var1;
  441.       }
  442.  
  443.       var1 = ((Applet)this).getParameter("axis");
  444.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  445.          this.m_axis = var1;
  446.       }
  447.  
  448.       var1 = ((Applet)this).getParameter("clockwise");
  449.       if (var1 != null && !var1.equalsIgnoreCase("")) {
  450.          this.m_clockwise = new Boolean(var1);
  451.       }
  452.  
  453.       try {
  454.          this.mySite = new URL(((Applet)this).getDocumentBase(), this.address + "?" + ((Applet)this).getDocumentBase());
  455.       } catch (Exception var2) {
  456.       }
  457.  
  458.       ((Container)this).setLayout((LayoutManager)null);
  459.       if (this.firsttime) {
  460.          ((Container)this).add(this.site = new Button("About"));
  461.       }
  462.  
  463.    }
  464.  
  465.    public void setMyColor(Graphics var1, String var2) {
  466.       if (var2.equals("white")) {
  467.          var1.setColor(Color.white);
  468.       } else if (var2.equals("black")) {
  469.          var1.setColor(Color.black);
  470.       } else if (var2.equals("gray")) {
  471.          var1.setColor(Color.gray);
  472.       } else if (var2.equals("red")) {
  473.          var1.setColor(Color.red);
  474.       } else if (var2.equals("pink")) {
  475.          var1.setColor(Color.pink);
  476.       } else if (var2.equals("orange")) {
  477.          var1.setColor(Color.orange);
  478.       } else if (var2.equals("yellow")) {
  479.          var1.setColor(Color.yellow);
  480.       } else if (var2.equals("green")) {
  481.          var1.setColor(Color.green);
  482.       } else if (var2.equals("magenta")) {
  483.          var1.setColor(Color.magenta);
  484.       } else if (var2.equals("cyan")) {
  485.          var1.setColor(Color.cyan);
  486.       } else {
  487.          if (var2.equals("blue")) {
  488.             var1.setColor(Color.blue);
  489.          }
  490.  
  491.       }
  492.    }
  493. }
  494.