home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / JDesignerPro / Jdp3_0.exe / data1.cab / Program_Files / JDPCustomPopup.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-09  |  3.8 KB  |  168 lines

  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.Panel;
  12. import java.awt.Rectangle;
  13. import java.awt.image.ImageObserver;
  14.  
  15. public class JDPCustomPopup extends Panel {
  16.    Image offscreen;
  17.    Rectangle offscreensize;
  18.    // $FF: renamed from: gr java.awt.Graphics
  19.    Graphics field_0;
  20.    Container target;
  21.    boolean borderOn;
  22.    Rectangle Bounds;
  23.    // $FF: renamed from: fm java.awt.FontMetrics
  24.    protected FontMetrics field_1;
  25.    int[] boldWidths;
  26.    Font thisFont;
  27.    Font lastFont;
  28.    int prevFontHeight;
  29.  
  30.    public void paint(Graphics var1) {
  31.       this.update(var1);
  32.    }
  33.  
  34.    public void setBorder(boolean var1) {
  35.       this.borderOn = var1;
  36.       ((Component)this).repaint();
  37.    }
  38.  
  39.    public boolean getBorder() {
  40.       return this.borderOn;
  41.    }
  42.  
  43.    public Dimension minimumSize() {
  44.       Dimension var1 = new Dimension(100, 100);
  45.       this.StringWidth(" ");
  46.       if (this.field_1 == null && ((Component)this).getParent() != null) {
  47.          this.field_1 = ((Component)this).getParent().getGraphics().getFontMetrics();
  48.          this.lastFont = ((Component)this).getParent().getGraphics().getFont();
  49.          this.boldWidths = this.field_1.getWidths();
  50.       }
  51.  
  52.       if (this.field_1 != null) {
  53.          this.field_1 = ((Component)this).getParent().getGraphics().getFontMetrics();
  54.          int var2 = this.field_1.getHeight();
  55.          int var3 = this.StringWidth("2");
  56.          var1 = new Dimension(var3 * 20, (int)((double)var2 * (double)8.5F));
  57.       }
  58.  
  59.       return var1;
  60.    }
  61.  
  62.    public void update(Graphics var1) {
  63.       Rectangle var2 = ((Component)this).bounds();
  64.       if (var2.width != 0 && var2.height != 0) {
  65.          if (this.offscreen == null || var2.width != this.offscreensize.width || var2.height != this.offscreensize.height) {
  66.             if (var2.width < 6) {
  67.                var2.width = 6;
  68.             }
  69.  
  70.             if (var2.height < 6) {
  71.                var2.height = 6;
  72.             }
  73.  
  74.             this.offscreen = ((Component)this).createImage(var2.width, var2.height);
  75.             this.offscreensize = var2;
  76.             this.field_0 = this.offscreen.getGraphics();
  77.             this.field_0.setFont(((Component)this).getFont());
  78.          }
  79.  
  80.          this.field_0.setColor(((Component)this).getBackground());
  81.          this.field_0.fillRect(0, 0, var2.width, var2.height);
  82.          this.field_0.setColor(((Component)this).getForeground());
  83.          this.field_0.setFont(((Component)this).getFont());
  84.          this.StringWidth("");
  85.          int var3 = 0;
  86.          if (this.field_1 != null) {
  87.             var3 = this.field_1.getHeight();
  88.             if (var3 != this.prevFontHeight && this.prevFontHeight != 0 || var3 != ((Component)this).bounds().height) {
  89.                this.prevFontHeight = var3;
  90.                if (this.target == null) {
  91.                   this.target = ((Component)this).getParent();
  92.                }
  93.  
  94.                this.target.layout();
  95.                this.target.paintAll(this.target.getGraphics());
  96.             }
  97.  
  98.             this.prevFontHeight = var3;
  99.          }
  100.  
  101.          this.Bounds = ((Component)this).bounds();
  102.          if (this.borderOn) {
  103.             this.field_0.setColor(JDPUtils.brighter(((Component)this).getBackground()));
  104.             this.field_0.drawLine(0, 0, this.Bounds.width - 1, 0);
  105.             this.field_0.drawLine(0, 0, 0, this.Bounds.height - 1);
  106.             this.field_0.setColor(JDPUtils.darker(((Component)this).getBackground()));
  107.             this.field_0.drawLine(0, this.Bounds.height - 1, 0, this.Bounds.height - 1);
  108.             this.field_0.drawLine(this.Bounds.width - 1, 0, this.Bounds.width - 1, 0);
  109.             this.field_0.drawLine(1, this.Bounds.height - 2, this.Bounds.width - 2, this.Bounds.height - 2);
  110.             this.field_0.drawLine(this.Bounds.width - 2, 1, this.Bounds.width - 2, this.Bounds.height - 2);
  111.             this.field_0.setColor(Color.black);
  112.             this.field_0.drawLine(1, this.Bounds.height - 1, this.Bounds.width - 1, this.Bounds.height - 1);
  113.             this.field_0.drawLine(this.Bounds.width - 1, 1, this.Bounds.width - 1, this.Bounds.height - 1);
  114.          }
  115.  
  116.          var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
  117.       }
  118.    }
  119.  
  120.    public Dimension preferredSize() {
  121.       return this.minimumSize();
  122.    }
  123.  
  124.    public JDPCustomPopup() {
  125.       if (!JDPButton.activated) {
  126.          System.out.println("Software Violation - this class may only be used in conjunction with JDesignerPro.");
  127.       } else {
  128.          this.PanelMain();
  129.       }
  130.    }
  131.  
  132.    void PanelMain() {
  133.       ((Container)this).setLayout(new BorderLayout());
  134.    }
  135.  
  136.    public void layout() {
  137.       ((Component)this).repaint();
  138.    }
  139.  
  140.    public boolean handleEvent(Event var1) {
  141.       switch (var1.id) {
  142.          case 202:
  143.             ((Component)this).repaint();
  144.             return false;
  145.          case 502:
  146.             Event var2 = new Event(this, var1.when, 1001, var1.x, var1.y, var1.key, var1.modifiers, "");
  147.             super.postEvent(var2);
  148.             return true;
  149.          case 1001:
  150.             return false;
  151.          case 1005:
  152.             return false;
  153.          default:
  154.             return false;
  155.       }
  156.    }
  157.  
  158.    int StringWidth(String var1) {
  159.       if (this.field_0 != null && (this.field_1 == null || this.lastFont == null || this.field_0 != null && !this.field_0.getFont().equals(this.lastFont))) {
  160.          this.field_1 = this.field_0.getFontMetrics();
  161.          this.lastFont = this.field_0.getFont();
  162.          this.boldWidths = this.field_1.getWidths();
  163.       }
  164.  
  165.       return this.field_1 != null ? this.field_1.stringWidth(var1) : 0;
  166.    }
  167. }
  168.