home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / WDESAMPL.BIN / XYZApp.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-11-19  |  4.5 KB  |  180 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Dimension;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.io.InputStream;
  8. import java.net.URL;
  9.  
  10. public class XYZApp extends Applet implements Runnable {
  11.    // $FF: renamed from: md XYZChemModel
  12.    XYZChemModel field_0;
  13.    boolean painted = true;
  14.    float xfac;
  15.    int prevx;
  16.    int prevy;
  17.    float xtheta;
  18.    float ytheta;
  19.    float scalefudge = 1.0F;
  20.    Matrix3D amat = new Matrix3D();
  21.    Matrix3D tmat = new Matrix3D();
  22.    String mdname;
  23.    String message;
  24.    Image backBuffer;
  25.    Graphics backGC;
  26.    Dimension backSize;
  27.  
  28.    private synchronized void newBackBuffer() {
  29.       this.backBuffer = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  30.       this.backGC = this.backBuffer.getGraphics();
  31.       this.backSize = ((Component)this).size();
  32.    }
  33.  
  34.    public void init() {
  35.       this.mdname = ((Applet)this).getParameter("model");
  36.  
  37.       try {
  38.          this.scalefudge = Float.valueOf(((Applet)this).getParameter("scale"));
  39.       } catch (Exception var1) {
  40.       }
  41.  
  42.       this.amat.yrot((double)20.0F);
  43.       this.amat.xrot((double)20.0F);
  44.       if (this.mdname == null) {
  45.          this.mdname = "model.obj";
  46.       }
  47.  
  48.       ((Applet)this).resize(((Component)this).size().width <= 20 ? 400 : ((Component)this).size().width, ((Component)this).size().height <= 20 ? 400 : ((Component)this).size().height);
  49.       this.newBackBuffer();
  50.    }
  51.  
  52.    public void run() {
  53.       InputStream var1 = null;
  54.  
  55.       try {
  56.          Thread.currentThread().setPriority(1);
  57.          var1 = (new URL(((Applet)this).getDocumentBase(), this.mdname)).openStream();
  58.          XYZChemModel var2 = new XYZChemModel(var1);
  59.          Atom.setApplet(this);
  60.          this.field_0 = var2;
  61.          var2.findBB();
  62.          float var3 = var2.xmax - var2.xmin;
  63.          float var4 = var2.ymax - var2.ymin;
  64.          float var5 = var2.zmax - var2.zmin;
  65.          if (var4 > var3) {
  66.             var3 = var4;
  67.          }
  68.  
  69.          if (var5 > var3) {
  70.             var3 = var5;
  71.          }
  72.  
  73.          float var6 = (float)((Component)this).size().width / var3;
  74.          float var7 = (float)((Component)this).size().height / var3;
  75.          this.xfac = 0.7F * (var6 < var7 ? var6 : var7) * this.scalefudge;
  76.       } catch (Exception var9) {
  77.          ((Throwable)var9).printStackTrace();
  78.          this.field_0 = null;
  79.          this.message = ((Throwable)var9).toString();
  80.       }
  81.  
  82.       try {
  83.          if (var1 != null) {
  84.             var1.close();
  85.          }
  86.       } catch (Exception var8) {
  87.       }
  88.  
  89.       ((Component)this).repaint();
  90.    }
  91.  
  92.    public void start() {
  93.       if (this.field_0 == null && this.message == null) {
  94.          (new Thread(this)).start();
  95.       }
  96.  
  97.    }
  98.  
  99.    public void stop() {
  100.    }
  101.  
  102.    public boolean mouseDown(Event var1, int var2, int var3) {
  103.       this.prevx = var2;
  104.       this.prevy = var3;
  105.       return true;
  106.    }
  107.  
  108.    public boolean mouseDrag(Event var1, int var2, int var3) {
  109.       this.tmat.unit();
  110.       float var4 = (float)(this.prevy - var3) * (360.0F / (float)((Component)this).size().width);
  111.       float var5 = (float)(var2 - this.prevx) * (360.0F / (float)((Component)this).size().height);
  112.       this.tmat.xrot((double)var4);
  113.       this.tmat.yrot((double)var5);
  114.       this.amat.mult(this.tmat);
  115.       if (this.painted) {
  116.          this.painted = false;
  117.          ((Component)this).repaint();
  118.       }
  119.  
  120.       this.prevx = var2;
  121.       this.prevy = var3;
  122.       return true;
  123.    }
  124.  
  125.    public void update(Graphics var1) {
  126.       if (this.backBuffer == null) {
  127.          var1.clearRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  128.       }
  129.  
  130.       this.paint(var1);
  131.    }
  132.  
  133.    public void paint(Graphics var1) {
  134.       if (this.field_0 != null) {
  135.          this.field_0.mat.unit();
  136.          this.field_0.mat.translate(-(this.field_0.xmin + this.field_0.xmax) / 2.0F, -(this.field_0.ymin + this.field_0.ymax) / 2.0F, -(this.field_0.zmin + this.field_0.zmax) / 2.0F);
  137.          this.field_0.mat.mult(this.amat);
  138.          this.field_0.mat.scale(this.xfac, -this.xfac, 16.0F * this.xfac / (float)((Component)this).size().width);
  139.          this.field_0.mat.translate((float)(((Component)this).size().width / 2), (float)(((Component)this).size().height / 2), 8.0F);
  140.          this.field_0.transformed = false;
  141.          if (this.backBuffer != null) {
  142.             if (!this.backSize.equals(((Component)this).size())) {
  143.                this.newBackBuffer();
  144.             }
  145.  
  146.             this.backGC.setColor(((Component)this).getBackground());
  147.             this.backGC.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  148.             this.field_0.paint(this.backGC);
  149.             var1.drawImage(this.backBuffer, 0, 0, this);
  150.          } else {
  151.             this.field_0.paint(var1);
  152.          }
  153.  
  154.          this.setPainted();
  155.       } else {
  156.          if (this.message != null) {
  157.             var1.drawString("Error in model:", 3, 20);
  158.             var1.drawString(this.message, 10, 40);
  159.          }
  160.  
  161.       }
  162.    }
  163.  
  164.    private synchronized void setPainted() {
  165.       this.painted = true;
  166.       this.notifyAll();
  167.    }
  168.  
  169.    private synchronized void waitPainted() {
  170.       while(!this.painted) {
  171.          try {
  172.             this.wait();
  173.          } catch (InterruptedException var1) {
  174.          }
  175.       }
  176.  
  177.       this.painted = false;
  178.    }
  179. }
  180.