edu.princeton.swing
Class PScrollablePanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.princeton.swing.PScrollablePanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class PScrollablePanel
extends JPanel
implements Scrollable

PScrollablePanel is just like a JPanel except that it implements scrollable.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static byte TRACKING_POLICY_ALWAYS
          The tracking policy whereby this PScrollablePanel will never track JViewport's width/height.
static byte TRACKING_POLICY_IF_WILL_EXPAND
          The tracking policy whereby this PScrollablePanel will track JViewport's width/height only if will cause the panel to expand.
static byte TRACKING_POLICY_NEVER
          The tracking policy whereby this PScrollablePanel will always track JViewport's width/height.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PScrollablePanel()
          Creates a new PScrollablePanel.
PScrollablePanel(boolean isDoubleBuffered)
          Creates a new PScrollablePanel.
PScrollablePanel(LayoutManager layout)
          Creates a new PScrollablePanel.
PScrollablePanel(LayoutManager layout, boolean isDoubleBuffered)
          Creates a new PScrollablePanel.
 
Method Summary
 Dimension getActualPreferredScrollableViewportSize()
          Returns the value passed to setPreferredScrollableViewportSize().
 byte getHeightTrackingPolicy()
          Returns the height-tracking policy of the PScrollablePanel.
 Dimension getPreferredScrollableViewportSize()
          Returns the preferred size of the viewport for a view component.
 int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.
 boolean getScrollableTracksViewportHeight()
          Return true if a viewport should always force the height of this Scrollable to match the height of the viewport.
 boolean getScrollableTracksViewportWidth()
          Return true if a viewport should always force the width of this Scrollable to match the width of the viewport.
 int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
          Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation.
 byte getWidthTrackingPolicy()
          Returns the width-tracking policy of the PScrollablePanel.
 void setHeightTrackingPolicy(byte heightTrackingPolicy)
          Sets the height-tracking policy of the PScrollablePanel.
 void setPreferredScrollableViewportSize(Dimension preferredScrollableViewportSize)
          Allows the user to set what getPreferredScrollableViewportSize() will return.
 void setWidthTrackingPolicy(byte widthTrackingPolicy)
          Sets the width-tracking policy of the PScrollablePanel.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACKING_POLICY_NEVER

public static final byte TRACKING_POLICY_NEVER
The tracking policy whereby this PScrollablePanel will always track JViewport's width/height.

See Also:
setWidthTrackingPolicy(byte), setHeightTrackingPolicy(byte), Constant Field Values

TRACKING_POLICY_IF_WILL_EXPAND

public static final byte TRACKING_POLICY_IF_WILL_EXPAND
The tracking policy whereby this PScrollablePanel will track JViewport's width/height only if will cause the panel to expand.

See Also:
setWidthTrackingPolicy(byte), setHeightTrackingPolicy(byte), Constant Field Values

TRACKING_POLICY_ALWAYS

public static final byte TRACKING_POLICY_ALWAYS
The tracking policy whereby this PScrollablePanel will never track JViewport's width/height.

See Also:
setWidthTrackingPolicy(byte), setHeightTrackingPolicy(byte), Constant Field Values
Constructor Detail

PScrollablePanel

public PScrollablePanel()
Creates a new PScrollablePanel.


PScrollablePanel

public PScrollablePanel(boolean isDoubleBuffered)
Creates a new PScrollablePanel.


PScrollablePanel

public PScrollablePanel(LayoutManager layout)
Creates a new PScrollablePanel.


PScrollablePanel

public PScrollablePanel(LayoutManager layout,
                        boolean isDoubleBuffered)
Creates a new PScrollablePanel.

Method Detail

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for a view component. For example the preferredSize of a JList component is the size required to acommodate all of the cells in its list however the value of preferredScrollableViewportSize is the size required for JList.getVisibleRowCount() rows. A component without any properties that would effect the viewport size should just return getPreferredSize() here.

Specified by:
getPreferredScrollableViewportSize in interface Scrollable
See Also:
getActualPreferredScrollableViewportSize(), setPreferredScrollableViewportSize(Dimension)

getActualPreferredScrollableViewportSize

public Dimension getActualPreferredScrollableViewportSize()
Returns the value passed to setPreferredScrollableViewportSize(). A null value indicates that getPreferredScrollableViewportSize() should return getPreferredSize().

Returns:
The value passed to setPreferredScrollableViewportSize().
See Also:
getPreferredScrollableViewportSize(), setPreferredScrollableViewportSize(Dimension)

setPreferredScrollableViewportSize

public void setPreferredScrollableViewportSize(Dimension preferredScrollableViewportSize)
Allows the user to set what getPreferredScrollableViewportSize() will return. A null value indicates that such calls will be passed to getPreferredSize(). Null is the default.

Parameters:
preferredScrollableViewportSize - The new preferred size of the viewport. A null value indicates that such calls will be passed to getPreferredSize().
See Also:
getPreferredScrollableViewportSize(), setPreferredScrollableViewportSize(Dimension)

getScrollableUnitIncrement

public int getScrollableUnitIncrement(Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one new row or column, depending on the value of orientation. Ideally, components should handle a partially exposed row or column by returning the distance required to completely expose the item.

Scrolling containers, like JScrollPane, will use this method each time the user requests a unit scroll.

PScrollablePanel's implementation of this function attempts to see if the relevant child of the panel is a Scrollable. If not, it will default to a tenth of the visible screen.

Specified by:
getScrollableUnitIncrement in interface Scrollable
Parameters:
visibleRect - The view area visible within the viewport.
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "block" increment for scrolling in the specified direction.

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Components that display logical rows or columns should compute the scroll increment that will completely expose one block of rows or columns, depending on the value of orientation.

Scrolling containers, like JScrollPane, will use this method each time the user requests a block scroll.

PScrollablePanel's implementation of this function attempts to see if the relevant child of the panel is a Scrollable. If not, it will default to a full visible screen.

Specified by:
getScrollableBlockIncrement in interface Scrollable
Parameters:
visibleRect - The view area visible within the viewport.
orientation - Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
direction - Less than zero to scroll up/left, greater than zero for down/right.
Returns:
The "block" increment for scrolling in the specified direction.

getWidthTrackingPolicy

public byte getWidthTrackingPolicy()
Returns the width-tracking policy of the PScrollablePanel. This policy determines the return value of getScrollableTracksViewportWidth().

Returns:
The width-tracking policy of the PScrollablePanel.
See Also:
TRACKING_POLICY_NEVER, TRACKING_POLICY_IF_WILL_EXPAND, TRACKING_POLICY_ALWAYS

setWidthTrackingPolicy

public void setWidthTrackingPolicy(byte widthTrackingPolicy)
Sets the width-tracking policy of the PScrollablePanel. This policy determines the return value of getScrollableTracksViewportWidth(). The default value is TRACKING_POLICY_IF_WILL_EXPAND.

Parameters:
widthTrackingPolicy - The width-tracking policy of the PScrollablePanel. An IllegalArgumentException will be thrown if this is not valid.
See Also:
TRACKING_POLICY_NEVER, TRACKING_POLICY_IF_WILL_EXPAND, TRACKING_POLICY_ALWAYS

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Return true if a viewport should always force the width of this Scrollable to match the width of the viewport. For example a noraml text view that supported line wrapping would return true here, since it would be undesirable for wrapped lines to disappear beyond the right edge of the viewport. Note that returning true for a Scrollable whose ancestor is a JScrollPane effectively disables horizontal scrolling.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportWidth in interface Scrollable
Returns:
True if a viewport should force the Scrollables width to match its own.

getHeightTrackingPolicy

public byte getHeightTrackingPolicy()
Returns the height-tracking policy of the PScrollablePanel. This policy determines the return value of getScrollableTracksViewportHeight().

Returns:
The height-tracking policy of the PScrollablePanel.
See Also:
TRACKING_POLICY_NEVER, TRACKING_POLICY_IF_WILL_EXPAND, TRACKING_POLICY_ALWAYS

setHeightTrackingPolicy

public void setHeightTrackingPolicy(byte heightTrackingPolicy)
Sets the height-tracking policy of the PScrollablePanel. This policy determines the return value of getScrollableTracksViewportHeight(). The default value is TRACKING_POLICY_IF_WILL_EXPAND.

Parameters:
heightTrackingPolicy - The height-tracking policy of the PScrollablePanel. An IllegalArgumentException will be thrown if this is not valid.
See Also:
TRACKING_POLICY_NEVER, TRACKING_POLICY_IF_WILL_EXPAND, TRACKING_POLICY_ALWAYS

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Return true if a viewport should always force the height of this Scrollable to match the height of the viewport. For example a columnar text view that flowed text in left to right columns could effectively disable vertical scrolling by returning true here.

Scrolling containers, like JViewport, will use this method each time they are validated.

Specified by:
getScrollableTracksViewportHeight in interface Scrollable
Returns:
True if a viewport should force the Scrollables height to match its own.