home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.2 KB | 130 lines |
- // Keypad.java
- // 28.02.96
- //
- // your basic keypad
-
- package cybcerone.utils;
-
- import java.awt.Graphics;
- import java.awt.Event;
- import java.awt.Rectangle;
- import java.awt.Image;
- import java.awt.image.ImageFilter;
- import java.awt.image.CropImageFilter;
- import java.awt.image.FilteredImageSource;
-
-
- /**
- * A panel that automatically takes the right side of the screen and
- * contains a bunch of buttons that the user can click on.
- */
- public class Keypad extends IdPanel {
- private static final Rectangle placement = new Rectangle (734, 0, 290, 668);
-
- /**
- * The standard background image should be the keypad with the buttons
- * unpressed. When one is pressed, the correct portion of this image
- * will be drawn over top of it. This image should therefore contain
- * all buttons pressed at the same time.
- */
- protected Image activeBg;
-
- /**
- * This is the actual data structure that holds the buttons.
- */
- protected KeypadButtonGroup buttons;
-
- /** Make me. */
- public Keypad (String id, String statusText, Appletlike app) {
- super (id, statusText, app);
- reshape (placement);
-
- buttons = new KeypadButtonGroup ();
- }
-
- /**
- * Set this single image showing all the buttons pushed. Regions of this
- * are clipped to show individual buttons pushed.
- */
- protected void setActiveBackground (Image activeBg) {
- this.activeBg = activeBg;
- }
-
- /**
- * Same as above, but a filename and priority.
- */
- protected void setActiveBackground (String activeBgFile, int priority) {
- this.activeBg = app.getImage (activeBgFile, priority);
- }
-
- /**
- * Add a logical button to this keypad.
- */
- protected void addButton (Object value, int x, int y,
- int width, int height) {
- addButton (value, x, y, width, height, buttons);
- }
-
- protected void addButton (Object value, int x, int y, int width, int height,
- KeypadButtonGroup theButtonGroup) {
- KeypadButton theButton =
- new KeypadButton (value, scale (x), scale (y),
- scale (width), scale (height));
-
- theButtonGroup.add (theButton);
-
- }
-
-
- /**
- * Which button is at (x, y)?
- */
- protected KeypadButton whichButton (int x, int y) {
- return buttons.whichButton (x, y);
- }
-
- /**
- * Which button has this value?
- */
- protected KeypadButton whichButton (Object value) {
- return buttons.whichButton (value);
- }
-
- public void paint (Graphics g) {
- super.paint (g);
- paintActive (g);
- }
-
- /**
- * Paint the active button.
- */
- protected void paintActive (Graphics g) {
- KeypadButton activeButton = buttons.getHighlighted ();
-
- if (activeBg != null && activeButton != null) {
- Rectangle placement = activeButton.getPlacement ();
- g.clipRect (placement.x, placement.y, placement.width, placement.height);
- g.drawImage (activeBg, 0, 0, this);
- }
- }
-
- public void update (KeypadButton theButton) {
- if (theButton != null) {
- buttons.setHighlighted (theButton);
- app.update (theButton.getValue ());
- repaint ();
- }
- }
-
- /**
- * If the user clicked on a button, make it the active, send it's
- * value to the parent, and repaint.
- */
- public boolean mouseDown (Event evt, int x, int y) {
- KeypadButton theButton = whichButton (x, y);
- update (theButton);
- return true;
- }
-
- }
-