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

📄 metalborders.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* MetalBorders.java   Copyright (C) 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.metal;import java.awt.Color;import java.awt.Component;import java.awt.Graphics;import java.awt.Insets;import javax.swing.AbstractButton;import javax.swing.ButtonModel;import javax.swing.JButton;import javax.swing.JInternalFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.JToggleButton;import javax.swing.JToolBar;import javax.swing.SwingConstants;import javax.swing.UIManager;import javax.swing.border.AbstractBorder;import javax.swing.border.Border;import javax.swing.plaf.BorderUIResource;import javax.swing.plaf.UIResource;import javax.swing.plaf.basic.BasicBorders;import javax.swing.text.JTextComponent;/** * A factory class that creates borders for the different Swing components. * * @author Roman Kennke (roman@kennke.org) */public class MetalBorders{  /** The shared instance for getButtonBorder(). */  private static Border buttonBorder;  /** The shared instance for getToggleButtonBorder(). */  private static Border toggleButtonBorder;  /** The shared instance for getDesktopIconBorder(). */  private static Border desktopIconBorder;  /** The shared instance for getRolloverButtonBorder(). */  private static Border toolbarButtonBorder;  /** The shared instance for getTextFieldBorder(). */  private static Border textFieldBorder;  /** The shared instance for getTextBorder(). */  private static Border textBorder;  /** The shared instance for getRolloverBorder(). */  private static Border rolloverBorder;  /**   * A MarginBorder that gets shared by multiple components.   * Created on demand by the private helper function {@link   * #getMarginBorder()}.   */  private static BasicBorders.MarginBorder marginBorder;  /**   * A border used for {@link JButton} components.   */  public static class ButtonBorder extends AbstractBorder implements UIResource  {    /** The borders insets. */    protected static Insets borderInsets = new Insets(3, 3, 3, 3);    /**     * Creates a new instance of <code>ButtonBorder</code>.     */    public ButtonBorder()    {      // Nothing to do here.    }    /**     * Paints the button border.     *     * @param c the component for which we paint the border     * @param g the Graphics context to use     * @param x the X coordinate of the upper left corner of c     * @param y the Y coordinate of the upper left corner of c     * @param w the width of c     * @param h the height of c     */    public void paintBorder(Component c, Graphics g, int x, int y, int w,                            int h)    {      // With the OceanTheme the button border is painted entirely different.      // However, I couldn't figure out how this is determined besides checking      // for instanceof OceanTheme. The button painting is definitely not      // influenced by a UI default property and it is definitely performed      // by the same Border class.      if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme)        paintOceanButtonBorder(c, g, x, y, w, h);      else        {          ButtonModel bmodel = null;                if (c instanceof AbstractButton)            bmodel = ((AbstractButton) c).getModel();          Color darkShadow = MetalLookAndFeel.getControlDarkShadow();          Color shadow = MetalLookAndFeel.getControlShadow();          Color light = MetalLookAndFeel.getControlHighlight();          Color middle = MetalLookAndFeel.getControl();          if (c.isEnabled())            {              // draw dark border              g.setColor(darkShadow);              g.drawRect(x, y, w - 2, h - 2);              if (!bmodel.isPressed())                {                  // draw light border                  g.setColor(light);                  g.drawRect(x + 1, y + 1, w - 2, h - 2);                  // draw crossing pixels of both borders                  g.setColor(middle);                  g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);                  g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);                }              else                {                  // draw light border                  g.setColor(light);                  g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);                  g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);                  // draw shadow border                  g.setColor(middle);                  g.drawLine(x + 1, y + 1, x + w - 2, y + 1);                  g.drawLine(x + 1, y + 1, x + 1, y + h - 2);                   // draw crossing pixels of both borders                  g.setColor(shadow);                  g.drawRect(x + 1, y + h - 2, 0, 0);                  g.drawRect(x + w - 2, y + 1, 0, 0);                }            }          else             {              // draw disabled border              g.setColor(MetalLookAndFeel.getInactiveControlTextColor());              g.drawRect(x, y, w - 2, h - 2);                      }        }    }    /**     * Paints the button border for the OceanTheme.     *     * @param c the button     * @param g the graphics context     * @param x the X coordinate of the upper left corner of the painting rect     * @param y the Y coordinate of the upper left corner of the painting rect     * @param w the width of the painting rect     * @param h the height of the painting rect     */    private void paintOceanButtonBorder(Component c, Graphics g, int x,                                        int y, int w, int h)    {      ButtonModel bmodel = null;            if (c instanceof AbstractButton)        bmodel = ((AbstractButton) c).getModel();      Color darkShadow = MetalLookAndFeel.getControlDarkShadow();      Color shadow = MetalLookAndFeel.getControlShadow();      Color light = MetalLookAndFeel.getControlHighlight();      Color middle = MetalLookAndFeel.getControl();      if (c.isEnabled())        {          if (bmodel.isPressed())            {              // draw fat border              g.drawLine(x + 1, y + 1, x + w - 2, y + 1);              g.drawLine(x + 1, y + 1, x + 1, y + h - 2);            }          else if (bmodel.isRollover())            {              g.setColor(shadow);              g.drawRect(x, y, w - 1, h - 1);              g.drawRect(x + 2, y + 2, w - 5, h - 5);              g.setColor(darkShadow);              g.drawRect(x + 1, y + 1, w - 3, h - 3);            }          else            {              g.setColor(darkShadow);              g.drawRect(x, y, w - 1, h - 1);            }        }      else         {          // draw disabled border          g.setColor(MetalLookAndFeel.getInactiveControlTextColor());          g.drawRect(x, y, w - 2, h - 2);                  }    }    /**     * Returns the insets of the <code>ButtonBorder</code>.     *     * @param c the component for which the border is used     *     * @return The insets of the ButtonBorder     */    public Insets getBorderInsets(Component c)    {      return getBorderInsets(c, null);    }    /**     * Returns the insets of the <code>ButtonBorder</code> in the specified      * <code>newInsets</code> object.     *     * @param c the component for which the border is used     * @param newInsets the insets object where to put the values (if      *        <code>null</code>, a new instance is created).     *     * @return The insets.     */    public Insets getBorderInsets(Component c, Insets newInsets)    {      if (newInsets == null)        newInsets = new Insets(0, 0, 0, 0);      newInsets.bottom = borderInsets.bottom;      newInsets.left = borderInsets.left;      newInsets.right = borderInsets.right;      newInsets.top = borderInsets.top;      return newInsets;    }  }  /**   * A border used when painting {@link JInternalFrame} instances.   */  static class DesktopIconBorder extends AbstractBorder    implements UIResource  {    /**     * Creates a new border instance.     */    public DesktopIconBorder()    {      // Nothing to do here.    }        /**     * Returns the border insets.     *      * @param c  the component (ignored).     *      * @return The border insets.     */    public Insets getBorderInsets(Component c)    {      return getBorderInsets(c, null);    }        /**     * Returns the border insets.     *      * @param c  the component (ignored).     * @return The border insets.     */    public Insets getBorderInsets(Component c, Insets newInsets)    {      if (newInsets == null)        newInsets = new Insets(3, 3, 2, 3);      else        {          newInsets.top = 3;          newInsets.left = 3;          newInsets.bottom = 2;          newInsets.right = 3;        }      return newInsets;      }        /**     * Paints the border for the specified component.     *      * @param c  the component.     * @param g  the graphics device.     * @param x  the x-coordinate.     * @param y  the y-coordinate.     * @param w  the width.     * @param h  the height.     */    public void paintBorder(Component c, Graphics g, int x, int y, int w,         int h)    {      g.setColor(MetalLookAndFeel.getControlDarkShadow());            g.drawRect(x, y, w - 1, h - 1);     }      }  /**   * A simple 3D border.   */  public static class Flush3DBorder extends AbstractBorder    implements UIResource  {    /**     * Creates a new border instance.     */    public Flush3DBorder()    {      // Nothing to do here.    }        /**     * Returns the border insets.     *      * @param c  the component (ignored).     *      * @return The border insets.     */    public Insets getBorderInsets(Component c)    {      return getBorderInsets(c, null);    }        /**     * Returns the border insets.     *      * @param c  the component (ignored).     * @return The border insets.     */    public Insets getBorderInsets(Component c, Insets newInsets)    {      if (newInsets == null)        newInsets = new Insets(2, 2, 2, 2);      else        {          newInsets.top = 2;          newInsets.left = 2;          newInsets.bottom = 2;          newInsets.right = 2;        }      return newInsets;      }        /**     * Paints the border for the specified component.     *      * @param c  the component (ignored).     * @param g  the graphics device.     * @param x  the x-coordinate.     * @param y  the y-coordinate.     * @param w  the width.     * @param h  the height.     */    public void paintBorder(Component c, Graphics g, int x, int y, int w,         int h)    {                    Color savedColor = g.getColor();      g.setColor(MetalLookAndFeel.getControlDarkShadow());      g.drawRect(x, y, w - 2, h - 2);      g.setColor(MetalLookAndFeel.getControlHighlight());      g.drawRect(x + 1, y + 1, w - 2, h - 2);      g.setColor(MetalLookAndFeel.getControl());      g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);      g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);      g.setColor(savedColor);    }      }      /**   * A border used for a {@link JInternalFrame} when it is being used as a    * palette.   *    * @since 1.3   */  public static class PaletteBorder extends AbstractBorder    implements UIResource  {    /**     * Creates a new <code>PaletteBorder</code>.     */    public PaletteBorder()    {      // Nothing to do here.    }        /**     * Returns the border insets.     *      * @param c  the component (ignored).     *      * @return The border insets.     */    public Insets getBorderInsets(Component c)    {      return getBorderInsets(c, null);    }    /**     * Returns the border insets.     *      * @param c  the component (ignored).     * @param newInsets  the insets object that, if non-<code>null</code>, will      *                   be populated with the result from this method.     *      * @return The border insets.     */    public Insets getBorderInsets(Component c, Insets newInsets)    {              if (newInsets == null)        newInsets = new Insets(1, 1, 1, 1);      else        {          newInsets.top = 1;          newInsets.left = 1;          newInsets.bottom = 1;          newInsets.right = 1;        }      return newInsets;      }        /**     * Paints the border for the specified component.     *      * @param c  the component (ignored).     * @param g  the graphics device.     * @param x  the x-coordinate.     * @param y  the y-coordinate.     * @param w  the width.     * @param h  the height.     */    public void paintBorder(Component c, Graphics g, int x, int y, int w,             int h)    {      Color savedColor = g.getColor();            // draw the outline      g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());      g.drawRect(x, y, w - 1, h - 1);            // put a dot in each corner      g.setColor(MetalLookAndFeel.getControl());      g.fillRect(x, y, 1, 1);      g.fillRect(x + w - 1, y, 1, 1);      g.fillRect(x + w - 1, y + h - 1, 1, 1);      g.fillRect(x, y + h - 1, 1, 1);            g.setColor(savedColor);    }  }      /**   * A border used for the {@link JTextField} component.   */  public static class TextFieldBorder extends Flush3DBorder    implements UIResource  {    /**     * Creates a new border instance.     */    public TextFieldBorder()    {      // Nothing to do here.    }        /**     * Paints the border for the specified component.     *      * @param c  the component (ignored).     * @param g  the graphics device.

⌨️ 快捷键说明

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