buoy.widget
Class BScrollPane

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.WidgetContainer
              extended by buoy.widget.BScrollPane

public class BScrollPane
extends WidgetContainer

A BScrollPane is a WidgetContainer with up to five children: an arbitrary "content" Widget that fills most of the BScrollPane, optional "row header" and "column header" Widgets along the left and top edges, respectively, and optional BScrollBars along the right and bottom edges. It displays only a portion of the content, row header, and column header Widgets, and allows the user to scroll through them by means of the two BScrollBars.

If the BScrollPane does not have a horizontal and/or vertical scrollbar, then by default it will force the corresponding dimension of the content and header Widgets to exactly match the size of the visible area. For example, if the content is a BTextArea with word wrap enabled, you would normally only have a vertical scrollbar. The width of the BTextArea should then be forced to exactly match the width of the visible area, so that words will wrap at the correct place. You can override this behavior by calling setForceWidth() and setForceHeight(). For example, you might want to control the scroll position through some external means, in which case the BScrollPane would not provide scrollbars but should still allow the content Widget to be its preferred size.

Author:
Peter Eastman

Nested Class Summary
static class BScrollPane.ScrollbarPolicy
          This inner class represents a scrollbar policy for the horizontal or vertical scrollbar.
 
Field Summary
static BScrollPane.ScrollbarPolicy SCROLLBAR_ALWAYS
           
static BScrollPane.ScrollbarPolicy SCROLLBAR_AS_NEEDED
           
static BScrollPane.ScrollbarPolicy SCROLLBAR_NEVER
           
 
Constructor Summary
BScrollPane()
          Create a new BScrollPane with no content or header Widgets.
BScrollPane(BScrollPane.ScrollbarPolicy horizontalPolicy, BScrollPane.ScrollbarPolicy verticalPolicy)
          Create a new BScrollPane with no content or header Widgets.
BScrollPane(Widget contentWidget)
          Create a new BScrollPane with the specified Widget as its content.
BScrollPane(Widget contentWidget, BScrollPane.ScrollbarPolicy horizontalPolicy, BScrollPane.ScrollbarPolicy verticalPolicy)
          Create a new BScrollPane with the specified Widget as its content.
 
Method Summary
 int getChildCount()
          Get the number of children in this container.
 java.util.Collection<Widget> getChildren()
          Get a Collection containing all child Widgets of this container.
 Widget getColHeader()
          Get the column header Widget.
 javax.swing.JScrollPane getComponent()
          Get the java.awt.Component corresponding to this Widget.
 Widget getContent()
          Get the content Widget.
 boolean getForceHeight()
          Get whether the BScrollPane should force the height of the content and row header Widgets to exactly match the height of the visible area.
 boolean getForceWidth()
          Get whether the BScrollPane should force the width of the content and column header Widgets to exactly match the width of the visible area.
 BScrollBar getHorizontalScrollBar()
          Get the horizontal BScrollBar.
 BScrollPane.ScrollbarPolicy getHorizontalScrollbarPolicy()
          Get the horizontal scrollbar policy.
 java.awt.Dimension getMinimumSize()
          Get the smallest size at which this Widget can reasonably be drawn.
 java.awt.Dimension getPreferredSize()
          Get the preferred size at which this Widget will look best.
 java.awt.Dimension getPreferredViewSize()
          Get the preferred size for the content's view area.
 Widget getRowHeader()
          Get the row header Widget.
 BScrollBar getVerticalScrollBar()
          Get the vertical BScrollBar.
 BScrollPane.ScrollbarPolicy getVerticalScrollbarPolicy()
          Get the vertical scrollbar policy.
 java.awt.Dimension getViewSize()
          Get the current size of the content's view area.
 void layoutChildren()
          Layout the child Widgets.
 void remove(Widget widget)
          Remove a child Widget from this container.
 void removeAll()
          Remove the content, row header, and column header Widgets from this container.
 void setBackground(java.awt.Color background)
          Set the background color of this Widget.
 void setColHeader(Widget widget)
          Set the column header Widget.
 void setContent(Widget widget)
          Set the content Widget.
 void setForceHeight(boolean force)
          Set whether the BScrollPane should force the height of the content and row header Widgets to exactly match the height of the visible area.
 void setForceWidth(boolean force)
          Set whether the BScrollPane should force the width of the content and column header Widgets to exactly match the width of the visible area.
 void setHorizontalScrollbarPolicy(BScrollPane.ScrollbarPolicy policy)
          Set the horizontal scrollbar policy.
 void setPreferredViewSize(java.awt.Dimension size)
          Set the preferred size for the content's view area.
 void setRowHeader(Widget widget)
          Set the row header Widget.
 void setVerticalScrollbarPolicy(BScrollPane.ScrollbarPolicy policy)
          Set the vertical scrollbar policy.
 
Methods inherited from class buoy.widget.WidgetContainer
isOpaque, setOpaque
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getName, getParent, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setCursor, setEnabled, setFocusable, setFont, setName, setVisible
 
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
 

Field Detail

SCROLLBAR_NEVER

public static final BScrollPane.ScrollbarPolicy SCROLLBAR_NEVER

SCROLLBAR_AS_NEEDED

public static final BScrollPane.ScrollbarPolicy SCROLLBAR_AS_NEEDED

SCROLLBAR_ALWAYS

public static final BScrollPane.ScrollbarPolicy SCROLLBAR_ALWAYS
Constructor Detail

BScrollPane

public BScrollPane()
Create a new BScrollPane with no content or header Widgets. The horizontal and vertical scrollbar policies default to SCROLLBAR_AS_NEEDED.


BScrollPane

public BScrollPane(Widget contentWidget)
Create a new BScrollPane with the specified Widget as its content. The horizontal and vertical scrollbar policies default to SCROLLBAR_AS_NEEDED.

Parameters:
contentWidget - the Widget to use as the content of the BScrollPane

BScrollPane

public BScrollPane(BScrollPane.ScrollbarPolicy horizontalPolicy,
                   BScrollPane.ScrollbarPolicy verticalPolicy)
Create a new BScrollPane with no content or header Widgets.

Parameters:
horizontalPolicy - specifies when the horizontal scrollbar should be displayed. This should be equal to SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.
verticalPolicy - specifies when the vertical scrollbar should be displayed. This should be equal to SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.

BScrollPane

public BScrollPane(Widget contentWidget,
                   BScrollPane.ScrollbarPolicy horizontalPolicy,
                   BScrollPane.ScrollbarPolicy verticalPolicy)
Create a new BScrollPane with the specified Widget as its content.

Parameters:
contentWidget - the Widget to use as the content of the BScrollPane
horizontalPolicy - specifies when the horizontal scrollbar should be displayed. This should be equal to SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.
verticalPolicy - specifies when the vertical scrollbar should be displayed. This should be equal to SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.
Method Detail

getComponent

public javax.swing.JScrollPane getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

getContent

public Widget getContent()
Get the content Widget.


setContent

public void setContent(Widget widget)
Set the content Widget.


getRowHeader

public Widget getRowHeader()
Get the row header Widget.


setRowHeader

public void setRowHeader(Widget widget)
Set the row header Widget.


getColHeader

public Widget getColHeader()
Get the column header Widget.


setColHeader

public void setColHeader(Widget widget)
Set the column header Widget.


getHorizontalScrollBar

public BScrollBar getHorizontalScrollBar()
Get the horizontal BScrollBar.


getVerticalScrollBar

public BScrollBar getVerticalScrollBar()
Get the vertical BScrollBar.


getHorizontalScrollbarPolicy

public BScrollPane.ScrollbarPolicy getHorizontalScrollbarPolicy()
Get the horizontal scrollbar policy. This will be either SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.


setHorizontalScrollbarPolicy

public void setHorizontalScrollbarPolicy(BScrollPane.ScrollbarPolicy policy)
Set the horizontal scrollbar policy. This should be either SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.


getVerticalScrollbarPolicy

public BScrollPane.ScrollbarPolicy getVerticalScrollbarPolicy()
Get the vertical scrollbar policy. This will be either SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.


setVerticalScrollbarPolicy

public void setVerticalScrollbarPolicy(BScrollPane.ScrollbarPolicy policy)
Set the vertical scrollbar policy. This should be either SCROLLBAR_ALWAYS, SCROLLBAR_AS_NEEDED, or SCROLLBAR_NEVER.


getPreferredViewSize

public java.awt.Dimension getPreferredViewSize()
Get the preferred size for the content's view area. This may be null, in which case the preferred view size is equal to the preferred size of the content Widget.


setPreferredViewSize

public void setPreferredViewSize(java.awt.Dimension size)
Set the preferred size for the content's view area. This may be null, in which case the preferred view size is equal to the preferred size of the content Widget.


getViewSize

public java.awt.Dimension getViewSize()
Get the current size of the content's view area.


getForceWidth

public boolean getForceWidth()
Get whether the BScrollPane should force the width of the content and column header Widgets to exactly match the width of the visible area. By default, this is true if the horizontal scrollbar policy was initialized to SCROLLBAR_NEVER, and false otherwise.

Note that even if this option is enabled, the BScrollPane will never make the content Widget smaller than its minimum size or larger than its maximum size.


setForceWidth

public void setForceWidth(boolean force)
Set whether the BScrollPane should force the width of the content and column header Widgets to exactly match the width of the visible area. By default, this is true if the horizontal scrollbar policy was initialized to SCROLLBAR_NEVER, and false otherwise.

Note that even if this option is enabled, the BScrollPane will never make the content Widget smaller than its minimum size or larger than its maximum size.


getForceHeight

public boolean getForceHeight()
Get whether the BScrollPane should force the height of the content and row header Widgets to exactly match the height of the visible area. By default, this is true if the vertical scrollbar policy was initialized to SCROLLBAR_NEVER, and false otherwise.

Note that even if this option is enabled, the BScrollPane will never make the content Widget smaller than its minimum size or larger than its maximum size.


setForceHeight

public void setForceHeight(boolean force)
Set whether the BScrollPane should force the height of the content and row header Widgets to exactly match the height of the visible area. By default, this is true if the vertical scrollbar policy was initialized to SCROLLBAR_NEVER, and false otherwise.

Note that even if this option is enabled, the BScrollPane will never make the content Widget smaller than its minimum size or larger than its maximum size.


getChildCount

public int getChildCount()
Get the number of children in this container.

Specified by:
getChildCount in class WidgetContainer

getChildren

public java.util.Collection<Widget> getChildren()
Get a Collection containing all child Widgets of this container.

Specified by:
getChildren in class WidgetContainer

remove

public void remove(Widget widget)
Remove a child Widget from this container. The scrollbars are built into the scroll pane and may never be removed, although they can be hidden by setting the appropriate scrollbar policy to SCROLLBAR_NEVER.

Specified by:
remove in class WidgetContainer

removeAll

public void removeAll()
Remove the content, row header, and column header Widgets from this container. The scrollbars are built into the scroll pane and may never be removed, although they can be hidden by setting the appropriate scrollbar policy to SCROLLBAR_NEVER.

Specified by:
removeAll in class WidgetContainer

layoutChildren

public void layoutChildren()
Layout the child Widgets. This may be invoked whenever something has changed (the size of this WidgetContainer, the preferred size of one of its children, etc.) that causes the layout to no longer be correct. If a child is itself a WidgetContainer, its layoutChildren() method will be called in turn.

Specified by:
layoutChildren in class WidgetContainer

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.

Overrides:
getMinimumSize in class Widget

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.

Overrides:
getPreferredSize in class Widget

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.

Overrides:
setBackground in class Widget


Written by Peter Eastman.