home *** CD-ROM | disk | FTP | other *** search
- import java.awt.AWTException;
- 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;
-
- public abstract class ButtonBase extends Canvas {
- protected boolean pressed = false;
- protected boolean released = true;
- protected boolean inButton;
- protected boolean notifyWhilePressed = false;
- protected boolean running = false;
- protected boolean notified = false;
- protected boolean showFocus;
- protected int bevel = 1;
- protected int notifyDelay = 1000;
- protected int pressedAdjustment = 0;
- protected Timer notifyTimer = null;
- protected Image imgBG;
-
- protected ButtonBase() {
- ((Component)this).resize(10, 10);
- }
-
- public void setBevelHeight(int size) {
- try {
- this.checkBevelSize(size);
- } catch (AWTException var2) {
- System.err.println("Invalid Bevel Size " + size);
- }
-
- this.bevel = size;
- ((Component)this).invalidate();
- }
-
- public int getBevelHeight() {
- return this.bevel;
- }
-
- public void setNotifyWhilePressed(boolean f) {
- this.notifyWhilePressed = f;
- if (this.notifyWhilePressed) {
- this.notifyTimer = new Timer(this, this.notifyDelay, true, 1001);
- } else {
- if (this.notifyTimer != null) {
- this.notifyTimer = null;
- }
-
- }
- }
-
- public boolean getNotifyWhilePressed() {
- return this.notifyWhilePressed;
- }
-
- public void setNotifyDelay(int d) {
- this.notifyDelay = d;
- }
-
- public int getNotifyDelay() {
- return this.notifyDelay;
- }
-
- public void setShowFocus(boolean f) {
- this.showFocus = f;
- }
-
- public boolean getShowFocus() {
- return this.showFocus;
- }
-
- public void setBGImage(Image img) {
- this.imgBG = img;
- ((Component)this).invalidate();
- }
-
- public boolean mouseUp(Event e, int x, int y) {
- if (this.running) {
- this.running = false;
- this.notifyTimer.stop();
- }
-
- if (this.pressed) {
- this.pressed = false;
- this.pressedAdjustment = 0;
- if (!this.notifyWhilePressed || !this.notified) {
- ((Component)this).postEvent(new Event(this, 1001, (Object)null));
- }
- }
-
- this.released = true;
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseDown(Event e, int x, int y) {
- if (this.notifyWhilePressed && !this.running) {
- this.running = true;
- this.notifyTimer.start();
- }
-
- this.pressed = true;
- this.released = false;
- this.pressedAdjustment = this.bevel;
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseEnter(Event e, int x, int y) {
- this.inButton = true;
- if (!this.released) {
- this.mouseDown(e, x, y);
- }
-
- return true;
- }
-
- public boolean mouseExit(Event e, int x, int y) {
- this.inButton = false;
- if (this.pressed) {
- this.pressed = false;
- this.pressedAdjustment = 0;
- }
-
- return true;
- }
-
- public boolean action(Event e, Object o) {
- if (this.notifyWhilePressed && e.target == this.notifyTimer && !Beans.isDesignTime()) {
- ((Component)this).postEvent(new Event(this, 1001, (Object)null));
- return true;
- } else {
- return super.action(e, o);
- }
- }
-
- public void enable() {
- if (!((Component)this).isEnabled()) {
- super.enable();
- this.pressed = false;
- this.pressedAdjustment = 0;
- }
-
- ((Component)this).repaint();
- }
-
- public void disable() {
- if (((Component)this).isEnabled()) {
- super.disable();
- if (this.notifyTimer != null) {
- this.notifyTimer.stop();
- }
-
- this.pressed = false;
- this.pressedAdjustment = 0;
- }
-
- ((Component)this).repaint();
- }
-
- public void update(Graphics g) {
- Dimension s = ((Component)this).size();
- this.paint(g);
- }
-
- public void paint(Graphics g) {
- Dimension s = ((Component)this).size();
- int width = s.width;
- int height = s.height;
- int x = this.bevel + 1;
- int y = this.bevel + 1;
- int w = width - 1;
- int h = height - 1;
- if (this.pressed) {
- int var10000 = x + (this.bevel > 0 ? 2 : 1);
- g.setColor(Color.lightGray);
-
- for(int i = 1; i < this.bevel + 1; ++i) {
- g.drawLine(i, h - i, w - i, h - i);
- g.drawLine(w - i, h - i, w - i, i);
- }
-
- g.setColor(Color.gray);
-
- for(int var12 = 1; var12 < this.bevel + 1; ++var12) {
- g.drawLine(var12, h, var12, var12);
- g.drawLine(var12, var12, w, var12);
- }
-
- } else {
- g.setColor(Color.white);
-
- for(int i = 1; i < this.bevel + 1; ++i) {
- g.drawLine(i, h - i, i, i);
- g.drawLine(i, i, w - i, i);
- }
-
- g.setColor(Color.gray);
-
- for(int var10 = 1; var10 < this.bevel + 2; ++var10) {
- g.drawLine(var10, h - var10, w - var10, h - var10);
- g.drawLine(w - var10, h - var10, w - var10, var10);
- }
-
- }
- }
-
- private void checkBevelSize(int i) throws AWTException {
- Dimension s = ((Component)this).size();
- if (i < 0 || i >= s.width / 2 || i >= s.height / 2) {
- throw new AWTException("invalid bevel size");
- }
- }
- }
-