/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.accessibility.*;
/**
* The "viewport" or "porthole" through which you see the underlying
* information. When you scroll, what moves is the viewport. It is like
* peering through a camera's viewfinder. Moving the viewfinder upwards
* brings new things into view at the top of the picture and loses
* things that were at the bottom.
* <p>
* By default, <code>JViewport</code> is opaque. To change this, use the
* <code>setOpaque</code> method.
* <p>
* <b>NOTE:</b>We have implemented a faster scrolling algorithm that
* does not require a buffer to draw in. The algorithm works as follows:
* <ol><li>The view and parent view and checked to see if they are
* <code>JComponents</code>,
* if they aren't, stop and repaint the whole viewport.
* <li>If the viewport is obscured by an ancestor, stop and repaint the whole
* viewport.
* <li>Compute the region that will become visible, if it is as big as
* the viewport, stop and repaint the whole view region.
* <li>Obtain the ancestor <code>Window</code>'s graphics and
* do a <code>copyArea</code> on the scrolled region.
* <li>Message the view to repaint the newly visible region.
* <li>The next time paint is invoked on the viewport, if the clip region
* is smaller than the viewport size a timer is kicked off to repaint the
* whole region.
* </ol>
* In general this approach is much faster. Compared to the backing store
* approach this avoids the overhead of maintaining an offscreen buffer and
* having to do two <code>copyArea</code>s.
* Compared to the non backing store case this
* approach will greatly reduce the painted region.
* <p>
* This approach can cause slower times than the backing store approach
* when the viewport is obscured by another window, or partially offscreen.
* When another window
* obscures the viewport the copyArea will copy garbage and a
* paint event will be generated by the system to inform us we need to
* paint the newly exposed region. The only way to handle this is to
* repaint the whole viewport, which can cause slower performance than the
* backing store case. In most applications very rarely will the user be
* scrolling while the viewport is obscured by another window or offscreen,
* so this optimization is usually worth the performance hit when obscured.
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
* href="package-summary.html#threading">Swing's Threading
* Policy</a>.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Hans Muller
* @author Philip Milne
* @see JScrollPane
*/
{
/**
* @see #getUIClassID
* @see #readObject
*/
/** Property used to indicate window blitting should not be done.
*/
/**
* True when the viewport dimensions have been determined.
* The default is false.
*/
protected boolean isViewSizeSet = false;
/**
* The last <code>viewPosition</code> that we've painted, so we know how
* much of the backing store image is valid.
*/
/**
* 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 <code>false</code>.
*
* @deprecated As of Java 2 platform v1.3
* @see #setScrollMode
*/
protected boolean backingStore = false;
/** The view image used for a backing store. */
/**
* The <code>scrollUnderway</code> flag is used for components like
* <code>JList</code>. When the downarrow key is pressed on a
* <code>JList</code> and the selected
* cell is the last in the list, the <code>scrollpane</code> 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
* <code>setViewPosition(Point)</code>.
* When <code>setBounds</code> is called through other routes,
* the flag is off and the view repaints normally. Another approach
* would be to remove this from the <code>JViewport</code>
* class and have the <code>JList</code> manage this case by using
* <code>setBackingStoreEnabled</code>. The default is
* <code>false</code>.
*/
protected boolean scrollUnderway = false;
/*
* Listener that is notified each time the view changes size.
*/
/* Only one <code>ChangeEvent</code> is needed per
* <code>JViewport</code> instance since the
* event's only (read-only) state is the source property. The source
* of events generated here is always "this".
*/
/**
* Use <code>graphics.copyArea</code> to implement scrolling.
* This is the fastest for most applications.
*
* @see #setScrollMode
* @since 1.3
*/
/**
* Draws viewport contents into an offscreen image.
* This was previously the default mode for <code>JTable</code>.
* This mode may offer advantages over "blit mode"
* in some cases, but it requires a large chunk of extra RAM.
*
* @see #setScrollMode
* @since 1.3
*/
/**
* 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.
*
* @see #setScrollMode
* @since 1.3
*/
/**
* @see #setScrollMode
* @since 1.3
*/
//
// Window blitting:
//
// As mentioned in the javadoc when using windowBlit a paint event
// will be generated by the system if copyArea copies a non-visible
// portion of the view (in other words, it copies garbage). We are
// not guaranteed to receive the paint event before other mouse events,
// so we can not be sure we haven't already copied garbage a bunch of
// times to different parts of the view. For that reason when a blit
// happens and the Component is obscured (the check for obscurity
// is not supported on all platforms and is checked via ComponentPeer
// methods) the ivar repaintAll is set to true. When paint is received
// if repaintAll is true (we previously did a blit) it is set to
// false, and if the clip region is smaller than the viewport
// waitingForRepaint is set to true and a timer is started. When
// the timer fires if waitingForRepaint is true, repaint is invoked.
// In the mean time, if the view is asked to scroll and waitingForRepaint
// is true, a blit will not happen, instead the non-backing store case
// of scrolling will happen, which will reset waitingForRepaint.
// waitingForRepaint is set to false in paint when the clip rect is
// bigger (or equal) to the size of the viewport.
// A Timer is used instead of just a repaint as it appeared to offer
// better performance.
/**
* This is set to true in <code>setViewPosition</code>
* if doing a window blit and the viewport is obscured.
*/
private transient boolean repaintAll;
/**
* This is set to true in paint, if <code>repaintAll</code>
* 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.
*/
private transient boolean waitingForRepaint;
/**
* Instead of directly invoking repaint, a <code>Timer</code>
* is started and when it fires, repaint is invoked.
*/
/**
* Set to true in paintView when paint is invoked.
*/
private transient boolean inBlitPaint;
/**
* Whether or not a valid view has been installed.
*/
private boolean hasHadValidView;
/**
* When view is changed we have to synchronize scrollbar values
* with viewport (see the BasicScrollPaneUI#syncScrollPaneWithViewport method).
* This flag allows to invoke that method while ScrollPaneLayout#layoutContainer
* is running.
*/
private boolean viewChanged;
/** Creates a <code>JViewport</code>. */
public JViewport() {
super();
setOpaque(true);
updateUI();
setInheritsPopupMenu(true);
}
/**
* Returns the L&F object that renders this component.
*
* @return a <code>ViewportUI</code> object
* @since 1.3
*/
return (ViewportUI)ui;
}
/**
* Sets the L&F object that renders this component.
*
* @param ui the <code>ViewportUI</code> L&F object
* @see UIDefaults#getUI
* @beaninfo
* bound: true
* hidden: true
* attribute: visualUpdate true
* description: The UI object that implements the Component's LookAndFeel.
* @since 1.3
*/
}
/**
* Resets the UI property to a value from the current look and feel.
*
* @see JComponent#updateUI
*/
public void updateUI() {
}
/**
* Returns a string that specifies the name of the L&F class
* that renders this component.
*
* @return the string "ViewportUI"
*
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
return uiClassID;
}
/**
* Sets the <code>JViewport</code>'s one lightweight child,
* which can be <code>null</code>.
* (Since there is only one child which occupies the entire viewport,
* the <code>constraints</code> and <code>index</code>
* arguments are ignored.)
*
* @param child the lightweight <code>child</code> of the viewport
* @param constraints the <code>constraints</code> to be respected
* @param index the index
* @see #setView
*/
}
/**
* Removes the <code>Viewport</code>s one lightweight child.
*
* @see #setView
*/
}
/**
* Scrolls the view so that <code>Rectangle</code>
* within the view becomes visible.
* <p>
* This attempts to validate the view before scrolling if the
* view is currently not valid - <code>isValid</code> 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 <code>Window</code> or <code>Applet</code>.
* <p>
* Note that this method will not scroll outside of the
* valid viewport; for example, if <code>contentRect</code> is larger
* than the viewport, scrolling will be confined to the viewport's
* bounds.
*
* @param contentRect the <code>Rectangle</code> to display
* @see JComponent#isValidateRoot
* @see java.awt.Component#isValid
* @see java.awt.Component#getPeer
*/
return;
} else {
// If the view is not valid, validate. scrollRectToVisible
// may fail if the view is not valid first, contentRect
// could be bigger than invalid size.
validateView();
}
int startX = viewPosition.x;
int startY = viewPosition.y;
viewPosition.x -= dx;
viewPosition.y -= dy;
// Only constrain the location if the view is valid. If the
// the view isn't valid, it typically indicates the view
// isn't visible yet and most likely has a bogus size as will
// we, and therefore we shouldn't constrain the scrolling
} else if (viewPosition.x < 0) {
viewPosition.x = 0;
}
} else {
} else {
}
}
}
else if (viewPosition.y < 0) {
viewPosition.y = 0;
}
}
// NOTE: How JViewport currently works with the
// backing store is not foolproof. The sequence of
// events when setViewPosition
// (scrollRectToVisible) is called is to reset the
// views bounds, which causes a repaint on the
// visible region and sets an ivar indicating
// scrolling (scrollUnderway). When
// JViewport.paint is invoked if scrollUnderway is
// true, the backing store is blitted. This fails
// if between the time setViewPosition is invoked
// and paint is received another repaint is queued
// indicating part of the view is invalid. There
// is no way for JViewport to notice another
// repaint has occured and it ends up blitting
// what is now a dirty region and the repaint is
// never delivered.
// It just so happens JTable encounters this
// behavior by way of scrollRectToVisible, for
// this reason scrollUnderway is set to false
// here, which effectively disables the backing
// store.
scrollUnderway = false;
}
}
}
}
/**
* Ascends the <code>Viewport</code>'s parents stopping when
* a component is found that returns
* <code>true</code> to <code>isValidateRoot</code>.
* If all the <code>Component</code>'s parents are visible,
* <code>validate</code> will then be invoked on it. The
* <code>RepaintManager</code> is then invoked with
* <code>removeInvalidComponent</code>. This
* is the synchronous version of a <code>revalidate</code>.
*/
private void validateView() {
if (validateRoot == null) {
return;
}
// Validate the root.
// And let the RepaintManager it does not have to validate from
// validateRoot anymore.
}
}
/* Used by the scrollRectToVisible method to determine the
* proper direction and amount to move by. The integer variables are named
* width, but this method is applicable to height also. The code assumes that
* parentWidth/childWidth are positive and childAt can be negative.
*/
// +-----+
// | --- | No Change
// +-----+
return 0;
}
// +-----+
// --------- No Change
// +-----+
return 0;
}
// +-----+ +-----+
// | ---- -> | ----|
// +-----+ +-----+
}
// +-----+ +-----+
// | -------- -> |--------
// +-----+ +-----+
return -childAt;
}
// +-----+ +-----+
// ---- | -> |---- |
// +-----+ +-----+
return -childAt;
}
// +-----+ +-----+
//-------- | -> --------|
// +-----+ +-----+
}
return 0;
}
/**
* The viewport "scrolls" its child (called the "view") by the
* the opposite direction of the scroll). A non-<code>null</code> 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 <code>JViewport</code> with a border,
* add it to a <code>JPanel</code> that has a border.
* <p>Note: If <code>border</code> is non-<code>null</code>, this
* method will throw an exception as borders are not supported on
* a <code>JViewPort</code>.
*
* @param border the <code>Border</code> to set
* @exception IllegalArgumentException this method is not implemented
*/
throw new IllegalArgumentException("JViewport.setBorder() not supported");
}
}
/**
* Returns the insets (border) dimensions as (0,0,0,0), since borders
* are not supported on a <code>JViewport</code>.
*
* @return a <code>Rectange</code> of zero dimension and zero origin
* @see #setBorder
*/
}
/**
* Returns an <code>Insets</code> object containing this
* <code>JViewport</code>s inset values. The passed-in
* <code>Insets</code> object will be reinitialized, and
* all existing values within this object are overwritten.
*
* @param insets the <code>Insets</code> object which can be reused
* @return this viewports inset values
* @see #getInsets
* @beaninfo
* expert: true
*/
return insets;
}
return bsg;
}
try {
} finally {
}
}
try {
} finally {
}
}
/**
* The <code>JViewport</code> overrides the default implementation of
* this method (in <code>JComponent</code>) to return false.
* This ensures
* that the drawing machinery will call the <code>Viewport</code>'s
* <code>paint</code>
* implementation rather than messaging the <code>JViewport</code>'s
* children directly.
*
* @return false
*/
public boolean isOptimizedDrawingEnabled() {
return false;
}
/**
* Returns true if scroll mode is a {@code BACKINGSTORE_SCROLL_MODE} to cause
* painting to originate from {@code JViewport}, or one of its
* ancestors. Otherwise returns {@code false}.
*
* @return true if if scroll mode is a {@code BACKINGSTORE_SCROLL_MODE}.
* @see JComponent#isPaintingOrigin()
*/
protected boolean isPaintingOrigin() {
return scrollMode == BACKINGSTORE_SCROLL_MODE;
}
/**
* Only used by the paint method below.
*/
return view.getLocation();
}
else {
}
}
/**
* Depending on whether the <code>backingStore</code> 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.
* <blockquote>
* 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.)
* </blockquote>
*
* @param g the <code>Graphics</code> context within which to paint
*/
{
return;
}
if (inBlitPaint) {
// We invoked paint as part of copyArea cleanup, let it through.
super.paint(g);
return;
}
if (repaintAll) {
repaintAll = false;
waitingForRepaint = true;
if (repaintTimer == null) {
}
repaintTimer.stop();
// We really don't need to paint, a future repaint will
// take care of it, but if we don't we get an ugly flicker.
}
else {
if (repaintTimer != null) {
repaintTimer.stop();
}
waitingForRepaint = false;
}
}
else if (waitingForRepaint) {
// Need a complete repaint before resetting waitingForRepaint
waitingForRepaint = false;
repaintTimer.stop();
}
}
super.paint(g);
return;
}
// If the view is smaller than the viewport and we are not opaque
// (that is, we won't paint our background), we should set the
// clip. Otherwise, as the bounds of the view vary, we will
// blit garbage into the exposed areas.
if (!isOpaque()) {
}
if (backingStoreImage == null) {
// Backing store is enabled but this is the first call to paint.
// Create the backing store, paint it and then copy to g.
// The backing store image will be created with the size of
// the viewport. We must make sure the clip region is the
// same size, otherwise when scrolling the backing image
// the region outside of the clipped region will not be painted,
// and result in empty areas.
if (!isOpaque()) {
}
else {
}
paintViaBackingStore(g, clip);
}
else {
}
}
else {
// No scrolling happened: repaint required area via backing store.
} else {
// The image was scrolled. Manipulate the backing store and flush it to g.
if (!canBlit) {
// The image was either moved diagonally or
// moved by more than the image size: paint normally.
} else {
// Move the relevant part of the backing store.
// We don't want to inherit the clip region when copying
// bits, if it is inherited it will result in not moving
// all of the image resulting in garbage appearing on
// the screen.
try {
// Paint the rest of the view; the part that has just been exposed.
// Copy whole of the backing store to g.
} finally {
}
}
}
}
scrollUnderway = false;
}
/**
* Sets the bounds of this viewport. If the viewport's width
* or height has changed, fire a <code>StateChanged</code> event.
*
* @param x left edge of the origin
* @param y top edge of the origin
* @param w width in pixels
* @param h height in pixels
*
* @see JComponent#reshape(int, int, int, int)
*/
public void reshape(int x, int y, int w, int h) {
if (sizeChanged) {
}
super.reshape(x, y, w, h);
if (sizeChanged || viewChanged) {
viewChanged = false;
}
}
/**
* 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.
*
* @param mode one of the following values:
* <ul>
* <li> JViewport.BLIT_SCROLL_MODE
* <li> JViewport.BACKINGSTORE_SCROLL_MODE
* <li> JViewport.SIMPLE_SCROLL_MODE
* </ul>
*
* @see #BLIT_SCROLL_MODE
* @see #BACKINGSTORE_SCROLL_MODE
* @see #SIMPLE_SCROLL_MODE
*
* @beaninfo
* bound: false
* description: Method of moving contents for incremental scrolls.
* enum: BLIT_SCROLL_MODE JViewport.BLIT_SCROLL_MODE
* BACKINGSTORE_SCROLL_MODE JViewport.BACKINGSTORE_SCROLL_MODE
* SIMPLE_SCROLL_MODE JViewport.SIMPLE_SCROLL_MODE
*
* @since 1.3
*/
scrollMode = mode;
}
/**
* Returns the current scrolling mode.
*
* @return the <code>scrollMode</code> property
* @see #setScrollMode
* @since 1.3
*/
public int getScrollMode() {
return scrollMode;
}
/**
* Returns <code>true</code> if this viewport is maintaining
* an offscreen image of its contents.
*
* @return <code>true</code> if <code>scrollMode</code> is
* <code>BACKINGSTORE_SCROLL_MODE</code>
*
* @deprecated As of Java 2 platform v1.3, replaced by
* <code>getScrollMode()</code>.
*/
public boolean isBackingStoreEnabled() {
return scrollMode == BACKINGSTORE_SCROLL_MODE;
}
/**
* 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 <code>viewPosition</code>.
* Rather than repainting the entire viewport we use
* <code>Graphics.copyArea</code> to effect some of the scroll.
*
* @param enabled if true, maintain an offscreen backing store
*
* @deprecated As of Java 2 platform v1.3, replaced by
* <code>setScrollMode()</code>.
*/
if (enabled) {
} else {
}
}
private boolean isBlitting() {
return (scrollMode == BLIT_SCROLL_MODE) &&
}
/**
* Returns the <code>JViewport</code>'s one child or <code>null</code>.
*
* @return the viewports child, or <code>null</code> if none exists
*
* @see #setView
*/
}
/**
* Sets the <code>JViewport</code>'s one lightweight child
* (<code>view</code>), which can be <code>null</code>.
*
* @param view the viewport's new lightweight child
*
* @see #getView
*/
/* Remove the viewport's existing children, if any.
* Note that removeAll() isn't used here because it
* doesn't call remove() (which JViewport overrides).
*/
int n = getComponentCount();
for(int i = n - 1; i >= 0; i--) {
remove(getComponent(i));
}
isViewSizeSet = false;
}
if (hasHadValidView) {
// Only fire a change if a view has been installed.
}
hasHadValidView = true;
}
viewChanged = true;
revalidate();
repaint();
}
/**
* 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.
*
* @return a <code>Dimension</code> object specifying the size of the view
*/
}
else if (isViewSizeSet) {
}
else {
return view.getPreferredSize();
}
}
/**
* Sets the size of the view. A state changed event will be fired.
*
* @param newSize a <code>Dimension</code> object specifying the new
* size of the view
*/
// scrollUnderway will be true if this is invoked as the
// result of a validate and setViewPosition was previously
// invoked.
scrollUnderway = false;
isViewSizeSet = true;
}
}
}
/**
* Returns the view coordinates that appear in the upper left
* hand corner of the viewport, or 0,0 if there's no view.
*
* @return a <code>Point</code> object giving the upper left coordinates
*/
p.x = -p.x;
p.y = -p.y;
return p;
}
else {
}
}
/**
* Sets the view coordinates that appear in the upper left
* hand corner of the viewport, does nothing if there's no view.
*
* @param p a <code>Point</code> object giving the upper left coordinates
*/
{
return;
}
/* Collect the old x,y values for the views location
* and do the song and dance to avoid allocating
* a Rectangle object if we don't have to.
*/
if (view instanceof JComponent) {
}
else {
oldX = r.x;
oldY = r.y;
}
/* The view scrolls in the opposite direction to mouse
* movement.
*/
int newX = -x;
int newY = -y;
// The cast to JComponent will work, if view is not
// a JComponent, isBlitting will return false.
rm.beginPaint();
try {
// Repaint the complete component if the blit succeeded
// and needsRepaintAfterBlit returns true.
repaintAll = (windowBlitPaint(g) &&
g.dispose();
rm.markCompletelyClean(this);
} finally {
}
}
else {
// The visible region is dirty, no point in doing copyArea
repaintAll = false;
}
}
else {
scrollUnderway = true;
// This calls setBounds(), and then repaint().
repaintAll = false;
}
revalidate();
}
}
/**
* Returns a rectangle whose origin is <code>getViewPosition</code>
* and size is <code>getExtentSize</code>.
* This is the visible part of the view, in view coordinates.
*
* @return a <code>Rectangle</code> giving the visible part of
* the view using view coordinates.
*/
}
/**
* Computes the parameters for a blit where the backing store image
* currently contains <code>oldLoc</code> in the upper left hand corner
* and we're scrolling to <code>newLoc</code>.
* The parameters are modified
* to return the values required for the blit.
*
* @param dx the horizontal delta
* @param dy the vertical delta
* @param blitFrom the <code>Point</code> we're blitting from
* @param blitTo the <code>Point</code> we're blitting to
* @param blitSize the <code>Dimension</code> of the area to blit
* @param blitPaint the area to blit
* @return true if the parameters are modified and we're ready to blit;
* false otherwise
*/
protected boolean computeBlit(
int dx,
int dy,
{
if (dy < 0) {
blitTo.y = 0;
}
else {
blitFrom.y = 0;
blitPaint.y = 0;
}
return true;
}
if (dx < 0) {
blitTo.x = 0;
}
else {
blitFrom.x = 0;
blitPaint.x = 0;
}
return true;
}
else {
return false;
}
}
/**
* Returns the size of the visible part of the view in view coordinates.
*
* @return a <code>Dimension</code> object giving the size of the view
*/
return getSize();
}
/**
* Converts a size in pixel coordinates to view coordinates.
* Subclasses of viewport that support "logical coordinates"
* will override this method.
*
* @param size a <code>Dimension</code> object using pixel coordinates
* @return a <code>Dimension</code> object converted to view coordinates
*/
}
/**
* Converts a point in pixel coordinates to view coordinates.
* Subclasses of viewport that support "logical coordinates"
* will override this method.
*
* @param p a <code>Point</code> object using pixel coordinates
* @return a <code>Point</code> object converted to view coordinates
*/
return new Point(p);
}
/**
* Sets the size of the visible part of the view using view coordinates.
*
* @param newExtent a <code>Dimension</code> object specifying
* the size of the view
*/
}
}
/**
* A listener for the view.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
{
revalidate();
}
}
/**
* Creates a listener for the view.
* @return a <code>ViewListener</code>
*/
return new ViewListener();
}
/**
* Subclassers can override this to install a different
* layout manager (or <code>null</code>) in the constructor. Returns
* the <code>LayoutManager</code> to install on the <code>JViewport</code>.
*
* @return a <code>LayoutManager</code>
*/
return ViewportLayout.SHARED_INSTANCE;
}
/**
* Adds a <code>ChangeListener</code> to the list that is
* notified each time the view's
* size, position, or the viewport's extent size has changed.
*
* @param l the <code>ChangeListener</code> to add
* @see #removeChangeListener
* @see #setViewPosition
* @see #setViewSize
* @see #setExtentSize
*/
}
/**
* Removes a <code>ChangeListener</code> from the list that's notified each
* time the views size, position, or the viewports extent size
* has changed.
*
* @param l the <code>ChangeListener</code> to remove
* @see #addChangeListener
*/
}
/**
* Returns an array of all the <code>ChangeListener</code>s added
* to this JViewport with addChangeListener().
*
* @return all of the <code>ChangeListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
}
/**
* Notifies all <code>ChangeListeners</code> when the views
* size, position, or the viewports extent size has changed.
*
* @see #addChangeListener
* @see #removeChangeListener
* @see EventListenerList
*/
protected void fireStateChanged()
{
if (listeners[i] == ChangeListener.class) {
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
}
}
}
/**
* Always repaint in the parents coordinate system to make sure
* only one paint is performed by the <code>RepaintManager</code>.
*
* @param tm maximum time in milliseconds before update
* @param x the <code>x</code> coordinate (pixels over from left)
* @param y the <code>y</code> coordinate (pixels down from top)
* @param w the width
* @param h the height
* @see java.awt.Component#update(java.awt.Graphics)
*/
else
}
/**
* Returns a string representation of this <code>JViewport</code>.
* 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 <code>null</code>.
*
* @return a string representation of this <code>JViewport</code>
*/
"true" : "false");
"true" : "false");
return super.paramString() +
",isViewSizeSet=" + isViewSizeSetString +
",lastPaintPosition=" + lastPaintPositionString +
",scrollUnderway=" + scrollUnderwayString;
}
//
// Following is used when doBlit is true.
//
/**
* Notifies listeners of a property change. This is subclassed to update
* the <code>windowBlit</code> property.
* (The <code>putClientProperty</code> property is final).
*
* @param propertyName a string containing the property name
* @param oldValue the old value of the property
* @param newValue the new value of the property
*/
} else {
}
}
}
/**
* Returns true if the component needs to be completely repainted after
* a blit and a paint is received.
*/
private boolean needsRepaintAfterBlit() {
// Find the first heavy weight ancestor. isObscured and
// canDetermineObscurity are only appropriate for heavy weights.
}
if (heavyParent != null) {
!peer.isObscured()) {
// The peer says we aren't obscured, therefore we can assume
// that we won't later be messaged to paint a portion that
// we tried to blit that wasn't valid.
// It is certainly possible that when we blited we were
// obscured, and by the time this is invoked we aren't, but the
// chances of that happening are pretty slim.
return false;
}
}
return true;
}
// waitingForRepaint will be false if a paint came down
// with the complete clip rect, in which case we don't
// have to cause a repaint.
if (waitingForRepaint) {
repaint();
}
}
});
timer.setRepeats(false);
return timer;
}
/**
* If the repaint manager has a dirty region for the view, the view is
* asked to paint.
*
* @param g the <code>Graphics</code> context within which to paint
*/
// Only happens in 1.2
}
clip = g.getClipBounds();
// Only paint the dirty region if it is visible.
paintView(g);
}
}
}
/**
* Used when blitting.
*
* @param g the <code>Graphics</code> context within which to paint
* @return true if blitting succeeded; otherwise false
*/
return false;
}
boolean retValue;
if (lastPaintPosition == null ||
paintView(g);
retValue = false;
} else {
// The image was scrolled. Manipulate the backing store and flush
// it to g.
if (!canBlit) {
paintView(g);
retValue = false;
} else {
// Prepare the rest of the view; the part that has just been
// exposed.
retValue = true;
}
}
return retValue;
}
//
// NOTE: the code below uses paintForceDoubleBuffered for historical
// reasons. If we're going to allow a blit we've already accounted for
// everything that paintImmediately and _paintImmediately does, for that
// reason we call into paintForceDoubleBuffered to diregard whether or
// not setDoubleBuffered(true) was invoked on the view.
//
// NOTE:
// not the views coordinate space.
// clip* are in the views coordinate space.
// Shift the scrolled region
if (g instanceof Graphics2D) {
}
false);
if (oldComposite != null) {
}
// Paint the newly exposed region.
g.translate(x, y);
g.translate(-x, -y);
}
/**
* Called to paint the view, usually when <code>blitPaint</code>
* can not blit.
*
* @param g the <code>Graphics</code> context within which to paint
*/
// Graphics is relative to JViewport, need to map to view's
// coordinates space.
g.translate(x, y);
g.translate(-x, -y);
}
else {
// To avoid any problems that may result from the viewport being
// bigger than the view we start painting from the viewport.
try {
inBlitPaint = true;
} finally {
inBlitPaint = false;
}
}
}
/**
* 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 <code>copyArea</code> will work,
* but will not produce the expected behavior.
*/
private boolean canUseWindowBlitter() {
!(getView() instanceof JComponent))) {
return false;
}
if (isPainting()) {
// We're in the process of painting, don't blit. If we were
// to blit we would draw on top of what we're already drawing,
// so bail.
return false;
}
// Part of the scrollpane needs to be repainted too, don't blit.
return false;
}
int x, y, w, h;
return false;
int index = 0;
if(comps[i] == lastParent) {
index = i - 1;
break;
}
}
while(index >= 0) {
return false;
index--;
}
}
clip.x += x;
clip.y += y;
lastParent = parent;
}
// No Window parent.
return false;
}
return true;
}
/////////////////
// Accessibility support
////////////////
/**
* 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.
*
* @return an AccessibleJViewport that serves as the
* AccessibleContext of this JViewport
*/
if (accessibleContext == null) {
accessibleContext = new AccessibleJViewport();
}
return accessibleContext;
}
/**
* This class implements accessibility support for the
* <code>JViewport</code> class. It provides an implementation of the
* Java Accessibility API appropriate to viewport user-interface elements.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
/**
* Get the role of this object.
*
* @return an instance of AccessibleRole describing the role of
* the object
*/
return AccessibleRole.VIEWPORT;
}
} // inner class AccessibleJViewport
}