_
+-------------------------------+ ...........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
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)
backingStore
protected boolean backingStore
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.
lastPaintPosition
protected Point lastPaintPosition
The position at which the view has been drawn the last time. This is used
to determine the bittable area.
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.
dx
- the horizontal deltady
- the vertical deltablitFrom
- the position from where to blit; set by this methodblitTo
- the position where to blit area is copied to; set by this
methodblitSize
- the size of the blitted area; set by this methodblitPaint
- the area that needs repainting; set by this method
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.
- a LayoutManager to use for this viewport
getUI
public ViewportUI getUI()
This method returns the viewport's UI delegate.
- The viewport's UI delegate.
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.
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.
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.
- isOptimizedDrawingEnabled in interface JComponent
paint
public void paint(Graphics g)
Paints this component on the screen. The clipping region in the graphics
context will indicate the region that requires painting. This is called
whenever the component first shows, or needs to be repaired because
something was temporarily drawn on top. It is not necessary for
subclasses to call super.paint(g)
. Components with no area
are not painted.
- paint in interface JComponent
g
- the graphics context for this paint job
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.
- repaint in interface JComponent
tm
- number of milliseconds to defer the repaint requestx
- the X coordinate of the upper left corner of the dirty areay
- the Y coordinate of the upper left corner of the dirty areaw
- the width of the dirty areah
- the height of the dirty area
reshape
public void reshape(int x,
int y,
int w,
int h)
use Component.setBounds(int,int,int,int)
instead
Sets the bounding rectangle for this component to the specified values.
Note that these coordinates are relative to the parent, not to the screen.
- reshape in interface JComponent
x
- the X coordinate of the upper left corner of the rectangley
- the Y coordinate of the upper left corner of the rectangle
setUI
public void setUI(ViewportUI ui)
This method sets the viewport's UI delegate.
ui
- The viewport's UI delegate.
JViewport.java --
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.