home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.5 KB | 130 lines |
- // ControlButton.java
- // 19.03.96
- //
- // a button on the control panel
-
- package cybcerone.control;
-
- import java.awt.Image;
- import java.awt.Graphics;
- import java.awt.Event;
-
- import cybcerone.utils.Appletlike;
- import cybcerone.utils.IdPanel;
-
- /**
- * The common ancestor of all of the buttons on the control bar.
- */
- class ControlButton extends IdPanel {
- protected static final String imagePath = ControlPanel.imagePath;
-
- private Image pressedBg;
- private Image disabledBg;
- protected boolean pressed;
- protected boolean disabled;
-
- ControlButton (String id, String statusText, Appletlike app) {
- super (id, statusText, app);
- pressed = false;
- disabled = true;
- }
-
- /**
- * Assign the pressed image.
- */
- protected void setPressedBg (String PressedBgFile, int priority) {
- this.pressedBg = app.getImage (PressedBgFile, priority);
- }
-
- /**
- * Assign the diabled image.
- */
- protected void setDisabledBg (String DisabledBgFile, int priority) {
- this.disabledBg = app.getImage (DisabledBgFile, priority);
- }
-
- /**
- * Press the button.
- */
- public boolean mouseDown (Event evt, int x, int y) {
- if (!disabled) {
- pressed = true;
- repaint ();
- }
- return true;
- }
-
- /**
- * Unpress the button.
- */
- public boolean mouseUp (Event evt, int x, int y) {
- if (!disabled) {
- if (pressed)
- doAction ();
- pressed = false;
- repaint ();
- }
- return true;
- }
-
- /**
- * Unpress the button.
- */
- public boolean mouseExit (Event evt, int x, int y) {
- if (!disabled) {
- pressed = false;
- repaint ();
- }
- return true;
- }
-
- /**
- * Draw the image for this button's current state.
- */
- public void paint (Graphics g) {
- if (disabled) {
- if (disabledBg != null)
- g.drawImage (disabledBg, 0, 0, this);
- else
- hide ();
- } else if (pressed) {
- if (pressedBg != null) g.drawImage (pressedBg, 0, 0, this);
- } else {
- super.paint (g);
- }
- }
-
- /**
- * Disable this button.
- */
- public void disable () {
- disabled = true;
- repaint ();
- }
-
- /**
- * Enable this button.
- */
- public void enable () {
- disabled = false;
- show ();
- repaint ();
- }
-
- /**
- * When the button is pushed, this is the screen it leads to.
- */
- public void setNext (String next) {
- super.setNext (next);
- }
-
- /**
- * The time has come to take action. Override this to take a
- * specific action.
- */
- protected void doAction () {
- if (next != null)
- app.update (next);
- }
- }
-