buoy.widget
Class Widget

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
Direct Known 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(java.lang.Class eventType, java.lang.Object target, java.lang.reflect.Method method)
          Create an event link from this object.
 void dispatchEvent(java.lang.Object event)
          Send out an object representing an event to every appropriate event link that has been added to this object.
 java.awt.Color getBackground()
          Get the background color of this Widget.
 java.awt.Rectangle getBounds()
          Get the current location and size of this Widget.
 java.awt.Component getComponent()
          Get the java.awt.Component corresponding to this Widget.
 java.awt.Cursor getCursor()
          Get the Cursor to display when the mouse is over this Widget.
 java.awt.Font getFont()
          Get the font used to draw text in this Widget.
 java.awt.Dimension getMaximumSize()
          Get the largest size at which this Widget can reasonably be drawn.
 java.awt.Dimension getMinimumSize()
          Get the smallest size at which this Widget can reasonably be drawn.
 java.lang.String getName()
          Get the name of this Widget.
 WidgetContainer getParent()
          Get this Widget's parent in the layout hierarchy (may be null).
 java.awt.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(java.awt.Color background)
          Set the background color of this Widget.
 void setCursor(java.awt.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(java.awt.Font font)
          Set the font used to draw text in this Widget.
 void setName(java.lang.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, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getComponent

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


getParent

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


getMinimumSize

public java.awt.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.


getMaximumSize

public java.awt.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.


getPreferredSize

public java.awt.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.


getBounds

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


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.


isVisible

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


setVisible

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


isEnabled

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


setEnabled

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


getCursor

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


setCursor

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


getBackground

public java.awt.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.


setBackground

public void setBackground(java.awt.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.


getFont

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


setFont

public void setFont(java.awt.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.


hasFocus

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


requestFocus

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


isFocusable

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


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.


getName

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


setName

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


addEventLink

public void addEventLink(java.lang.Class eventType,
                         java.lang.Object target,
                         java.lang.reflect.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 class 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(java.lang.Object event)
Send out an object representing an event to every appropriate event link that has been added to this object.

Overrides:
dispatchEvent in class EventSource


Written by Peter Eastman.