javax.swing
Class JViewport

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JViewport
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, MenuContainer, Serializable

public class JViewport
extends JComponent
implements Accessible

Safe:

See Also:
Serialized Form

Field Summary
protected  boolean backingStore
          Deprecated. As of Java 2 platform v1.3
static int BACKINGSTORE_SCROLL_MODE
          Enabled: Draws viewport contents into an offscreen image.
protected  Image backingStoreImage
          The view image used for a backing store.
static int BLIT_SCROLL_MODE
          Enabled: Use graphics.copyArea to implement scrolling.
private  ChangeEvent changeEvent
           
(package private) static Object EnableWindowBlit
          Property used to indicate window blitting should not be done.
protected  boolean isViewSizeSet
          True when the viewport dimensions have been determined.
protected  Point lastPaintPosition
          The last viewPosition that we've painted, so we know how much of the backing store image is valid.
private  boolean repaintAll
          This is set to true in setViewPosition if doing a window blit and the viewport is obscured.
private  Timer repaintTimer
          Instead of directly invoking repaint, a Timer is started and when it fires, repaint is invoked.
private  int scrollMode
           
protected  boolean scrollUnderway
          The scrollUnderway flag is used for components like JList.
static int SIMPLE_SCROLL_MODE
          Enabled: This mode uses the very simple method of redrawing the entire contents of the scrollpane each time it is scrolled.
private static String uiClassID
           
private  ComponentListener viewListener
           
private  boolean waitingForRepaint
          This is set to true in paint, if repaintAll is true and the clip rectangle does not match the bounds.
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JViewport()
          Enabled: Creates a JViewport.
 
Method Summary
 void addChangeListener(ChangeListener l)
          Enabled: Adds a ChangeListener to the list that is notified each time the view's size, position, or the viewport's extent size has changed.
protected  void addImpl(Component child, Object constraints, int index)
          Sets the JViewport's one lightweight child, which can be null.
private  void blitDoubleBuffered(JComponent view, Graphics g, int clipX, int clipY, int clipW, int clipH, int blitFromX, int blitFromY, int blitToX, int blitToY, int blitW, int blitH, Image off)
           
private  void blitWindowGraphics(int x, int y, int w, int h, int ox, int oy)
          Blits the parent windows graphics from the given region offset to ox, oy.
private  boolean canUseWindowBlitter()
          Returns true if the viewport is not obscured by one of its ancestors, or its ancestors children and if the viewport is showing.
protected  boolean computeBlit(int dx, int dy, Point blitFrom, Point blitTo, Dimension blitSize, Rectangle blitPaint)
          Computes the parameters for a blit where the backing store image currently contains oldLoc in the upper left hand corner and we're scrolling to newLoc.
protected  LayoutManager createLayoutManager()
          Subclassers can override this to install a different layout manager (or null) in the constructor.
private  Timer createRepaintTimer()
           
protected  javax.swing.JViewport.ViewListener createViewListener()
          Creates a listener for the view.
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Notifies listeners of a property change.
protected  void fireStateChanged()
          Notifies all ChangeListeners when the views size, position, or the viewports extent size has changed.
private  void flushViewDirtyRegion(Graphics g)
          If the repaint manager has a dirty region for the view, the view is asked to paint.
 AccessibleContext getAccessibleContext()
          Suppressed: Gets the AccessibleContext associated with this JViewport.
private  Graphics getBackingStoreGraphics(Graphics g)
           
 ChangeListener[] getChangeListeners()
          Suppressed: Returns an array of all the ChangeListeners added to this JViewport with addChangeListener().
 Dimension getExtentSize()
          Enabled: Returns the size of the visible part of the view in view coordinates.
 Insets getInsets()
          Enabled: Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on a JViewport.
 Insets getInsets(Insets insets)
          Suppressed: Returns an Insets object containing this JViewports inset values.
 int getScrollMode()
          Enabled: Returns the current scrolling mode.
 javax.swing.plaf.ViewportUI getUI()
          Suppressed: Returns the L&F object that renders this component.
 String getUIClassID()
          Suppressed: Returns a string that specifies the name of the L&F class that renders this component.
 Component getView()
          Enabled: Returns the JViewport's one child or null.
private  Point getViewLocation()
          Only used by the paint method below.
 Point getViewPosition()
          Enabled: Returns the view coordinates that appear in the upper left hand corner of the viewport, or 0,0 if there's no view.
 Rectangle getViewRect()
          Enabled: Returns a rectangle whose origin is getViewPosition and size is getExtentSize.
 Dimension getViewSize()
          Enabled: If the view's size hasn't been explicitly set, return the preferred size, otherwise return the view's current size.
 boolean isBackingStoreEnabled()
          Deprecated. As of Java 2 platform v1.3, replaced by getScrollMode().
private  boolean isBlitting()
           
 boolean isOptimizedDrawingEnabled()
          Enabled: The JViewport overrides the default implementation of this method (in JComponent) to return false.
private  boolean needsRepaintAfterBlit()
          Returns true if the component needs to be completely repainted after a blit and a paint is received.
 void paint(Graphics g)
          Suppressed: Depending on whether the backingStore is enabled, either paint the image through the backing store or paint just the recently exposed part, using the backing store to "blit" the remainder.
private  void paintViaBackingStore(Graphics g)
           
private  void paintViaBackingStore(Graphics g, Rectangle oClip)
           
private  void paintView(Graphics g)
          Called to paint the view, usually when blitPaint can not blit.
private  void paintViewDoubleBuffered(JComponent view, Graphics g, int clipX, int clipY, int clipW, int clipH, Image off)
           
protected  String paramString()
          Returns a string representation of this JViewport.
private  int positionAdjustment(int parentWidth, int childWidth, int childAt)
           
 void remove(Component child)
          Enabled: Removes the Viewports one lightweight child.
 void removeChangeListener(ChangeListener l)
          Enabled: Removes a ChangeListener from the list that's notified each time the views size, position, or the viewports extent size has changed.
 void repaint(long tm, int x, int y, int w, int h)
          Enabled: Always repaint in the parents coordinate system to make sure only one paint is performed by the RepaintManager.
 void reshape(int x, int y, int w, int h)
          Enabled: Sets the bounds of this viewport.
 void scrollRectToVisible(Rectangle contentRect)
          Enabled: Scrolls the view so that Rectangle within the view becomes visible.
 void setBackingStoreEnabled(boolean enabled)
          Deprecated. As of Java 2 platform v1.3, replaced by setScrollMode().
 void setBorder(javax.swing.border.Border border)
          Enabled: The viewport "scrolls" its child (called the "view") by the normal parent/child clipping (typically the view is moved in the opposite direction of the scroll).
 void setExtentSize(Dimension newExtent)
          Enabled: Sets the size of the visible part of the view using view coordinates.
 void setScrollMode(int mode)
          Enabled: Used to control the method of scrolling the viewport contents.
 void setUI(javax.swing.plaf.ViewportUI ui)
          Suppressed: Sets the L&F object that renders this component.
 void setView(Component view)
          Enabled: Sets the JViewport's one lightweight child (view), which can be null.
 void setViewPosition(Point p)
          Enabled: Sets the view coordinates that appear in the upper left hand corner of the viewport, does nothing if there's no view.
 void setViewSize(Dimension newSize)
          Enabled: Sets the size of the view.
 Dimension toViewCoordinates(Dimension size)
          Enabled: Converts a size in pixel coordinates to view coordinates.
 Point toViewCoordinates(Point p)
          Enabled: Converts a point in pixel coordinates to view coordinates.
 void updateUI()
          Suppressed: Resets the UI property to a value from the current look and feel.
private  void validateView()
          Ascends the Viewport's parents stopping when a component is found that returns true to isValidateRoot.
private  boolean windowBlitPaint(Graphics g)
          Used when blitting.
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, alwaysOnTop, checkIfChildObscuredBySibling, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getListeners, getLocation, getManagingFocusBackwardTraversalKeys, getManagingFocusForwardTraversalKeys, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getWriteObjCounter, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, rectangleIsObscured, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, setWriteObjCounter, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, get, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, iterate, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, size, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, toString, transferFocus, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uiClassID

private static final String uiClassID
See Also:
getUIClassID(), JComponent.readObject(java.io.ObjectInputStream)

EnableWindowBlit

static final Object EnableWindowBlit
Property used to indicate window blitting should not be done.


isViewSizeSet

protected boolean isViewSizeSet
True when the viewport dimensions have been determined. The default is false.


lastPaintPosition

protected Point lastPaintPosition
The last viewPosition that we've painted, so we know how much of the backing store image is valid.


backingStore

protected boolean backingStore
Deprecated. As of Java 2 platform v1.3

True when this viewport is maintaining an offscreen image of its contents, so that some scrolling can take place using fast "bit-blit" operations instead of by accessing the view object to construct the display. The default is false.

See Also:
setScrollMode(int)

backingStoreImage

protected transient Image backingStoreImage
The view image used for a backing store.


scrollUnderway

protected boolean scrollUnderway
The scrollUnderway flag is used for components like JList. When the downarrow key is pressed on a JList and the selected cell is the last in the list, the scrollpane autoscrolls. Here, the old selected cell needs repainting and so we need a flag to make the viewport do the optimized painting only when there is an explicit call to setViewPosition(Point). When setBounds is called through other routes, the flag is off and the view repaints normally. Another approach would be to remove this from the JViewport class and have the JList manage this case by using setBackingStoreEnabled. The default is false.


viewListener

private ComponentListener viewListener

changeEvent

private transient ChangeEvent changeEvent

BLIT_SCROLL_MODE

public static final int BLIT_SCROLL_MODE
Enabled: Use graphics.copyArea to implement scrolling. This is the fastest for most applications.

Since:
1.3
See Also:
setScrollMode(int)

BACKINGSTORE_SCROLL_MODE

public static final int BACKINGSTORE_SCROLL_MODE
Enabled: Draws viewport contents into an offscreen image. This was previously the default mode for JTable. This mode may offer advantages over "blit mode" in some cases, but it requires a large chunk of extra RAM.

Since:
1.3
See Also:
setScrollMode(int)

SIMPLE_SCROLL_MODE

public static final int SIMPLE_SCROLL_MODE
Enabled: This mode uses the very simple method of redrawing the entire contents of the scrollpane each time it is scrolled. This was the default behavior in Swing 1.0 and Swing 1.1. Either of the other two options will provide better performance in most cases.

Since:
1.3
See Also:
setScrollMode(int)

scrollMode

private int scrollMode
Since:
1.3
See Also:
setScrollMode(int)

repaintAll

private transient boolean repaintAll
This is set to true in setViewPosition if doing a window blit and the viewport is obscured.


waitingForRepaint

private transient boolean waitingForRepaint
This is set to true in paint, if repaintAll is true and the clip rectangle does not match the bounds. If true, and scrolling happens the repaint manager is not cleared which then allows for the repaint previously invoked to succeed.


repaintTimer

private transient Timer repaintTimer
Instead of directly invoking repaint, a Timer is started and when it fires, repaint is invoked.

Constructor Detail

JViewport

public JViewport()
Enabled: Creates a JViewport.

Method Detail

getUI

public javax.swing.plaf.ViewportUI getUI()
Suppressed: Returns the L&F object that renders this component.

Returns:
a ViewportUI object

setUI

public void setUI(javax.swing.plaf.ViewportUI ui)
Suppressed: Sets the L&F object that renders this component.

Parameters:
ui - the ViewportUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
Suppressed: Resets the UI property to a value from the current look and feel.

Overrides:
updateUI in class JComponent
See Also:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
Suppressed: Returns a string that specifies the name of the L&F class that renders this component.

Overrides:
getUIClassID in class JComponent
Returns:
the string "ViewportUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

addImpl

protected void addImpl(Component child,
                       Object constraints,
                       int index)
Sets the JViewport's one lightweight child, which can be null. (Since there is only one child which occupies the entire viewport, the constraints and index arguments are ignored.)

Overrides:
addImpl in class Container
Parameters:
child - the lightweight child of the viewport
constraints - the constraints to be respected
index - the index
See Also:
setView(java.awt.Component)

remove

public void remove(Component child)
Enabled: Removes the Viewports one lightweight child.

Overrides:
remove in class Container
Parameters:
child - the component to be removed
See Also:
setView(java.awt.Component)

scrollRectToVisible

public void scrollRectToVisible(Rectangle contentRect)
Enabled: Scrolls the view so that Rectangle within the view becomes visible.

This attempts to validate the view before scrolling if the view is currently not valid - isValid returns false. To avoid excessive validation when the containment hierarchy is being created this will not validate if one of the ancestors does not have a peer, or there is no validate root ancestor, or one of the ancestors is not a Window or Applet.

Note that this method will not scroll outside of the valid viewport; for example, if contentRect is larger than the viewport, scrolling will be confined to the viewport's bounds.

Overrides:
scrollRectToVisible in class JComponent
Parameters:
contentRect - the Rectangle to display
See Also:
JComponent.isValidateRoot(), java.awt.Component#isValid, java.awt.Component#getPeer

validateView

private void validateView()
Ascends the Viewport's parents stopping when a component is found that returns true to isValidateRoot. If all the Component's parents are visible, validate will then be invoked on it. The RepaintManager is then invoked with removeInvalidComponent. This is the synchronous version of a revalidate.


positionAdjustment

private int positionAdjustment(int parentWidth,
                               int childWidth,
                               int childAt)

setBorder

public final void setBorder(javax.swing.border.Border border)
Enabled: The viewport "scrolls" its child (called the "view") by the normal parent/child clipping (typically the view is moved in the opposite direction of the scroll). A non-null border, or non-zero insets, isn't supported, to prevent the geometry of this component from becoming complex enough to inhibit subclassing. To create a JViewport with a border, add it to a JPanel that has a border.

Note: If border is non-null, this method will throw an exception as borders are not supported on a JViewPort.

Overrides:
setBorder in class JComponent
Parameters:
border - the Border to set
See Also:
Border, CompoundBorder

getInsets

public final Insets getInsets()
Enabled: Returns the insets (border) dimensions as (0,0,0,0), since borders are not supported on a JViewport.

Overrides:
getInsets in class JComponent
Returns:
a Rectange of zero dimension and zero origin
See Also:
setBorder(javax.swing.border.Border)

getInsets

public final Insets getInsets(Insets insets)
Suppressed: Returns an Insets object containing this JViewports inset values. The passed-in Insets object will be reinitialized, and all existing values within this object are overwritten.

Overrides:
getInsets in class JComponent
Parameters:
insets - the Insets object which can be reused
Returns:
this viewports inset values
See Also:
getInsets()

getBackingStoreGraphics

private Graphics getBackingStoreGraphics(Graphics g)

paintViaBackingStore

private void paintViaBackingStore(Graphics g)

paintViaBackingStore

private void paintViaBackingStore(Graphics g,
                                  Rectangle oClip)

isOptimizedDrawingEnabled

public boolean isOptimizedDrawingEnabled()
Enabled: The JViewport overrides the default implementation of this method (in JComponent) to return false. This ensures that the drawing machinery will call the Viewport's paint implementation rather than messaging the JViewport's children directly.

Overrides:
isOptimizedDrawingEnabled in class JComponent
Returns:
false

getViewLocation

private Point getViewLocation()
Only used by the paint method below.


paint

public void paint(Graphics g)
Suppressed: Depending on whether the backingStore is enabled, either paint the image through the backing store or paint just the recently exposed part, using the backing store to "blit" the remainder.
The term "blit" is the pronounced version of the PDP-10 BLT (BLock Transfer) instruction, which copied a block of bits. (In case you were curious.)

Overrides:
paint in class JComponent
Parameters:
g - the Graphics context within which to paint
See Also:
JComponent.paintComponent(java.awt.Graphics), JComponent.paintBorder(java.awt.Graphics), JComponent.paintChildren(java.awt.Graphics), JComponent.getComponentGraphics(java.awt.Graphics), JComponent.repaint(long, int, int, int, int)

reshape

public void reshape(int x,
                    int y,
                    int w,
                    int h)
Enabled: Sets the bounds of this viewport. If the viewport's width or height has changed, fire a StateChanged event.

Overrides:
reshape in class JComponent
Parameters:
x - left edge of the origin
y - top edge of the origin
w - width in pixels
h - height in pixels
See Also:
JComponent.reshape(int, int, int, int)

setScrollMode

public void setScrollMode(int mode)
Enabled: Used to control the method of scrolling the viewport contents. You may want to change this mode to get maximum performance for your use case.

Parameters:
mode - one of the following values:
  • JViewport.BLIT_SCROLL_MODE
  • JViewport.BACKINGSTORE_SCROLL_MODE
  • JViewport.SIMPLE_SCROLL_MODE
Since:
1.3
See Also:
BLIT_SCROLL_MODE, BACKINGSTORE_SCROLL_MODE, SIMPLE_SCROLL_MODE

getScrollMode

public int getScrollMode()
Enabled: Returns the current scrolling mode.

Returns:
the scrollMode property
Since:
1.3
See Also:
setScrollMode(int)

isBackingStoreEnabled

public boolean isBackingStoreEnabled()
Deprecated. As of Java 2 platform v1.3, replaced by getScrollMode().

Enabled: Returns true if this viewport is maintaining an offscreen image of its contents.

Returns:
true if scrollMode is BACKINGSTORE_SCROLL_MODE

setBackingStoreEnabled

public void setBackingStoreEnabled(boolean enabled)
Deprecated. As of Java 2 platform v1.3, replaced by setScrollMode().

Enabled: If true if this viewport will maintain an offscreen image of its contents. The image is used to reduce the cost of small one dimensional changes to the viewPosition. Rather than repainting the entire viewport we use Graphics.copyArea to effect some of the scroll.

Parameters:
enabled - if true, maintain an offscreen backing store

isBlitting

private final boolean isBlitting()

getView

public Component getView()
Enabled: Returns the JViewport's one child or null.

Returns:
the viewports child, or null if none exists
See Also:
setView(java.awt.Component)

setView

public void setView(Component view)
Enabled: Sets the JViewport's one lightweight child (view), which can be null.

Parameters:
view - the viewport's new lightweight child
See Also:
getView()

getViewSize

public Dimension getViewSize()
Enabled: If the view's size hasn't been explicitly set, return the preferred size, otherwise return the view's current size. If there is no view, return 0,0.

Returns:
a Dimension object specifying the size of the view

setViewSize

public void setViewSize(Dimension newSize)
Enabled: Sets the size of the view. A state changed event will be fired.

Parameters:
newSize - a Dimension object specifying the new size of the view

getViewPosition

public Point getViewPosition()
Enabled: Returns the view coordinates that appear in the upper left hand corner of the viewport, or 0,0 if there's no view.

Returns:
a Point object giving the upper left coordinates

setViewPosition

public void setViewPosition(Point p)
Enabled: Sets the view coordinates that appear in the upper left hand corner of the viewport, does nothing if there's no view.

Parameters:
p - a Point object giving the upper left coordinates

getViewRect

public Rectangle getViewRect()
Enabled: Returns a rectangle whose origin is getViewPosition and size is getExtentSize. This is the visible part of the view, in view coordinates.

Returns:
a Rectangle giving the visible part of the view using view coordinates.

computeBlit

protected boolean computeBlit(int dx,
                              int dy,
                              Point blitFrom,
                              Point blitTo,
                              Dimension blitSize,
                              Rectangle blitPaint)
Computes the parameters for a blit where the backing store image currently contains oldLoc in the upper left hand corner and we're scrolling to newLoc. The parameters are modified to return the values required for the blit.

Parameters:
dx - the horizontal delta
dy - the vertical delta
blitFrom - the Point we're blitting from
blitTo - the Point we're blitting to
blitSize - the Dimension of the area to blit
blitPaint - the area to blit
Returns:
true if the parameters are modified and we're ready to blit; false otherwise

getExtentSize

public Dimension getExtentSize()
Enabled: Returns the size of the visible part of the view in view coordinates.

Returns:
a Dimension object giving the size of the view

toViewCoordinates

public Dimension toViewCoordinates(Dimension size)
Enabled: Converts a size in pixel coordinates to view coordinates. Subclasses of viewport that support "logical coordinates" will override this method.

Parameters:
size - a Dimension object using pixel coordinates
Returns:
a Dimension object converted to view coordinates

toViewCoordinates

public Point toViewCoordinates(Point p)
Enabled: Converts a point in pixel coordinates to view coordinates. Subclasses of viewport that support "logical coordinates" will override this method.

Parameters:
p - a Point object using pixel coordinates
Returns:
a Point object converted to view coordinates

setExtentSize

public void setExtentSize(Dimension newExtent)
Enabled: Sets the size of the visible part of the view using view coordinates.

Parameters:
newExtent - a Dimension object specifying the size of the view

createViewListener

protected javax.swing.JViewport.ViewListener createViewListener()
Creates a listener for the view.

Returns:
a ViewListener

createLayoutManager

protected LayoutManager createLayoutManager()
Subclassers can override this to install a different layout manager (or null) in the constructor. Returns a new ViewportLayout object.

Returns:
a LayoutManager

addChangeListener

public void addChangeListener(ChangeListener l)
Enabled: Adds a ChangeListener to the list that is notified each time the view's size, position, or the viewport's extent size has changed.

Parameters:
l - the ChangeListener to add
See Also:
removeChangeListener(javax.swing.event.ChangeListener), setViewPosition(java.awt.Point), setViewSize(java.awt.Dimension), setExtentSize(java.awt.Dimension)

removeChangeListener

public void removeChangeListener(ChangeListener l)
Enabled: Removes a ChangeListener from the list that's notified each time the views size, position, or the viewports extent size has changed.

Parameters:
l - the ChangeListener to remove
See Also:
addChangeListener(javax.swing.event.ChangeListener)

getChangeListeners

public ChangeListener[] getChangeListeners()
Suppressed: Returns an array of all the ChangeListeners added to this JViewport with addChangeListener().

Returns:
all of the ChangeListeners added or an empty array if no listeners have been added
Since:
1.4

fireStateChanged

protected void fireStateChanged()
Notifies all ChangeListeners when the views size, position, or the viewports extent size has changed.

See Also:
addChangeListener(javax.swing.event.ChangeListener), removeChangeListener(javax.swing.event.ChangeListener), EventListenerList

repaint

public void repaint(long tm,
                    int x,
                    int y,
                    int w,
                    int h)
Enabled: Always repaint in the parents coordinate system to make sure only one paint is performed by the RepaintManager.

Overrides:
repaint in class JComponent
Parameters:
tm - maximum time in milliseconds before update
x - the x coordinate (pixels over from left)
y - the y coordinate (pixels down from top)
w - the width of the dirty region
h - the height of the dirty region
See Also:
java.awt.Component#update(java.awt.Graphics)

paramString

protected String paramString()
Returns a string representation of this JViewport. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString in class JComponent
Returns:
a string representation of this JViewport

firePropertyChange

protected void firePropertyChange(String propertyName,
                                  Object oldValue,
                                  Object newValue)
Notifies listeners of a property change. This is subclassed to update the windowBlit property. (The putClientProperty property is final).

Overrides:
firePropertyChange in class JComponent
Parameters:
propertyName - a string containing the property name
oldValue - the old value of the property
newValue - the new value of the property
See Also:
java.beans.PropertyChangeSupport

needsRepaintAfterBlit

private boolean needsRepaintAfterBlit()
Returns true if the component needs to be completely repainted after a blit and a paint is received.


createRepaintTimer

private Timer createRepaintTimer()

flushViewDirtyRegion

private void flushViewDirtyRegion(Graphics g)
If the repaint manager has a dirty region for the view, the view is asked to paint.

Parameters:
g - the Graphics context within which to paint

windowBlitPaint

private boolean windowBlitPaint(Graphics g)
Used when blitting.

Parameters:
g - the Graphics context within which to paint
Returns:
true if blitting succeeded; otherwise false

blitDoubleBuffered

private void blitDoubleBuffered(JComponent view,
                                Graphics g,
                                int clipX,
                                int clipY,
                                int clipW,
                                int clipH,
                                int blitFromX,
                                int blitFromY,
                                int blitToX,
                                int blitToY,
                                int blitW,
                                int blitH,
                                Image off)

paintView

private void paintView(Graphics g)
Called to paint the view, usually when blitPaint can not blit.

Parameters:
g - the Graphics context within which to paint

paintViewDoubleBuffered

private void paintViewDoubleBuffered(JComponent view,
                                     Graphics g,
                                     int clipX,
                                     int clipY,
                                     int clipW,
                                     int clipH,
                                     Image off)

blitWindowGraphics

private void blitWindowGraphics(int x,
                                int y,
                                int w,
                                int h,
                                int ox,
                                int oy)
Blits the parent windows graphics from the given region offset to ox, oy.


canUseWindowBlitter

private boolean canUseWindowBlitter()
Returns true if the viewport is not obscured by one of its ancestors, or its ancestors children and if the viewport is showing. Blitting when the view isn't showing will work, or rather copyArea will work, but will not produce the expected behavior.


getAccessibleContext

public AccessibleContext getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this JViewport. For viewports, the AccessibleContext takes the form of an AccessibleJViewport. A new AccessibleJViewport instance is created if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
Returns:
an AccessibleJViewport that serves as the AccessibleContext of this JViewport


comments?