jdk/src/share/classes/javax/swing/JViewport.java

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.peer.ComponentPeer;

  31 import java.beans.Transient;
  32 import javax.swing.plaf.ViewportUI;
  33 
  34 import javax.swing.event.*;
  35 import javax.swing.border.*;
  36 import javax.accessibility.*;
  37 
  38 import java.io.Serializable;
  39 
  40 /**
  41  * The "viewport" or "porthole" through which you see the underlying
  42  * information. When you scroll, what moves is the viewport. It is like
  43  * peering through a camera's viewfinder. Moving the viewfinder upwards
  44  * brings new things into view at the top of the picture and loses
  45  * things that were at the bottom.
  46  * <p>
  47  * By default, <code>JViewport</code> is opaque. To change this, use the
  48  * <code>setOpaque</code> method.
  49  * <p>
  50  * <b>NOTE:</b>We have implemented a faster scrolling algorithm that


 281     }
 282 
 283 
 284 
 285     /**
 286      * Returns the L&amp;F object that renders this component.
 287      *
 288      * @return a <code>ViewportUI</code> object
 289      * @since 1.3
 290      */
 291     public ViewportUI getUI() {
 292         return (ViewportUI)ui;
 293     }
 294 
 295 
 296     /**
 297      * Sets the L&amp;F object that renders this component.
 298      *
 299      * @param ui  the <code>ViewportUI</code> L&amp;F object
 300      * @see UIDefaults#getUI
 301      * @beaninfo
 302      *        bound: true
 303      *       hidden: true
 304      *    attribute: visualUpdate true
 305      *  description: The UI object that implements the Component's LookAndFeel.
 306      * @since 1.3
 307      */


 308     public void setUI(ViewportUI ui) {
 309         super.setUI(ui);
 310     }
 311 
 312 
 313     /**
 314      * Resets the UI property to a value from the current look and feel.
 315      *
 316      * @see JComponent#updateUI
 317      */
 318     public void updateUI() {
 319         setUI((ViewportUI)UIManager.getUI(this));
 320     }
 321 
 322 
 323     /**
 324      * Returns a string that specifies the name of the L&amp;F class
 325      * that renders this component.
 326      *
 327      * @return the string "ViewportUI"


 570     /**
 571      * Returns the insets (border) dimensions as (0,0,0,0), since borders
 572      * are not supported on a <code>JViewport</code>.
 573      *
 574      * @return a <code>Rectangle</code> of zero dimension and zero origin
 575      * @see #setBorder
 576      */
 577     public final Insets getInsets() {
 578         return new Insets(0, 0, 0, 0);
 579     }
 580 
 581     /**
 582      * Returns an <code>Insets</code> object containing this
 583      * <code>JViewport</code>s inset values.  The passed-in
 584      * <code>Insets</code> object will be reinitialized, and
 585      * all existing values within this object are overwritten.
 586      *
 587      * @param insets the <code>Insets</code> object which can be reused
 588      * @return this viewports inset values
 589      * @see #getInsets
 590      * @beaninfo
 591      *   expert: true
 592      */

 593     public final Insets getInsets(Insets insets) {
 594         insets.left = insets.top = insets.right = insets.bottom = 0;
 595         return insets;
 596     }
 597 
 598 
 599     private Graphics getBackingStoreGraphics(Graphics g) {
 600         Graphics bsg = backingStoreImage.getGraphics();
 601         bsg.setColor(g.getColor());
 602         bsg.setFont(g.getFont());
 603         bsg.setClip(g.getClipBounds());
 604         return bsg;
 605     }
 606 
 607 
 608     private void paintViaBackingStore(Graphics g) {
 609         Graphics bsg = getBackingStoreGraphics(g);
 610         try {
 611             super.paint(bsg);
 612             g.drawImage(backingStoreImage, 0, 0, this);


 842         }
 843     }
 844 
 845 
 846     /**
 847       * Used to control the method of scrolling the viewport contents.
 848       * You may want to change this mode to get maximum performance for your
 849       * use case.
 850       *
 851       * @param mode one of the following values:
 852       * <ul>
 853       * <li> JViewport.BLIT_SCROLL_MODE
 854       * <li> JViewport.BACKINGSTORE_SCROLL_MODE
 855       * <li> JViewport.SIMPLE_SCROLL_MODE
 856       * </ul>
 857       *
 858       * @see #BLIT_SCROLL_MODE
 859       * @see #BACKINGSTORE_SCROLL_MODE
 860       * @see #SIMPLE_SCROLL_MODE
 861       *
 862       * @beaninfo
 863       *        bound: false
 864       *  description: Method of moving contents for incremental scrolls.
 865       *         enum: BLIT_SCROLL_MODE JViewport.BLIT_SCROLL_MODE
 866       *               BACKINGSTORE_SCROLL_MODE JViewport.BACKINGSTORE_SCROLL_MODE
 867       *               SIMPLE_SCROLL_MODE JViewport.SIMPLE_SCROLL_MODE
 868       *
 869       * @since 1.3
 870       */





 871     public void setScrollMode(int mode) {
 872         scrollMode = mode;
 873         backingStore = mode == BACKINGSTORE_SCROLL_MODE;
 874     }
 875 
 876     /**
 877       * Returns the current scrolling mode.
 878       *
 879       * @return the <code>scrollMode</code> property
 880       * @see #setScrollMode
 881       * @since 1.3
 882       */
 883     public int getScrollMode() {
 884         return scrollMode;
 885     }
 886 
 887     /**
 888      * Returns <code>true</code> if this viewport is maintaining
 889      * an offscreen image of its contents.
 890      *




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.peer.ComponentPeer;
  31 import java.beans.BeanProperty;
  32 import java.beans.Transient;
  33 import javax.swing.plaf.ViewportUI;
  34 
  35 import javax.swing.event.*;
  36 import javax.swing.border.*;
  37 import javax.accessibility.*;
  38 
  39 import java.io.Serializable;
  40 
  41 /**
  42  * The "viewport" or "porthole" through which you see the underlying
  43  * information. When you scroll, what moves is the viewport. It is like
  44  * peering through a camera's viewfinder. Moving the viewfinder upwards
  45  * brings new things into view at the top of the picture and loses
  46  * things that were at the bottom.
  47  * <p>
  48  * By default, <code>JViewport</code> is opaque. To change this, use the
  49  * <code>setOpaque</code> method.
  50  * <p>
  51  * <b>NOTE:</b>We have implemented a faster scrolling algorithm that


 282     }
 283 
 284 
 285 
 286     /**
 287      * Returns the L&amp;F object that renders this component.
 288      *
 289      * @return a <code>ViewportUI</code> object
 290      * @since 1.3
 291      */
 292     public ViewportUI getUI() {
 293         return (ViewportUI)ui;
 294     }
 295 
 296 
 297     /**
 298      * Sets the L&amp;F object that renders this component.
 299      *
 300      * @param ui  the <code>ViewportUI</code> L&amp;F object
 301      * @see UIDefaults#getUI





 302      * @since 1.3
 303      */
 304     @BeanProperty(hidden = true, visualUpdate = true, description
 305             = "The UI object that implements the Component's LookAndFeel.")
 306     public void setUI(ViewportUI ui) {
 307         super.setUI(ui);
 308     }
 309 
 310 
 311     /**
 312      * Resets the UI property to a value from the current look and feel.
 313      *
 314      * @see JComponent#updateUI
 315      */
 316     public void updateUI() {
 317         setUI((ViewportUI)UIManager.getUI(this));
 318     }
 319 
 320 
 321     /**
 322      * Returns a string that specifies the name of the L&amp;F class
 323      * that renders this component.
 324      *
 325      * @return the string "ViewportUI"


 568     /**
 569      * Returns the insets (border) dimensions as (0,0,0,0), since borders
 570      * are not supported on a <code>JViewport</code>.
 571      *
 572      * @return a <code>Rectangle</code> of zero dimension and zero origin
 573      * @see #setBorder
 574      */
 575     public final Insets getInsets() {
 576         return new Insets(0, 0, 0, 0);
 577     }
 578 
 579     /**
 580      * Returns an <code>Insets</code> object containing this
 581      * <code>JViewport</code>s inset values.  The passed-in
 582      * <code>Insets</code> object will be reinitialized, and
 583      * all existing values within this object are overwritten.
 584      *
 585      * @param insets the <code>Insets</code> object which can be reused
 586      * @return this viewports inset values
 587      * @see #getInsets


 588      */
 589     @BeanProperty(expert = true)
 590     public final Insets getInsets(Insets insets) {
 591         insets.left = insets.top = insets.right = insets.bottom = 0;
 592         return insets;
 593     }
 594 
 595 
 596     private Graphics getBackingStoreGraphics(Graphics g) {
 597         Graphics bsg = backingStoreImage.getGraphics();
 598         bsg.setColor(g.getColor());
 599         bsg.setFont(g.getFont());
 600         bsg.setClip(g.getClipBounds());
 601         return bsg;
 602     }
 603 
 604 
 605     private void paintViaBackingStore(Graphics g) {
 606         Graphics bsg = getBackingStoreGraphics(g);
 607         try {
 608             super.paint(bsg);
 609             g.drawImage(backingStoreImage, 0, 0, this);


 839         }
 840     }
 841 
 842 
 843     /**
 844       * Used to control the method of scrolling the viewport contents.
 845       * You may want to change this mode to get maximum performance for your
 846       * use case.
 847       *
 848       * @param mode one of the following values:
 849       * <ul>
 850       * <li> JViewport.BLIT_SCROLL_MODE
 851       * <li> JViewport.BACKINGSTORE_SCROLL_MODE
 852       * <li> JViewport.SIMPLE_SCROLL_MODE
 853       * </ul>
 854       *
 855       * @see #BLIT_SCROLL_MODE
 856       * @see #BACKINGSTORE_SCROLL_MODE
 857       * @see #SIMPLE_SCROLL_MODE
 858       *







 859       * @since 1.3
 860       */
 861     @BeanProperty(bound = false, enumerationValues = {
 862             "JViewport.BLIT_SCROLL_MODE",
 863             "JViewport.BACKINGSTORE_SCROLL_MODE",
 864             "JViewport.SIMPLE_SCROLL_MODE"}, description
 865             = "Method of moving contents for incremental scrolls.")
 866     public void setScrollMode(int mode) {
 867         scrollMode = mode;
 868         backingStore = mode == BACKINGSTORE_SCROLL_MODE;
 869     }
 870 
 871     /**
 872       * Returns the current scrolling mode.
 873       *
 874       * @return the <code>scrollMode</code> property
 875       * @see #setScrollMode
 876       * @since 1.3
 877       */
 878     public int getScrollMode() {
 879         return scrollMode;
 880     }
 881 
 882     /**
 883      * Returns <code>true</code> if this viewport is maintaining
 884      * an offscreen image of its contents.
 885      *