javax.swing

Class JViewport

public class JViewport extends JComponent implements Accessible

                                                     _
   +-------------------------------+    ...........Y1 \
   |  view                         |                .  \
   |  (this component's child)     |                .   > VY
   |                               |                .  / = Y2-Y1
   |         +------------------------------+  ....Y2_/
   |         | viewport            |        |       .
   |         | (this component)    |        |       .
   |         |                     |        |       .
   |         |                     |        |       .
   |         |                     |        |       .
   |         |                     |        |       .
   |         +------------------------------+  ....Y3
   |                               |                .
   |         .                     |        .       .
   |         .                     |        .       .
   +---------.---------------------+    ...........Y4
   .         .                     .        .
   .         .                     .        .
   .         .                     .        .
   X1.......X2.....................X3.......X4
   \____  ___/
        \/
        VX = X2-X1

A viewport is, like all swing components, located at some position in the swing component tree; that location is exactly the same as any other components: the viewport's "bounds".

But in terms of drawing its child, the viewport thinks of itself as covering a particular position of the view's coordinate space. For example, the {@link #getViewPosition} method returns the position (VX,VY) shown above, which is an position in "view space", even though this is implemented by positioning the underlying child at position (-VX,-VY)

Nested Class Summary
protected classJViewport.AccessibleJViewport
Provides accessibility support for JViewport.
protected classJViewport.ViewListener
A {@link java.awt.event.ComponentListener} that listens for changes of the view's size.
Field Summary
protected booleanbackingStore
This flag indicates whether we use a backing store for drawing.
protected ImagebackingStoreImage
The backingstore image used for the backingstore and blit scroll methods.
static intBACKINGSTORE_SCROLL_MODE
static intBLIT_SCROLL_MODE
protected booleanisViewSizeSet
protected PointlastPaintPosition
The position at which the view has been drawn the last time.
protected booleanscrollUnderway
static intSIMPLE_SCROLL_MODE
Constructor Summary
JViewport()
Initializes the default setting for the scrollMode property.
Method Summary
voidaddChangeListener(ChangeListener listener)
protected voidaddImpl(Component comp, Object constraints, int index)
protected booleancomputeBlit(int dx, int dy, Point blitFrom, Point blitTo, Dimension blitSize, Rectangle blitPaint)
Computes the parameters for the blitting scroll method.
protected LayoutManagercreateLayoutManager()
Creates the LayoutManager that is used for this viewport.
protected JViewport.ViewListenercreateViewListener()
Creates a {@link ViewListener} that is supposed to listen for size changes on the view component.
protected voidfireStateChanged()
AccessibleContextgetAccessibleContext()
Returns the accessible context for this JViewport.
ChangeListener[]getChangeListeners()
DimensiongetExtentSize()
InsetsgetInsets()
InsetsgetInsets(Insets insets)
intgetScrollMode()
ViewportUIgetUI()
This method returns the viewport's UI delegate.
StringgetUIClassID()
This method returns the String ID of the UI class of Separator.
ComponentgetView()
PointgetViewPosition()
Get the viewport's position in view space.
RectanglegetViewRect()
DimensiongetViewSize()
Returns the viewSize when set, or the preferred size of the set Component view.
booleanisBackingStoreEnabled()
booleanisOptimizedDrawingEnabled()
Overridden to return false, so the JViewport's paint method gets called instead of directly calling the children.
voidpaint(Graphics g)
voidremoveChangeListener(ChangeListener listener)
voidrepaint(long tm, int x, int y, int w, int h)
Forward repaint to parent to make sure only one paint is performed by the RepaintManager.
voidreshape(int x, int y, int w, int h)
voidscrollRectToVisible(Rectangle contentRect)
Scrolls the view so that contentRect becomes visible.
voidsetBackingStoreEnabled(boolean b)
voidsetBorder(Border border)
voidsetExtentSize(Dimension newSize)
voidsetScrollMode(int mode)
voidsetUI(ViewportUI ui)
This method sets the viewport's UI delegate.
voidsetView(Component v)
voidsetViewPosition(Point p)
voidsetViewSize(Dimension newSize)
DimensiontoViewCoordinates(Dimension size)
PointtoViewCoordinates(Point p)
voidupdateUI()
This method resets the UI used to the Look and Feel defaults..

Field Detail

backingStore

protected boolean backingStore

Deprecated: since JDK 1.3

This flag indicates whether we use a backing store for drawing.

backingStoreImage

protected Image backingStoreImage
The backingstore image used for the backingstore and blit scroll methods.

BACKINGSTORE_SCROLL_MODE

public static final int BACKINGSTORE_SCROLL_MODE

BLIT_SCROLL_MODE

public static final int BLIT_SCROLL_MODE

isViewSizeSet

protected boolean isViewSizeSet

lastPaintPosition

protected Point lastPaintPosition
The position at which the view has been drawn the last time. This is used to determine the bittable area.

scrollUnderway

protected boolean scrollUnderway

SIMPLE_SCROLL_MODE

public static final int SIMPLE_SCROLL_MODE

Constructor Detail

JViewport

public JViewport()
Initializes the default setting for the scrollMode property.

Method Detail

addChangeListener

public void addChangeListener(ChangeListener listener)

addImpl

protected void addImpl(Component comp, Object constraints, int index)

computeBlit

protected boolean computeBlit(int dx, int dy, Point blitFrom, Point blitTo, Dimension blitSize, Rectangle blitPaint)
Computes the parameters for the blitting scroll method. dx and dy specifiy the X and Y offset by which the viewport is scrolled. All other arguments are output parameters and are filled by this method. blitFrom holds the position of the blit rectangle in the viewport rectangle before scrolling, blitTo where the blitArea is copied to. blitSize holds the size of the blit area and blitPaint is the area of the view that needs to be painted. This method returns true if blitting is possible and false if the viewport has to be repainted completetly without blitting.

Parameters: dx the horizontal delta dy the vertical delta blitFrom the position from where to blit; set by this method blitTo the position where to blit area is copied to; set by this method blitSize the size of the blitted area; set by this method blitPaint the area that needs repainting; set by this method

Returns: true if blitting is possible, false otherwise

createLayoutManager

protected LayoutManager createLayoutManager()
Creates the LayoutManager that is used for this viewport. Override this method if you want to use a custom LayoutManager.

Returns: a LayoutManager to use for this viewport

createViewListener

protected JViewport.ViewListener createViewListener()
Creates a {@link ViewListener} that is supposed to listen for size changes on the view component.

Returns: a ViewListener instance

fireStateChanged

protected void fireStateChanged()

getAccessibleContext

public AccessibleContext getAccessibleContext()
Returns the accessible context for this JViewport. This will be an instance of {@link AccessibleJViewport}.

Returns: the accessible context for this JViewport

getChangeListeners

public ChangeListener[] getChangeListeners()

getExtentSize

public Dimension getExtentSize()

getInsets

public final Insets getInsets()

getInsets

public final Insets getInsets(Insets insets)

getScrollMode

public int getScrollMode()

getUI

public ViewportUI getUI()
This method returns the viewport's UI delegate.

Returns: The viewport's UI delegate.

getUIClassID

public String getUIClassID()
This method returns the String ID of the UI class of Separator.

Returns: The UI class' String ID.

getView

public Component getView()

getViewPosition

public Point getViewPosition()
Get the viewport's position in view space. Despite confusing name, this really does return the viewport's (0,0) position in view space, not the view's position.

getViewRect

public Rectangle getViewRect()

getViewSize

public Dimension getViewSize()
Returns the viewSize when set, or the preferred size of the set Component view. If no viewSize and no Component view is set an empty Dimension is returned.

isBackingStoreEnabled

public boolean isBackingStoreEnabled()

Deprecated: 1.4

isOptimizedDrawingEnabled

public boolean isOptimizedDrawingEnabled()
Overridden to return false, so the JViewport's paint method gets called instead of directly calling the children. This is necessary in order to get a useful clipping and translation on the children.

Returns: false

paint

public void paint(Graphics g)

removeChangeListener

public void removeChangeListener(ChangeListener listener)

repaint

public void repaint(long tm, int x, int y, int w, int h)
Forward repaint to parent to make sure only one paint is performed by the RepaintManager.

Parameters: tm number of milliseconds to defer the repaint request x the X coordinate of the upper left corner of the dirty area y the Y coordinate of the upper left corner of the dirty area w the width of the dirty area h the height of the dirty area

reshape

public void reshape(int x, int y, int w, int h)

scrollRectToVisible

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

Parameters: contentRect the rectangle to make visible within the view

setBackingStoreEnabled

public void setBackingStoreEnabled(boolean b)

Deprecated: 1.4

setBorder

public final void setBorder(Border border)

setExtentSize

public void setExtentSize(Dimension newSize)

setScrollMode

public void setScrollMode(int mode)

setUI

public void setUI(ViewportUI ui)
This method sets the viewport's UI delegate.

Parameters: ui The viewport's UI delegate.

setView

public void setView(Component v)

setViewPosition

public void setViewPosition(Point p)

setViewSize

public void setViewSize(Dimension newSize)

toViewCoordinates

public Dimension toViewCoordinates(Dimension size)

toViewCoordinates

public Point toViewCoordinates(Point p)

updateUI

public void updateUI()
This method resets the UI used to the Look and Feel defaults..