📄 titledborder.java
字号:
/* TitledBorder.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.border;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Insets;import java.awt.Rectangle;import java.awt.Shape;import javax.swing.UIManager;/** * A border that paints a title on top of another border. * * @author Sascha Brawer (brawer@dandelis.ch) */public class TitledBorder extends AbstractBorder{ /** * A value for the <code>titlePosition</code> property that vertically * positions the title text at the default vertical position, which * is in the middle of the top line of the border. * * @see #getTitlePosition() * @see #setTitlePosition(int) */ public static final int DEFAULT_POSITION = 0; /** * A value for the <code>titlePosition</code> property that vertically * positions the title text above the top line of the border. * * @see #getTitlePosition() * @see #setTitlePosition(int) */ public static final int ABOVE_TOP = 1; /** * A value for the <code>titlePosition</code> property that vertically * positions the title text at the middle of the top line * of the border. * * @see #getTitlePosition() * @see #setTitlePosition(int) */ public static final int TOP = 2; /** * A value for the <code>titlePosition</code> property that vertically * positions the title text below the top line of the border. * * @see #getTitlePosition() * @see #setTitlePosition(int) */ public static final int BELOW_TOP = 3; /** * A value for the <code>titlePosition</code> property that vertically * positions the title text above the bottom line of the border. * * @see #getTitlePosition() * @see #setTitlePosition(int) */ public static final int ABOVE_BOTTOM = 4; /** * A value for the <code>titlePosition</code> property that vertically * positions the title text at the center of the bottom line * of the border. * * @see #getTitlePosition() * @see #setTitlePosition(int) */ public static final int BOTTOM = 5; /** * A value for the <code>titlePosition</code> property that vertically * positions the title text below the bottom line of the border. * * @see #getTitlePosition() * @see #setTitlePosition(int) */ public static final int BELOW_BOTTOM = 6; /** * A value for the <code>titleJustification</code> property that * horizontally aligns the title text with either the left or the * right edge of the border, depending on the orientation of the * component nested into the border. If the component orientation * is left-to-right, the title text is aligned with the left edge; * otherwise, it is aligned with the right edge. This is the same * behavior as with {@link #LEADING}. * * @see #getTitleJustification() * @see #setTitleJustification(int) * @see java.awt.ComponentOrientation#isLeftToRight() */ public static final int DEFAULT_JUSTIFICATION = 0; /** * A value for the <code>titleJustification</code> property that * horizontally aligns the title text with the left-hand edge of * the border. * * @see #getTitleJustification() * @see #setTitleJustification(int) */ public static final int LEFT = 1; /** * A value for the <code>titleJustification</code> property that * horizontally aligns the title text with the center of the border. * * @see #getTitleJustification() * @see #setTitleJustification(int) */ public static final int CENTER = 2; /** * A value for the <code>titleJustification</code> property that * horizontally aligns the title text with the right-hand edge of * the border. * * @see #getTitleJustification() * @see #setTitleJustification(int) */ public static final int RIGHT = 3; /** * A value for the <code>titleJustification</code> property that * horizontally aligns the title text with either the left or the * right edge of the border, depending on the orientation of the * component nested into the border. If the component orientation * is left-to-right, the title text is aligned with the left edge; * otherwise, it is aligned with the right edge. This is the same * behavior as with {@link #DEFAULT_JUSTIFICATION}. * * @see #getTitleJustification() * @see #setTitleJustification(int) * @see java.awt.ComponentOrientation#isLeftToRight() */ public static final int LEADING = 4; /** * A value for the <code>titleJustification</code> property that * horizontally aligns the title text with either the right or the * left edge of the border, depending on the orientation of the * component nested into the border. If the component orientation * is left-to-right, the title text is aligned with the right edge; * otherwise, it is aligned with the left edge. * * @see #getTitleJustification() * @see #setTitleJustification(int) * @see java.awt.ComponentOrientation#isLeftToRight() */ public static final int TRAILING = 5; /** * The number of pixels between the inside of {@link #border} * and the bordered component. */ protected static final int EDGE_SPACING = 2; /** * The number of pixels between the outside of this TitledBorder * and the beginning (if left-aligned) or end (if right-aligned) * of the title text. */ protected static final int TEXT_INSET_H = 5; /** * The number of pixels between the title text and {@link #border}. * This value is only relevant if the title text does not intersect * {@link #border}. No intersection occurs if {@link #titlePosition} * is one of {@link #ABOVE_TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, * or {@link #BELOW_BOTTOM}. */ protected static final int TEXT_SPACING = 2; /** * Determined using the <code>serialver</code> tool of Apple/Sun JDK 1.3.1 * on MacOS X 10.1.5. */ static final long serialVersionUID = 8012999415147721601L; /** * The title, or <code>null</code> to display no title. */ protected String title; /** * The border underneath the title. If this value is * <code>null</code>, the border will be retrieved from the {@link * javax.swing.UIManager}’s defaults table using the key * <code>"TitledBorder.border"</code>. */ protected Border border; /** * The vertical position of the title text relative to the border, * which is one of {@link #ABOVE_TOP}, {@link #TOP}, {@link * #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link * #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}. */ protected int titlePosition; /** * The horizontal alignment of the title text in relation to the * border, which is one of {@link #LEFT}, {@link #CENTER}, {@link * #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link * #DEFAULT_JUSTIFICATION}. */ protected int titleJustification; /** * The font for displaying the title text. If this value is * <code>null</code>, the font will be retrieved from the {@link * javax.swing.UIManager}’s defaults table using the key * <code>"TitledBorder.font"</code>. */ protected Font titleFont; /** * The color for displaying the title text. If this value is * <code>null</code>, the color will be retrieved from the {@link * javax.swing.UIManager}’s defaults table using the key * <code>"TitledBorder.titleColor"</code>. */ protected Color titleColor; /** * Constructs a TitledBorder given the text of its title. * * @param title the title text, or <code>null</code> to use no title text. */ public TitledBorder(String title) { this(/* border */ null, title, DEFAULT_JUSTIFICATION, DEFAULT_POSITION, /* titleFont */ null, /* titleColor */ null); } /** * Constructs an initially untitled TitledBorder given another border. * * @param border the border underneath the title, or <code>null</code> * to use a default from the current look and feel. */ public TitledBorder(Border border) { this(border, /* title */ "", DEFAULT_JUSTIFICATION, DEFAULT_POSITION, /* titleFont */ null, /* titleColor */ null); } /** * Constructs a TitledBorder given its border and title text. * * @param border the border underneath the title, or <code>null</code> * to use a default from the current look and feel. * * @param title the title text, or <code>null</code> to use no title * text. */ public TitledBorder(Border border, String title) { this(border, title, DEFAULT_JUSTIFICATION, DEFAULT_POSITION, /* titleFont */ null, /* titleColor */ null); } /** * Constructs a TitledBorder given its border, title text, horizontal * alignment, and vertical position. * * @param border the border underneath the title, or <code>null</code> * to use a default from the current look and feel. * * @param title the title text, or <code>null</code> to use no title * text. * * @param titleJustification the horizontal alignment of the title * text in relation to the border. The value must be one of * {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, * {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}. * @param titlePosition the vertical position of the title text * in relation to the border. The value must be one of * {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, * {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, * or {@link #DEFAULT_POSITION}. * * @throws IllegalArgumentException if <code>titleJustification</code> * or <code>titlePosition</code> have an unsupported value. */ public TitledBorder(Border border, String title, int titleJustification, int titlePosition) { this(border, title, titleJustification, titlePosition, /* titleFont */ null, /* titleColor */ null); } /** * Constructs a TitledBorder given its border, title text, horizontal * alignment, vertical position, and font. * * @param border the border underneath the title, or <code>null</code> * to use a default from the current look and feel. * * @param title the title text, or <code>null</code> to use no title * text. * * @param titleJustification the horizontal alignment of the title * text in relation to the border. The value must be one of * {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, * {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}. * * @param titlePosition the vertical position of the title text * in relation to the border. The value must be one of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -