home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / WDESAMPL.BIN / RoundButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-23  |  2.9 KB  |  118 lines

  1. package actual;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.AWTEventMulticaster;
  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.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.MouseEvent;
  13.  
  14. public class RoundButton extends Component {
  15.    ActionListener actionListener;
  16.    String label;
  17.    protected boolean pressed;
  18.  
  19.    public RoundButton() {
  20.       this("");
  21.    }
  22.  
  23.    public RoundButton(String var1) {
  24.       this.pressed = false;
  25.       this.label = var1;
  26.       ((Component)this).enableEvents(16L);
  27.    }
  28.  
  29.    public String getLabel() {
  30.       return this.label;
  31.    }
  32.  
  33.    public void setLabel(String var1) {
  34.       this.label = var1;
  35.       ((Component)this).invalidate();
  36.       ((Component)this).repaint();
  37.    }
  38.  
  39.    public void paint(Graphics var1) {
  40.       int var2 = Math.min(((Component)this).getSize().width - 1, ((Component)this).getSize().height - 1);
  41.       if (this.pressed) {
  42.          var1.setColor(((Component)this).getBackground().darker().darker());
  43.       } else {
  44.          var1.setColor(((Component)this).getBackground());
  45.       }
  46.  
  47.       var1.fillArc(0, 0, var2, var2, 0, 360);
  48.       var1.setColor(((Component)this).getBackground().darker().darker().darker());
  49.       var1.drawArc(0, 0, var2, var2, 0, 360);
  50.       Font var3 = ((Component)this).getFont();
  51.       if (var3 != null) {
  52.          FontMetrics var4 = ((Component)this).getFontMetrics(((Component)this).getFont());
  53.          var1.setColor(((Component)this).getForeground());
  54.          var1.drawString(this.label, var2 / 2 - var4.stringWidth(this.label) / 2, var2 / 2 + var4.getMaxDescent());
  55.       }
  56.  
  57.    }
  58.  
  59.    public Dimension getPreferredSize() {
  60.       Font var1 = ((Component)this).getFont();
  61.       if (var1 != null) {
  62.          FontMetrics var2 = ((Component)this).getFontMetrics(((Component)this).getFont());
  63.          int var3 = Math.max(var2.stringWidth(this.label) + 40, var2.getHeight() + 40);
  64.          return new Dimension(var3, var3);
  65.       } else {
  66.          return new Dimension(100, 100);
  67.       }
  68.    }
  69.  
  70.    public Dimension getMinimumSize() {
  71.       return new Dimension(100, 100);
  72.    }
  73.  
  74.    public void addActionListener(ActionListener var1) {
  75.       this.actionListener = AWTEventMulticaster.add(this.actionListener, var1);
  76.       ((Component)this).enableEvents(16L);
  77.    }
  78.  
  79.    public void removeActionListener(ActionListener var1) {
  80.       this.actionListener = AWTEventMulticaster.remove(this.actionListener, var1);
  81.    }
  82.  
  83.    public boolean contains(int var1, int var2) {
  84.       int var3 = ((Component)this).getSize().width / 2;
  85.       int var4 = ((Component)this).getSize().height / 2;
  86.       return (var3 - var1) * (var3 - var1) + (var4 - var2) * (var4 - var2) <= var3 * var3;
  87.    }
  88.  
  89.    public void processMouseEvent(MouseEvent var1) {
  90.       switch (((AWTEvent)var1).getID()) {
  91.          case 501:
  92.             this.pressed = true;
  93.             ((Component)this).repaint();
  94.             break;
  95.          case 502:
  96.             if (this.actionListener != null) {
  97.                this.actionListener.actionPerformed(new ActionEvent(this, 1001, this.label));
  98.             }
  99.  
  100.             if (this.pressed) {
  101.                this.pressed = false;
  102.                ((Component)this).repaint();
  103.             }
  104.          case 503:
  105.          case 504:
  106.          default:
  107.             break;
  108.          case 505:
  109.             if (this.pressed) {
  110.                this.pressed = false;
  111.                ((Component)this).repaint();
  112.             }
  113.       }
  114.  
  115.       super.processMouseEvent(var1);
  116.    }
  117. }
  118.