home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / main.bin / ButtonBase.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-04  |  7.2 KB  |  315 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Canvas;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Dimension;
  8. import java.awt.Event;
  9. import java.awt.Graphics;
  10. import java.awt.LayoutManager;
  11. import java.awt.Panel;
  12. import java.awt.Point;
  13. import symantec.beans.Beans;
  14. import symantec.itools.util.Timer;
  15.  
  16. public abstract strictfp class ButtonBase extends Canvas {
  17.    protected boolean pressed = false;
  18.    protected boolean released = true;
  19.    protected boolean inButton;
  20.    protected boolean notifyWhilePressed = false;
  21.    protected boolean showInfoTip = false;
  22.    protected boolean running = false;
  23.    protected boolean notified = false;
  24.    protected boolean showFocus;
  25.    protected boolean doInfoTip;
  26.    protected int bevel;
  27.    protected int notifyDelay;
  28.    protected int infoTipDelay;
  29.    protected int pressedAdjustment;
  30.    protected String infoTipText;
  31.    protected Color infoTipTextColor;
  32.    protected Timer notifyTimer = null;
  33.    protected Timer infoTipTimer = null;
  34.    protected int infoTipX;
  35.    protected int infoTipY;
  36.    protected LayoutManager infoTipLayoutManager;
  37.  
  38.    protected ButtonBase() {
  39.       this.infoTipTextColor = Color.black;
  40.       this.notifyDelay = 1000;
  41.       this.infoTipDelay = 1000;
  42.       this.bevel = 1;
  43.       this.pressedAdjustment = 0;
  44.       ((Component)this).resize(10, 10);
  45.    }
  46.  
  47.    public void setBevelHeight(int size) {
  48.       try {
  49.          this.checkBevelSize(size);
  50.       } catch (AWTException var2) {
  51.          System.err.println("Invalid Bevel Size " + size);
  52.       }
  53.  
  54.       this.bevel = size;
  55.       ((Component)this).invalidate();
  56.    }
  57.  
  58.    public int getBevelHeight() {
  59.       return this.bevel;
  60.    }
  61.  
  62.    public void setNotifyWhilePressed(boolean f) {
  63.       this.notifyWhilePressed = f;
  64.       if (this.notifyWhilePressed) {
  65.          this.notifyTimer = new Timer(this, this.notifyDelay, true, 1001);
  66.       } else {
  67.          if (this.notifyTimer != null) {
  68.             this.notifyTimer = null;
  69.          }
  70.  
  71.       }
  72.    }
  73.  
  74.    public boolean getNotifyWhilePressed() {
  75.       return this.notifyWhilePressed;
  76.    }
  77.  
  78.    public void setNotifyDelay(int d) {
  79.       this.notifyDelay = d;
  80.    }
  81.  
  82.    public int getNotifyDelay() {
  83.       return this.notifyDelay;
  84.    }
  85.  
  86.    public void setShowInfoTip(boolean f) {
  87.       this.showInfoTip = f;
  88.       if (this.showInfoTip) {
  89.          this.infoTipTimer = new Timer(this, this.notifyDelay, true, 1001);
  90.       } else {
  91.          if (this.infoTipTimer != null) {
  92.             this.infoTipTimer = null;
  93.          }
  94.  
  95.       }
  96.    }
  97.  
  98.    public boolean getShowInfoTip() {
  99.       return this.showInfoTip;
  100.    }
  101.  
  102.    public void setInfoTipDelay(int d) {
  103.       this.infoTipDelay = d;
  104.    }
  105.  
  106.    public int getInfoTipDelay() {
  107.       return this.infoTipDelay;
  108.    }
  109.  
  110.    public void setShowFocus(boolean f) {
  111.       this.showFocus = f;
  112.    }
  113.  
  114.    public boolean getShowFocus() {
  115.       return this.showFocus;
  116.    }
  117.  
  118.    public void setInfoTipText(String t) {
  119.       this.infoTipText = t;
  120.    }
  121.  
  122.    public String getInfoTipText() {
  123.       return this.infoTipText;
  124.    }
  125.  
  126.    public void setInfoTipTextColor(Color c) {
  127.       this.infoTipTextColor = c;
  128.    }
  129.  
  130.    public Color getInfoTipTextColor() {
  131.       return this.infoTipTextColor;
  132.    }
  133.  
  134.    public boolean mouseUp(Event e, int x, int y) {
  135.       if (this.running) {
  136.          this.running = false;
  137.          this.notifyTimer.stop();
  138.       }
  139.  
  140.       if (this.pressed) {
  141.          this.pressed = false;
  142.          this.pressedAdjustment = 0;
  143.          if (!this.notifyWhilePressed || !this.notified) {
  144.             ((Component)this).postEvent(new Event(this, 1001, (Object)null));
  145.          }
  146.       }
  147.  
  148.       this.released = true;
  149.       ((Component)this).repaint();
  150.       return true;
  151.    }
  152.  
  153.    public boolean mouseDown(Event e, int x, int y) {
  154.       if (this.notifyWhilePressed && !this.running) {
  155.          this.running = true;
  156.          this.notifyTimer.start();
  157.       }
  158.  
  159.       this.pressed = true;
  160.       this.released = false;
  161.       this.pressedAdjustment = this.bevel;
  162.       ((Component)this).repaint();
  163.       return true;
  164.    }
  165.  
  166.    public boolean mouseEnter(Event e, int x, int y) {
  167.       this.inButton = true;
  168.       if (this.showInfoTip) {
  169.          this.infoTipX = x;
  170.          this.infoTipY = y;
  171.          this.infoTipTimer.start();
  172.       }
  173.  
  174.       if (!this.released) {
  175.          this.mouseDown(e, x, y);
  176.       }
  177.  
  178.       return true;
  179.    }
  180.  
  181.    public boolean mouseExit(Event e, int x, int y) {
  182.       this.inButton = false;
  183.       if (this.showInfoTip) {
  184.          this.infoTipTimer.stop();
  185.          Panel infoTipPanel = InfoTipManager.getInfoTipPanel();
  186.          ((Component)infoTipPanel).getParent().setLayout(this.infoTipLayoutManager);
  187.          ((Component)infoTipPanel).hide();
  188.       }
  189.  
  190.       if (this.pressed) {
  191.          this.pressed = false;
  192.          this.pressedAdjustment = 0;
  193.       }
  194.  
  195.       return true;
  196.    }
  197.  
  198.    public boolean action(Event e, Object o) {
  199.       if (this.notifyWhilePressed && e.target == this.notifyTimer && !Beans.isDesignTime()) {
  200.          ((Component)this).postEvent(new Event(this, 1001, (Object)null));
  201.          return true;
  202.       } else if (this.showInfoTip && e.target == this.infoTipTimer) {
  203.          this.doInfoTip = true;
  204.          ((Component)this).repaint();
  205.          this.infoTipTimer.stop();
  206.          return true;
  207.       } else {
  208.          return super.action(e, o);
  209.       }
  210.    }
  211.  
  212.    public void enable() {
  213.       if (!((Component)this).isEnabled()) {
  214.          super.enable();
  215.          this.pressed = false;
  216.          this.pressedAdjustment = 0;
  217.       }
  218.  
  219.       ((Component)this).repaint();
  220.    }
  221.  
  222.    public void disable() {
  223.       if (((Component)this).isEnabled()) {
  224.          super.disable();
  225.          if (this.notifyTimer != null) {
  226.             this.notifyTimer.stop();
  227.          }
  228.  
  229.          if (this.infoTipTimer != null) {
  230.             this.infoTipTimer.stop();
  231.          }
  232.  
  233.          this.pressed = false;
  234.          this.pressedAdjustment = 0;
  235.       }
  236.  
  237.       ((Component)this).repaint();
  238.    }
  239.  
  240.    public void update(Graphics g) {
  241.       Dimension s = ((Component)this).size();
  242.       g.clipRect(0, 0, s.width, s.height);
  243.       this.paint(g);
  244.    }
  245.  
  246.    public void paint(Graphics g) {
  247.       Dimension s = ((Component)this).size();
  248.       int width = s.width;
  249.       int height = s.height;
  250.       int x = this.bevel + 1;
  251.       int y = this.bevel + 1;
  252.       int w = width - 1;
  253.       int h = height - 1;
  254.       g.setColor(Color.lightGray);
  255.       g.fillRect(0, 0, width, height);
  256.       if (this.pressed) {
  257.          int var10000 = x + (this.bevel > 0 ? 2 : 1);
  258.          g.setColor(Color.lightGray);
  259.  
  260.          for(int i = 1; i < this.bevel + 1; ++i) {
  261.             g.drawLine(i, h - i, w - i, h - i);
  262.             g.drawLine(w - i, h - i, w - i, i);
  263.          }
  264.  
  265.          g.setColor(Color.gray);
  266.  
  267.          for(int var10 = 1; var10 < this.bevel + 1; ++var10) {
  268.             g.drawLine(var10, h, var10, var10);
  269.             g.drawLine(var10, var10, w, var10);
  270.          }
  271.       } else {
  272.          g.setColor(Color.white);
  273.  
  274.          for(int i = 1; i < this.bevel + 1; ++i) {
  275.             g.drawLine(i, h - i, i, i);
  276.             g.drawLine(i, i, w - i, i);
  277.          }
  278.  
  279.          g.setColor(Color.gray);
  280.  
  281.          for(int var12 = 1; var12 < this.bevel + 2; ++var12) {
  282.             g.drawLine(var12, h - var12, w - var12, h - var12);
  283.             g.drawLine(w - var12, h - var12, w - var12, var12);
  284.          }
  285.       }
  286.  
  287.       g.setColor(Color.black);
  288.       g.drawLine(1, 0, width - 2, 0);
  289.       g.drawLine(0, 1, 0, height - 2);
  290.       g.drawLine(1, height - 1, width - 2, height - 1);
  291.       g.drawLine(width - 1, height - 2, width - 1, 1);
  292.       if (this.showInfoTip && this.doInfoTip) {
  293.          this.drawInfoTip();
  294.       }
  295.  
  296.    }
  297.  
  298.    protected void drawInfoTip() {
  299.       this.doInfoTip = false;
  300.       Point p = ((Component)this).location();
  301.       Panel infoTipPanel = InfoTipManager.getInfoTipPanel();
  302.       this.infoTipX += p.x;
  303.       this.infoTipY += p.y;
  304.       this.infoTipLayoutManager = ((Component)infoTipPanel).getParent().getLayout();
  305.       InfoTipManager.draw(this.infoTipX, this.infoTipY, this.infoTipText, ((Component)this).getFontMetrics(((Component)this).getFont()), Color.yellow, Color.black);
  306.    }
  307.  
  308.    private void checkBevelSize(int i) throws AWTException {
  309.       Dimension s = ((Component)this).size();
  310.       if (i < 0 || i >= s.width / 2 || i >= s.height / 2) {
  311.          throw new AWTException("invalid bevel size");
  312.       }
  313.    }
  314. }
  315.