home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / plaf / basic / ImageComponent.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  3.6 KB  |  151 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.JComponent;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.Insets;
  10. import java.awt.image.ImageObserver;
  11.  
  12. class ImageComponent extends JComponent implements ImageObserver {
  13.    protected Image img;
  14.    private boolean imgKnown;
  15.    protected Dimension isize = new Dimension(-1, -1);
  16.    protected Dimension prefsize = new Dimension(0, 0);
  17.    boolean fixedSize = false;
  18.    long lastUpdateTime;
  19.  
  20.    public ImageComponent() {
  21.    }
  22.  
  23.    public ImageComponent(Image var1) {
  24.       this.setImage(var1);
  25.    }
  26.  
  27.    public ImageComponent(String var1) {
  28.       this.setImage(((Component)this).getToolkit().getImage(var1));
  29.    }
  30.  
  31.    public void setSize(int var1, int var2) {
  32.       if (var1 != this.isize.width || var2 != this.isize.height) {
  33.          this.isize.width = var1;
  34.          this.isize.height = var2;
  35.          ((Container)this).invalidate();
  36.       }
  37.  
  38.    }
  39.  
  40.    public void setBounds(int var1, int var2, int var3, int var4) {
  41.       super.setBounds(var1, var2, var3, var4);
  42.       this.setSize(var3, var4);
  43.    }
  44.  
  45.    public void setImage(Image var1) {
  46.       if (this.img != var1) {
  47.          this.img = var1;
  48.          if (var1 != null) {
  49.             this.setSize(var1.getWidth(this), var1.getHeight(this));
  50.          }
  51.  
  52.          if (((Component)this).isShowing()) {
  53.             ((Component)this).repaint(10L);
  54.          }
  55.  
  56.       }
  57.    }
  58.  
  59.    private synchronized void waitSize() {
  60.       if (this.img != null) {
  61.          try {
  62.             while(this.isize.width < 0 || this.isize.height < 0) {
  63.                this.wait();
  64.             }
  65.  
  66.          } catch (InterruptedException var1) {
  67.          }
  68.       }
  69.    }
  70.  
  71.    protected boolean immediatePaint() {
  72.       return true;
  73.    }
  74.  
  75.    public synchronized boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
  76.       long var7 = System.currentTimeMillis();
  77.       if ((var2 & 48) != 0) {
  78.          if (this.immediatePaint()) {
  79.             Graphics var9 = ((JComponent)this).getGraphics();
  80.             if (var9 != null) {
  81.                this.paint(var9);
  82.                var9.dispose();
  83.             }
  84.          } else {
  85.             ((Component)this).repaint(0L);
  86.          }
  87.  
  88.          this.lastUpdateTime = var7;
  89.       }
  90.  
  91.       if ((var2 & 192) != 0) {
  92.          Object var10 = null;
  93.          this.isize.width = 0;
  94.          this.isize.height = 0;
  95.          this.notifyAll();
  96.          return false;
  97.       } else {
  98.          if ((var2 & 1) != 0) {
  99.             this.isize.width = var1.getWidth(this);
  100.          }
  101.  
  102.          if ((var2 & 2) != 0) {
  103.             this.isize.height = var1.getHeight(this);
  104.          }
  105.  
  106.          this.notifyAll();
  107.          return (var2 & 32) == 0;
  108.       }
  109.    }
  110.  
  111.    public Dimension getPreferredSize() {
  112.       Insets var1 = ((JComponent)this).getInsets();
  113.       this.waitSize();
  114.       this.prefsize.width = this.isize.width + var1.left + var1.right;
  115.       this.prefsize.height = this.isize.height + var1.top + var1.bottom;
  116.       return this.prefsize;
  117.    }
  118.  
  119.    public Dimension getMinimumSize() {
  120.       return this.getPreferredSize();
  121.    }
  122.  
  123.    protected void locateImage() {
  124.    }
  125.  
  126.    public void paint(Graphics var1) {
  127.       Insets var2 = ((JComponent)this).getInsets();
  128.       Image var3 = this.img;
  129.       if (var3 == null) {
  130.          this.locateImage();
  131.          if ((var3 = this.img) == null) {
  132.             return;
  133.          }
  134.       }
  135.  
  136.       if (var1 == null) {
  137.          System.out.println("NULL GRAPHICS");
  138.       }
  139.  
  140.       if (var2 == null) {
  141.          System.out.println("NULL INSETS");
  142.       }
  143.  
  144.       var1.drawImage(var3, var2.left, var2.top, this);
  145.    }
  146.  
  147.    public void update(Graphics var1) {
  148.       this.paint(var1);
  149.    }
  150. }
  151.