home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 June / INTERNET92.ISO / pc / software / windows / building / visual_dhtml / visualdhtmlwin9x_nt.exe / oc3dtb.___ (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-15  |  7.0 KB  |  350 lines

  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.Event;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.Panel;
  9.  
  10. class oc3dtb extends Panel implements Runnable {
  11.    public String buttonText = "";
  12.    static final int A_RIGHT = 3;
  13.    static final int A_LEFT = 1;
  14.    static final int A_CENTER = 2;
  15.    static final int BUTTON_DOWN = 100;
  16.    static final int BUTTON_HELD = 101;
  17.    static final int BUTTON_UP = 102;
  18.    private int bHeight = 50;
  19.    private int bWidth = 20;
  20.    private boolean hasText;
  21.    private Thread goauto;
  22.    private boolean first_run;
  23.    private boolean bypass;
  24.    private boolean mouse_down;
  25.    private boolean h_drawn;
  26.    private boolean call_set_text;
  27.    private boolean call_set_text2;
  28.    private String[] msg_lines;
  29.    private Event the_e;
  30.    // $FF: renamed from: mx int
  31.    private int field_0;
  32.    // $FF: renamed from: my int
  33.    private int field_1;
  34.    private Color button_color;
  35.    private Color text_color;
  36.    private Color htext_color;
  37.    private int auto_delay;
  38.    private int auto_rate;
  39.    private Image sboff;
  40.    private Graphics g_boff;
  41.    private int lMargin;
  42.    private int hAlign;
  43.    // $FF: renamed from: fm java.awt.FontMetrics
  44.    private FontMetrics field_2;
  45.    private Font font;
  46.  
  47.    public void start() {
  48.       if (this.goauto == null) {
  49.          this.goauto = new Thread(this);
  50.          this.goauto.start();
  51.       }
  52.  
  53.    }
  54.  
  55.    public void stop() {
  56.       if (this.goauto != null) {
  57.          this.goauto.stop();
  58.          this.goauto = null;
  59.       }
  60.  
  61.    }
  62.  
  63.    public void setColors(Color bc, Color tc, Color htc) {
  64.       this.button_color = bc;
  65.       this.text_color = tc;
  66.       this.htext_color = htc;
  67.       if (this.first_run) {
  68.          this.drawTheButton(((Component)this).getGraphics(), true);
  69.       }
  70.    }
  71.  
  72.    public boolean mouseExit(Event e, int x, int y) {
  73.       if (this.h_drawn) {
  74.          this.h_drawn = false;
  75.          this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
  76.          this.paintIt(((Component)this).getGraphics());
  77.          return true;
  78.       } else {
  79.          return true;
  80.       }
  81.    }
  82.  
  83.    oc3dtb(int width, int height) {
  84.       this.button_color = Color.lightGray;
  85.       this.text_color = Color.black;
  86.       this.htext_color = Color.yellow;
  87.       this.auto_delay = 5;
  88.       this.auto_rate = 40;
  89.       this.lMargin = 4;
  90.       this.hAlign = 2;
  91.       ((Component)this).setFont(this.font = new Font("Helvetica", 0, 12));
  92.       this.field_2 = ((Component)this).getFontMetrics(this.font);
  93.       if (width >= 1 && height >= 1) {
  94.          this.bWidth = width;
  95.          this.bHeight = height;
  96.       } else {
  97.          IllegalArgumentException er = new IllegalArgumentException("Negative Button Dimension");
  98.          throw er;
  99.       }
  100.    }
  101.  
  102.    public boolean mouseMove(Event event, int cx, int cy) {
  103.       if (cx > 0 && cx < this.bWidth && cy > 0 && cy < this.bHeight) {
  104.          if (this.h_drawn) {
  105.             return true;
  106.          } else {
  107.             this.h_drawn = true;
  108.             this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.htext_color, true);
  109.             this.paintIt(((Component)this).getGraphics());
  110.             return true;
  111.          }
  112.       } else if (this.h_drawn) {
  113.          this.h_drawn = false;
  114.          this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
  115.          this.paintIt(((Component)this).getGraphics());
  116.          return true;
  117.       } else {
  118.          return true;
  119.       }
  120.    }
  121.  
  122.    public boolean mouseDown(Event e, int x, int y) {
  123.       this.field_0 = x;
  124.       this.field_1 = y;
  125.       this.mouse_down = true;
  126.       this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 2, this.htext_color, true);
  127.       this.paintIt(((Component)this).getGraphics());
  128.       e.id = 100;
  129.       ((Component)this).postEvent(e);
  130.       this.the_e = e;
  131.       this.start();
  132.       return true;
  133.    }
  134.  
  135.    private void paintIt(Graphics g) {
  136.       if (!this.first_run) {
  137.          ((Component)this).setBackground(this.button_color);
  138.          this.sboff = ((Component)this).createImage(this.bWidth, this.bHeight);
  139.          this.g_boff = this.sboff.getGraphics();
  140.          this.first_run = true;
  141.          this.drawTheButton(g, false);
  142.          if (this.call_set_text) {
  143.             this.setText(this.buttonText);
  144.             this.call_set_text = false;
  145.          }
  146.  
  147.          if (this.call_set_text2) {
  148.             this.setText(this.buttonText);
  149.             this.call_set_text2 = false;
  150.          }
  151.       } else {
  152.          g.drawImage(this.sboff, 0, 0, this);
  153.       }
  154.  
  155.    }
  156.  
  157.    public boolean mouseDrag(Event event, int cx, int cy) {
  158.       this.field_0 = cx;
  159.       this.field_1 = cy;
  160.       if (cx > 0 && cx < this.bWidth && cy > 0 && cy < this.bHeight) {
  161.          if (this.h_drawn) {
  162.             return true;
  163.          } else {
  164.             this.h_drawn = true;
  165.             this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 2, this.htext_color, true);
  166.             this.paintIt(((Component)this).getGraphics());
  167.             this.start();
  168.             return true;
  169.          }
  170.       } else if (this.h_drawn) {
  171.          this.h_drawn = false;
  172.          this.bypass = true;
  173.          this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
  174.          this.paintIt(((Component)this).getGraphics());
  175.          this.stop();
  176.          return true;
  177.       } else {
  178.          return true;
  179.       }
  180.    }
  181.  
  182.    public boolean mouseUp(Event evt, int cx, int cy) {
  183.       this.mouse_down = false;
  184.       this.bypass = false;
  185.       if (this.h_drawn) {
  186.          this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.htext_color, true);
  187.       } else {
  188.          this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, true);
  189.       }
  190.  
  191.       this.paintIt(((Component)this).getGraphics());
  192.       this.stop();
  193.       if (cx > 0 && cx < this.bWidth && cy > 0 && cy < this.bHeight) {
  194.          evt.id = 103;
  195.          ((Component)this).postEvent(evt);
  196.       }
  197.  
  198.       return true;
  199.    }
  200.  
  201.    public void run() {
  202.       while(true) {
  203.          if (!this.bypass) {
  204.             try {
  205.                Thread.sleep((long)(this.auto_delay * 100));
  206.             } catch (InterruptedException var4) {
  207.             }
  208.          } else {
  209.             this.bypass = false;
  210.          }
  211.  
  212.          while(this.mouse_down) {
  213.             if (this.field_0 >= 0 && this.field_1 >= 0 && this.field_0 <= this.bWidth && this.field_1 <= this.bHeight) {
  214.                this.the_e.id = 101;
  215.                ((Component)this).postEvent(this.the_e);
  216.  
  217.                try {
  218.                   Thread.sleep((long)this.auto_rate);
  219.                } catch (InterruptedException var3) {
  220.                }
  221.             }
  222.          }
  223.       }
  224.    }
  225.  
  226.    public void setText(String bm, int margin, Font sfont, int halign) {
  227.       if (this.lMargin > 0) {
  228.          this.lMargin = margin;
  229.       }
  230.  
  231.       if (this.hAlign > 0 && this.hAlign < 4) {
  232.          this.hAlign = halign;
  233.       }
  234.  
  235.       if (bm == null) {
  236.          this.buttonText = "";
  237.          this.hasText = false;
  238.       } else {
  239.          this.buttonText = bm;
  240.          this.hasText = true;
  241.          if (!this.first_run) {
  242.             this.call_set_text2 = true;
  243.          } else {
  244.             this.font = sfont;
  245.             this.g_boff.setFont(this.font);
  246.             this.field_2 = this.g_boff.getFontMetrics(this.font);
  247.             this.msg_lines = ocwordw.WrapText(this.buttonText, this.bWidth - this.lMargin * 2, this.field_2);
  248.             if (this.mouse_down) {
  249.                this.drawText(true, this.text_color);
  250.             } else {
  251.                this.drawText(false, this.text_color);
  252.             }
  253.  
  254.             this.paintIt(((Component)this).getGraphics());
  255.          }
  256.       }
  257.    }
  258.  
  259.    public void setText(String bm) {
  260.       if (bm == null) {
  261.          this.buttonText = "";
  262.          this.hasText = false;
  263.       } else {
  264.          this.buttonText = bm;
  265.          this.hasText = true;
  266.          if (!this.first_run) {
  267.             this.call_set_text = true;
  268.          } else {
  269.             this.g_boff.setFont(this.font);
  270.             this.field_2 = this.g_boff.getFontMetrics(this.font);
  271.             this.msg_lines = ocwordw.WrapText(this.buttonText, this.bWidth - this.lMargin * 2, this.field_2);
  272.             if (this.mouse_down) {
  273.                this.drawText(true, this.text_color);
  274.             } else {
  275.                this.drawText(false, this.text_color);
  276.             }
  277.  
  278.             this.paintIt(((Component)this).getGraphics());
  279.          }
  280.       }
  281.    }
  282.  
  283.    private void drawText(boolean offset, Color tc) {
  284.       this.g_boff.setColor(tc);
  285.       int cur_y = (this.bHeight - 4 - this.msg_lines.length * this.field_2.getHeight()) / 2;
  286.       int xoff = 0;
  287.       if (offset) {
  288.          ++cur_y;
  289.          xoff = 1;
  290.       }
  291.  
  292.       for(int l = 0; l < this.msg_lines.length; ++l) {
  293.          cur_y += this.field_2.getHeight();
  294.          if (this.hAlign == 2) {
  295.             this.g_boff.drawString(this.msg_lines[l], xoff + (this.bWidth - this.field_2.stringWidth(this.msg_lines[l])) / 2, cur_y);
  296.          }
  297.  
  298.          if (this.hAlign == 1) {
  299.             this.g_boff.drawString(this.msg_lines[l], xoff + this.lMargin, cur_y);
  300.          }
  301.  
  302.          if (this.hAlign == 3) {
  303.             this.g_boff.drawString(this.msg_lines[l], xoff + (this.bWidth - this.field_2.stringWidth(this.msg_lines[l])) - this.lMargin, cur_y);
  304.          }
  305.       }
  306.  
  307.    }
  308.  
  309.    private void drawButton(int x, int y, int width, int height, int type, Color tc, boolean do_text) {
  310.       this.g_boff.setColor(this.button_color);
  311.       if (type == 1) {
  312.          this.g_boff.fillRect(x + 2, y + 2, width - 2, height - 2);
  313.       } else {
  314.          this.g_boff.fillRect(x + 1, y + 1, width - 1, height - 1);
  315.       }
  316.  
  317.       if (type == 1) {
  318.          this.g_boff.setColor(Color.lightGray);
  319.          this.g_boff.drawRect(x + 1, y + 1, width - 1, height - 1);
  320.          this.g_boff.setColor(Color.gray);
  321.          this.g_boff.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
  322.          this.g_boff.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 1);
  323.          this.g_boff.setColor(Color.white);
  324.          this.g_boff.drawRect(x, y, width, height);
  325.          this.g_boff.setColor(Color.black);
  326.          this.g_boff.drawLine(x, y + height, x + width, y + height);
  327.          this.g_boff.drawLine(x + width, y, x + width, y + height);
  328.          if (do_text && this.hasText) {
  329.             this.drawText(false, tc);
  330.          }
  331.       } else {
  332.          this.g_boff.setColor(Color.gray);
  333.          this.g_boff.drawRect(x, y, width, height);
  334.          if (do_text && this.hasText) {
  335.             this.drawText(true, tc);
  336.          }
  337.       }
  338.  
  339.    }
  340.  
  341.    private void drawTheButton(Graphics g, boolean text) {
  342.       this.drawButton(0, 0, this.bWidth - 1, this.bHeight - 1, 1, this.text_color, text);
  343.       g.drawImage(this.sboff, 0, 0, this);
  344.    }
  345.  
  346.    public void paint(Graphics g) {
  347.       this.paintIt(((Component)this).getGraphics());
  348.    }
  349. }
  350.