home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.7 KB | 105 lines |
- // DualKeypad.java
- // 01.03.96
- //
- // A keypad with two regions of pressable buttons
- // i.e. two buttons can be pressed at the same time, one in each region
-
- package cybcerone.utils;
-
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Rectangle;
-
- public class DualKeypad extends Keypad {
-
- /** this is the second group of buttons */
- protected KeypadButtonGroup moreButtons;
-
- public DualKeypad (String id, String statusText, Appletlike app) {
- super (id, statusText, app);
-
- moreButtons = new KeypadButtonGroup ();
- }
-
- /**
- * Add a logical button to this DualKeypad
- *
- * @param whichGroup all true buttons are in 1 group, false in the other
- **/
- protected void addButton (Object value, int x, int y,
- int width, int height, boolean whichGroup) {
- if (whichGroup) {
- addButton (value, x, y, width, height, buttons);
- } else {
- addButton (value, x, y, width, height, moreButtons);
- }
- }
-
- protected KeypadButton whichButton (int x, int y) {
- KeypadButton theButton = super.whichButton (x, y);
-
- if (theButton == null)
- theButton = moreButtons.whichButton (x, y);
-
- return theButton;
- }
-
- protected KeypadButton whichButton (Object value) {
- KeypadButton theButton = super.whichButton (value);
-
- if (theButton == null)
- theButton = moreButtons.whichButton (value);
-
- return theButton;
- }
-
- /**
- * Paint the active buttons.
- */
- protected void paintActive (Graphics g) {
- paintActive (g, buttons.getHighlighted ());
- paintActive (g, moreButtons.getHighlighted ());
- }
-
- protected void paintActive (Graphics g, KeypadButton activeButton) {
- if (activeBg != null && activeButton != null) {
- Rectangle placement = activeButton.getPlacement ();
- Graphics active = g.create ();
- active.clipRect (placement.x, placement.y,
- placement.width, placement.height);
- active.drawImage (activeBg, 0, 0, this);
- }
- }
-
-
- /**
- * If the user clicked on a button, make it the active button within
- * its group, send its value to the parent, and repaint.
- */
- public boolean mouseDown (Event evt, int x, int y) {
- KeypadButton theButton = whichButton (x, y);
-
- if (theButton != null) {
- if (buttons.contains (theButton)) {
- buttons.setHighlighted (theButton);
- } else {
- moreButtons.setHighlighted (theButton);
- }
- app.update (theButton.getValue ());
- repaint ();
- }
- return true;
- }
-
- public void update (KeypadButton theButton) {
- if (theButton != null) {
- if (buttons.contains (theButton))
- buttons.setHighlighted (theButton);
- else
- moreButtons.setHighlighted (theButton);
- app.update (theButton.getValue ());
- repaint ();
- }
- }
- }
-