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

📄 basicinternalframeui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* BasicInternalFrameUI.java --   Copyright (C) 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.plaf.basic;import java.awt.AWTEvent;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Insets;import java.awt.LayoutManager;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyVetoException;import java.beans.VetoableChangeListener;import javax.swing.DefaultDesktopManager;import javax.swing.DesktopManager;import javax.swing.JComponent;import javax.swing.JDesktopPane;import javax.swing.JInternalFrame;import javax.swing.KeyStroke;import javax.swing.LookAndFeel;import javax.swing.SwingConstants;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.border.AbstractBorder;import javax.swing.event.InternalFrameEvent;import javax.swing.event.InternalFrameListener;import javax.swing.event.MouseInputAdapter;import javax.swing.event.MouseInputListener;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.InternalFrameUI;import javax.swing.plaf.UIResource;/** * This is the UI delegate for the Basic look and feel for JInternalFrames. */public class BasicInternalFrameUI extends InternalFrameUI{  /**   * This is a helper class that listens to the JInternalFrame for   * InternalFrameEvents.   */  protected class BasicInternalFrameListener implements InternalFrameListener  {    /**     * This method is called when the JInternalFrame is activated.     *     * @param e The InternalFrameEvent.     */    public void internalFrameActivated(InternalFrameEvent e)    {      // FIXME: Implement.    }    /**     * This method is called when the JInternalFrame is closed.     *     * @param e The InternalFrameEvent.     */    public void internalFrameClosed(InternalFrameEvent e)    {      // FIXME: Implement.    }    /**     * This method is called when the JInternalFrame is closing.     *     * @param e The InternalFrameEvent.     */    public void internalFrameClosing(InternalFrameEvent e)    {      // FIXME: Implement.    }    /**     * This method is called when the JInternalFrame is deactivated.     *     * @param e The InternalFrameEvent.     */    public void internalFrameDeactivated(InternalFrameEvent e)    {      // FIXME: Implement.    }    /**     * This method is called when the JInternalFrame is  deiconified.     *     * @param e The InternalFrameEvent.     */    public void internalFrameDeiconified(InternalFrameEvent e)    {      // FIXME: Implement.    }    /**     * This method is called when the JInternalFrame is  iconified.     *     * @param e The InternalFrameEvent.     */    public void internalFrameIconified(InternalFrameEvent e)    {      // FIXME: Implement.    }    /**     * This method is called when the JInternalFrame is opened.     *     * @param e The InternalFrameEvent.     */    public void internalFrameOpened(InternalFrameEvent e)    {      // FIXME: Implement.    }  }  /**   * This helper class listens to the edges of the JInternalFrame and the   * TitlePane for mouse events. It is responsible for dragging  and resizing   * the JInternalFrame in response to the MouseEvents.   */  protected class BorderListener extends MouseInputAdapter    implements SwingConstants  {    /** FIXME: Use for something. */    protected final int RESIZE_NONE = 0;    /** The x offset from the top left corner of the JInternalFrame. */    private transient int xOffset = 0;    /** The y offset from the top left corner of the JInternalFrame. */    private transient int yOffset = 0;    /** The direction that the resize is occuring in. */    private transient int direction = -1;    /** Cache rectangle that can be reused. */    private transient Rectangle cacheRect = new Rectangle();    /**     * This method is called when the mouse is clicked.     *     * @param e The MouseEvent.     */    public void mouseClicked(MouseEvent e)    {      // There is nothing to do when the mouse is clicked      // on the border.    }    /**     * This method is called when the mouse is dragged. This method is     * responsible for resizing or dragging the JInternalFrame.     *     * @param e The MouseEvent.     */    public void mouseDragged(MouseEvent e)    {      // If the frame is maximized, there is nothing that      // can be dragged around.      if (frame.isMaximum())        return;      DesktopManager dm = getDesktopManager();      Rectangle b = frame.getBounds();      Dimension min = frame.getMinimumSize();      if (min == null)        min = new Dimension(0, 0);      Insets insets = frame.getInsets();      int x = e.getX();      int y = e.getY();      if (e.getSource() == frame && frame.isResizable())        {          switch (direction)            {            case NORTH:              cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height                                                         - min.height),                                  b.width, b.height - y);              break;            case NORTH_EAST:              cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height                                                         - min.height), x,                                  b.height - y);              break;            case EAST:              cacheRect.setBounds(b.x, b.y, x, b.height);              break;            case SOUTH_EAST:              cacheRect.setBounds(b.x, b.y, x, y);              break;            case SOUTH:              cacheRect.setBounds(b.x, b.y, b.width, y);              break;            case SOUTH_WEST:              cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),                                  b.y, b.width - x, y);              break;            case WEST:              cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),                                  b.y, b.width - x, b.height);              break;            case NORTH_WEST:              cacheRect.setBounds(                                  Math.min(b.x + x, b.x + b.width - min.width),                                  Math.min(b.y + y, b.y + b.height - min.height),                                  b.width - x, b.height - y);              break;            }          dm.resizeFrame(frame, cacheRect.x, cacheRect.y,                         Math.max(min.width, cacheRect.width),                         Math.max(min.height, cacheRect.height));        }      else if (e.getSource() == titlePane)        {          Rectangle fBounds = frame.getBounds();          dm.dragFrame(frame, e.getX() - xOffset + b.x, e.getY() - yOffset                                                        + b.y);        }    }    /**     * This method is called when the mouse exits the JInternalFrame.     *     * @param e The MouseEvent.     */    public void mouseExited(MouseEvent e)    {      // There is nothing to do when the mouse exits       // the border area.    }    /**     * This method is called when the mouse is moved inside the     * JInternalFrame.     *     * @param e The MouseEvent.     */    public void mouseMoved(MouseEvent e)    {      // There is nothing to do when the mouse moves      // over the border area.    }    /**     * This method is called when the mouse is pressed.     *     * @param e The MouseEvent.     */    public void mousePressed(MouseEvent e)    {      activateFrame(frame);      DesktopManager dm = getDesktopManager();      int x = e.getX();      int y = e.getY();      Insets insets = frame.getInsets();      if (e.getSource() == frame && frame.isResizable())        {          direction = sectionOfClick(x, y);          dm.beginResizingFrame(frame, direction);        }      else if (e.getSource() == titlePane)        {          Rectangle tBounds = titlePane.getBounds();          xOffset = e.getX() - tBounds.x + insets.left;          yOffset = e.getY() - tBounds.y + insets.top;          dm.beginDraggingFrame(frame);        }    }    /**     * This method is called when the mouse is released.     *     * @param e The MouseEvent.     */    public void mouseReleased(MouseEvent e)    {      DesktopManager dm = getDesktopManager();      xOffset = 0;      yOffset = 0;      if (e.getSource() == frame && frame.isResizable())        dm.endResizingFrame(frame);      else if (e.getSource() == titlePane)        dm.endDraggingFrame(frame);    }    /**     * This method determines the direction of the resize based on the     * coordinates and the size of the JInternalFrame.     *     * @param x The x coordinate of the MouseEvent.     * @param y The y coordinate of the MouseEvent.     *     * @return The direction of the resize (a SwingConstant direction).     */    private int sectionOfClick(int x, int y)    {      Insets insets = frame.getInsets();      Rectangle b = frame.getBounds();      if (x < insets.left && y < insets.top)        return NORTH_WEST;      else if (x > b.width - insets.right && y < insets.top)        return NORTH_EAST;      else if (x > b.width - insets.right && y > b.height - insets.bottom)        return SOUTH_EAST;      else if (x < insets.left && y > b.height - insets.bottom)        return SOUTH_WEST;      else if (y < insets.top)        return NORTH;      else if (x < insets.left)        return WEST;      else if (y > b.height - insets.bottom)        return SOUTH;      else if (x > b.width - insets.right)        return EAST;      return -1;    }  }  /**   * This helper class listens to the JDesktopPane that parents this   * JInternalFrame and listens for resize events and resizes the   * JInternalFrame appropriately.   */  protected class ComponentHandler implements ComponentListener  {    /**     * This method is called when the JDesktopPane is hidden.     *      * @param e     *          The ComponentEvent fired.     */    public void componentHidden(ComponentEvent e)    {      // Do nothing.    }    /**     * This method is called when the JDesktopPane is moved.     *      * @param e     *          The ComponentEvent fired.     */    public void componentMoved(ComponentEvent e)    {      // Do nothing.    }    /**     * This method is called when the JDesktopPane is resized.     *      * @param e     *          The ComponentEvent fired.     */    public void componentResized(ComponentEvent e)    {      if (frame.isMaximum())        {          JDesktopPane pane = (JDesktopPane) e.getSource();          Insets insets = pane.getInsets();          Rectangle bounds = pane.getBounds();          frame.setBounds(bounds.x + insets.left, bounds.y + insets.top,                          bounds.width - insets.left - insets.right,                          bounds.height - insets.top - insets.bottom);          frame.revalidate();          frame.repaint();        }      // Sun also resizes the icons. but it doesn't seem to do anything.    }    /**     * This method is called when the JDesktopPane is shown.     *      * @param e     *          The ComponentEvent fired.     */    public void componentShown(ComponentEvent e)    {      // Do nothing.    }  }  /**   * This helper class acts as the LayoutManager for JInternalFrames.   */

⌨️ 快捷键说明

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