home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / JDesignerPro / Jdp3_0.exe / data1.cab / Program_Files / JDPMain.jar / JDPPopupMessage.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-09  |  5.1 KB  |  264 lines

  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.Container;
  4. import java.awt.Event;
  5. import java.awt.Font;
  6. import java.awt.FontMetrics;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.LayoutManager;
  10. import java.awt.Panel;
  11. import java.awt.Rectangle;
  12. import java.awt.image.ImageObserver;
  13. import java.util.Vector;
  14.  
  15. public class JDPPopupMessage extends Panel {
  16.    JDPUser user;
  17.    Container targetPanel;
  18.    Image offscreen;
  19.    Rectangle offscreensize;
  20.    // $FF: renamed from: gr java.awt.Graphics
  21.    Graphics field_0;
  22.    Panel parent;
  23.    Rectangle Bounds;
  24.    int[] widths;
  25.    Font lastFont;
  26.    // $FF: renamed from: fm java.awt.FontMetrics
  27.    FontMetrics field_1;
  28.    int maxXwidth;
  29.    Vector activeAreas;
  30.    String prevMessage;
  31.    String prevStatusBarMessage;
  32.    String popupMessage;
  33.    String statusBarMessage;
  34.    boolean firstClear = true;
  35.  
  36.    void createPopup(JDPUser var1, Container var2) {
  37.       this.user = var1;
  38.       this.targetPanel = var2;
  39.       ((Component)this).setFont(var1.plainFont);
  40.       ((Container)this).setLayout((LayoutManager)null);
  41.       if (!JDPUser.classactivated) {
  42.          System.out.println("Software Violation - this class may only be used in conjunction with JDesignerPro.");
  43.       } else {
  44.          this.removeAllComponents();
  45.          ((Component)this).hide();
  46.          this.offscreen = ((Component)this).createImage(10, 10);
  47.       }
  48.    }
  49.  
  50.    public void setTarget(Container var1) {
  51.       this.targetPanel = var1;
  52.    }
  53.  
  54.    public void addComponent(Component var1, String var2, String var3) {
  55.       Vector var4 = new Vector();
  56.       var4.addElement(var1);
  57.       var4.addElement(var2);
  58.       var4.addElement(var3);
  59.       this.activeAreas.addElement(var4);
  60.    }
  61.  
  62.    public void paint(Graphics var1) {
  63.       this.update(var1);
  64.    }
  65.  
  66.    int[] getWidths() {
  67.       this.field_1 = this.field_0.getFontMetrics();
  68.       this.widths = this.field_1.getWidths();
  69.       return this.widths;
  70.    }
  71.  
  72.    public JDPPopupMessage(JDPUser var1, Panel var2) {
  73.       this.createPopup(var1, (Container)var2);
  74.    }
  75.  
  76.    public JDPPopupMessage(JDPUser var1, Container var2) {
  77.       this.createPopup(var1, var2);
  78.    }
  79.  
  80.    public void update(Graphics var1) {
  81.       Rectangle var2 = ((Component)this).bounds();
  82.       if (this.offscreen == null || var2.width != this.offscreensize.width || var2.height != this.offscreensize.height) {
  83.          this.offscreen = ((Component)this).createImage(var2.width, var2.height);
  84.          this.offscreensize = var2;
  85.          this.field_0 = this.offscreen.getGraphics();
  86.          this.field_0.setFont(((Component)this).getFont());
  87.       }
  88.  
  89.       this.Bounds = ((Component)this).bounds();
  90.       this.field_0.setColor(Color.white);
  91.       this.field_0.fillRect(0, 0, this.Bounds.width, this.Bounds.height);
  92.       this.field_0.setColor(Color.black);
  93.       this.field_0.drawRect(0, 0, this.Bounds.width - 1, this.Bounds.height - 1);
  94.       this.field_0.drawString(this.popupMessage, 3, this.StringHeight() - 1);
  95.       var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
  96.       this.firstClear = true;
  97.    }
  98.  
  99.    int StringHeight() {
  100.       if (this.field_0 == null) {
  101.          return 0;
  102.       } else {
  103.          if (this.field_0.getFont() != this.lastFont) {
  104.             this.getWidths();
  105.             this.lastFont = this.field_0.getFont();
  106.          }
  107.  
  108.          return this.field_1.getHeight();
  109.       }
  110.    }
  111.  
  112.    public void removeAllComponents() {
  113.       this.activeAreas = null;
  114.       this.activeAreas = new Vector();
  115.    }
  116.  
  117.    public void removeComponent(Component var1) {
  118.       for(int var2 = 0; var2 < this.activeAreas.size(); ++var2) {
  119.          Vector var3 = (Vector)this.activeAreas.elementAt(var2);
  120.          if (var1.equals((Component)var3.elementAt(0))) {
  121.             this.activeAreas.removeElementAt(var2);
  122.             return;
  123.          }
  124.       }
  125.  
  126.    }
  127.  
  128.    void display(int var1, int var2) {
  129.       this.position(var1, var2);
  130.       ((Component)this).repaint();
  131.       ((Component)this).enable();
  132.       this.user.mainmsg.setStatusMsg(this.statusBarMessage, 500, 5, this);
  133.       this.prevMessage = this.popupMessage;
  134.       this.prevStatusBarMessage = this.statusBarMessage;
  135.    }
  136.  
  137.    public void layout() {
  138.       ((Component)this).repaint();
  139.    }
  140.  
  141.    public boolean handleEvent(Event var1) {
  142.       switch (var1.id) {
  143.          case 501:
  144.          case 502:
  145.          case 506:
  146.             if (((Component)this).isEnabled()) {
  147.                ((Component)this).hide();
  148.                this.user.mainmsg.clearPopupMsg();
  149.             }
  150.  
  151.             return false;
  152.          case 503:
  153.          case 504:
  154.          case 505:
  155.             if (!var1.target.equals(this) && this.targetPanel != null && this.activeAreas != null && this.activeAreas.size() > 0) {
  156.                for(int var2 = 0; var2 < this.activeAreas.size(); ++var2) {
  157.                   Vector var3 = (Vector)this.activeAreas.elementAt(var2);
  158.                   Component var4 = (Component)var3.elementAt(0);
  159.                   if (var4 != null && var4.isVisible() && var4.isShowing()) {
  160.                      Rectangle var5 = var4.bounds();
  161.                      Container var6 = var4.getParent();
  162.                      if (var6 != null && ((Component)var6).isVisible() && ((Component)var6).isShowing()) {
  163.                         Rectangle var7 = ((Component)var6).bounds();
  164.  
  165.                         while(var6 != null && !var6.equals(this.targetPanel)) {
  166.                            var7 = ((Component)var6).bounds();
  167.                            var5.x += var7.x;
  168.                            var5.y += var7.y;
  169.                            var6 = ((Component)var6).getParent();
  170.                            if (var6 == null || !((Component)var6).isVisible()) {
  171.                               var5.x += 2000;
  172.                            }
  173.                         }
  174.  
  175.                         var5.x -= var7.x;
  176.                         var5.y -= var7.y;
  177.                         if (var5.inside(var1.x, var1.y)) {
  178.                            var1.x += var7.x;
  179.                            var1.y += var7.y;
  180.                            this.popupMessage = (String)var3.elementAt(1);
  181.                            this.statusBarMessage = (String)var3.elementAt(2);
  182.                            if (((Component)this).isEnabled() && !((Component)this).isVisible()) {
  183.                               if (this.popupMessage.equals(this.prevMessage) && this.statusBarMessage.equals(this.prevStatusBarMessage)) {
  184.                                  this.user.mainmsg.waitMore(1000);
  185.                                  this.position(var1.x, var1.y);
  186.                               } else {
  187.                                  this.display(var1.x, var1.y);
  188.                               }
  189.                            } else if (((Component)this).isEnabled() && ((Component)this).isVisible()) {
  190.                               if (!this.firstClear) {
  191.                                  this.user.mainmsg.clearPopupMsg();
  192.                               }
  193.  
  194.                               this.firstClear = false;
  195.                            } else if (!((Component)this).isEnabled()) {
  196.                               this.display(var1.x, var1.y);
  197.                            } else if (!this.popupMessage.equals(this.prevMessage) || !this.statusBarMessage.equals(this.prevStatusBarMessage)) {
  198.                               this.user.mainmsg.clearInfoMsg();
  199.                               this.display(var1.x, var1.y);
  200.                               this.firstClear = true;
  201.                            }
  202.  
  203.                            return true;
  204.                         }
  205.                      }
  206.                   }
  207.                }
  208.             }
  209.  
  210.             if (((Component)this).isEnabled()) {
  211.                this.user.mainmsg.clearPopupMsg();
  212.                ((Component)this).hide();
  213.                ((Component)this).disable();
  214.                return true;
  215.             } else {
  216.                return true;
  217.             }
  218.          default:
  219.             return false;
  220.       }
  221.    }
  222.  
  223.    void position(int var1, int var2) {
  224.       var2 += 26;
  225.       var1 += 10;
  226.       if (this.offscreen == null) {
  227.          Rectangle var3 = ((Component)this).bounds();
  228.          this.offscreen = ((Component)this).createImage(10, 10);
  229.          this.offscreensize = var3;
  230.          if (this.offscreen == null) {
  231.             return;
  232.          }
  233.  
  234.          this.field_0 = this.offscreen.getGraphics();
  235.          this.field_0.setFont(((Component)this).getFont());
  236.       }
  237.  
  238.       this.parent = (Panel)((Component)this).getParent();
  239.       this.maxXwidth = this.user.u.StringWidth(this.field_0, this.popupMessage);
  240.       int var8 = this.StringHeight();
  241.       if (this.parent != null) {
  242.          Rectangle var4 = this.parent.bounds();
  243.  
  244.          for(int var5 = var1 - 10 + this.maxXwidth + 20; var5 > var4.width; var5 = var1 - 10 + this.maxXwidth + 20) {
  245.             var1 -= 5;
  246.          }
  247.  
  248.          if (var2 + var8 + 6 > var4.height) {
  249.             var2 = var2 - 32 - var8;
  250.          }
  251.       }
  252.  
  253.       if (var1 < 10) {
  254.          var1 = 10;
  255.       }
  256.  
  257.       if (var2 < 10) {
  258.          var2 = 10;
  259.       }
  260.  
  261.       ((Component)this).reshape(var1, var2, this.maxXwidth + 5, var8 + 4);
  262.    }
  263. }
  264.