home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 June / INTERNET92.ISO / pc / software / windows / building / visual_dhtml / visualdhtmlwin9x_nt.exe / ocsb.___ (.txt) < prev    next >
Encoding:
Java Class File  |  1998-05-08  |  9.9 KB  |  593 lines

  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.Dimension;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.awt.Panel;
  8.  
  9. class ocsb extends Panel implements Runnable {
  10.    public static final int SCROLL_LINE_UP = 601;
  11.    public static final int SCROLL_LINE_DOWN = 602;
  12.    public static final int SCROLL_PAGE_UP = 603;
  13.    public static final int SCROLL_PAGE_DOWN = 604;
  14.    public static final int SCROLL_ABSOLUTE = 605;
  15.    public int sbHeight;
  16.    public int sbWidth;
  17.    private int sbValue;
  18.    private int pageIncrement;
  19.    private int sbMax;
  20.    private int sbIncrement = 1;
  21.    private Thread goauto;
  22.    private boolean paint_called;
  23.    private boolean first_run = true;
  24.    private boolean on_top;
  25.    private boolean on_bottom;
  26.    private boolean m_down;
  27.    private boolean dragging_bubble;
  28.    private boolean bad_scroll = true;
  29.    private boolean mouse_in;
  30.    private boolean m_off;
  31.    private boolean bypass;
  32.    private Event the_e;
  33.    private int auto_type;
  34.    // $FF: renamed from: mx int
  35.    private int field_0;
  36.    // $FF: renamed from: my int
  37.    private int field_1;
  38.    private int drag_move;
  39.    private float hbp;
  40.    private Color button_color;
  41.    private Color arrow_color;
  42.    private Color harrow_color;
  43.    private Color bg_color;
  44.    private Color slider_color;
  45.    private Color outline_color;
  46.    private int slider_inset;
  47.    private int last_button;
  48.    private int auto_delay;
  49.    private int auto_rate;
  50.    private int bubble_range;
  51.    private float bubble_pos;
  52.    private float bubble_inc;
  53.    private int position;
  54.    private Image sboff;
  55.    private Graphics g_sboff;
  56.  
  57.    public void start() {
  58.       if (this.goauto == null) {
  59.          this.goauto = new Thread(this);
  60.          this.goauto.start();
  61.       }
  62.  
  63.    }
  64.  
  65.    public void stop() {
  66.       if (this.goauto != null) {
  67.          this.goauto.stop();
  68.          this.goauto = null;
  69.       }
  70.  
  71.    }
  72.  
  73.    public void reshape(int x, int y, int width, int height) {
  74.       if (width * height > 0) {
  75.          this.sbWidth = width;
  76.          this.sbHeight = height;
  77.          this.figureBubble(true);
  78.          super.reshape(x, y, width, height);
  79.       }
  80.    }
  81.  
  82.    public boolean mouseExit(Event e, int x, int y) {
  83.       if (this.bad_scroll) {
  84.          return true;
  85.       } else {
  86.          this.mouse_in = false;
  87.          this.m_off = true;
  88.          this.undoHButtons();
  89.          return true;
  90.       }
  91.    }
  92.  
  93.    private void checkDbutton(Event e, int type) {
  94.       if (type == 1) {
  95.          this.sbValue += this.sbIncrement;
  96.          if (this.sbValue > this.sbMax) {
  97.             this.sbValue = this.sbMax;
  98.          }
  99.  
  100.          this.DrawBubble(false);
  101.          this.paintIt(((Component)this).getGraphics());
  102.          e.id = 602;
  103.          ((Component)this).postEvent(e);
  104.       } else if (type == 2) {
  105.          this.sbValue -= this.sbIncrement;
  106.          if (this.sbValue < 0) {
  107.             this.sbValue = 0;
  108.          }
  109.  
  110.          this.DrawBubble(false);
  111.          this.paintIt(((Component)this).getGraphics());
  112.          e.id = 601;
  113.          ((Component)this).postEvent(e);
  114.       } else if (type == 3) {
  115.          this.sbValue -= this.pageIncrement;
  116.          if (this.sbValue < 0) {
  117.             this.sbValue = 0;
  118.          }
  119.  
  120.          this.DrawBubble(false);
  121.          this.paintIt(((Component)this).getGraphics());
  122.          e.id = 603;
  123.          ((Component)this).postEvent(e);
  124.       } else {
  125.          if (type == 4) {
  126.             this.sbValue += this.pageIncrement;
  127.             if (this.sbValue > this.sbMax) {
  128.                this.sbValue = this.sbMax;
  129.             }
  130.  
  131.             this.DrawBubble(false);
  132.             this.paintIt(((Component)this).getGraphics());
  133.             e.id = 604;
  134.             ((Component)this).postEvent(e);
  135.          }
  136.  
  137.       }
  138.    }
  139.  
  140.    public boolean mouseMove(Event event, int cx, int cy) {
  141.       if (!this.m_down && !this.bad_scroll) {
  142.          if (this.cButtons(cy)) {
  143.             return true;
  144.          } else {
  145.             this.undoHButtons();
  146.             return true;
  147.          }
  148.       } else {
  149.          return true;
  150.       }
  151.    }
  152.  
  153.    private void undoHButtons() {
  154.       if (this.on_bottom) {
  155.          this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 2, this.arrow_color);
  156.          this.paintIt(((Component)this).getGraphics());
  157.          this.on_bottom = false;
  158.       }
  159.  
  160.       if (this.on_top) {
  161.          this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 1, this.arrow_color);
  162.          this.paintIt(((Component)this).getGraphics());
  163.          this.on_top = false;
  164.       }
  165.  
  166.    }
  167.  
  168.    private void DrawBubble(boolean absolute) {
  169.       if (!this.bad_scroll) {
  170.          this.g_sboff.setColor(this.bg_color);
  171.          this.g_sboff.fillRect(0, (int)this.bubble_pos, this.sbWidth, this.sbWidth);
  172.          this.drawSlider();
  173.          if (!absolute) {
  174.             this.bubble_pos = (float)this.sbValue * this.bubble_inc + (float)this.sbWidth;
  175.          } else {
  176.             this.bubble_pos = this.hbp;
  177.             float temp = (this.bubble_pos - (float)this.sbWidth) / (float)this.bubble_range;
  178.             this.sbValue = (int)(temp * (float)this.sbMax);
  179.          }
  180.  
  181.          this.drawButton(0, (int)this.bubble_pos, this.sbWidth - 1, this.sbWidth - 1, 0, this.arrow_color);
  182.       }
  183.  
  184.    }
  185.  
  186.    public boolean mouseDown(Event e, int x, int y) {
  187.       this.m_down = true;
  188.       if (this.bad_scroll) {
  189.          return true;
  190.       } else if (this.on_bottom) {
  191.          this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 4, this.harrow_color);
  192.          this.last_button = 1;
  193.          this.auto_type = 1;
  194.          this.checkDbutton(e, this.auto_type);
  195.          this.the_e = e;
  196.          this.start();
  197.          return true;
  198.       } else if (this.on_top) {
  199.          this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 3, this.harrow_color);
  200.          this.last_button = 2;
  201.          this.auto_type = 2;
  202.          this.checkDbutton(e, this.auto_type);
  203.          this.the_e = e;
  204.          this.start();
  205.          return true;
  206.       } else {
  207.          if (x >= 0 && x <= this.sbWidth) {
  208.             if ((float)y >= this.bubble_pos && (float)y < this.bubble_pos + (float)this.sbWidth) {
  209.                this.dragging_bubble = true;
  210.                this.drag_move = y;
  211.                return true;
  212.             }
  213.  
  214.             if ((float)y < this.bubble_pos) {
  215.                this.field_1 = y;
  216.                this.field_0 = x;
  217.                this.auto_type = 3;
  218.                this.checkDbutton(e, this.auto_type);
  219.                this.the_e = e;
  220.                this.start();
  221.             } else {
  222.                this.field_1 = y;
  223.                this.field_0 = x;
  224.                this.auto_type = 4;
  225.                this.checkDbutton(e, this.auto_type);
  226.                this.the_e = e;
  227.                this.start();
  228.             }
  229.          }
  230.  
  231.          return true;
  232.       }
  233.    }
  234.  
  235.    public void setBarStyle(int si, Color bc, Color ac, Color hc, Color bgc, Color sc, Color oc) {
  236.       this.button_color = bc;
  237.       this.arrow_color = ac;
  238.       this.harrow_color = hc;
  239.       this.bg_color = bgc;
  240.       this.slider_color = sc;
  241.       this.outline_color = oc;
  242.       this.slider_inset = si;
  243.    }
  244.  
  245.    private synchronized void paintIt(Graphics g) {
  246.       if (this.paint_called) {
  247.          if (!this.first_run) {
  248.             ((Component)this).setBackground(this.bg_color);
  249.             if (this.sbWidth * this.sbHeight <= 0) {
  250.                return;
  251.             }
  252.  
  253.             this.sboff = ((Component)this).createImage(this.sbWidth, this.sbHeight);
  254.             this.g_sboff = this.sboff.getGraphics();
  255.             this.drawBar(g);
  256.             this.first_run = true;
  257.          } else {
  258.             g.drawImage(this.sboff, 0, 0, this);
  259.          }
  260.  
  261.       }
  262.    }
  263.  
  264.    private void drawBar(Graphics g) {
  265.       this.g_sboff.setColor(this.bg_color);
  266.       this.g_sboff.fillRect(0, 0, this.sbWidth, this.sbHeight);
  267.       this.drawSlider();
  268.       if (!this.bad_scroll) {
  269.          this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 1, this.arrow_color);
  270.          this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 2, this.arrow_color);
  271.          this.DrawBubble(false);
  272.       } else {
  273.          this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 1, Color.gray);
  274.          this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 2, Color.gray);
  275.       }
  276.  
  277.       g.drawImage(this.sboff, 0, 0, this);
  278.    }
  279.  
  280.    public boolean mouseEnter(Event e, int x, int y) {
  281.       this.mouse_in = true;
  282.       return true;
  283.    }
  284.  
  285.    public void resize(Dimension d) {
  286.       if (d.width * d.height > 0) {
  287.          this.sbWidth = d.width;
  288.          this.sbHeight = d.height;
  289.          this.figureBubble(true);
  290.          super.resize(d);
  291.       }
  292.    }
  293.  
  294.    public void resize(int width, int height) {
  295.       if (width * height > 0) {
  296.          this.sbWidth = width;
  297.          this.sbHeight = height;
  298.          this.figureBubble(true);
  299.          super.resize(width, height);
  300.       }
  301.    }
  302.  
  303.    public int getValue() {
  304.       return this.sbValue;
  305.    }
  306.  
  307.    public boolean mouseDrag(Event event, int cx, int cy) {
  308.       this.field_0 = cx;
  309.       this.field_1 = cy;
  310.       if (this.bad_scroll) {
  311.          return true;
  312.       } else {
  313.          if (this.dragging_bubble) {
  314.             if (this.drag_move != cy) {
  315.                this.hbp = this.bubble_pos + (float)(cy - this.drag_move);
  316.                if (this.hbp > (float)(this.bubble_range + this.sbWidth)) {
  317.                   this.hbp = (float)(this.bubble_range + this.sbWidth);
  318.                }
  319.  
  320.                if (this.hbp < (float)this.sbWidth) {
  321.                   this.hbp = (float)this.sbWidth;
  322.                }
  323.  
  324.                this.DrawBubble(true);
  325.                this.paintIt(((Component)this).getGraphics());
  326.                event.id = 605;
  327.                ((Component)this).postEvent(event);
  328.                this.drag_move = cy;
  329.             }
  330.          } else {
  331.             if (this.auto_type > 2) {
  332.                return true;
  333.             }
  334.  
  335.             if (cx > 0 && cx < this.sbWidth && this.cButtons(cy)) {
  336.                this.m_off = false;
  337.                return true;
  338.             }
  339.  
  340.             this.m_off = true;
  341.             this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 2, this.arrow_color);
  342.             this.on_bottom = false;
  343.             this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 1, this.arrow_color);
  344.             this.on_top = false;
  345.             this.stop();
  346.             this.auto_type = 0;
  347.             this.paintIt(((Component)this).getGraphics());
  348.          }
  349.  
  350.          return true;
  351.       }
  352.    }
  353.  
  354.    public Dimension preferredSize() {
  355.       return new Dimension(14, 75);
  356.    }
  357.  
  358.    public boolean mouseUp(Event evt, int x, int y) {
  359.       if (this.bad_scroll) {
  360.          return true;
  361.       } else {
  362.          this.m_down = false;
  363.          this.dragging_bubble = false;
  364.          this.last_button = 0;
  365.          this.stop();
  366.          this.auto_type = 0;
  367.          if (this.m_off) {
  368.             this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 2, this.arrow_color);
  369.             this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 1, this.arrow_color);
  370.             this.paintIt(((Component)this).getGraphics());
  371.             this.on_bottom = false;
  372.             this.on_top = false;
  373.             this.m_off = false;
  374.             return true;
  375.          } else if (this.on_bottom) {
  376.             this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 2, this.harrow_color);
  377.             this.paintIt(((Component)this).getGraphics());
  378.             return true;
  379.          } else if (this.on_top) {
  380.             this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 1, this.harrow_color);
  381.             this.paintIt(((Component)this).getGraphics());
  382.             return true;
  383.          } else {
  384.             return true;
  385.          }
  386.       }
  387.    }
  388.  
  389.    ocsb() {
  390.       this.button_color = Color.lightGray;
  391.       this.arrow_color = Color.black;
  392.       this.harrow_color = Color.yellow;
  393.       this.bg_color = Color.white;
  394.       this.slider_color = Color.black;
  395.       this.outline_color = Color.lightGray;
  396.       this.auto_delay = 5;
  397.       this.auto_rate = 40;
  398.    }
  399.  
  400.    ocsb(int width, int height) {
  401.       this.button_color = Color.lightGray;
  402.       this.arrow_color = Color.black;
  403.       this.harrow_color = Color.yellow;
  404.       this.bg_color = Color.white;
  405.       this.slider_color = Color.black;
  406.       this.outline_color = Color.lightGray;
  407.       this.auto_delay = 5;
  408.       this.auto_rate = 40;
  409.       this.sbWidth = width;
  410.       this.sbHeight = height;
  411.       this.figureBubble(false);
  412.    }
  413.  
  414.    public void run() {
  415.       while(true) {
  416.          if (!this.bypass) {
  417.             try {
  418.                Thread.sleep((long)(this.auto_delay * 100));
  419.             } catch (InterruptedException var4) {
  420.             }
  421.          } else {
  422.             this.bypass = false;
  423.          }
  424.  
  425.          while(this.m_down) {
  426.             if (this.auto_type != 3 && this.auto_type != 4 || this.field_0 > 0 && this.field_0 < this.sbWidth && this.field_1 <= this.sbHeight - this.sbWidth && this.field_1 >= this.sbWidth && (this.auto_type != 3 || !((float)this.field_1 > this.bubble_pos)) && (this.auto_type != 4 || !((float)this.field_1 < this.bubble_pos + (float)this.sbWidth))) {
  427.                this.checkDbutton(this.the_e, this.auto_type);
  428.  
  429.                try {
  430.                   Thread.sleep((long)this.auto_rate);
  431.                } catch (InterruptedException var3) {
  432.                }
  433.             }
  434.          }
  435.       }
  436.    }
  437.  
  438.    private void drawSlider() {
  439.       this.g_sboff.setColor(this.slider_color);
  440.       this.g_sboff.fillRect(this.slider_inset, this.sbWidth, this.sbWidth - (this.slider_inset * 2 + 1), this.sbHeight - this.sbWidth * 2);
  441.       this.g_sboff.setColor(this.outline_color);
  442.       this.g_sboff.drawLine(this.slider_inset, this.sbWidth, this.slider_inset, this.sbHeight - (this.sbWidth + 1));
  443.       this.g_sboff.drawLine(this.sbWidth - (this.slider_inset + 1), this.sbWidth, this.sbWidth - (this.slider_inset + 1), this.sbHeight - (this.sbWidth + 1));
  444.    }
  445.  
  446.    public void setValues(int pageinc, int end) {
  447.       this.sbMax = end;
  448.       this.pageIncrement = pageinc;
  449.       if (this.sbMax < 1) {
  450.          this.bad_scroll = true;
  451.          this.bubble_pos = (float)this.sbWidth;
  452.       } else {
  453.          this.bad_scroll = false;
  454.       }
  455.  
  456.       this.bubble_pos = 0.0F;
  457.       this.sbValue = 0;
  458.       this.figureBubble(true);
  459.    }
  460.  
  461.    private void drawButton(int x, int y, int width, int height, int type, Color ac) {
  462.       this.g_sboff.setColor(this.button_color);
  463.       if (type != 0 && type != 1 && type != 2) {
  464.          this.g_sboff.fillRect(x + 1, y + 1, width - 1, height - 1);
  465.       } else {
  466.          this.g_sboff.fillRect(x + 2, y + 2, width - 2, height - 2);
  467.       }
  468.  
  469.       if (type == 1 || type == 2 || type == 3 || type == 4) {
  470.          int ystart = 0;
  471.          int size = 6;
  472.          int vadd = 2;
  473.          int xstart = width / 2 - 2;
  474.          if (width < 11) {
  475.             size = 4;
  476.             vadd = 1;
  477.             xstart = width / 2 - 2;
  478.          } else {
  479.             xstart = width / 2 - 3;
  480.          }
  481.  
  482.          if (type != 2 && type != 4) {
  483.             ystart = height / 2 + vadd;
  484.          } else {
  485.             ystart = this.sbHeight - height / 2 - (vadd + 2);
  486.          }
  487.  
  488.          this.g_sboff.setColor(ac);
  489.          if (type == 3 || type == 4) {
  490.             ++xstart;
  491.             ++ystart;
  492.          }
  493.  
  494.          for(int i = size; i >= 0; i -= 2) {
  495.             this.g_sboff.drawLine(xstart, ystart, xstart + i, ystart);
  496.             ++xstart;
  497.             if (type != 2 && type != 4) {
  498.                --ystart;
  499.             } else {
  500.                ++ystart;
  501.             }
  502.          }
  503.       }
  504.  
  505.       if (type != 0 && type != 1 && type != 2) {
  506.          this.g_sboff.setColor(Color.gray);
  507.          this.g_sboff.drawRect(x, y, width, height);
  508.       } else {
  509.          this.g_sboff.setColor(Color.lightGray);
  510.          this.g_sboff.drawRect(x + 1, y + 1, width - 1, height - 1);
  511.          this.g_sboff.setColor(Color.gray);
  512.          this.g_sboff.drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
  513.          this.g_sboff.drawLine(x + width - 1, y + 1, x + width - 1, y + height - 1);
  514.          this.g_sboff.setColor(Color.white);
  515.          this.g_sboff.drawRect(x, y, width, height);
  516.          this.g_sboff.setColor(Color.black);
  517.          this.g_sboff.drawLine(x, y + height, x + width, y + height);
  518.          this.g_sboff.drawLine(x + width, y, x + width, y + height);
  519.       }
  520.  
  521.    }
  522.  
  523.    public void figureBubble(boolean redo) {
  524.       this.bubble_range = this.sbHeight - this.sbWidth * 3;
  525.       this.bubble_inc = (float)this.bubble_range / (float)this.sbMax;
  526.       this.bubble_pos = (float)this.sbValue * this.bubble_inc + (float)this.sbWidth;
  527.       if (redo) {
  528.          this.first_run = false;
  529.          this.paintIt(((Component)this).getGraphics());
  530.       }
  531.  
  532.    }
  533.  
  534.    public void paint(Graphics g) {
  535.       this.paint_called = true;
  536.       this.paintIt(((Component)this).getGraphics());
  537.    }
  538.  
  539.    public void setBubblePos(int sbval) {
  540.       if (sbval < 1) {
  541.          this.sbValue = 1;
  542.       }
  543.  
  544.       if (sbval > this.sbMax) {
  545.          this.sbValue = this.sbMax;
  546.       }
  547.  
  548.       this.figureBubble(true);
  549.    }
  550.  
  551.    private boolean cButtons(int cy) {
  552.       if (cy < this.sbWidth && cy >= 0) {
  553.          if (!this.on_top) {
  554.             this.on_top = true;
  555.             if (!this.m_down) {
  556.                this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 1, this.harrow_color);
  557.             } else if (this.last_button != 1) {
  558.                this.drawButton(0, 0, this.sbWidth - 1, this.sbWidth - 1, 3, this.harrow_color);
  559.                this.bypass = true;
  560.                this.auto_type = 2;
  561.                this.start();
  562.             } else {
  563.                this.on_top = false;
  564.             }
  565.  
  566.             this.paintIt(((Component)this).getGraphics());
  567.          }
  568.  
  569.          return true;
  570.       } else if (cy > this.sbHeight - this.sbWidth && cy <= this.sbHeight) {
  571.          if (!this.on_bottom) {
  572.             this.on_bottom = true;
  573.             if (!this.m_down) {
  574.                this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 2, this.harrow_color);
  575.             } else if (this.last_button != 2) {
  576.                this.drawButton(0, this.sbHeight - this.sbWidth, this.sbWidth - 1, this.sbWidth - 1, 4, this.harrow_color);
  577.                this.bypass = true;
  578.                this.auto_type = 1;
  579.                this.start();
  580.             } else {
  581.                this.on_bottom = false;
  582.             }
  583.  
  584.             this.paintIt(((Component)this).getGraphics());
  585.          }
  586.  
  587.          return true;
  588.       } else {
  589.          return false;
  590.       }
  591.    }
  592. }
  593.