home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / netobjects / nfx / wizard / WizardPageView$ImageCanvas.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  4.1 KB  |  109 lines

  1. package asp.netobjects.nfx.wizard;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.Toolkit;
  12. import java.awt.image.ImageObserver;
  13. import java.util.Enumeration;
  14. import java.util.Vector;
  15.  
  16. class WizardPageView$ImageCanvas extends Canvas implements ImageObserver {
  17.    // $FF: synthetic field
  18.    private final WizardPageView this$0;
  19.    private int dmTextYInc;
  20.    private int dmWidth;
  21.    private int dmHeight;
  22.    private Image dmImage;
  23.    private boolean dmPainted;
  24.  
  25.    public WizardPageView$ImageCanvas(WizardPageView this$0, int width, int height) {
  26.       this.this$0 = this$0;
  27.       this.this$0 = this$0;
  28.       this.dmTextYInc = 12;
  29.       this.dmPainted = false;
  30.       this.dmWidth = width;
  31.       this.dmHeight = height;
  32.    }
  33.  
  34.    public Dimension getMinumumSize() {
  35.       return new Dimension(this.dmWidth, this.dmHeight);
  36.    }
  37.  
  38.    public Dimension getMaximumSize() {
  39.       return new Dimension(this.dmWidth, this.dmHeight);
  40.    }
  41.  
  42.    public Dimension getPreferredSize() {
  43.       return new Dimension(this.dmWidth, this.dmHeight);
  44.    }
  45.  
  46.    public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
  47.       return true;
  48.    }
  49.  
  50.    private void drawText(Graphics g) {
  51.       g.setColor(super.getBackground());
  52.       g.fillRect(0, 0, this.dmWidth, this.dmHeight);
  53.       int curY = 0;
  54.       Dimension dim = ((Component)this).getSize();
  55.       g.setColor(Color.black);
  56.       Font plainFont = new Font("Helvetica", 0, 12);
  57.       Font bulletFont = new Font("Helvetica", 1, 14);
  58.       FontMetrics plainFontMet = Toolkit.getDefaultToolkit().getFontMetrics(plainFont);
  59.       FontMetrics bulletFontMet = Toolkit.getDefaultToolkit().getFontMetrics(bulletFont);
  60.       g.setFont(bulletFont);
  61.       String s = this.this$0.getModel().getBulletText();
  62.       int w = this.getMinumumSize().width;
  63.       Vector v = WizardPageView.access$0(this.this$0, s, w, 999, bulletFontMet);
  64.       Enumeration e = v.elements();
  65.  
  66.       while(e.hasMoreElements()) {
  67.          curY += this.dmTextYInc;
  68.          g.drawString((String)e.nextElement(), 0, curY);
  69.       }
  70.  
  71.       String last = (String)v.lastElement();
  72.       int lastWidth = bulletFontMet.charsWidth(last.toCharArray(), 0, last.length());
  73.       if (lastWidth < w) {
  74.          g.setFont(plainFont);
  75.          s = " - " + this.this$0.getModel().getInfoText();
  76.          v = WizardPageView.access$0(this.this$0, s, w - lastWidth, 1, plainFontMet);
  77.          last = (String)v.lastElement();
  78.          g.drawString(last, lastWidth, curY);
  79.          s = s.substring(last.length() + 1);
  80.       }
  81.  
  82.       v = WizardPageView.access$0(this.this$0, s, w, 999, plainFontMet);
  83.       e = v.elements();
  84.  
  85.       while(e.hasMoreElements()) {
  86.          curY += this.dmTextYInc;
  87.          g.drawString((String)e.nextElement(), 0, curY);
  88.       }
  89.  
  90.    }
  91.  
  92.    public void paint(Graphics g) {
  93.       if (this.dmImage == null) {
  94.          this.dmImage = ((Component)this).createImage(this.dmWidth, this.dmHeight);
  95.       }
  96.  
  97.       if (this.dmImage != null) {
  98.          Graphics g2 = this.dmImage.getGraphics();
  99.          if (!this.dmPainted && this.this$0.getModel() != null) {
  100.             this.drawText(g2);
  101.             this.dmPainted = true;
  102.          }
  103.  
  104.          g.drawImage(this.dmImage, 0, 0, this);
  105.       }
  106.  
  107.    }
  108. }
  109.