📄 borderuiresource.java
字号:
/* BorderUIResource.java Copyright (C) 2002, 2003 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., 59 Temple Place, Suite 330, Boston, MA02111-1307 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;import javax.swing.border.*;import javax.swing.Icon;import java.io.Serializable;import java.awt.Component;import java.awt.Graphics;import java.awt.Insets;import java.awt.Font;import java.awt.Color;/** * A wrapper for {@link javax.swing.border.Border} that also * implements the {@link UIResource} marker interface. This is useful * for implementing pluggable look-and-feels: When switching the * current LookAndFeel, only those borders are replaced that are * marked as {@link UIResource}. For this reason, a look-and-feel * should always install borders that implement * <code>UIResource</code>, such as the borders provided by this * class. * * @serial * @serialField delegate Border the <code>Border</code> wrapped * * @author Brian Jones (cbj@gnu.org) * @author Sascha Brawer (brawer@dandelis.ch) */public class BorderUIResource extends Object implements Border, UIResource, Serializable{ /** * Verified using the <code>serialver</code> tool * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5. */ static final long serialVersionUID = -3440553684010079691L; /** * A shared instance of an {@link EtchedBorderUIResource}, or * <code>null</code> if the {@link #getEtchedBorderUIResource()} * method has not yet been called. */ private static Border etchedBorderUIResource; /** * A shared instance of a {@link BevelBorderUIResource} whose * <code>bevelType</code> is {@link * javax.swing.border.BevelBorder#LOWERED}, or <code>null</code> if * the {@link #getLoweredBevelBorderUIResource()} has not yet been * called. */ private static Border loweredBevelBorderUIResource; /** * A shared instance of a {@link BevelBorderUIResource} whose * <code>bevelType</code> is {@link * javax.swing.border.BevelBorder#RAISED}, or <code>null</code> if * the {@link #getRaisedBevelBorderUIResource()} has not yet been * called. */ private static Border raisedBevelBorderUIResource; /** * A shared instance of a {@link LineBorderUIResource} for * a one-pixel thick black line, or <code>null</code> if * the {@link #getBlackLineBorderUIResource()} has not yet been * called. */ private static Border blackLineBorderUIResource; /** * Returns a shared instance of an etched border which also * is marked as an {@link UIResource}. * * @see javax.swing.border.EtchedBorder */ public static Border getEtchedBorderUIResource() { /* Swing is not designed to be thread-safe, so there is no * need to synchronize the access to the global variable. */ if (etchedBorderUIResource == null) etchedBorderUIResource = new EtchedBorderUIResource(); return etchedBorderUIResource; } /** * Returns a shared instance of {@link BevelBorderUIResource} whose * <code>bevelType</code> is {@link * javax.swing.border.BevelBorder#LOWERED}. * * @see javax.swing.border.BevelBorder */ public static Border getLoweredBevelBorderUIResource() { /* Swing is not designed to be thread-safe, so there is no * need to synchronize the access to the global variable. */ if (loweredBevelBorderUIResource == null) loweredBevelBorderUIResource = new BevelBorderUIResource( BevelBorder.LOWERED); return loweredBevelBorderUIResource; } /** * Returns a shared instance of {@link BevelBorderUIResource} whose * <code>bevelType</code> is {@link * javax.swing.border.BevelBorder#RAISED}. * * @see javax.swing.border.BevelBorder */ public static Border getRaisedBevelBorderUIResource() { /* Swing is not designed to be thread-safe, so there is no * need to synchronize the access to the global variable. */ if (raisedBevelBorderUIResource == null) raisedBevelBorderUIResource = new BevelBorderUIResource( BevelBorder.RAISED); return raisedBevelBorderUIResource; } /** * Returns a shared instance of {@link LineBorderUIResource} for * a black, one-pixel width border. * * @see javax.swing.border.LineBorder */ public static Border getBlackLineBorderUIResource() { /* Swing is not designed to be thread-safe, so there is no * need to synchronize the access to the global variable. */ if (blackLineBorderUIResource == null) blackLineBorderUIResource = new LineBorderUIResource(Color.black); return blackLineBorderUIResource; } /** * The wrapped border. */ private Border delegate; /** * Constructs a <code>BorderUIResource</code> for wrapping * a <code>Border</code> object. * * @param delegate the border to be wrapped. */ public BorderUIResource(Border delegate) { if (delegate == null) throw new IllegalArgumentException(); this.delegate = delegate; } /** * Paints the border around an enclosed component by calling * the <code>paintBorder</code> method of the wrapped delegate. * * @param c the component whose border is to be painted. * @param g the graphics for painting. * @param x the horizontal position for painting the border. * @param y the vertical position for painting the border. * @param width the width of the available area for painting the border. * @param height the height of the available area for painting the border. */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { delegate.paintBorder(c, g, x, y, width, height); } /** * Measures the width of this border by calling the * <code>getBorderInsets</code> method of the wrapped * delegate. * * @param c the component whose border is to be measured. * * @return an Insets object whose <code>left</code>, <code>right</code>, * <code>top</code> and <code>bottom</code> fields indicate the * width of the border at the respective edge. */ public Insets getBorderInsets(Component c) { return delegate.getBorderInsets(c); } /** * Determines whether this border fills every pixel in its area * when painting by calling the <code>isBorderOpaque</code> * method of the wrapped delegate. * * @return <code>true</code> if the border is fully opaque, or * <code>false</code> if some pixels of the background * can shine through the border. */ public boolean isBorderOpaque() { return delegate.isBorderOpaque(); } /** * A {@link javax.swing.border.BevelBorder} that also implements the * {@link UIResource} marker interface. This is useful for * implementing pluggable look-and-feels: When switching the current * LookAndFeel, only those borders are replaced that are marked as * {@link UIResource}. For this reason, a look-and-feel should * always install borders that implement <code>UIResource</code>, * such as the borders provided by this class. * * @author Brian Jones (cbj@gnu.org) * @author Sascha Brawer (brawer@dandelis.ch) */ public static class BevelBorderUIResource extends BevelBorder implements UIResource, Serializable { /** * Constructs a BevelBorderUIResource whose colors will be derived * from the background of the enclosed component. The background * color is retrieved each time the border is painted, so a border * constructed by this method will automatically reflect a change * to the component’s background color. * * <p><img src="../border/doc-files/BevelBorder-1.png" * width="500" height="150" * alt="[An illustration showing raised and lowered BevelBorders]" /> * * @param bevelType the desired appearance of the border. The value * must be either {@link javax.swing.border.BevelBorder#RAISED} * or {@link javax.swing.border.BevelBorder#LOWERED}. * * @throws IllegalArgumentException if <code>bevelType</code> has * an unsupported value. */ public BevelBorderUIResource(int bevelType) { super(bevelType); } /** * Constructs a BevelBorderUIResource given its appearance type * and two colors for its highlight and shadow. * * <p><img src="../border/doc-files/BevelBorder-2.png" width="500" * height="150" alt="[An illustration showing BevelBorders that were * constructed with this method]" /> *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -