/* * Scroller.java */ import java.awt.*; /* Scroller Object */ public class Scroller extends Panel3D { int ratio, base; Thumb thumb; Button3D up, down; /* Line Up/Down Button */ /** Scroller Constructor */ public Scroller(int _type) { this(_type, 10);} /** Scroller Constructor with Ratio Setting */ public Scroller(int _type, int _ratio) { int tofs; ratio = _ratio; setLayout(new BorderLayout()); add("Center", thumb = new Thumb(_type)); if ( thumb.type == Scrollbar.HORIZONTAL ) { add("West", up = new Button3D(Button3D.LEFT)); add("East", down = new Button3D(Button3D.RIGHT)); } else { add("North", up = new Button3D(Button3D.UP)); add("South", down = new Button3D(Button3D.DOWN)); } setBase(18); thumb.setValue(0, 1, 0, 1, false); } /** Set Scale Base */ public void setBase(int _base) { base = _base; up.setBase(base); down.setBase(base); } /** Overwrite Preferred Size */ public Dimension preferredSize() { if ( thumb.type == Scrollbar.HORIZONTAL ) return new Dimension(base*ratio, base); else return new Dimension(base, base*ratio); } /** Set Current Value */ public synchronized boolean setValue(int _value, int _visible, int _minimum, int _maximum, boolean frepaint) { thumb.setValue(_value, _visible, _minimum, _maximum, frepaint); boolean _active = (thumb.range > thumb.visible); up.setActive(_active); down.setActive(_active); return true; } /** Set Current Value */ public synchronized boolean setValue(int _value, boolean frepaint) { return thumb.setValue(_value, frepaint);} /* Get Scroller Paramters */ public int getValue() { return thumb.value;} /** Component Action Event */ public boolean action(Event ev, Object arg) { if (arg == up) { if ( ev.id != Event.MOUSE_UP ) thumb.moveThumb(-1); return true; } else if (arg == down) { if ( ev.id != Event.MOUSE_UP ) thumb.moveThumb(1); return true; } else if (arg == thumb) { Notify(ev, this); return true; } return false; } }