home *** CD-ROM | disk | FTP | other *** search
- package hhapplet;
-
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
- import java.util.Vector;
-
- public class CanvasButton extends Canvas {
- protected Rectangle inside;
- protected Image img;
- protected Vector listeners;
- protected boolean button_push_state;
-
- public CanvasButton(Image var1) {
- this();
- this.img = var1;
- }
-
- public CanvasButton() {
- this.button_push_state = false;
- this.img = null;
- this.listeners = new Vector();
- this.button_push_state = false;
- ((Component)this).setBackground(new Color(192, 192, 192));
- }
-
- public void paint(Graphics var1) {
- try {
- var1.setColor(((Component)this).getBackground());
- var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
- if (this.img != null) {
- var1.drawImage(this.img, 2, 2, (ImageObserver)null);
- }
-
- if (this.button_push_state) {
- this.paintBorderIn(var1);
- } else {
- this.paintBorderOut(var1);
- }
- } catch (Exception var3) {
- ((Throwable)var3).printStackTrace();
- }
- }
-
- public void paintBorderOut(Graphics var1) {
- Rectangle var2 = ((Component)this).bounds();
- Color var3 = ((Component)this).getBackground().brighter();
- Color var4 = var3.darker();
- Color var5 = var4.darker();
- Color var6 = var5.darker();
- var1.setColor(var3);
- var1.drawLine(0, 0, var2.width - 1, 0);
- var1.drawLine(0, 0, 0, var2.height - 1);
- var1.setColor(var4);
- var1.drawLine(1, 1, var2.width - 2, 1);
- var1.drawLine(1, 1, 1, var2.height - 2);
- var1.setColor(var6);
- var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
- var1.drawLine(1, var2.height - 2, var2.width - 2, var2.height - 2);
- var1.setColor(var5);
- var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 1);
- var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
- }
-
- public void update(Graphics var1) {
- this.paint(var1);
- }
-
- public void paintBorderIn(Graphics var1) {
- Rectangle var2 = ((Component)this).bounds();
- Color var3 = ((Component)this).getBackground().brighter();
- Color var4 = var3.darker();
- Color var5 = var4.darker();
- Color var6 = var5.darker();
- var1.setColor(var6);
- var1.drawLine(0, 0, var2.width - 1, 0);
- var1.drawLine(0, 0, 0, var2.height - 1);
- var1.setColor(var5);
- var1.drawLine(1, 1, var2.width - 2, 1);
- var1.drawLine(1, 1, 1, var2.height - 2);
- var1.setColor(var4);
- var1.drawLine(var2.width - 2, 1, var2.width - 2, var2.height - 2);
- var1.drawLine(1, var2.height - 2, var2.width - 2, var2.height - 2);
- var1.setColor(var3);
- var1.drawLine(var2.width - 1, 1, var2.width - 1, var2.height - 1);
- var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
- }
-
- public void removeButtonPushEventListener(ButtonPushEventListener var1) {
- this.listeners.removeElement(var1);
- }
-
- public Dimension preferredSize() {
- return this.img != null ? new Dimension(this.img.getWidth(this) + 4, this.img.getHeight(this) + 4) : new Dimension(20, 20);
- }
-
- public void addButtonPushEventListener(ButtonPushEventListener var1) {
- this.listeners.addElement(var1);
- }
-
- public boolean handleEvent(Event var1) {
- if (var1.id == 501) {
- this.button_push_state = true;
- ((Component)this).repaint();
- return true;
- } else if (var1.id == 502 && this.button_push_state) {
- this.button_push_state = false;
- ((Component)this).repaint();
- Rectangle var3 = ((Component)this).bounds();
- var3.x = 0;
- var3.y = 0;
- if (var3.inside(var1.x, var1.y)) {
- this.doAction(var1);
- }
-
- return true;
- } else if (var1.id == 506) {
- Rectangle var2 = ((Component)this).bounds();
- var2.x = 0;
- var2.y = 0;
- if (!var2.inside(var1.x, var1.y)) {
- if (this.button_push_state) {
- this.button_push_state = false;
- ((Component)this).repaint();
- }
- } else if (!this.button_push_state) {
- this.button_push_state = true;
- ((Component)this).repaint();
- }
-
- return true;
- } else {
- return false;
- }
- }
-
- protected void doAction(Event var1) {
- ButtonPushEvent var3 = new ButtonPushEvent(this, var1.x, var1.y);
- synchronized(this){}
-
- Vector var2;
- try {
- var2 = (Vector)this.listeners.clone();
- } catch (Throwable var9) {
- throw var9;
- }
-
- for(int var4 = 0; var4 < var2.size(); ++var4) {
- ButtonPushEventListener var5 = (ButtonPushEventListener)this.listeners.elementAt(var4);
- var5.notifyButtonPushEvent(var3);
- }
-
- }
- }
-