/* * Button3D.java */ import java.awt.*; /* 3D Button Object */ public class Button3D extends Label3D { final static int NORMAL = 0; /* Normal Button */ final static int LEFT = 1; /* Left Triangle Button */ final static int RIGHT = 2; /* Right Triangle Button */ final static int UP = 3; /* Up Triangle Button */ final static int DOWN = 4; /* Down Triangle Button */ final static int S_LEFT = 5; /* Small Left Triangle Button */ final static int S_RIGHT = 6; /* Small Right Triangle Button */ final static int S_UP = 7; /* Small Up Triangle Button */ final static int S_DOWN = 8; /* Small Down Triangle Button */ final static int CHECKBTN = 9; /* Check Button */ int type = NORMAL; /* Button's Type Number */ boolean autoRepeat = true; /* Auto Repeat */ boolean postAction = true; /* Notify Parent when release */ boolean pressed = false; /* If Button Pressed */ boolean mousePressed = false; /* If Mouse Pressed */ /** Normal Button with Text */ public Button3D(String _text) { super(_text); raise = true; mode = 1; } /** Normal Button with Active Setting */ public Button3D(String _text, boolean _active) { this(_text); setActive(_active); } /** Special Button */ public Button3D(int _type) { super(""); raise = true; mode = 1; type = _type; postAction = (_type == NORMAL) || (type == CHECKBTN); } /** Special Button with Text */ public Button3D(int _type, String _text) { this(_text); type = _type; } /** Special Button with Text and active setting */ public Button3D(int _type, String _text, boolean _active) { this(_text); type = _type; setActive(_active); } /** Overwrite the Preferred Size Setting */ public Dimension preferredSize() { switch ( type ) { case LEFT : case RIGHT : case UP : case DOWN : return new Dimension(base, base); case S_LEFT : case S_RIGHT : return new Dimension(base/2, base); case S_UP : case S_DOWN : return new Dimension(base, base/2); default : return new Dimension(base*ratio, base); } } /** Change Button Type */ public boolean setType(int _type) { if ( type == _type ) return false; type = _type; repaint(); return true; } /** Change Button Concave/Convex Mode */ public boolean setMode(int _mode) { if ( mode == _mode ) return false; mode = _mode; repaint(); return true; } /** Change Button State */ public boolean setState(boolean _pressed) { if ( pressed == _pressed ) return false; pressed = _pressed; setMode(pressed ? -1 : 1); return true; } /** Drawing Action Here */ public void update(Graphics g) { Color LT, RB; int i, w, h, wm, hm; if ( g == null ) return; w = size().width-1; h = size().height-1; wm = w/2; hm = h/2; if ( !pressed ) { LT = ltGray; RB = dkGray; } else { LT = dkGray; RB = ltGray; } switch ( type ) { case LEFT : case S_LEFT : { /* Left Button */ g.setColor(getBackground()); g.fillRect(0, 0, size().width, size().height); for (i=0; i