Class Button
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Button

public class netscape.application.Button
    extends netscape.application.View
    implements netscape.application.Target,
               netscape.application.DrawingSequenceOwner,
{
    /* Fields
     */
    public final static java.lang.String CLICK;
    public final static int CONTINUOUS_TYPE;
    public final static int IMAGE_ABOVE;
    public final static int IMAGE_BELOW;
    public final static int IMAGE_BENEATH;
    public final static int IMAGE_ON_LEFT;
    public final static int IMAGE_ON_RIGHT;
    public final static int PUSH_TYPE;
    public final static int RADIO_TYPE;
    public final static java.lang.String SEND_COMMAND;
    public final static int TOGGLE_TYPE;

    /* Constructors
     */
    public Button();
    public Button(Rect);
    public Button(int, int, int, int);

    /* Methods
     */
    public static Button createCheckButton(int, int, int, int);
    public static Button createPushButton(int, int, int, int);
    public static Button createRadioButton(int, int, int, int);

    public Image altImage();
    public String altTitle();
    protected void ancestorWasAddedToViewHierarchy(View);
    public void click();
    public int clickCount();
    public String command();
    public void decode(Decoder);
    public void describeClassInfo(ClassInfo);
    public Color disabledTitleColor();
    public void drawView(Graphics);
    public void drawViewBackground(Graphics, Rect, boolean);
    public void drawViewInterior(Graphics, String, Image, Rect);
    public void drawViewTitleInRect(Graphics, String, Font, Rect, int);
    public void drawingSequenceCompleted(DrawingSequence);
    public void drawingSequenceFrameChanged(DrawingSequence);
    public void encode(Encoder);
    public Font font();
    public Image image();
    public Size imageAreaSize();
    public int imagePosition();
    public boolean isBordered();
    public boolean isEnabled();
    public boolean isTransparent();
    public Border loweredBorder();
    public Color loweredColor();
    public Size minSize();
    public boolean mouseDown(MouseEvent);
    public Sound mouseDownSound();
    public void mouseDragged(MouseEvent);
    public void mouseUp(MouseEvent);
    public Sound mouseUpSound();
    public void performCommand(String, Object);
    public Border raisedBorder();
    public Color raisedColor();
    public int repeatDelay();
    public void sendCommand();
    public void setAltImage(Image);
    public void setAltTitle(String);
    public void setBordered(boolean);
    public void setCommand(String);
    public void setDisabledTitleColor(Color);
    public void setEnabled(boolean);
    public void setFont(Font);
    public void setImage(Image);
    public void setImagePosition(int);
    public void setLoweredBorder(Border);
    public void setLoweredColor(Color);
    public void setMouseDownSound(Sound);
    public void setMouseUpSound(Sound);
    public void setRaisedBorder(Border);
    public void setRaisedColor(Color);
    public void setRepeatDelay(int);
    public void setState(boolean);
    public void setTarget(Target);
    public void setTitle(String);
    public void setTitleColor(Color);
    public void setTransparent(boolean);
    public void setType(int);
    public boolean state();
    public Target target();
    public String title();
    public Color titleColor();
    public int type();
}
View subclass that implementing a "button" control, an object with two states: "on" and "off." The user changes a Button's state by clicking it, which may also cause the Button to draw itself differently. For example, when clicked most Buttons draw themselves to appear "pressed" in. The Button class supports several types of Button, from PUSH_TYPE to TOGGLE_TYPE to RADIO_TYPE to CONTINUOUS_TYPE. See the setType() method documentation for more information.
See Also:
setType

Fields

PUSH_TYPE

  public final static int PUSH_TYPE
Push button type.

TOGGLE_TYPE

  public final static int TOGGLE_TYPE
Toggle button type.

RADIO_TYPE

  public final static int RADIO_TYPE
Radio button type.

CONTINUOUS_TYPE

  public final static int CONTINUOUS_TYPE
Continuous button type.

IMAGE_ON_LEFT

  public final static int IMAGE_ON_LEFT
Position Image to the title's left.

IMAGE_ON_RIGHT

  public final static int IMAGE_ON_RIGHT
Position Image to the title's right.

IMAGE_ABOVE

  public final static int IMAGE_ABOVE
Position Image above the title.

IMAGE_BELOW

  public final static int IMAGE_BELOW
Position Image below the title.

IMAGE_BENEATH

  public final static int IMAGE_BENEATH
Draw title on top of Image.

SEND_COMMAND

  public final static String SEND_COMMAND
Command causing the Button to send its command to its Target.

CLICK

  public final static String CLICK
Command causing the Button to visually "click," as if pressed, as well as send its command to its Target.

Constructors

Button

  public Button()
Constructs a Button with origin (0, 0) and zero width and height.

Button

  public Button(Rect rect)
Constructs a Button with bounds rect.

Button

  public Button(int x,
                int y,
                int width,
                int height)
Constructs a Button with bounds (x, y, width, height).

Methods

createPushButton

  public static Button createPushButton(int x,
                                        int y,
                                        int width,
                                        int height)
Returns a new Button instance configured to look and behave like a "push" button, a Button of type PUSH_TYPE.

createCheckButton

  public static Button createCheckButton(int x,
                                         int y,
                                         int width,
                                         int height)
Returns a new Button instance configured to look and behave like a "check" button, a Button of type TOGGLE_TYPE that displays a check mark when on.

createRadioButton

  public static Button createRadioButton(int x,
                                         int y,
                                         int width,
                                         int height)
Returns a new Button instance configured to look and behave like a "radio" button, a Button of type RADIO_TYPE that can only be on if the others in its group are off.

setTitle

  public void setTitle(String aString)
Sets the Button's title and then calls the Button's draw() method to redraw it. If aString contains newlines, the title will break and wrap to the next line at those points. If you don't want to immediately redraw the Button, you should first call its disableDrawing() method.
See Also:
disableDrawing

title

  public String title()
Returns the Button's title.
See Also:
setTitle

setAltTitle

  public void setAltTitle(String aString)
Sets the Button's alternate title, the title the Button displays when it's in its alternate state, and then calls the Button's draw() method to redraw it. If aString contains newlines, the title will break and wrap to the next line at those points. If you don't want to immediately redraw the Button, you should first call its disableDrawing() method.
See Also:
setTitle, disableDrawing

altTitle

  public String altTitle()
Returns the Button's alternate title.
See Also:
setAltTitle

setEnabled

  public void setEnabled(boolean enabled)
Sets the Button's "enabled" state and then calls the Button's draw() method to redraw it. A disabled Button does not react to mouse clicks. If you do not want to immediately redraw the Button, you should first call its disableDrawing() method.
See Also:
disableDrawing

isEnabled

  public boolean isEnabled()
Returns true if the Button is enabled.
See Also:
setEnabled

setState

  public void setState(boolean newState)
Sets the Button's state (a boolean value where false is the normal, "up" state and true is the down or "pressed" state) and then calls the Button's draw() method to redraw it. If you do not want to immediately redraw the Button, you should first call its disableDrawing() method.
See Also:
disableDrawing

state

  public boolean state()
Returns the Button's state.
See Also:
setState

setTarget

  public void setTarget(Target aTarget)
Sets the Button's Target, the object that will receive the a performCommand() message when the user clicks the Button.

target

  public Target target()
Returns the Button's Target.
See Also:
setTarget

setCommand

  public void setCommand(String command)
Sets the Button's command.
See Also:
setTarget

command

  public String command()
Returns the Button's command.
See Also:
setCommand

imageAreaSize

  public Size imageAreaSize()
Returns the Size required to display the Button's Images.
See Also:
setImage

minSize

  public Size minSize()
Returns the minimum Size required to fully display the Button's Border, title, and Images.
Overrides:
minSize in class View

setFont

  public void setFont(Font aFont)
Sets the Font used to display the Button's title.
See Also:
setTitle

font

  public Font font()
Returns the Font used to display the Button's title.
See Also:
setFont

setTitleColor

  public void setTitleColor(Color aColor)
Sets the Color used to draw the Button's title.
See Also:
setTitle

titleColor

  public Color titleColor()
Returns the Color used to draw the Button's title.
See Also:
setTitleColor

setDisabledTitleColor

  public void setDisabledTitleColor(Color aColor)
Sets the Color used to draw the Button's title when disabled.
See Also:
setTitle

disabledTitleColor

  public Color disabledTitleColor()
Returns the Color used to draw the Button's title when disabled.
See Also:
setDisabledTitleColor

setRaisedColor

  public void setRaisedColor(Color aColor)
Sets the background Color used to draw the Button in its raised state.

raisedColor

  public Color raisedColor()
Returns the background Color used to draw the Button in its raised state.
See Also:
setRaisedColor

setLoweredColor

  public void setLoweredColor(Color aColor)
Sets the background Color used to draw the Button in its lowered state.

loweredColor

  public Color loweredColor()
Returns the background Color used to draw the Button in its lowered state.
See Also:
setLoweredColor

setImage

  public void setImage(Image anImage)
Sets the Image displayed by the Button. If anImage is a DrawingSequence, sets the Button to be the DrawingSequence's owner and starts the sequence when the user releases the Button (after a press).
See Also:
DrawingSequence, setAltImage

image

  public Image image()
Returns the Image displayed by the Button.
See Also:
setImage

setAltImage

  public void setAltImage(Image anImage)
Sets the Image the button displays when pressed. If anImage is a DrawingSequence, sets the Button to be the DrawingSequence's owner and starts the sequence when the user presses the Button.
See Also:
DrawingSequence

altImage

  public Image altImage()
Returns the Image the Button displays when pressed.
See Also:
setAltImage

setRaisedBorder

  public void setRaisedBorder(Border border)
Sets the raised Border, the Border the Button draws around its perimeter when in the "up" state.

raisedBorder

  public Border raisedBorder()
Returns the Button's raised Border.
See Also:
setRaisedBorder

setLoweredBorder

  public void setLoweredBorder(Border border)
Sets the lowered Border, the Border the Button draws around its perimeter when in the "down" state.

loweredBorder

  public Border loweredBorder()
Returns the Button's lowered Border.
See Also:
setLoweredBorder

setMouseDownSound

  public void setMouseDownSound(Sound aSound)
Sets the Sound the Button plays when pressed.

mouseDownSound

  public Sound mouseDownSound()
Returns the Sound the Button plays when pressed.
See Also:
setMouseDownSound

setMouseUpSound

  public void setMouseUpSound(Sound aSound)
Sets the Sound the Button plays when released, after being pressed.

mouseUpSound

  public Sound mouseUpSound()
Returns the Sound the Button plays when released.
See Also:
setMouseUpSound

setBordered

  public void setBordered(boolean flag)
Sets whether the Button draws its Border.

isBordered

  public boolean isBordered()
Returns true if the Button draws its Border.
See Also:
setBordered

setType

  public void setType(int buttonType)
Sets the Button's type, which can be one of the following:
  1. A PUSH_TYPE Button appears to press in when clicked and sends its command to its Target when released, returning to its original "up" state.
  2. A TOGGLE_TYPE Button changes its state between off and on and sends its command to its Target on each click.
  3. A RADIO_TYPE button behaves like a TOGGLE_TYPE button, except when clicked it turns off any other RADIO_TYPE buttons with the same superview.
  4. A CONTINUOUS_TYPE Button behaves like a PUSH_TYPE Button, except that it sends its command to its Target while pressed, every repeatDelay() milliseconds.
See Also:
setRepeatDelay

type

  public int type()
Returns the Button's type.
See Also:
setType

setRepeatDelay

  public void setRepeatDelay(int milliseconds)
Sets the Button's repeat delay, the time delay a CONTINUOUS_TYPE Button uses when sending its command to its Target while being pressed.
See Also:
setType

repeatDelay

  public int repeatDelay()
Returns the Button's repeat delay.
See Also:
setRepeatDelay

setImagePosition

  public void setImagePosition(int aPosition)
Sets the relationship between the Button's Images and its title. Options are IMAGE_ON_LEFT, IMAGE_ON_RIGHT, IMAGE_ABOVE, IMAGE_BELOW, and IMAGE_BENEATH.
See Also:
setImage, setTitle

imagePosition

  public int imagePosition()
Returns the integer describing the relationship between the Button's Images and title.
See Also:
setImagePosition

setTransparent

  public void setTransparent(boolean flag)
Overridden to configure the Button not to draw its Border, if configured to be transparent. A transparent Button does not display a Border (unless subsequently configured to do so) or a background color, only its title and Images, if any.

isTransparent

  public boolean isTransparent()
Overridden to return true if the Button is transparent.
Overrides:
isTransparent in class View
See Also:
setTransparent

ancestorWasAddedToViewHierarchy

  protected void ancestorWasAddedToViewHierarchy(View aView)
Overridden to support RADIO_TYPE buttons.
Overrides:
ancestorWasAddedToViewHierarchy in class View

drawViewTitleInRect

  public void drawViewTitleInRect(Graphics g,
                                  String title,
                                  Font titleFont,
                                  Rect textBounds,
                                  int justification)
Sets the appropriate Color (according to whether or not the Button's enabled) and calls Graphics' drawStringInRect() to draw the Button's title within textBounds using the justification justification. You never call this method directly, but should override to produce any custom title drawing.

drawViewInterior

  public void drawViewInterior(Graphics g,
                               String title,
                               Image image,
                               Rect interiorRect)
Draws the Button's interior. title is the appropriate String and image is the appropriate Image to be drawn in the Button's current state. interiorRect is the Rect defining the Button's interior (the entire Button without its border). Calls drawViewTitleInRect() to draw the Button's title. You never call this method directly, but should override to implement any custom drawing.

drawViewBackground

  public void drawViewBackground(Graphics g,
                                 Rect interiorRect,
                                 boolean drawDownState)
Draws the Button's background (a Border, or solid rectangle if no Border and opaque). You never call this method directly, but should override to perform any custom background drawing. You must modify interiorRect to define the area available to draw the Button's title and/or Image.

drawView

  public void drawView(Graphics g)
Draws the Button. Calls drawViewBackground() and drawViewInterior(). You never call this method directly, but may override to implement custom Button drawing. Use the draw() method to draw the Button.
Overrides:
drawView in class View
See Also:
draw

mouseDown

  public boolean mouseDown(MouseEvent event)
Overridden to interpret Button clicks. For CONTINUOUS_TYPE Buttons, starts a Timer that sends the Button's command to its Target every repeatDelay() milliseconds.
Overrides:
mouseDown in class View
See Also:
setRepeatDelay

mouseDragged

  public void mouseDragged(MouseEvent event)
Overridden to support Button clicks.
Overrides:
mouseDragged in class View

mouseUp

  public void mouseUp(MouseEvent event)
Overridden to support Button clicks.
Overrides:
mouseUp in class View

clickCount

  public int clickCount()
If the Button is currently pressed, returns the current mouse click count (single-click, double-click, and so on).

click

  public void click()
Presses the Button, as if the user clicked it with the mouse.

performCommand

  public void performCommand(String command,
                             Object data)
Implements the Button's commands:

drawingSequenceFrameChanged

  public void drawingSequenceFrameChanged(DrawingSequence aSequence)
DrawingSequenceOwner method implemented to handle DrawingSequences assigned to the Button as Images.
See Also:
drawingSequenceFrameChanged

drawingSequenceCompleted

  public void drawingSequenceCompleted(DrawingSequence aSequence)
DrawingSequenceOwner method implemented to handle DrawingSequences assigned to the Button as Images.
See Also:
drawingSequenceCompleted

sendCommand

  public void sendCommand()
Called by the Button to send its command to its Target.
See Also:
setTarget

describeClassInfo

  public void describeClassInfo(ClassInfo info)
Describes the Button class' information.
Overrides:
describeClassInfo in class View
See Also:
describeClassInfo

encode

  public void encode(Encoder encoder) throws CodingException
Encodes the Button instance.
Overrides:
encode in class View
See Also:
encode

decode

  public void decode(Decoder decoder) throws CodingException
Decodes the Button instance.
Overrides:
decode in class View
See Also:
encode

All Packages  Class Hierarchy  This Package  Previous  Next  Index