buoy.widget

Class Widget

Known Direct Subclasses:
AWTWidget, BButton, BCheckBox, BColorChooser, BComboBox, BDocumentViewer, BFileChooser, BLabel, BList, BMenuItem, BProgressBar, BRadioButton, BScrollBar, BSeparator, BSlider, BSpinner, BTable, BTable.BTableHeader, BToolTip, BTree, CustomWidget, TextWidget, WidgetContainer

public abstract class Widget
extends EventSource

A Widget is a graphical object. It occupies a fixed region of the screen, and can respond to user actions. This is an abstract class. There are subclasses corresponding to particular kinds of Widgets.

Every Widget is mapped to a specific AWT/Swing Component. This class can therefore be thought of as a wrapper around the Component class.

All Widgets generate the following types of events:

Author:
Peter Eastman

Method Summary

void
addEventLink(Class eventType, Object target, Method method)
Create an event link from this object.
void
dispatchEvent(Object event)
Send out an object representing an event to every appropriate event link that has been added to this object.
Color
getBackground()
Get the background color of this Widget.
Rectangle
getBounds()
Get the current location and size of this Widget.
Component
getComponent()
Get the java.awt.Component corresponding to this Widget.
Cursor
getCursor()
Get the Cursor to display when the mouse is over this Widget.
Font
getFont()
Get the font used to draw text in this Widget.
Dimension
getMaximumSize()
Get the largest size at which this Widget can reasonably be drawn.
Dimension
getMinimumSize()
Get the smallest size at which this Widget can reasonably be drawn.
String
getName()
Get the name of this Widget.
WidgetContainer
getParent()
Get this Widget's parent in the layout hierarchy (may be null).
Dimension
getPreferredSize()
Get the preferred size at which this Widget will look best.
boolean
hasFocus()
Determine whether this Widget currently has keyboard focus, so that WidgetKeyEvents will be sent to it.
boolean
isEnabled()
Determine whether this Widget is currently enabled.
boolean
isFocusable()
Determine whether this Widget can receive keyboard focus through the user pressing Tab or Shift-Tab to cycle between Widgets.
boolean
isVisible()
Determine whether this Widget is currently visible.
void
repaint()
Request that this Widget be repainted.
void
requestFocus()
Request that keyboard focus be transferred to this Widget, so that WidgetKeyEvents will be sent to it.
void
setBackground(Color background)
Set the background color of this Widget.
void
setCursor(Cursor cursor)
Set the Cursor to display when the mouse is over this Widget.
void
setEnabled(boolean enabled)
Set whether this Widget should be enabled.
void
setFocusable(boolean focusable)
Set whether this Widget can receive keyboard focus through the user pressing Tab or Shift-Tab to cycle between Widgets.
void
setFont(Font font)
Set the font used to draw text in this Widget.
void
setName(String name)
Set the name of this Widget.
void
setVisible(boolean visible)
Set whether this Widget should be visible.

Methods inherited from class buoy.event.EventSource

addEventLink, addEventLink, addEventLink, dispatchEvent, removeEventLink

Method Details

addEventLink

public void addEventLink(Class eventType,
                         Object target,
                         Method method)
Create an event link from this object. When events of the desired class (or any of its subclasses) are generated by this object, the specified method will be called on the target object.
Overrides:
addEventLink in interface EventSource
Parameters:
eventType - the event class or interface which the target method wants to receive
target - the object to send the events to
method - the method to invoke on the target object. The method must either take no arguments, or take an object of class eventType (or any of its superclasses or interfaces) as its only argument.

dispatchEvent

public void dispatchEvent(Object event)
Send out an object representing an event to every appropriate event link that has been added to this object.
Overrides:
dispatchEvent in interface EventSource

getBackground

public Color getBackground()
Get the background color of this Widget. If that is null and this Widget has been added to a WidgetContainer, this returns the background color of the parent container.

getBounds

public Rectangle getBounds()
Get the current location and size of this Widget.

getComponent

public Component getComponent()
Get the java.awt.Component corresponding to this Widget.

getCursor

public Cursor getCursor()
Get the Cursor to display when the mouse is over this Widget.

getFont

public Font getFont()
Get the font used to draw text in this Widget.

getMaximumSize

public Dimension getMaximumSize()
Get the largest size at which this Widget can reasonably be drawn. When a WidgetContainer lays out its contents, it will attempt never to make this Widget larger than its maximum size.

getMinimumSize

public Dimension getMinimumSize()
Get the smallest size at which this Widget can reasonably be drawn. When a WidgetContainer lays out its contents, it will attempt never to make this Widget smaller than its minimum size.

getName

public String getName()
Get the name of this Widget. This is used primarily to identify Widgets when they are serialized to XML files.

getParent

public WidgetContainer getParent()
Get this Widget's parent in the layout hierarchy (may be null).

getPreferredSize

public Dimension getPreferredSize()
Get the preferred size at which this Widget will look best. When a WidgetContainer lays out its contents, it will attempt to make this Widget as close as possible to its preferred size.

hasFocus

public boolean hasFocus()
Determine whether this Widget currently has keyboard focus, so that WidgetKeyEvents will be sent to it.

isEnabled

public boolean isEnabled()
Determine whether this Widget is currently enabled.

isFocusable

public boolean isFocusable()
Determine whether this Widget can receive keyboard focus through the user pressing Tab or Shift-Tab to cycle between Widgets.

isVisible

public boolean isVisible()
Determine whether this Widget is currently visible.

repaint

public void repaint()
Request that this Widget be repainted. This method does not actually paint the Widget immediately. Instead, it causes a repaint request to be placed onto the global event queue. As a result, this method can be safely called from any thread.

requestFocus

public void requestFocus()
Request that keyboard focus be transferred to this Widget, so that WidgetKeyEvents will be sent to it.

setBackground

public void setBackground(Color background)
Set the background color of this Widget. If this is set to null, the Widget will use the background color of its parent WidgetContainer.

setCursor

public void setCursor(Cursor cursor)
Set the Cursor to display when the mouse is over this Widget.

setEnabled

public void setEnabled(boolean enabled)
Set whether this Widget should be enabled.

setFocusable

public void setFocusable(boolean focusable)
Set whether this Widget can receive keyboard focus through the user pressing Tab or Shift-Tab to cycle between Widgets.

setFont

public void setFont(Font font)
Set the font used to draw text in this Widget. If this is set to null, the Widget will use the Font of its parent WidgetContainer.

setName

public void setName(String name)
Set the name of this Widget. This is used primarily to identify Widgets when they are serialized to XML files.

setVisible

public void setVisible(boolean visible)
Set whether this Widget should be visible.

Written by Peter Eastman.