📄 metalborders.java
字号:
* This border is used in Toolbar buttons as inner border. */ static class RolloverMarginBorder extends AbstractBorder { /** The borders insets. */ protected static Insets borderInsets = new Insets(3, 3, 3, 3); /** * Creates a new instance of RolloverBorder. */ public RolloverMarginBorder() { // Nothing to do here. } /** * Returns the insets of the RolloverBorder. * * @param c the component for which the border is used * * @return the insets of the RolloverBorder */ public Insets getBorderInsets(Component c) { return getBorderInsets(c, null); } /** * Returns the insets of the RolloverMarginBorder in the specified * Insets object. * * @param c the component for which the border is used * @param newInsets the insets object where to put the values * * @return the insets of the RolloverMarginBorder */ public Insets getBorderInsets(Component c, Insets newInsets) { if (newInsets == null) newInsets = new Insets(0, 0, 0, 0); AbstractButton b = (AbstractButton) c; Insets margin = b.getMargin(); newInsets.bottom = borderInsets.bottom; newInsets.left = borderInsets.left; newInsets.right = borderInsets.right; newInsets.top = borderInsets.top; return newInsets; } } /** * A border implementation for popup menus. */ public static class PopupMenuBorder extends AbstractBorder implements UIResource { /** The border's insets. */ protected static Insets borderInsets = new Insets(3, 1, 2, 1); /** * Constructs a new PopupMenuBorder. */ public PopupMenuBorder() { // Nothing to do here. } /** * Returns the insets of the border, creating a new Insets instance * with each call. * * @param c the component for which we return the border insets * (not used here) */ public Insets getBorderInsets(Component c) { return getBorderInsets(c, null); } /** * Returns the insets of the border, using the supplied Insets instance. * * @param c the component for which we return the border insets * (not used here) * @param i the Insets instance to fill with the Insets values */ public Insets getBorderInsets(Component c, Insets i) { Insets insets; if (i == null) insets = new Insets(borderInsets.top, borderInsets.left, borderInsets.bottom, borderInsets.right); else { insets = i; insets.top = borderInsets.top; insets.left = borderInsets.left; insets.bottom = borderInsets.bottom; insets.right = borderInsets.right; } return insets; } /** * Paints the border for component <code>c</code> using the * Graphics context <code>g</code> with the dimension * <code>x, y, w, h</code>. * * @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) { Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow(); Color light = MetalLookAndFeel.getPrimaryControlHighlight(); // draw dark outer border g.setColor(darkShadow); g.drawRect(x, y, w - 1, h - 1); // draw highlighted inner border (only top and left) g.setColor(light); g.drawLine(x + 1, y + 1, x + w - 2, y + 1); } } /** * A border used for the {@link JToggleButton} component. * * @since 1.3 */ public static class ToggleButtonBorder extends ButtonBorder { /** * Creates a new border instance. */ public ToggleButtonBorder() { // Nothing to do here. } /** * Paints the toggle 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) { ButtonModel bmodel = null; if (c instanceof AbstractButton) bmodel = ((AbstractButton) c).getModel(); Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); Color shadow = MetalLookAndFeel.getControlShadow(); Color light = MetalLookAndFeel.getWhite(); Color middle = MetalLookAndFeel.getControl(); if (c.isEnabled()) { // draw dark border g.setColor(darkShadow); g.drawRect(x, y, w - 2, h - 2); if (!bmodel.isArmed()) { // draw light border g.setColor(light); g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); if (bmodel.isSelected()) g.setColor(middle); g.drawLine(x + 1, y + 1, x + w - 3, y + 1); g.drawLine(x + 1, y + 1, x + 1, y + h - 3); // draw crossing pixels of both borders g.setColor(shadow); 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(shadow); 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.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); } // draw corners g.setColor(middle); g.drawLine(x, y + h - 1, x, y + h - 1); g.drawLine(x + w - 1, y, x + w - 1, y); } else { // draw disabled border g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawRect(x, y, w - 2, h - 2); } } } /** * A border used for the {@link JToolBar} component. */ public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants { /** * Creates a new border instance. */ public ToolBarBorder() { // 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) { JToolBar tb = (JToolBar) c; if (tb.getOrientation() == JToolBar.HORIZONTAL) { if (newInsets == null) newInsets = new Insets(2, 16, 2, 2); else { newInsets.top = 2; newInsets.left = 16; newInsets.bottom = 2; newInsets.right = 2; } return newInsets; } else // assume JToolBar.VERTICAL { if (newInsets == null) newInsets = new Insets(16, 2, 2, 2); else { newInsets.top = 16; newInsets.left = 2; newInsets.bottom = 2; newInsets.right = 2; } 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) { JToolBar tb = (JToolBar) c; if (tb.getOrientation() == JToolBar.HORIZONTAL) { MetalUtils.fillMetalPattern(tb, g, x + 2, y + 2, x + 11, y + h - 5, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow()); } else { MetalUtils.fillMetalPattern(tb, g, x + 2, y + 2, x + w - 5, y + 11, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow()); } } } /** * A border for table header cells. * * @since 1.3 */ public static class TableHeaderBorder extends AbstractBorder { /** * The insets of this border. */ // TODO: According to tests that I have done, this is really the border // that should be returned by getBorderInsets(). However, the name // is very distracting. Is there any deeper meaning in it? protected Insets editorBorderInsets; /** * Creates a new instance of <code>TableHeaderBorder</code>. */ public TableHeaderBorder() { editorBorderInsets = new Insets(1, 1, 1, 1); } /** * Return the insets of this border. * * @return the insets of this border */ public Insets getBorderInsets(Component c) { return editorBorderInsets; } /** * Paints the border. * * @param c the component for which to paint the border * @param g the graphics context to use * @param x the x cooridinate of the border rectangle * @param y the y cooridinate of the border rectangle * @param w the width of the border rectangle * @param h the height of the border rectangle */ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color dark = MetalLookAndFeel.getControlDarkShadow(); Color light = MetalLookAndFeel.getWhite(); Color old = g.getColor(); g.setColor(light); g.drawLine(x, y, x + w - 2, y); g.drawLine(x, y, x, y + h - 2); g.setColor(dark); g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); g.setColor(old); } } /** * Returns a border for Swing buttons in the Metal Look & Feel. * * @return a border for Swing buttons in the Metal Look & Feel */ public static Border getButtonBorder() { if (buttonBorder == null) { Border outer = new ButtonBorder(); Border inner = getMarginBorder(); buttonBorder = new BorderUIResource.CompoundBorderUIResource (outer, inner); } return buttonBorder; } /** * Returns a border for use with {@link JToggleButton} components. * * @return A border. * * @since 1.3 */ public static Border getToggleButtonBorder() { if (toggleButtonBorder == null) { Border outer = new ToggleButtonBorder(); Border inner = getMarginBorder(); toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource (outer, inner); } return toggleButtonBorder; } /** * Returns a border instance that is used with a {@link JInternalFrame} when * it is in the iconified state. * * @return A border. * * @since 1.3 */ public static Border getDesktopIconBorder() { if (desktopIconBorder == null) desktopIconBorder = new DesktopIconBorder(); return desktopIconBorder; } /** * Returns a border for use by the {@link JTextField} component. * * @return A border. * * @since 1.3 */ public static Border getTextFieldBorder() { if (textFieldBorder == null) { Border inner = getMarginBorder(); Border outer = new TextFieldBorder(); textFieldBorder = new BorderUIResource.CompoundBorderUIResource(outer, inner); } return textFieldBorder; } /** * Returns the border that is used for text components (except text fields, * which use {@link #getTextFieldBorder}. * * @return the border that is used for text components * * @since 1.3 */ public static Border getTextBorder() { if (textBorder == null) { Border inner = getMarginBorder(); Border outer = new Flush3DBorder(); textBorder = new BorderUIResource.CompoundBorderUIResource(outer, inner); } return textBorder; } /** * Returns a border for Toolbar buttons in the Metal Look & Feel. * * @return a border for Toolbar buttons in the Metal Look & Feel */ static Border getToolbarButtonBorder() { if (toolbarButtonBorder == null) { Border outer = new ButtonBorder(); Border inner = new RolloverMarginBorder(); toolbarButtonBorder = new BorderUIResource.CompoundBorderUIResource (outer, inner); } return toolbarButtonBorder; } /** * Returns a shared instance of {@link BasicBorders.MarginBorder}. * * @return a shared instance of {@link BasicBorders.MarginBorder} */ static Border getMarginBorder() { if (marginBorder == null) marginBorder = new BasicBorders.MarginBorder(); return marginBorder; } /** * Returns a shared instance of a compound border for rollover buttons. * * @return A shared border instance. */ static Border getRolloverBorder() { if (rolloverBorder == null) { Border outer = new MetalBorders.RolloverButtonBorder(); Border inner = MetalBorders.getMarginBorder(); rolloverBorder = new BorderUIResource.CompoundBorderUIResource(outer, inner); } return rolloverBorder; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -