⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jviewport.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* 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 modifyit under the terms of the GNU General Public License as published bythe 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, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Component;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Image;import java.awt.Insets;import java.awt.LayoutManager;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.io.Serializable;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.swing.border.Border;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.plaf.ViewportUI;/** *   * <pre> *                                                     _ *   +-------------------------------+    ...........Y1 \ *   |  view                         |                .  \ *   |  (this component's child)     |                .   > VY *   |                               |                .  / = Y2-Y1 *   |         +------------------------------+  ....Y2_/ *   |         | viewport            |        |       . *   |         | (this component)    |        |       . *   |         |                     |        |       . *   |         |                     |        |       . *   |         |                     |        |       . *   |         |                     |        |       . *   |         +------------------------------+  ....Y3 *   |                               |                . *   |         .                     |        .       . *   |         .                     |        .       . *   +---------.---------------------+    ...........Y4 *   .         .                     .        . *   .         .                     .        . *   .         .                     .        . *   X1.......X2.....................X3.......X4 *   \____  ___/ *        \/ *        VX = X2-X1 *</pre> *   * <p>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".</p> * * <p>But in terms of drawing its child, the viewport thinks of itself as * covering a particular position <em>of the view's coordinate space</em>. * For example, the {@link #getViewPosition} method returns * the position <code>(VX,VY)</code> shown above, which is an position in * "view space", even though this is <em>implemented</em> by positioning * the underlying child at position <code>(-VX,-VY)</code></p> * */public class JViewport extends JComponent implements Accessible{  /**   * Provides accessibility support for <code>JViewport</code>.   *   * @author Roman Kennke (roman@kennke.org)   */  protected class AccessibleJViewport extends AccessibleJComponent  {    /**     * Creates a new instance of <code>AccessibleJViewport</code>.     */    public AccessibleJViewport()    {      // Nothing to do here.    }    /**     * Returns the accessible role of <code>JViewport</code>, which is     * {@link AccessibleRole#VIEWPORT}.     *     * @return the accessible role of <code>JViewport</code>     */    public AccessibleRole getAccessibleRole()    {      return AccessibleRole.VIEWPORT;    }  }  /**   * A {@link java.awt.event.ComponentListener} that listens for   * changes of the view's size. This triggers a revalidate() call on the   * viewport.   */  protected class ViewListener extends ComponentAdapter implements Serializable  {    private static final long serialVersionUID = -2812489404285958070L;    /**     * Creates a new instance of ViewListener.     */    protected ViewListener()    {      // Nothing to do here.    }    /**     * Receives notification when a component (in this case: the view     * component) changes it's size. This simply triggers a revalidate() on the     * viewport.     *     * @param ev the ComponentEvent describing the change     */    public void componentResized(ComponentEvent ev)    {      revalidate();    }  }  public static final int SIMPLE_SCROLL_MODE = 0;  public static final int BLIT_SCROLL_MODE = 1;  public static final int BACKINGSTORE_SCROLL_MODE = 2;  private static final long serialVersionUID = -6925142919680527970L;    protected boolean scrollUnderway;  protected boolean isViewSizeSet;  /**   * This flag indicates whether we use a backing store for drawing.   *   * @deprecated since JDK 1.3   */  protected boolean backingStore;  /**   * The backingstore image used for the backingstore and blit scroll methods.   */  protected Image backingStoreImage;  /**   * The position at which the view has been drawn the last time. This is used   * to determine the bittable area.   */  protected Point lastPaintPosition;  ChangeEvent changeEvent = new ChangeEvent(this);  int scrollMode;  /**    * The width and height of the Viewport's area in terms of view   * coordinates.  Typically this will be the same as the width and height   * of the viewport's bounds, unless the viewport transforms units of   * width and height, which it may do, for example if it magnifies or   * rotates its view.   *   * @see #toViewCoordinates(Dimension)   */  Dimension extentSize;  /**   * The width and height of the view in its own coordinate space.   */  Dimension viewSize;  /**   * The ViewListener instance.   */  ViewListener viewListener;  /**   * Stores the location from where to blit. This is a cached Point object used   * in blitting calculations.   */  Point cachedBlitFrom;  /**   * Stores the location where to blit to. This is a cached Point object used   * in blitting calculations.   */  Point cachedBlitTo;  /**   * Stores the width of the blitted area. This is a cached Dimension object   * used in blitting calculations.   */  Dimension cachedBlitSize;  /**   * Stores the bounds of the area that needs to be repainted. This is a cached   * Rectangle object used in blitting calculations.    */  Rectangle cachedBlitPaint;  boolean damaged = true;  /**   * A flag indicating if the size of the viewport has changed since the   * last repaint. This is used in double buffered painting to check if we   * need a new double buffer, or can reuse the old one.   */  boolean sizeChanged = true;  public JViewport()  {    setOpaque(true);    String scrollModeProp =      System.getProperty("gnu.javax.swing.JViewport.scrollMode",                         "BLIT");    int myScrollMode;    if (scrollModeProp.equalsIgnoreCase("simple"))      myScrollMode = SIMPLE_SCROLL_MODE;    else if (scrollModeProp.equalsIgnoreCase("backingstore"))      myScrollMode = BACKINGSTORE_SCROLL_MODE;    else      myScrollMode = BLIT_SCROLL_MODE;    setScrollMode(myScrollMode);    updateUI();    setLayout(createLayoutManager());    lastPaintPosition = new Point();    cachedBlitFrom = new Point();    cachedBlitTo = new Point();    cachedBlitSize = new Dimension();    cachedBlitPaint = new Rectangle();  }  public Dimension getExtentSize()  {    if (extentSize == null)      return toViewCoordinates(getSize());    else      return extentSize;  }  public Dimension toViewCoordinates(Dimension size)  {    return size;  }  public Point toViewCoordinates(Point p)  {    Point pos = getViewPosition();    return new Point(p.x + pos.x,                     p.y + pos.y);  }  public void setExtentSize(Dimension newSize)  {    extentSize = newSize;    fireStateChanged();  }  /**   * 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.   */  public Dimension getViewSize()  {    if (isViewSizeSet)      return viewSize;    else      {	Component view = getView();	if (view != null)	  return view.getPreferredSize();	else	  return new Dimension();      }  }  public void setViewSize(Dimension newSize)  {    viewSize = newSize;    Component view = getView();    if (view != null)      {        if (newSize != view.getSize())          {            view.setSize(viewSize);            fireStateChanged();          }      }    isViewSizeSet = true;  }  /**   * 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.   */  public Point getViewPosition()  {    Component view = getView();    if (view == null)      return new Point(0,0);    else      {        Point p = view.getLocation();        p.x = -p.x;        p.y = -p.y;        return p;      }  }  public void setViewPosition(Point p)  {    if (getViewPosition().equals(p))      return;    Component view = getView();    if (view != null)      {        Point q = new Point(-p.x, -p.y);        view.setLocation(q);        isViewSizeSet = false;        fireStateChanged();      }    repaint();  }  public Rectangle getViewRect()  {    return new Rectangle(getViewPosition(),                          getExtentSize());  }  /**   * @deprecated 1.4   */  public boolean isBackingStoreEnabled()  {    return scrollMode == BACKINGSTORE_SCROLL_MODE;  }  /**   * @deprecated 1.4   */  public void setBackingStoreEnabled(boolean b)  {    if (b && scrollMode != BACKINGSTORE_SCROLL_MODE)      {        scrollMode = BACKINGSTORE_SCROLL_MODE;        fireStateChanged();      }  }  public void setScrollMode(int mode)  {    scrollMode = mode;    fireStateChanged();  }  public int getScrollMode()  {    return scrollMode;  }  public Component getView()  {    if (getComponentCount() == 0)      return null;      return getComponents()[0];  }  public void setView(Component v)  {    if (viewListener != null)      getView().removeComponentListener(viewListener);    if (v != null)      {        if (viewListener == null)          viewListener = createViewListener();        v.addComponentListener(viewListener);        add(v);        fireStateChanged();      }    revalidate();    repaint();  }  public void reshape(int x, int y, int w, int h)  {    if (w != getWidth() || h != getHeight())      sizeChanged = true;    super.reshape(x, y, w, h);    if (sizeChanged)      {        damaged = true;        fireStateChanged();      }  }  public final Insets getInsets()  {    return new Insets(0, 0, 0, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -