📄 basicborders.java
字号:
/* BasicBorders.java Copyright (C) 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.basic;import java.awt.Color;import java.awt.Component;import java.awt.Graphics;import java.awt.Insets;import java.awt.Rectangle;import java.io.Serializable;import javax.swing.AbstractButton;import javax.swing.ButtonModel;import javax.swing.JButton;import javax.swing.JPopupMenu;import javax.swing.JSplitPane;import javax.swing.JToolBar;import javax.swing.UIDefaults;import javax.swing.UIManager;import javax.swing.border.AbstractBorder;import javax.swing.border.BevelBorder;import javax.swing.border.Border;import javax.swing.plaf.UIResource;import javax.swing.plaf.BorderUIResource;import javax.swing.text.JTextComponent;/** * Provides various borders for the Basic look and feel. * * @author Sascha Brawer (brawer@dandelis.ch) */public class BasicBorders{ /** * A MarginBorder that gets shared by multiple components. * Created on demand by the private helper function {@link * #getMarginBorder()}. */ private static MarginBorder sharedMarginBorder; /** * Returns a border for drawing push buttons. * * <p>The colors of the border are retrieved from the * <code>UIDefaults</code> of the currently active look and feel * using the keys <code>“Button.shadow”</code>, * <code>“Button.darkShadow”</code>, * <code>“Button.light”</code>, and * <code>“Button.highlight”</code>. * * <p><img src="doc-files/BasicBorders.ButtonBorder-1.png" width="300" * height="170" alt="[A screen shot of the returned border]" /> * * @return a {@link * javax.swing.plaf.BorderUIResource#CompoundBorderUIResource} * whose outer border is a {@link #ButtonBorder} and whose * inner border is a {@link #MarginBorder}. */ public static Border getButtonBorder() { UIDefaults defaults; Border outer; defaults = UIManager.getLookAndFeelDefaults(); /* The keys for UIDefaults have been determined by writing a * test program that dumps the UIDefaults to stdout; that program * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API, * the key "light" is usually called "highlight", and "highlight" * is usually called "lightHighlight". */ outer = new ButtonBorder(defaults.getColor("Button.shadow"), defaults.getColor("Button.darkShadow"), defaults.getColor("Button.light"), defaults.getColor("Button.highlight")); /* While the inner border is shared between multiple buttons, * we do not share the outer border because ButtonBorders store * their border colors. We cannot guarantee that the colors * (which come from UIDefaults) are unchanged between invocations * of getButtonBorder. We could store the last colors, and share * the button border if the colors are the same as in the last * invocation, but it probably is not worth the effort. */ return new BorderUIResource.CompoundBorderUIResource( outer, /* inner */ getMarginBorder()); } /** * Returns a border for drawing radio buttons. * * <p>The colors of the border are retrieved from the * <code>UIDefaults</code> of the currently active look and feel * using the keys <code>“RadioButton.shadow”</code>, * <code>“RadioButton.darkShadow”</code>, * <code>“RadioButton.light”</code>, and * <code>“RadioButton.highlight”</code>. * * <p><img src="doc-files/BasicBorders.RadioButtonBorder-1.png" width="300" * height="135" alt="[A screen shot of the returned border]" /> * * @return a {@link * javax.swing.plaf.BorderUIResource#CompoundBorderUIResource} * whose outer border is a {@link #RadioButtonBorder} and whose * inner border is a {@link #MarginBorder}. */ public static Border getRadioButtonBorder() { UIDefaults defaults; Border outer; defaults = UIManager.getLookAndFeelDefaults(); /* The keys for UIDefaults have been determined by writing a * test program that dumps the UIDefaults to stdout; that program * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API, * the key "light" is usually called "highlight", and "highlight" * is usually called "lightHighlight". */ outer = new RadioButtonBorder( defaults.getColor("RadioButton.shadow"), defaults.getColor("RadioButton.darkShadow"), defaults.getColor("RadioButton.light"), defaults.getColor("RadioButton.highlight")); /* While the inner border is shared between multiple buttons, we * do not share the outer border because RadioButtonBorders, being * ButtonBorders, store their border colors. We cannot guarantee * that the colors (which come from UIDefaults) are unchanged * between invocations of getButtonBorder. We could store the last * colors, and share the button border if the colors are the same * as in the last invocation, but it probably is not worth the * effort. */ return new BorderUIResource.CompoundBorderUIResource( outer, /* inner */ getMarginBorder()); } /** * Returns a border for drawing toggle buttons. * * <p>The colors of the border are retrieved from the * <code>UIDefaults</code> of the currently active look and feel * using the keys <code>“ToggleButton.shadow”</code>, * <code>“ToggleButton.darkShadow”</code>, * <code>“ToggleButton.light”</code>, and * <code>“ToggleButton.highlight”</code>. * * <p><img src="doc-files/BasicBorders.ToggleButtonBorder-1.png" width="270" * height="135" alt="[A screen shot of the returned border]" /> * * @return a {@link * javax.swing.plaf.BorderUIResource#CompoundBorderUIResource} * whose outer border is a {@link #ToggleButtonBorder} and whose * inner border is a {@link #MarginBorder}. */ public static Border getToggleButtonBorder() { UIDefaults defaults; Border outer; defaults = UIManager.getLookAndFeelDefaults(); /* The keys for UIDefaults have been determined by writing a * test program that dumps the UIDefaults to stdout; that program * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API, * the key "light" is usually called "highlight", and "highlight" * is usually called "lightHighlight". */ outer = new ToggleButtonBorder( defaults.getColor("ToggleButton.shadow"), defaults.getColor("ToggleButton.darkShadow"), defaults.getColor("ToggleButton.light"), defaults.getColor("ToggleButton.highlight")); /* While the inner border is shared between multiple buttons, we * do not share the outer border because ToggleButtonBorders, being * ButtonBorders, store their border colors. We cannot guarantee * that the colors (which come from UIDefaults) are unchanged * between invocations of getButtonBorder. We could store the last * colors, and share the button border if the colors are the same * as in the last invocation, but it probably is not worth the * effort. */ return new BorderUIResource.CompoundBorderUIResource( outer, /* inner */ getMarginBorder()); } /** * Returns a border for drawing a two-pixel thick separator line * below menu bars. * * <p>The colors of the border are retrieved from the * <code>UIDefaults</code> of the currently active look and feel * using the keys <code>“MenuBar.shadow”</code> and * <code>“MenuBar.highlight”</code>. * * <p><img src="doc-files/BasicBorders.MenuBarBorder-1.png" width="500" * height="140" alt="[A screen shot of a JMenuBar with this border]" /> * * @return a {@link #MenuBarBorder}. * * @see javax.swing.JMenuBar */ public static Border getMenuBarBorder() { UIDefaults defaults; /* See comment in methods above for why this border is not shared. */ defaults = UIManager.getLookAndFeelDefaults(); return new MenuBarBorder(defaults.getColor("MenuBar.shadow"), defaults.getColor("MenuBar.highlight")); } /** * Returns a border for drawing a one-pixel thick border around * split panes that are interrupted where the divider joins the * border. * * <p>The colors of the border are retrieved from the * <code>UIDefaults</code> of the currently active look and feel * using the keys <code>“SplitPane.darkShadow”</code> and * <code>“SplitPane.highlight”</code>. * * <p><img src="doc-files/BasicBorders.SplitPaneBorder-1.png" width="520" * height="200" alt="[A screen shot for JSplitPane.HORIZONTAL_SPLIT]" /> * * <p><img src="doc-files/BasicBorders.SplitPaneBorder-2.png" width="520" * height="200" alt="[A screen shot for JSplitPane.VERTICAL_SPLIT]" /> * * @return a {@link #SplitPaneBorder}. * * @see javax.swing.JSplitPane * @see #getSplitPaneDividerBorder() */ public static Border getSplitPaneBorder() { UIDefaults defaults; /* See comment in methods above for why this border is not shared. */ defaults = UIManager.getLookAndFeelDefaults(); return new SplitPaneBorder(defaults.getColor("SplitPane.highlight"), defaults.getColor("SplitPane.darkShadow")); } /** * Returns a border for drawing a one-pixel thick border around * the divider of split panes. * * <p>The colors of the edges that are adjacent to the child components * of the <code>JSplitPane</code> are retrieved from the * <code>UIDefaults</code> of the currently active look and feel * using the keys <code>“SplitPane.darkShadow”</code> and * <code>“SplitPane.highlight”</code>. The color of the * other two edges is the background color of the divider. * * <p><img src="doc-files/BasicBorders.SplitPaneDividerBorder-1.png" * width="520" height="200" alt= * "[A screen shot for JSplitPane.HORIZONTAL_SPLIT]" /> * * @return an instance of <code>SplitPaneDividerBorder</code>, which is * not a public API class of this package. * * @see javax.swing.JSplitPane * @see javax.swing.plaf.basic.BasicSplitPaneDivider * @see #getSplitPaneBorder() * * @since 1.3 */ public static Border getSplitPaneDividerBorder() { UIDefaults defaults; /* See comment in methods above for why this border is not shared. */ defaults = UIManager.getLookAndFeelDefaults(); return new SplitPaneDividerBorder( defaults.getColor("SplitPane.highlight"), defaults.getColor("SplitPane.darkShadow")); } /** * Returns a border for drawing a border around a text field * that makes the field appear as etched into the surface. * * <p>The colors of the border are retrieved from the * <code>UIDefaults</code> of the currently active look and feel * using the keys <code>“TextField.shadow”</code>, * <code>“TextField.darkShadow”</code>, * <code>“TextField.light”</code>, and * <code>“TextField.highlight”</code>. * * <p><img src="doc-files/BasicBorders.FieldBorder-1.png" width="500" * height="200" alt="[A screen shot of a border returned by * this method]" /> * * @return an instance of * {@link javax.swing.plaf.basic.BasicBorders$FieldBorder}. * * @see javax.swing.JTextField * @see javax.swing.text.JTextComponent */ public static Border getTextFieldBorder() { UIDefaults defaults; /* See comment in methods above for why this border is not shared. */ defaults = UIManager.getLookAndFeelDefaults(); return new FieldBorder( defaults.getColor("TextField.shadow"), defaults.getColor("TextField.darkShadow"), defaults.getColor("TextField.light"), defaults.getColor("TextField.highlight")); } /** * Returns a two-pixel thick, green * <code>LineBorderUIResource</code>. This is so ugly that look and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -