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.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Date;
-
- public class ImageButton2 extends Applet implements Runnable {
- Thread runner;
- MediaTracker tracker;
- String marker = "nhgube EWUZ";
- boolean initialized = false;
- String loadText;
- Image offscreenI;
- Image offscreenResetI;
- Graphics offscreenG;
- Graphics offscreenResetG;
- Image background;
- Color panelColor;
- String[] statusS = new String[]{"_up_", "_above_", "_down_"};
- int numberOffButtons;
- Image[][] button;
- int[] buttonS;
- // $FF: renamed from: x int[]
- int[] field_0;
- // $FF: renamed from: y int[]
- int[] field_1;
- int[][] defaultButtonNumber;
- int buttonPressed;
- int mouseX;
- int mouseY;
- String defaultFont;
- String[][] text;
- int[][] height;
- int[][] type;
- int[][] color;
- int[] soundTime;
- long timeFlag;
- String marker2 = "ina qra Oretu";
- String[] statusText;
- int statusTextNumber = -1;
- boolean noString;
- boolean vertical;
- boolean mouseIn;
- boolean mouseDown;
- AudioClip[][] sound;
- int playButtonPressed;
- int lastPlayButtonPressed;
- int playButtonUp;
- int playButtonAbove;
- URL[] url;
- String[] target;
- boolean[] noUrl;
-
- public void init() {
- this.loadText = ((Applet)this).getParameter("loadmessage");
- if (this.loadText == null) {
- this.loadText = "loading";
- }
-
- do {
- while(this.marker != "nhgube EWUZ") {
- }
- } while(this.marker2 != "ina qra Oretu");
-
- }
-
- public void initApplet() {
- this.offscreenI = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
- this.offscreenG = this.offscreenI.getGraphics();
- this.offscreenResetI = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
- this.offscreenResetG = this.offscreenResetI.getGraphics();
- this.tracker = new MediaTracker(this);
- this.numberOffButtons = this.getNumber("numberoffbuttons", 1, true);
- this.button = new Image[this.numberOffButtons + 1][3];
- this.field_0 = new int[this.numberOffButtons + 1];
- this.field_1 = new int[this.numberOffButtons + 1];
- this.text = new String[this.numberOffButtons + 1][3];
- this.height = new int[this.numberOffButtons + 1][3];
- this.type = new int[this.numberOffButtons + 1][3];
- this.color = new int[this.numberOffButtons + 1][3];
- this.sound = new AudioClip[this.numberOffButtons + 1][3];
- this.buttonS = new int[this.numberOffButtons + 1];
- this.statusText = new String[this.numberOffButtons + 1];
- this.url = new URL[this.numberOffButtons + 1];
- this.target = new String[this.numberOffButtons + 1];
- this.noUrl = new boolean[this.numberOffButtons + 1];
- this.soundTime = new int[this.numberOffButtons + 1];
- this.defaultButtonNumber = new int[this.numberOffButtons + 1][3];
- this.buttonToTracker(0, 0, "button_up_default", 0, false);
- this.buttonToTracker(0, 1, "button_above_default", 0, false);
- this.buttonToTracker(0, 2, "button_down_default", 0, false);
- this.doTracker(0);
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- if (this.button[0][0] == null) {
- this.buttonToTracker(number, 0, "button_up_" + number, 1, true);
- } else {
- this.buttonToTracker(number, 0, "button_up_" + number, 1, false);
- }
-
- this.buttonToTracker(number, 1, "button_above_" + number, 1, false);
- this.buttonToTracker(number, 2, "button_down_" + number, 1, false);
- }
-
- this.doTracker(1);
- String tempString = this.getString("background", false);
- if (!this.noString) {
- this.background = ((Applet)this).getImage(((Applet)this).getCodeBase(), tempString);
- this.tracker.addImage(this.background, 2);
- this.doTracker(2);
- if (this.tracker.statusID(2, true) == 1) {
- this.errorOut("background not loaded retrying");
- }
- }
-
- if (this.tracker.isErrorID(0) || this.tracker.isErrorID(1) || this.tracker.isErrorID(2)) {
- this.errorOut("IO error some Images not loaded");
- }
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- for(int status = 0; status <= 2; ++status) {
- if (this.button[number][status] == null) {
- this.button[number][status] = this.button[this.defaultButtonNumber[number][status]][status];
- }
- }
- }
-
- tempString = this.getString("direction", true);
- if (tempString.equals("vertical")) {
- this.vertical = true;
- } else if (tempString.equals("horizontal")) {
- this.vertical = false;
- } else {
- this.errorOut("direction not equals vertical or horizontal");
- }
-
- int length = 0;
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- if (this.vertical) {
- length += this.button[number][0].getHeight(this);
- } else {
- length += this.button[number][0].getWidth(this);
- }
- }
-
- if (this.vertical) {
- this.field_0[1] = (((Component)this).size().width - this.button[1][0].getWidth(this)) / 2;
- this.field_1[1] = (((Component)this).size().height - length) / (this.numberOffButtons + 1);
-
- for(int number = 2; number <= this.numberOffButtons; ++number) {
- Image var10003 = this.button[number][0];
- this.field_0[number] = (((Component)this).size().width - var10003.getWidth(this)) / 2;
- this.field_1[number] = this.field_1[number - 1] + this.button[number - 1][0].getHeight(this) + this.field_1[1];
- }
- } else {
- this.field_0[1] = (((Component)this).size().width - length) / (this.numberOffButtons + 1);
- this.field_1[1] = (((Component)this).size().height - this.button[1][0].getHeight(this)) / 2;
-
- for(int number = 2; number <= this.numberOffButtons; ++number) {
- this.field_0[number] = this.field_0[number - 1] + this.button[number - 1][0].getWidth(this) + this.field_0[1];
- Image var51 = this.button[number][0];
- this.field_1[number] = (((Component)this).size().height - var51.getHeight(this)) / 2;
- }
- }
-
- this.field_0[0] = this.getNumber("button_x_default", 0, false);
- boolean xUser = !this.noString;
- this.field_1[0] = this.getNumber("button_y_default", 0, false);
- boolean yUser = !this.noString;
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- if (xUser) {
- this.field_0[number] = this.field_0[0];
- }
-
- if (yUser) {
- this.field_1[number] = this.field_1[0];
- }
-
- this.field_0[number] = this.getNumber("button_x_" + number, this.field_0[number], false);
- this.field_1[number] = this.getNumber("button_y_" + number, this.field_1[number], false);
- }
-
- this.defaultFont = this.getString("defaultfont", false);
- if (this.noString) {
- this.defaultFont = ((Component)this).getGraphics().getFont().getName();
- }
-
- for(int status = 0; status <= 2; ++status) {
- this.height[0][status] = this.getNumber("text_height" + this.statusS[status] + "default", 12, false);
- this.type[0][status] = this.getNumber("text_type" + this.statusS[status] + "default", 0, false);
- this.color[0][status] = this.getNumber("text_color" + this.statusS[status] + "default", 0, false);
- }
-
- for(int number = 0; number <= this.numberOffButtons; ++number) {
- for(int status = 0; status <= 2; ++status) {
- if (this.button[number][status] != null) {
- int buttonWidth = this.button[number][status].getWidth(this);
- int buttonHeight = this.button[number][status].getHeight(this);
- this.text[number][status] = this.getString("text" + this.statusS[status] + number, false);
- if (!this.noString) {
- Image tempScreenI = ((Component)this).createImage(buttonWidth, buttonHeight);
- Graphics tempScreenG = tempScreenI.getGraphics();
- tempScreenG.drawImage(this.button[number][status], 0, 0, this);
- int textHeight = this.getNumber("text_height" + this.statusS[status] + number, this.height[0][status], false);
- int textType = this.getNumber("text_type" + this.statusS[status] + number, this.type[0][status], false);
- Color textColor = new Color(this.getNumber("text_color" + this.statusS[status] + number, this.color[0][status], false));
- Font font = new Font(this.defaultFont, textType, textHeight);
- tempScreenG.setFont(font);
- FontMetrics fm = tempScreenG.getFontMetrics();
- tempScreenG.setColor(textColor);
- int x = (buttonWidth - fm.stringWidth(this.text[number][status])) / 2;
- int y = (buttonHeight + fm.getAscent() + 1) / 2 - fm.getDescent();
- tempScreenG.drawString(this.text[number][status], x, y);
- this.button[number][status] = tempScreenI;
- }
- }
- }
- }
-
- this.sound[0][0] = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), ((Applet)this).getParameter("sound_up_default"));
- this.sound[0][1] = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), ((Applet)this).getParameter("sound_above_default"));
- this.sound[0][2] = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), ((Applet)this).getParameter("sound_down_default"));
-
- for(int s = 0; s <= 2; ++s) {
- if (this.sound[0][s] != null) {
- this.sound[0][s].play();
- this.sound[0][s].stop();
- }
- }
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- for(int status = 0; status <= 2; ++status) {
- tempString = this.getString("sound" + this.statusS[status] + number, false);
- if (!this.noString) {
- this.sound[number][status] = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), tempString);
- this.sound[number][status].play();
- this.sound[number][status].stop();
- }
- }
- }
-
- this.soundTime[0] = this.getNumber("wait_for_sound_default", 0, false);
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- this.soundTime[number] = this.getNumber("wait_for_sound_" + number, this.soundTime[0], false);
- }
-
- tempString = ((Applet)this).getParameter("target_default");
- if (tempString != null) {
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- this.target[number] = tempString;
- }
- }
-
- boolean explorer = System.getProperty("java.vendor").equals("Microsoft Corp.");
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- tempString = ((Applet)this).getParameter("url_" + number);
- if (tempString != null) {
- this.statusText[number] = tempString;
- int anchor = tempString.lastIndexOf("#");
- if (explorer && anchor != -1) {
- tempString = tempString.substring(0, anchor) + "#" + tempString.substring(anchor, tempString.length());
- }
-
- if (!tempString.startsWith("http://") && !tempString.startsWith("mailto:")) {
- String codebase = ((Applet)this).getCodeBase().toString();
- int codebaseLength = codebase.length();
- String codebaseEnd = codebase.substring(codebaseLength - 4, codebaseLength);
- codebaseEnd.toUpperCase();
- if (!codebaseEnd.equals("HTML") && !codebase.equals(".HTM")) {
- boolean var50 = false;
- } else {
- boolean var10000 = true;
- }
-
- int lastSlash = codebase.lastIndexOf("/");
- codebase = codebase.substring(0, lastSlash + 1);
- tempString = codebase + tempString;
- }
-
- try {
- this.url[number] = new URL(tempString);
- } catch (MalformedURLException var23) {
- this.errorOut("button " + number + " illegal url.");
- }
-
- tempString = ((Applet)this).getParameter("target_" + number);
- if (tempString != null) {
- this.target[number] = tempString;
- }
-
- this.noUrl[number] = false;
- } else {
- this.noUrl[number] = true;
- }
- }
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- tempString = ((Applet)this).getParameter("statustext_" + number);
- if (tempString != null) {
- this.statusText[number] = tempString;
- }
- }
-
- this.panelColor = new Color(this.getNumber("bgcolor", 0, false));
- ((Component)this).setBackground(this.panelColor);
- this.offscreenResetG.setColor(this.panelColor);
- this.offscreenResetG.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- if (this.background != null) {
- for(int x = 0; x < ((Component)this).size().width; x += this.background.getWidth(this)) {
- for(int y = 0; y < ((Component)this).size().height; y += this.background.getHeight(this)) {
- this.offscreenResetG.drawImage(this.background, x, y, this);
- }
- }
- }
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- if (this.button[number][0] != null) {
- this.offscreenResetG.drawImage(this.button[number][0], this.field_0[number], this.field_1[number], this);
- }
- }
-
- this.offscreenG.drawImage(this.offscreenResetI, 0, 0, this);
- this.initialized = true;
- }
-
- private void buttonToTracker(int number, int status, String parameter, int id, boolean mustBeThere) {
- String tempString = this.getString(parameter, mustBeThere);
- if (!this.noString) {
- if (!tempString.startsWith("=")) {
- this.button[number][status] = ((Applet)this).getImage(((Applet)this).getCodeBase(), tempString);
- this.tracker.addImage(this.button[number][status], id);
- } else {
- try {
- this.defaultButtonNumber[number][status] = Integer.parseInt(tempString.substring(1, tempString.length()));
- } catch (NumberFormatException var7) {
- this.errorOut("parameter " + parameter + " wrong format");
- }
- }
- }
- }
-
- private void doTracker(int id) {
- try {
- this.tracker.waitForID(id);
- } catch (InterruptedException var2) {
- this.errorOut(" IO error image loading is interupted");
- }
-
- if (this.tracker.statusID(id, true) == 1) {
- this.errorOut("Image not loaded retrying");
- }
-
- }
-
- public String getString(String parameter, boolean mustBeThere) {
- String tempString = ((Applet)this).getParameter(parameter);
- this.noString = false;
- if (tempString != null) {
- return tempString;
- } else {
- if (mustBeThere) {
- this.errorOut("Parameter " + parameter + " isn't found");
- }
-
- this.noString = true;
- return null;
- }
- }
-
- private int getNumber(String parameter, int defaultNumber, boolean mustBeThere) {
- String tempString = ((Applet)this).getParameter(parameter);
-
- try {
- if (tempString == null) {
- if (mustBeThere) {
- this.errorOut("Parameter " + parameter + " isn't found");
- }
-
- this.noString = true;
- return defaultNumber;
- } else {
- return tempString.startsWith("#") ? Integer.parseInt(tempString.substring(1), 16) : Integer.parseInt(tempString);
- }
- } catch (NumberFormatException var5) {
- this.errorOut("ImageButton2: Illegal number " + tempString);
- return defaultNumber;
- }
- }
-
- public void run() {
- if (!this.initialized) {
- ((Component)this).getGraphics().drawString(this.loadText, 3, ((Component)this).size().height / 2);
- ((Component)this).repaint();
- this.initApplet();
- }
-
- this.drawer(-1, -1);
-
- for(; Thread.currentThread() == this.runner; this.pause(333)) {
- if (this.timeFlag != 0L && this.timeFlag < (new Date()).getTime()) {
- if (!this.noUrl[this.lastPlayButtonPressed]) {
- if (this.target[this.lastPlayButtonPressed] == null) {
- ((Applet)this).getAppletContext().showDocument(this.url[this.lastPlayButtonPressed]);
- } else {
- ((Applet)this).getAppletContext().showDocument(this.url[this.lastPlayButtonPressed], this.target[this.lastPlayButtonPressed]);
- }
- }
-
- this.timeFlag = 0L;
- this.buttonS[this.lastPlayButtonPressed] = 2;
- this.buttonPressed = -1;
- this.drawer(this.mouseX, this.mouseY);
- }
- }
-
- }
-
- public void start() {
- if (this.runner == null) {
- this.runner = new Thread(this);
- this.runner.start();
- }
-
- }
-
- public void stop() {
- if (this.runner != null) {
- this.runner.stop();
- this.runner = null;
- }
-
- }
-
- public boolean handleEvent(Event evt) {
- switch (evt.id) {
- case 501:
- this.mouseDown = true;
- if (this.mouseIn) {
- this.drawer(evt.x, evt.y);
- }
-
- return true;
- case 502:
- this.mouseDown = false;
- if (this.mouseIn) {
- this.drawer(evt.x, evt.y);
- }
-
- return true;
- case 503:
- if (this.mouseIn) {
- this.drawer(evt.x, evt.y);
- }
-
- return true;
- case 504:
- this.mouseIn = true;
- this.drawer(evt.x, evt.y);
- return true;
- case 505:
- this.mouseIn = false;
- this.drawer(evt.x, evt.y);
- return true;
- case 506:
- this.mouseDown = true;
- if (this.mouseIn) {
- this.drawer(evt.x, evt.y);
- }
-
- return true;
- default:
- return super.handleEvent(evt);
- }
- }
-
- private void drawer(int mouseX, int mouseY) {
- if (this.initialized) {
- this.mouseX = mouseX;
- this.mouseY = mouseY;
- this.offscreenG.drawImage(this.offscreenResetI, 0, 0, this);
- this.playButtonPressed = -1;
- this.playButtonAbove = -1;
- this.playButtonUp = -1;
- this.statusTextNumber = -1;
-
- for(int number = 1; number <= this.numberOffButtons; ++number) {
- if (this.mouseIn) {
- if (this.field_0[number] <= mouseX && this.field_0[number] + this.button[number][0].getWidth(this) > mouseX && this.field_1[number] < mouseY && this.field_1[number] + this.button[number][0].getHeight(this) >= mouseY) {
- if (this.mouseDown) {
- this.drawButton(number, 2);
- if (this.buttonS[number] != 2) {
- this.buttonS[number] = 2;
- this.buttonPressed = number;
- this.playButtonPressed = number;
- }
- } else {
- this.drawButton(number, 1);
- if (this.buttonS[number] != 1) {
- if (this.buttonS[number] != 2) {
- this.playButtonAbove = number;
- }
-
- this.buttonS[number] = 1;
- }
-
- if (this.statusText[number] != null) {
- this.statusTextNumber = number;
- }
- }
- } else if (this.buttonS[number] != 0) {
- this.buttonS[number] = 0;
- this.playButtonUp = number;
- }
- } else {
- if (this.buttonS[number] == 1 || this.buttonS[number] == 2) {
- this.playButtonUp = number;
- }
-
- this.buttonS[number] = 0;
- }
- }
-
- if (this.playButtonUp != -1 && this.playButtonUp != this.buttonPressed) {
- this.play(this.playButtonUp, 0);
- }
-
- if (this.playButtonAbove != -1 && this.playButtonAbove != this.buttonPressed) {
- this.play(this.playButtonAbove, 1);
- }
-
- if (this.playButtonPressed != -1) {
- this.play(this.playButtonPressed, 2);
- this.timeFlag = (new Date()).getTime() + (long)this.soundTime[this.playButtonPressed];
- this.lastPlayButtonPressed = this.playButtonPressed;
- }
-
- if (this.buttonPressed > 0) {
- this.drawButton(this.buttonPressed, 2);
- this.buttonS[this.buttonPressed] = 2;
- }
-
- if (this.timeFlag > (new Date()).getTime()) {
- this.drawButton(this.lastPlayButtonPressed, 2);
- this.buttonS[this.lastPlayButtonPressed] = 2;
- }
-
- if (this.playButtonUp != -1) {
- ((Applet)this).getAppletContext().showStatus(" ");
- }
-
- if (this.playButtonAbove != -1 && this.statusTextNumber != -1 && this.initialized) {
- ((Applet)this).getAppletContext().showStatus(this.statusText[this.statusTextNumber]);
- }
-
- ((Component)this).repaint();
- }
- }
-
- private void play(int number, int status) {
- if (this.initialized) {
- if (this.sound[number][status] != null || this.sound[0][status] != null) {
- if (this.sound[number][status] != null) {
- this.sound[number][status].play();
- } else {
- this.sound[0][status].play();
- }
- }
- }
- }
-
- public void update(Graphics g) {
- if (this.initialized && this.offscreenI != null) {
- g.drawImage(this.offscreenI, 0, 0, this);
- }
-
- }
-
- public void paint(Graphics g) {
- this.update(g);
- }
-
- public void pause(int sleeper) {
- try {
- Thread.sleep((long)sleeper);
- } catch (InterruptedException var2) {
- }
- }
-
- public void errorOut(String error) {
- ((Applet)this).getAppletContext().showStatus(error);
- System.out.println(error);
- this.pause(5000);
- }
-
- public String getAppletInfo() {
- return "(c) 1997 RJHM van den Bergh\nFrom Java download site : http://www.nedernet.nl/~rvdb\nrvdb@nedernet.nl";
- }
-
- private void drawButton(int number, int status) {
- if (this.button[number][status] != null) {
- this.offscreenG.drawImage(this.button[number][status], this.field_0[number], this.field_1[number], this);
- } else {
- if (status == 2 && this.button[number][1] != null) {
- this.offscreenG.drawImage(this.button[number][1], this.field_0[number], this.field_1[number], this);
- }
-
- }
- }
- }
-