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

📄 imgscrollpane.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*  * CVS identifier: *  * $Id: ImgScrollPane.java,v 1.10 2000/12/04 17:19:27 grosbois Exp $ *  * Class:                   ImgScrollPane *  * Description:             <short description of class> *  *  *  * COPYRIGHT: *  * This software module was originally developed by Rapha雔 Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askel鰂 (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, F閘ix Henry, Gerard Mozelle and Patrice Onno (Canon Research * Centre France S.A) in the course of development of the JPEG2000 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This * software module is an implementation of a part of the JPEG 2000 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio * Systems AB and Canon Research Centre France S.A (collectively JJ2000 * Partners) agree not to assert against ISO/IEC and users of the JPEG * 2000 Standard (Users) any of their rights under the copyright, not * including other intellectual property rights, for this software module * with respect to the usage by ISO/IEC and Users of this software module * or modifications thereof for use in hardware or software products * claiming conformance to the JPEG 2000 Standard. Those intending to use * this software module in hardware or software products are advised that * their use may infringe existing patents. The original developers of * this software module, JJ2000 Partners and ISO/IEC assume no liability * for use of this software module or modifications thereof. No license * or right to this software module is granted for non JPEG 2000 Standard * conforming products. JJ2000 Partners have full right to use this * software module for his/her own purpose, assign or donate this * software module to any third party and to inhibit third parties from * using this software module for non JPEG 2000 Standard conforming * products. This copyright notice must be included in all copies or * derivative works of this software module. *  * Copyright (c) 1999/2000 JJ2000 Partners. * */package jj2000.disp;import java.awt.event.*;import java.awt.image.*;import java.awt.*;/** * This class implements an image viewer that can display an image larger than * the actual display area, and presents scrollbars to scroll the viewable * area. This class also supports zooming in and out the image, with no extra * memory requirements. * * <P>The zoom factor by default is 1. It can be changed with the 'zoom()' and * 'setZoom()' methods. The maximum zoom factor is defined by MAX_ZOOM. * * <P>The zoom scaling is done directly by the AWT display system. In general * it is performed by dropping or repeating lines. It is just intended to * provide a display zoom and not for proper scaling of an image. * * <P>The scrolling can be performed by copying the actual displayed data to * the new scrolled position and redrawing the damaged parts, or by redrawing * the entire displayed image portion at the new scrolled position. Which is * more efficient depends on the JVM and working environment. By default it is * done by copying since it tends to provide less annoying visual artifacts * while scrolling, but that can be changed with 'setCopyScroll()'. * * <P>This class is very similar to the AWT ScrollPane one, but it is * optimized for display of large images and does not suffer from the problems * of ScrollPane when changing zoom. The Adjustable elements that represent * the scrollbars are made available as in ScrollPane, but the minimum, * maximum, visible amount and block increment should not be set * (IllegalArgumentException is thrown if attempted), since they are set * internally by this class. * * <P>Focus and key event listeners that are registered are in fact registered * with the components that implement the three areas (the image display and * the two scrollbars) so that if any such event is fired in any of these * areas it is handled by the registered listener. * * <P>Mouse and mouse movement event listeners that are registered are in fact  * registered with the image display component only. The mouse and mouse * movement events on the scrollbars are handled by the Scrollbar default * listeners only. * * <P>Although it is implemented as a container, it behaves like a * component. Specifically no components can be added or removed from objects * of this class. Furthermore, no layout manager can be set. It is internally * set and it can not be changed. * * <P>The implementation uses a lightweight container with an inner class to * display the image itself, and two scrollbars. The layout manager is a * BorderLayout. * * <P>This class should be really implemented as a Component, but it is * implemented as a Container for easyness. It should not be assumed it is a * subclass of Container since in the future it might be rewritten as a * subclass of Component only. * * * @see ScrollPane * * @see Adjustable * */public class ImgScrollPane extends Container {    /** The ID for always visible scrollbars */    public final static int SCROLLBARS_ALWAYS = ScrollPane.SCROLLBARS_ALWAYS;    /** The ID for as needed visible scrollbars */    public final static int SCROLLBARS_AS_NEEDED =        ScrollPane.SCROLLBARS_AS_NEEDED;    /** The ID for never visible scrollbars */    public final static int SCROLLBARS_NEVER = ScrollPane.SCROLLBARS_NEVER;    /** The maximum possible zoom factor: 32. */    // This is used because factors too large cause problems with JVMs.    public static final float MAX_ZOOM = 32f;    /** The thickness of the scrollbars: 16 pixels */    final static int SCROLLBAR_THICKNESS = 16;    /** The inetrnal gap between the elements, in pixels: 0 */    final static int INTERNAL_GAP = 0;    /** The propertion between the visible scrollbar length and the block     * increment amount: 0.8 */    final static float BLOCK_INCREMENT_PROPORTION = 0.8f;    /** The horizontal scrollbar.     *     * @serial     */    ISPScrollbar hsbar;    /** The vertical scrollabr.     *     * @serial     */    ISPScrollbar vsbar;    /** The image display     *     * @serial     */    private ImageScrollDisplay imgDisplay;    /** The scrollbar type (always, as needed, etc.)      *     * @serial     */    private int sbType;    /** The zoom to use in displaying the image. A factor larger than one     * produces a zoom in effect.      *     * @serial     */    private float zoom = 1f;    /** The zoom used in the last scrollbar calculation.     *     * @serial     */    private float lastZoom;    /** The viewable size used in the last scrollbar calculation.     *     * @serial     */    private Dimension lastSize;    /** If scrolling is to be done by copying ot not. If not done by copying     * everything is redrawn.      *     * @serial*/    private boolean copyScroll = true;    /**     * Creates a new ImgScrollPane with SCROLLBARS_AS_NEEDED scrollbars.     * */    public ImgScrollPane() {        this(SCROLLBARS_AS_NEEDED);    }    /**     * Creates a new ImgScrollPane with the specified type of scrollbar     * visibility.     *     * @param svt The scrollbar visibility type     * */    public ImgScrollPane(int svt) {        // Initialize        super.setLayout(new BorderLayout(INTERNAL_GAP,INTERNAL_GAP));        sbType = svt;        hsbar = new ISPScrollbar(Scrollbar.HORIZONTAL,0,1,0,1);        vsbar = new ISPScrollbar(Scrollbar.VERTICAL,0,1,0,1);        imgDisplay = new ImageScrollDisplay();        super.add(hsbar,BorderLayout.SOUTH);        super.add(vsbar,BorderLayout.EAST);        super.add(imgDisplay,BorderLayout.CENTER);        // Set the initial scrollbar visibility        switch (svt) {        case SCROLLBARS_NEVER:        case SCROLLBARS_AS_NEEDED:            hsbar.setVisible(false);            vsbar.setVisible(false);            break;        case SCROLLBARS_ALWAYS:            hsbar.setVisible(true);            vsbar.setVisible(true);            break;        default:            throw new IllegalArgumentException();        }    }    /**     * Sets the image to display in this component. If the image is not     * ready for display it will be prepared in the current thread. The     * current zoom factor applies.     *     * <P>If the image is not ready for display (i.e. it has not been     * rendered at its natural size) it will be rendered in the current     * thread, if not being already rendered in another one. This means     * that the current thread can block until the image is ready.     *     * <P>If the image is rendered incrementally (it depends on the     * underlying 'ImageProducer') it will be displayed in that way if the     * incremental display is set for the Component class. See the     * 'imageUpdate()' method of the 'Component' class.     *     * <P>If the image is the same as the current one nothing is done.     *     * @param img The image to display.     *     * @see Component#imageUpdate     * */    public void setImage(Image img) {        imgDisplay.setImage(img);    }    /**     * Returns the image that is displayed in this component.     *     * @return The image displayed in this component, or null if none.     * */    public synchronized Image getImage() {        return imgDisplay.img;    }    /**     * Sets the zoom factor to display the image. A zoom factor larger than 1     * corresponds to a zoom in. A factor of 1 corresponds to no     * scaling. After setting the zoom factor the component is invalidated and     * 'repaint()' is automatically called so that the image is redrawn at the     * new zoom factor. In order to revalidate the layout 'validate()' should     * be called on one of the parent containers. If the new zoom factor is     * larger than MAX_ZOOM, then MAX_ZOOM will be used.     *     * @param zf The zoom factor     * */    public synchronized void setZoom(float zf) {        if (zf == zoom || (zf > MAX_ZOOM && zoom == MAX_ZOOM)) {            // No change => do nothing            return;        }        // Set the zoom factor and recalculate the component dimensions        zoom = zf;        if (zoom > MAX_ZOOM) zoom = MAX_ZOOM;        setScrollbars();        // Check if we need to change the scrollbar display        if (sbType == SCROLLBARS_AS_NEEDED) doLayout();        // We need to erase previous scaled image        imgDisplay.erase = true;        // Redraw image        imgDisplay.repaint();    }    /**     * Modifies the current zoom factor by the given multiplier. After setting     * the zoom factor the component is invalidated and 'repaint()' is     * automatically called so that the image is redrawn at the new zoom     * factor. In order to revalidate the layout 'validate()' should be called     * on one of the parent containers. If the resulting zoom factor is larger     * than MAX_ZOOM, then MAX_ZOOM will be used.     *     * @param zm The zoom multiplier to apply.     * */    public synchronized void zoom(float zm) {        setZoom(zoom*zm);    }    /**     * Returns the current zoom factor.     *     * @return The current zoom factor     * */    public synchronized float getZoom() {        return zoom;    }    /**     * Returns the Adjustable object which represents the state of the     * horizontal scrollbar.     * */    public Adjustable getHAdjustable() {        return hsbar;    }    /**     * Returns the Adjustable object which represents the state of the     * vertical scrollbar.     * */    public Adjustable getVAdjustable() {        return vsbar;    }    /**     * Returns the display policy for the scrollbars.     *     * @return the display policy for the scrollbars     * */    public int getScrollbarDisplayPolicy() {        return sbType;    }    /**     * Sets the display policy for the scrollbars.     *     * @param v the display policy for the scrollbars     * */    public void setScrollbarDisplayPolicy(int v) {        // If no change do nothing        if (v == sbType) return;        switch (sbType) {        case SCROLLBARS_NEVER:        case SCROLLBARS_AS_NEEDED:            hsbar.setVisible(false);            vsbar.setVisible(false);            break;        case SCROLLBARS_ALWAYS:            hsbar.setVisible(true);            vsbar.setVisible(true);            break;        default:            throw new IllegalArgumentException();        }

⌨️ 快捷键说明

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