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

📄 picturepanel.java

📁 html 解析处理代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Compute the preferred size of the component.     * Computes the minimum bounding rectangle covering all the pictures in     * the panel. It then does some funky stuff to handle     * embedding in the view port of a scroll pane, basically asking     * up the ancestor heirarchy what size is available, and filling it.     * @return The optimal dimension for this component.     */    protected Dimension calculatePreferredSize ()    {        Enumeration enumeration;        int x;        int y;        Picture picture;        Component parent;        Insets insets;        Dimension ret;        enumeration = mMosaic.getPictures ();        x = 0;        y = 0;        picture = null;        while (enumeration.hasMoreElements ())        {            picture = (Picture)enumeration.nextElement ();            if (picture.x + picture.width > x)                x = picture.x + picture.width;            if (picture.y + picture.height > y)                y = picture.y + picture.height;        }        parent = getParent ();        if (parent instanceof JViewport)        {            ret = parent.getSize ();            insets = ((JViewport)parent).getInsets ();            ret.width -= insets.left + insets.right;            ret.height -= insets.top + insets.bottom;            if ((0 != ret.width) || (0 != ret.height))                ret.width -= 2; // ... I dunno why, it just needs it            if (ret.width < x)                ret.width = x;            if (ret.height < y)                ret.height = y;        }        else        {            insets = getInsets ();            x += insets.left + insets.right;            y += insets.top + insets.bottom;            ret = new Dimension (x, y);        }        return (ret);    }    //    // MouseListener Interface    //    /**     * Invoked when the mouse button has been clicked     * (pressed and released) on a component.     * <i>Not used.</i>     * @param event The object providing details of the mouse event.     */    public void mouseClicked (final MouseEvent event)    {    }    /**     *Invoked when a mouse button has been released on a component.     * <i>Not used.</i>     * @param event The object providing details of the mouse event.     */    public void mouseReleased (final MouseEvent event)    {    }    /**     * Invoked when the mouse enters a component.     * <i>Not used.</i>     * @param event The object providing details of the mouse event.     */    public void mouseEntered (final MouseEvent event)    {    }    /**     * Invoked when the mouse exits a component.     * <i>Not used.</i>     * @param event The object providing details of the mouse event.     */    public void mouseExited (final MouseEvent event)    {    }    /**     * Handle left click on a picture by bringing it to the top.     * @param event The object providing details of the mouse event.     */    public void mousePressed (final MouseEvent event)    {        Picture picture;        if (!event.isMetaDown ())        {            picture = mMosaic.pictureAt (event.getX (), event.getY ());            if (null != picture)                bringToTop (picture);        }    }    //    // Scrollable interface    //    /**     * Returns the preferred size of the viewport for a view component.     * For example the preferredSize of a JList component is the size     * required to accommodate all of the cells in its list however the     * value of preferredScrollableViewportSize is the size required for     * JList.getVisibleRowCount() rows.   A component without any properties     * that would effect the viewport size should just return     * getPreferredSize() here.     *     * @return The preferredSize of a JViewport whose view is this Scrollable.     * @see JViewport#getPreferredSize     */    public Dimension getPreferredScrollableViewportSize ()    {        return (getPreferredSize ());    }    /**     * Components that display logical rows or columns should compute     * the scroll increment that will completely expose one new row     * or column, depending on the value of orientation.  Ideally,     * components should handle a partially exposed row or column by     * returning the distance required to completely expose the item.     * <p>     * Scrolling containers, like JScrollPane, will use this method     * each time the user requests a unit scroll.     *     * @param visibleRect The view area visible within the viewport     * @param orientation Either SwingConstants.VERTICAL or     * SwingConstants.HORIZONTAL.     * @param direction Less than zero to scroll up/left,     * greater than zero for down/right.     * @return The "unit" increment for scrolling in the specified direction.     *         This value should always be positive.     */    public int getScrollableUnitIncrement (        final Rectangle visibleRect,        final int orientation,        final int direction)    {        return (UNIT_INCREMENT);    }    /**     * Components that display logical rows or columns should compute     * the scroll increment that will completely expose one block     * of rows or columns, depending on the value of orientation.     * <p>     * Scrolling containers, like JScrollPane, will use this method     * each time the user requests a block scroll.     *     * @param visibleRect The view area visible within the viewport     * @param orientation Either SwingConstants.VERTICAL or     * SwingConstants.HORIZONTAL.     * @param direction Less than zero to scroll up/left,     * greater than zero for down/right.     * @return The "block" increment for scrolling in the specified direction.     *         This value should always be positive.     */    public int getScrollableBlockIncrement (        final Rectangle visibleRect,        final int orientation,        final int direction)    {        return (BLOCK_INCREMENT);    }    /**     * Return true if a viewport should always force the width of this     * <code>Scrollable</code> to match the width of the viewport.     * For example a normal     * text view that supported line wrapping would return true here, since it     * would be undesirable for wrapped lines to disappear beyond the right     * edge of the viewport.  Note that returning true for a Scrollable     * whose ancestor is a JScrollPane effectively disables horizontal     * scrolling.     * <p>     * Scrolling containers, like JViewport, will use this method each     * time they are validated.     *     * @return <code>true</code> if a viewport should force the Scrollables     * width to match its own.     */    public boolean getScrollableTracksViewportWidth ()    {        return (false);    }    /**     * Return true if a viewport should always force the height of this     * Scrollable to match the height of the viewport.  For example a     * columnar text view that flowed text in left to right columns     * could effectively disable vertical scrolling by returning     * true here.     * <p>     * Scrolling containers, like JViewport, will use this method each     * time they are validated.     *     * @return <code>true</code> if a viewport should force the Scrollables     * height to match its own.     */    public boolean getScrollableTracksViewportHeight ()    {        return (false);    }    //    // ComponentListener interface    //    /**     * Invoked when the container's size changes.     * Un-caches the preferred size.     * @param event The resize event.     */    public void componentResized (final ComponentEvent event)    {        setPreferredSize (null);    }    /**     * Invoked when the component's position changes.     * <i>Not used.</I>     * @param event The component event.     */    public void componentMoved (final ComponentEvent event)    {    }    /**     * Invoked when the component has been made visible.     * <i>Not used.</I>     * @param event The component event.     */    public void componentShown (final ComponentEvent event)    {    }    /**     * Invoked when the component has been made invisible.     * <i>Not used.</I>     * @param event The component event.     */    public void componentHidden (final ComponentEvent event)    {    }    //    // HierarchyListener interface    //    /**     * Handles this components ancestor being added to a container.     * Registers this component as a listener for size changes on the     * ancestor so that we may un-cache the prefereed size and force     * a recalculation.     * @param event The heirarchy event.     */    public void hierarchyChanged (final HierarchyEvent event)    {        if (0 != (event.getChangeFlags () & HierarchyEvent.PARENT_CHANGED))        {            Component dad = event.getChanged ();            Component parent = getParent ();            if ((null != parent) && (parent.getParent () == dad))                dad.addComponentListener (this);        }    }}/* * Revision Control Modification History * * $Log: PicturePanel.java,v $ * Revision 1.2  2005/04/12 11:27:41  derrickoswald * Documentation revamp part two. * * Revision 1.1  2003/09/21 18:20:56  derrickoswald * Thumbelina * Created a lexer GUI application to extract images behind thumbnails. * Added a task in the ant build script - thumbelina - to create the jar file. * You need JDK 1.4.x to build it.  It can be run on JDK 1.3.x in crippled mode. * Usage: java -Xmx256M thumbelina.jar [URL] * * */

⌨️ 快捷键说明

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