home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 5.4 KB | 153 lines |
- package symantec.itools.awt;
-
- import java.awt.Canvas;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
-
- // 01/02/97 RKM Changed paintComponent to not cause recursive drawing on overlap
- // 01/02/97 RKM Changed paintComponent to flush image after it is used
- // 01/16/97 RKM Added override of update to avoid flicker
- // 01/18/07 RKM Added more documentation and checked return from img.getGraphics
- // 01/29/97 TWB Integrated changes from Windows and RKM's changes
- // 01/29/97 TWB Integrated changes from Macintosh
- // 02/01/97 RKM Extracted transparency drawing trick into TransparencyTrickUtils
-
- /**
- * Use this component to create an invisible area, usually within an image,
- * that initiates an action when clicked. Specifically, use InvisibleButton to
- * <UL>
- * <DT>╖ create a "hot spot" on an image or on a component</DT>
- * <DT>╖ accept or yield focus</DT>
- * <DT>╖ respond to a user event</DT>
- * <DT>╖ send an action event to another component</DT>
- * </UL>
- * Button tips:
- * <UL>
- * <DT>╖ Buttons accept and yield focus automatically by default.</DT>
- * <DT>╖ Buttons accept clicked events automatically by default.</DT>
- * <DT>╖ To send an action event to another component, use the Interaction
- * Wizard. Optionally, you can override the InvisibleButtonÆs click event in
- * project source code.</DT>
- * <DT>╖ Overlapping components - browsers handle components layered on each
- * other differently. Some browsers display/layer the InvisibleButtons on top
- * of a particular component, while others display them underneath. Therefore,
- * it often requires two sets of InvisibleButtons to ensure that one is "on top",
- * one on top of the particular component and the other underneath.
- * </UL>
- * Implements the Runnable interface to support threads.
- * <p>
- *
- */
- public class InvisibleButton
- extends Canvas
- implements TransparencyTrick
- {
- /**
- * True if the button is currently pressed.
- */
- protected boolean pressed;
-
- /**
- * Constructs an InvisibleButton.
- */
- public InvisibleButton() {
- pressed = false;
- }
-
- /**
- * Handles redrawing of this component on the screen.
- * This is a standard Java AWT method which gets called by the Java
- * AWT (repaint()) to handle repainting this component on the screen.
- * The graphics context clipping region is set to the bounding rectangle
- * of this component and its <0,0> coordinate is this component's
- * top-left corner.
- * Typically this method paints the background color to clear the
- * component's drawing space, sets graphics context to be the foreground
- * color, and then calls paint() to draw the component.
- *
- * It is overridden here to prevent the flicker associated with the standard
- * update() method's repainting of the background before painting the component
- * itself.
- *
- * @param g the graphics context
- * @see java.awt.Component#repaint
- * @see #paint
- */
- public void update(Graphics g)
- {
- paint(g);
- }
-
- /**
- * Paints this component using the given graphics context.
- * This is a standard Java AWT method which typically gets called
- * by the AWT to handle painting this component. It paints this component
- * using the given graphics context. The graphics context clipping region
- * is set to the bounding rectangle of this component and its <0,0>
- * coordinate is this component's top-left corner.
- * It paints what is under the button, so as to appear invisible.
- * @param g the graphics context used for painting
- * @see java.awt.Component#repaint
- * @see #update
- */
- public void paint(Graphics g) {
- TransparencyTrickUtils.paintComponentsBehind(this, g);
- }
-
- /**
- * Processes MOUSE_DOWN events.
- * This is a standard Java AWT method which gets called by the AWT
- * method handleEvent() in response to receiving a MOUSE_DOWN
- * event. These events occur when the mouse button is pressed while
- * inside this component.
- *
- * @param e the event
- * @param x the component-relative horizontal coordinate of the mouse
- * @param y the component-relative vertical coordinate of the mouse
- *
- * @return always true since the event was handled
- *
- * @see #mouseUp
- * @see java.awt.Component#handleEvent
- */
- public boolean mouseDown(Event e, int x, int y)
- {
- pressed = true;
-
- return true;
- }
-
- /**
- * Processes MOUSE_UP events.
- * This is a standard Java AWT method which gets called by the AWT
- * method handleEvent() in response to receiving a MOUSE_UP
- * event. These events occur when the mouse button is released while
- * inside this component.
- * If the mouse was pressed inside the button then an event is posted.
- *
- * @param e the event
- * @param x the component-relative horizontal coordinate of the mouse
- * @param y the component-relative vertical coordinate of the mouse
- *
- * @return always true since the event was handled
- *
- * @see #mouseDown
- * @see java.awt.Component#handleEvent
- */
- public boolean mouseUp(Event e, int x, int y)
- {
- if (pressed)
- {
- pressed = false;
- postEvent(new Event(this, Event.ACTION_EVENT, null));
- }
-
- return true;
- }
- }
-
-