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

📄 basicdesktopiconui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* BasicDesktopIconUI.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.BorderLayout;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Insets;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.beans.PropertyVetoException;import javax.swing.Icon;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JDesktopPane;import javax.swing.JInternalFrame;import javax.swing.JInternalFrame.JDesktopIcon;import javax.swing.SwingConstants;import javax.swing.border.Border;import javax.swing.event.MouseInputAdapter;import javax.swing.event.MouseInputListener;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.DesktopIconUI;/** * This class acts as the UI delegate for JDesktopIcons for the Basic look and feel. */public class BasicDesktopIconUI extends DesktopIconUI{  /**   * This helper class handles mouse events that occur on the JDesktopIcon.   */  public class MouseInputHandler extends MouseInputAdapter  {    /** The x offset from the MouseEvent coordinates to the top left corner. */    private transient int xOffset;    /** The y offset fromt he MouseEvent coordinates to the top left corner. */    private transient int yOffset;    /** A cached value of the JDesktopPane that parents this JDesktopIcon. */    private transient JDesktopPane pane;    /**     * This method is called when the mouse is dragged in the JDesktopIcon.     *     * @param e The MouseEvent.     */    public void mouseDragged(MouseEvent e)    {      Rectangle b = desktopIcon.getBounds();      moveAndRepaint(desktopIcon, b.x + e.getX() - xOffset,                     b.y + e.getY() - yOffset, b.width, b.height);    }    /**     * This method is called when the mouse is moved in the JDesktopIcon.     *     * @param e The MouseEvent.     */    public void mouseMoved(MouseEvent e)    {      // Nothing to do.    }    /**     * This method is called when the mouse is pressed in the JDesktopIcon.     *     * @param e The MouseEvent.     */    public void mousePressed(MouseEvent e)    {      xOffset = e.getX();      yOffset = e.getY();      pane = frame.getDesktopPane();      if (pane != null)	pane.getDesktopManager().beginDraggingFrame(desktopIcon);    }    /**     * This method is called when the mouse is released in the JDesktopIcon.     *     * @param e The MouseEvent.     */    public void mouseReleased(MouseEvent e)    {      if (pane != null)	pane.getDesktopManager().endDraggingFrame(desktopIcon);      xOffset = 0;      yOffset = 0;    }    /**     * This method moves and repaints the JDesktopIcon to the given bounds.     *     * @param f The JComponent to move and repaint.     * @param newX The new x coordinate.     * @param newY The new y coordinate.     * @param newWidth The new width.     * @param newHeight The new height.     */    public void moveAndRepaint(JComponent f, int newX, int newY, int newWidth,                               int newHeight)    {      if (pane != null)	pane.getDesktopManager().dragFrame(f, newX, newY);      else	desktopIcon.setBounds(newX, newY, newWidth, newHeight);    }  }  /**   * This class acts as the border for the JDesktopIcon.   */  private class DesktopIconBorder implements Border  {    /** The left inset value. */    int left = 10;    /** The top inset value. */    int top = 4;    /** The right inset value. */    int right = top;    /** The bottom inset value. */    int bottom = top;    /**     * This method returns the insets of the border.     *     * @param c The Component to find border insets for.     *     * @return The border insets.     */    public Insets getBorderInsets(Component c)    {      return new Insets(top, left, bottom, right);    }    /**     * This method returns whether the border is opaque.     *     * @return Whether the border is opaque.     */    public boolean isBorderOpaque()    {      return true;    }    /**     * This method paints the border.     *     * @param c The Component the border is in.     * @param g The Graphics object to paint with.     * @param x The x coordinate of the Component.     * @param y The y coordinate of the Component.     * @param width The width of the Component.     * @param height The height of the Component.     */    public void paintBorder(Component c, Graphics g, int x, int y, int width,                            int height)    {      g.translate(x, y);      Color saved = g.getColor();      g.setColor(Color.LIGHT_GRAY);      g.fillRect(0, 0, left, height);      g.fillRect(0, 0, width, top);      g.fillRect(0, height - bottom, width, bottom);      g.fillRect(width - right, 0, right, height);      g.setColor(Color.BLACK);      g.drawRect(0, 0, width - 1, height - 1);      int fHeight = height / 4;      int hLeft = left / 2;      g.setColor(Color.BLACK);      g.fillRect(hLeft, fHeight, 2, 2);      g.fillRect(hLeft, fHeight * 2, 2, 2);      g.fillRect(hLeft, fHeight * 3, 2, 2);      g.setColor(saved);      g.translate(-x, -y);    }  }  /** The static width and height of the iconSize. */  private static final int iconSize = 16;  /**   * This class represents the default frame icon when none   * is supplied by the JInternalFrame.   */  static class InternalFrameDefaultMenuIcon implements Icon  {    /**     * This returns the icon height.     *     * @return The icon height.     */    public int getIconHeight()    {      return iconSize;    }    /**     * This returns the icon width.     *     * @return The icon width.     */    public int getIconWidth()    {      return iconSize;    }    /**     * This method paints the icon.     *     * @param c The Component this icon belongs to.     * @param g The Graphics object to paint with.     * @param x The x coordinate to paint at.     * @param y The y coordinate to paint at.     */    public void paintIcon(Component c, Graphics g, int x, int y)    {      g.translate(x, y);      Color saved = g.getColor();      g.setColor(Color.BLUE);      g.fillRect(0, 0, iconSize, (int) ((double) iconSize / 3) + 1);      g.setColor(Color.WHITE);      g.fillRect(0, (int) ((double) iconSize / 3), iconSize, iconSize * 5 / 6);      g.setColor(Color.GRAY);      g.drawRect(0, 0, iconSize, iconSize);      g.setColor(saved);      g.translate(-x, -y);    }  }  /** The default JDesktopIcon width. */  private static final int iconWidth = 160;  /** The default JDesktopIcon height */  private static final int iconHeight = 35;  /** The JDesktopIcon this UI delegate represents. */  protected JDesktopIcon desktopIcon;

⌨️ 快捷键说明

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