home *** CD-ROM | disk | FTP | other *** search
- 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.Panel;
-
- class oc3dtb extends Panel implements Runnable {
- public String buttonText = "";
- static final int A_RIGHT = 3;
- static final int A_LEFT = 1;
- static final int A_CENTER = 2;
- static final int BUTTON_DOWN = 100;
- static final int BUTTON_HELD = 101;
- static final int BUTTON_UP = 102;
- private int bHeight = 50;
- private int bWidth = 20;
- private boolean hasText;
- private Thread goauto;
- private boolean first_run;
- private boolean bypass;
- private boolean mouse_down;
- private boolean h_drawn;
- private boolean call_set_text;
- private boolean call_set_text2;
- private String[] msg_lines;
- private Event the_e;
- // $FF: renamed from: mx int
- private int field_0;
- // $FF: renamed from: my int
- private int field_1;
- private Color button_color;
- private Color text_color;
- private Color htext_color;
- private int auto_delay;
- private int auto_rate;
- private Image sboff;
- private Graphics g_boff;
- private int lMargin;
- private int hAlign;
- // $FF: renamed from: fm java.awt.FontMetrics
- private FontMetrics field_2;
- private Font font;
-
- public void start() {
- if (this.goauto == null) {
- this.goauto = new Thread(this);
- this.goauto.start();
- }
-
- }
-
- public void stop() {
- if (this.goauto != null) {
- this.goauto.stop();
- this.goauto = null;
- }
-
- }
-
- public void setColors(Color bc, Color tc, Color htc) {
- this.button_color = bc;
- this.text_color = tc;
- this.htext_color = htc;
- if (this.first_run) {
- this.drawTheButton(((Component)this).getGraphics(), true);
- }
- }
-
- public boolean mouseExit(Event e, int x, int y) {
- if (this.h_drawn) {
- this.h_drawn = false;
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
- this.paintIt(((Component)this).getGraphics());
- return true;
- } else {
- return true;
- }
- }
-
- oc3dtb(int width, int height) {
- this.button_color = Color.lightGray;
- this.text_color = Color.black;
- this.htext_color = Color.yellow;
- this.auto_delay = 5;
- this.auto_rate = 40;
- this.lMargin = 4;
- this.hAlign = 2;
- ((Component)this).setFont(this.font = new Font("Helvetica", 0, 12));
- this.field_2 = ((Component)this).getFontMetrics(this.font);
- if (width >= 1 && height >= 1) {
- this.bWidth = width;
- this.bHeight = height;
- } else {
- IllegalArgumentException er = new IllegalArgumentException("Negative Button Dimension");
- throw er;
- }
- }
-
- public boolean mouseMove(Event event, int cx, int cy) {
- if (cx > 0 && cx < this.bWidth && cy > 0 && cy < this.bHeight) {
- if (this.h_drawn) {
- return true;
- } else {
- this.h_drawn = true;
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.htext_color, true);
- this.paintIt(((Component)this).getGraphics());
- return true;
- }
- } else if (this.h_drawn) {
- this.h_drawn = false;
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
- this.paintIt(((Component)this).getGraphics());
- return true;
- } else {
- return true;
- }
- }
-
- public boolean mouseDown(Event e, int x, int y) {
- this.field_0 = x;
- this.field_1 = y;
- this.mouse_down = true;
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 2, this.htext_color, true);
- this.paintIt(((Component)this).getGraphics());
- e.id = 100;
- ((Component)this).postEvent(e);
- this.the_e = e;
- this.start();
- return true;
- }
-
- private void paintIt(Graphics g) {
- if (!this.first_run) {
- ((Component)this).setBackground(this.button_color);
- this.sboff = ((Component)this).createImage(this.bWidth, this.bHeight);
- this.g_boff = this.sboff.getGraphics();
- this.first_run = true;
- this.drawTheButton(g, false);
- if (this.call_set_text) {
- this.setText(this.buttonText);
- this.call_set_text = false;
- }
-
- if (this.call_set_text2) {
- this.setText(this.buttonText);
- this.call_set_text2 = false;
- }
- } else {
- g.drawImage(this.sboff, 0, 0, this);
- }
-
- }
-
- public boolean mouseDrag(Event event, int cx, int cy) {
- this.field_0 = cx;
- this.field_1 = cy;
- if (cx > 0 && cx < this.bWidth && cy > 0 && cy < this.bHeight) {
- if (this.h_drawn) {
- return true;
- } else {
- this.h_drawn = true;
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 2, this.htext_color, true);
- this.paintIt(((Component)this).getGraphics());
- this.start();
- return true;
- }
- } else if (this.h_drawn) {
- this.h_drawn = false;
- this.bypass = true;
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
- this.paintIt(((Component)this).getGraphics());
- this.stop();
- return true;
- } else {
- return true;
- }
- }
-
- public boolean mouseUp(Event evt, int cx, int cy) {
- this.mouse_down = false;
- this.bypass = false;
- if (this.h_drawn) {
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.htext_color, true);
- } else {
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
- }
-
- this.paintIt(((Component)this).getGraphics());
- this.stop();
- if (cx > 0 && cx < this.bWidth && cy > 0 && cy < this.bHeight) {
- evt.id = 103;
- ((Component)this).postEvent(evt);
- }
-
- return true;
- }
-
- public void run() {
- while(true) {
- if (!this.bypass) {
- try {
- Thread.sleep((long)(this.auto_delay * 100));
- } catch (InterruptedException var4) {
- }
- } else {
- this.bypass = false;
- }
-
- while(this.mouse_down) {
- if (this.field_0 >= 0 && this.field_1 >= 0 && this.field_0 <= this.bWidth && this.field_1 <= this.bHeight) {
- this.the_e.id = 101;
- ((Component)this).postEvent(this.the_e);
-
- try {
- Thread.sleep((long)this.auto_rate);
- } catch (InterruptedException var3) {
- }
- }
- }
- }
- }
-
- public void setText(String bm, int margin, Font sfont, int halign) {
- if (this.lMargin > 0) {
- this.lMargin = margin;
- }
-
- if (this.hAlign > 0 && this.hAlign < 4) {
- this.hAlign = halign;
- }
-
- if (bm == null) {
- this.buttonText = "";
- this.hasText = false;
- } else {
- this.buttonText = bm;
- this.hasText = true;
- if (!this.first_run) {
- this.call_set_text2 = true;
- } else {
- this.font = sfont;
- this.g_boff.setFont(this.font);
- this.field_2 = this.g_boff.getFontMetrics(this.font);
- this.msg_lines = ocwordw.WrapText(this.buttonText, this.bWidth - this.lMargin * 2, this.field_2);
- if (this.mouse_down) {
- this.drawText(true, this.text_color);
- } else {
- this.drawText(false, this.text_color);
- }
-
- this.paintIt(((Component)this).getGraphics());
- }
- }
- }
-
- public void setText(String bm) {
- if (bm == null) {
- this.buttonText = "";
- this.hasText = false;
- } else {
- this.buttonText = bm;
- this.hasText = true;
- if (!this.first_run) {
- this.call_set_text = true;
- } else {
- this.g_boff.setFont(this.font);
- this.field_2 = this.g_boff.getFontMetrics(this.font);
- this.msg_lines = ocwordw.WrapText(this.buttonText, this.bWidth - this.lMargin * 2, this.field_2);
- if (this.mouse_down) {
- this.drawText(true, this.text_color);
- } else {
- this.drawText(false, this.text_color);
- }
-
- this.paintIt(((Component)this).getGraphics());
- }
- }
- }
-
- private void drawText(boolean offset, Color tc) {
- this.g_boff.setColor(tc);
- int cur_y = (this.bHeight - 4 - this.msg_lines.length * this.field_2.getHeight()) / 2;
- int xoff = 0;
- if (offset) {
- ++cur_y;
- xoff = 1;
- }
-
- for(int l = 0; l < this.msg_lines.length; ++l) {
- cur_y += this.field_2.getHeight();
- if (this.hAlign == 2) {
- this.g_boff.drawString(this.msg_lines[l], xoff + (this.bWidth - this.field_2.stringWidth(this.msg_lines[l])) / 2, cur_y);
- }
-
- if (this.hAlign == 1) {
- this.g_boff.drawString(this.msg_lines[l], xoff + this.lMargin, cur_y);
- }
-
- if (this.hAlign == 3) {
- this.g_boff.drawString(this.msg_lines[l], xoff + (this.bWidth - this.field_2.stringWidth(this.msg_lines[l])) - this.lMargin, cur_y);
- }
- }
-
- }
-
- private void drawButton(int x, int y, int width, int height, int type, Color tc, boolean do_text) {
- this.g_boff.setColor(this.button_color);
- if (type == 1) {
- this.g_boff.fillRect(x + 2, y + 2, width - 2, height - 2);
- } else {
- this.g_boff.fillRect(x + 1, y + 1, width - 1, height - 1);
- }
-
- if (type == 1) {
- this.g_boff.setColor(Color.lightGray);
- this.g_boff.drawRect(x + 1, y + 1, width - 1, height - 1);
- this.g_boff.setColor(Color.gray);
- this.g_boff.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
- this.g_boff.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 1);
- this.g_boff.setColor(Color.white);
- this.g_boff.drawRect(x, y, width, height);
- this.g_boff.setColor(Color.black);
- this.g_boff.drawLine(x, y + height, x + width, y + height);
- this.g_boff.drawLine(x + width, y, x + width, y + height);
- if (do_text && this.hasText) {
- this.drawText(false, tc);
- }
- } else {
- this.g_boff.setColor(Color.gray);
- this.g_boff.drawRect(x, y, width, height);
- if (do_text && this.hasText) {
- this.drawText(true, tc);
- }
- }
-
- }
-
- private void drawTheButton(Graphics g, boolean text) {
- this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, text);
- g.drawImage(this.sboff, 0, 0, this);
- }
-
- public void paint(Graphics g) {
- this.paintIt(((Component)this).getGraphics());
- }
- }
-