home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Panel;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
-
- public class imagebut extends Panel {
- private int buttonNum;
- private AudioClip clickSound;
- private static final Color defaultBorderColor = new Color(160, 160, 160);
- private static final Color defaultBackColor = new Color(192, 192, 192);
- private static final Color defaultInColor = new Color(192, 192, 192);
- private boolean isUp = true;
- private boolean lastPressed;
- private boolean isMouseDown;
- private int borderWidth;
- private Color borderColor;
- private Color backColor;
- private Color inColor;
- private afkal applet;
- private String name;
- private Image image;
- private Image buttonImage;
- private boolean upAllDrawn;
- private Image downImage;
- private boolean downAllDrawn;
- private MediaTracker tracker;
- private boolean doneLoading;
- private int height;
- private int width;
- private int oldW;
- private int oldH;
-
- private void createButton() {
- this.applet.showStatus("Generating buttons...");
- this.upAllDrawn = false;
- this.downAllDrawn = false;
- Rectangle var1 = ((Component)this).bounds();
- if (var1.width > 0 && var1.height > 0) {
- if (this.buttonImage != null) {
- this.buttonImage.flush();
- this.buttonImage = null;
- }
-
- if (this.downImage != null) {
- this.downImage.flush();
- this.buttonImage = null;
- }
-
- this.buttonImage = ((Component)this).createImage(var1.width, var1.height);
- this.downImage = ((Component)this).createImage(var1.width, var1.height);
- int var2 = -1;
- int var3 = -1;
- if (this.image != null) {
- int var4 = Math.min(var1.width, var1.height);
- double var5 = var4 == var1.width ? (double)(var4 - 2 * this.borderWidth) / (double)this.image.getWidth(this) : (double)(var4 - 2 * this.borderWidth) / (double)this.image.getHeight(this);
- var2 = (int)((double)this.image.getWidth(this) * var5);
- var3 = (int)((double)this.image.getHeight(this) * var5);
- if (var2 > var1.width - 2 * this.borderWidth) {
- var5 = (double)(var1.width - 2 * this.borderWidth) / (double)var2;
- var2 = (int)((double)var2 * var5);
- var3 = (int)((double)var3 * var5);
- }
-
- if (var3 > var1.height - 2 * this.borderWidth) {
- var5 = (double)(var1.height - 2 * this.borderWidth) / (double)var3;
- var2 = (int)((double)var2 * var5);
- var3 = (int)((double)var3 * var5);
- }
-
- if (var5 > (double)1.0F) {
- var5 = (double)1.0F;
- }
- }
-
- Graphics var11 = this.buttonImage.getGraphics();
- Graphics var14 = this.downImage.getGraphics();
- this.drawBorder(var11, true);
- new Point(-1, -1);
- if (this.image != null) {
- Point var6 = this.centreAt(var2, var3);
-
- while(!var11.drawImage(this.image, var6.x, var6.y, var2, var3, this)) {
- try {
- Thread.sleep(5L);
- } catch (InterruptedException var8) {
- }
- }
- }
-
- this.upAllDrawn = true;
- var2 = (int)((double)var2 * 0.9);
- var3 = (int)((double)var3 * 0.9);
- this.drawBorder(var14, false, (int)((double)var1.width * 0.9), (int)((double)var1.height * 0.9));
- if (this.image != null) {
- Point var16 = this.centreAt(var2, var3);
-
- while(!var14.drawImage(this.image, var16.x, var16.y, var2, var3, this)) {
- try {
- Thread.sleep(5L);
- } catch (InterruptedException var7) {
- }
- }
- }
-
- this.downAllDrawn = true;
- var11.dispose();
- Object var12 = null;
- var14.dispose();
- Object var15 = null;
- ((Component)this).repaint();
- System.gc();
- this.applet.showStatus("Buttons generated...");
- }
- }
-
- public boolean mouseEnter(Event var1, int var2, int var3) {
- if (this.isMouseDown) {
- this.isUp = !this.isUp;
- ((Component)this).repaint();
- this.clickSound.play();
- }
-
- return true;
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- if (this.isMouseDown) {
- this.isUp = !this.isUp;
- ((Component)this).repaint();
- this.clickSound.play();
- }
-
- return true;
- }
-
- public void paint(Graphics var1) {
- if (!this.doneLoading) {
- this.waitForImage(true);
- } else if (this.isUp) {
- if (!this.upAllDrawn) {
- return;
- }
-
- var1.drawImage(this.buttonImage, 0, 0, (ImageObserver)null);
- } else {
- if (!this.downAllDrawn) {
- return;
- }
-
- var1.drawImage(this.downImage, 0, 0, (ImageObserver)null);
- }
-
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- this.isMouseDown = false;
- this.popButton();
- var1.id = 1001;
- var1.arg = this;
- return super.action(var1, var1.arg);
- }
-
- public void drawBorder(Graphics var1, boolean var2) {
- Rectangle var3 = ((Component)this).bounds();
- int var4 = 0;
- int var5 = 0;
- int var6 = var3.width;
- int var7 = var3.height;
- var1.setColor(this.borderColor);
-
- for(int var8 = 0; var8 < this.borderWidth; ++var8) {
- var1.draw3DRect(var4, var5, var6, var7, var2);
- ++var4;
- ++var5;
- var6 -= 2;
- var7 -= 2;
- }
-
- if (var2) {
- var1.setColor(this.backColor);
- } else {
- var1.setColor(this.inColor);
- }
-
- var1.fillRect(var4, var5, var6 + 1, var7 + 1);
- }
-
- public void drawBorder(Graphics var1, boolean var2, int var3, int var4) {
- Rectangle var5 = ((Component)this).bounds();
- int var6 = (var5.width - var3) / 2;
- int var7 = (var5.height - var4) / 2;
- int var8 = var3;
- int var9 = var4;
- var1.setColor(this.applet.getBackground());
- var1.fillRect(0, 0, var5.width, var5.height);
- var1.setColor(this.borderColor);
-
- for(int var10 = 0; var10 < (int)((double)this.borderWidth * 0.9); ++var10) {
- var1.draw3DRect(var6, var7, var8, var9, var2);
- ++var6;
- ++var7;
- var8 -= 2;
- var9 -= 2;
- }
-
- if (var2) {
- var1.setColor(this.backColor);
- } else {
- var1.setColor(this.inColor);
- }
-
- var1.fillRect(var6, var7, var8 + 1, var9 + 1);
- }
-
- public Dimension minimumSize() {
- if (!this.doneLoading) {
- this.waitForImage(false);
- }
-
- return new Dimension(this.width, this.height);
- }
-
- public void waitForImage(boolean var1) {
- if (!this.doneLoading) {
- this.applet.showStatus("Loading image " + this.name + " ...");
-
- try {
- this.tracker.waitForID(0);
- } catch (InterruptedException var3) {
- System.out.println("Picture download was interrupted");
- } catch (Exception var4) {
- System.out.println("Error loading " + this.name + ":" + ((Throwable)var4).getMessage());
- this.image = null;
- }
-
- if (this.tracker.isErrorID(0)) {
- System.out.println("Error loading image " + this.name);
- this.image = null;
- }
-
- this.doneLoading = true;
- if (this.image != null) {
- int var2 = Math.max(this.image.getWidth(this), this.image.getHeight(this));
- this.width = var2 + 2 * this.borderWidth;
- this.height = this.width;
- }
-
- Container var5 = ((Component)this).getParent();
- if (var5 != null && var1) {
- var5.layout();
- }
-
- if (this.buttonImage != null) {
- ((Component)this).repaint();
- }
- }
-
- }
-
- private imagebut() {
- this.borderColor = defaultBorderColor;
- this.backColor = defaultBackColor;
- this.inColor = defaultInColor;
- this.oldW = -1;
- this.oldH = -1;
- }
-
- public imagebut(String var1, int var2, int var3, AudioClip var4, afkal var5) {
- this.borderColor = defaultBorderColor;
- this.backColor = defaultBackColor;
- this.inColor = defaultInColor;
- this.oldW = -1;
- this.oldH = -1;
- this.applet = var5;
- this.buttonNum = var2;
- this.image = ((Applet)var5).getImage(((Applet)var5).getDocumentBase(), var1);
- this.clickSound = var4;
- this.name = var1;
- this.borderWidth = var3;
- this.tracker = new MediaTracker(this);
- this.tracker.addImage(this.image, 0);
- }
-
- public int getButtonNum() {
- return this.buttonNum;
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- this.isMouseDown = true;
- this.isUp = false;
- ((Component)this).repaint();
- this.clickSound.play();
- return true;
- }
-
- public Dimension preferredSize() {
- if (!this.doneLoading) {
- this.waitForImage(false);
- }
-
- return new Dimension(this.width, this.height);
- }
-
- public void popButton() {
- if (!this.isUp) {
- this.isUp = !this.isUp;
- ((Component)this).repaint();
- }
-
- }
-
- private Point centreAt(int var1, int var2) {
- Rectangle var3 = ((Component)this).bounds();
- int var4 = var3.width;
- int var5 = var3.height;
- int var6 = var4 / 2 - var1 / 2;
- int var7 = var5 / 2 - var2 / 2;
- return new Point(var6, var7);
- }
-
- public synchronized void reshape(int var1, int var2, int var3, int var4) {
- if (!this.doneLoading) {
- this.waitForImage(false);
- }
-
- super.reshape(var1, var2, var3, var4);
- if (var3 != this.oldW || var4 != this.oldH) {
- this.createButton();
- this.oldW = var3;
- this.oldH = var4;
- }
-
- }
- }
-