📄 metalborders.java
字号:
* @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) { boolean enabledTextBorder; if (c instanceof JTextComponent) { JTextComponent tc = (JTextComponent) c; enabledTextBorder = tc.isEnabled() && tc.isEditable(); } else enabledTextBorder = false; if (enabledTextBorder) super.paintBorder(c, g, x, y, w, h); else { Color savedColor = g.getColor(); g.setColor(MetalLookAndFeel.getControlShadow()); g.drawRect(x, y, w - 1, h - 1); g.setColor(savedColor); } } } /** * A border used for the {@link JInternalFrame} component. */ public static class InternalFrameBorder extends AbstractBorder implements UIResource { /** * Creates a new border instance. */ public InternalFrameBorder() { // 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(5, 5, 5, 5); else { newInsets.top = 5; newInsets.left = 5; newInsets.bottom = 5; newInsets.right = 5; } 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) { JInternalFrame f = (JInternalFrame) c; if (f.isSelected()) g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); else g.setColor(MetalLookAndFeel.getControlDarkShadow()); // fill the border background g.fillRect(x, y, w, 5); g.fillRect(x, y, 5, h); g.fillRect(x + w - 5, y, 5, h); g.fillRect(x, y + h - 5, w, 5); // draw 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); // draw the lines g.setColor(MetalLookAndFeel.getBlack()); g.drawLine(x + 14, y + 2, x + w - 15, y + 2); g.drawLine(x + 14, y + h - 3, x + w - 15, y + h - 3); g.drawLine(x + 2, y + 14, x + 2, y + h - 15); g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15); // draw the line highlights if (f.isSelected()) g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); else g.setColor(MetalLookAndFeel.getControlShadow()); g.drawLine(x + 15, y + 3, x + w - 14, y + 3); g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2); g.drawLine(x + 3, y + 15, x + 3, y + h - 14); g.drawLine(x + w - 2, y + 15, x + w - 2, y + h - 14); } } /** * A border used for {@link JInternalFrame} components that are * presented as dialogs (by the {@link JOptionPane} class). */ public static class OptionDialogBorder extends AbstractBorder implements UIResource { /** * Creates a new border instance. */ public OptionDialogBorder() { // 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, 3, 3); else { newInsets.top = 3; newInsets.left = 3; newInsets.bottom = 3; 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) { JInternalFrame f = (JInternalFrame) c; g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); if (f.getContentPane() instanceof JOptionPane) { JOptionPane pane = (JOptionPane) f.getContentPane(); int type = pane.getMessageType(); if (type == JOptionPane.QUESTION_MESSAGE) { Color bc = UIManager.getColor( "OptionPane.questionDialog.border.background"); if (bc != null) g.setColor(bc); } if (type == JOptionPane.WARNING_MESSAGE) { Color bc = UIManager.getColor( "OptionPane.warningDialog.border.background"); if (bc != null) g.setColor(bc); } else if (type == JOptionPane.ERROR_MESSAGE) { Color bc = UIManager.getColor( "OptionPane.errorDialog.border.background"); if (bc != null) g.setColor(bc); } } // fill the border background g.fillRect(x, y, w, 3); g.fillRect(x, y, 3, h); g.fillRect(x + w - 3, y, 3, h); g.fillRect(x, y + h - 3, w, 3); // draw 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); } } /** * A border used for {@link JMenu} and {@link JMenuItem} components. */ public static class MenuItemBorder extends AbstractBorder implements UIResource { /** The border insets. */ protected static Insets borderInsets = new Insets(1, 1, 1, 1); /** * Creates a new border instance. */ public MenuItemBorder() { // Nothing to do here. } /** * Paints the border for the component. A border is painted only if the * component is a selected {@link JMenu} or an armed {@link JMenuItem}. * * @param c the component. * @param g the graphics device. * @param x the x-coordinate of the border area. * @param y the y-coordinate of the border area. * @param w the width of the border area. * @param h the height of the border area. */ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color dark = MetalLookAndFeel.getPrimaryControlDarkShadow(); Color light = MetalLookAndFeel.getPrimaryControlHighlight(); if (c instanceof JMenu) { JMenu menu = (JMenu) c; if (menu.isSelected()) { g.setColor(dark); g.drawLine(x, y, x, y + h); g.drawLine(x, y, x + w, y); g.drawLine(x + w - 2, y + 1, x + w - 2, y + h); g.setColor(light); g.drawLine(x + w - 1, y + 1, x + w - 1, y + h); } } else if (c instanceof JMenuItem) { JMenuItem item = (JMenuItem) c; if (item.isArmed()) { g.setColor(dark); g.drawLine(x, y, x + w, y); g.setColor(light); g.drawLine(x, y + h - 1, x + w, y + h - 1); } else { // Normally we draw a light line on the left. g.setColor(light); g.drawLine(x, y, x, y + h); } } } /** * Returns the border insets. * * @param c the component (ignored). * * @return The border insets. */ public Insets getBorderInsets(Component c) { return borderInsets; } /** * Populates <code>insets</code> with the border insets, then returns it. * * @param c the component (ignored). * @param insets the object to populate with the border insets. * * @return The border insets. * * @throws NullPointerException if <code>insets</code> is <code>null</code>. */ public Insets getBorderInsets(Component c, Insets insets) { insets.left = borderInsets.left; insets.top = borderInsets.top; insets.bottom = borderInsets.bottom; insets.right = borderInsets.right; return insets; } } /** * A border used for {@link JMenuBar} components. */ public static class MenuBarBorder extends AbstractBorder implements UIResource { /** The border insets. */ protected static Insets borderInsets = new Insets(1, 0, 1, 0); // TODO: find where this color really comes from private static Color borderColor = new Color(153, 153, 153); /** * Creates a new border instance. */ public MenuBarBorder() { // Nothing to do here. } /** * Paints the border for the component. A border is painted only if the * component is a selected {@link JMenu} or an armed {@link JMenuItem}. * * @param c the component. * @param g the graphics device. * @param x the x-coordinate of the border area. * @param y the y-coordinate of the border area. * @param w the width of the border area. * @param h the height of the border area. */ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.setColor(borderColor); g.drawLine(x, y + h - 1, x + w, y + h - 1); } /** * Returns the border insets. * * @param c the component (ignored). * * @return The border insets. */ public Insets getBorderInsets(Component c) { return borderInsets; } /** * Populates <code>insets</code> with the border insets, then returns it. * * @param c the component (ignored). * @param insets the object to populate with the border insets. * * @return The border insets. * * @throws NullPointerException if <code>insets</code> is <code>null</code>. */ public Insets getBorderInsets(Component c, Insets insets) { insets.left = borderInsets.left; insets.top = borderInsets.top; insets.bottom = borderInsets.bottom; insets.right = borderInsets.right; return insets; } } /** * A border for {@link JScrollPane} components. */ public static class ScrollPaneBorder extends AbstractBorder implements UIResource { /** The border insets. */ private static Insets insets = new Insets(1, 1, 2, 2); /** * Constructs a new ScrollPaneBorder. */ public ScrollPaneBorder() { // Nothing to do here. } /** * Returns the insets of the border for the Component <code>c</code>. * * @param c the Component for which we return the border insets */ public Insets getBorderInsets(Component c) { return insets; } /** * Paints the border. * * @param c the Component for which the border is painted * @param g the Graphics context * @param x the X coordinate of the upper left corner of the border * @param y the Y coordinate of the upper left corner of the border * @param w the width of the border * @param h the height of the border */ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color darkShadow = MetalLookAndFeel.getControlDarkShadow(); Color shadow = MetalLookAndFeel.getControlShadow(); Color light = MetalLookAndFeel.getWhite(); Color middle = MetalLookAndFeel.getControl(); // paint top border line g.setColor(darkShadow); g.drawLine(x, y, x + w - 2, y); // paint left border line g.drawLine(x, y, x, y + h - 2); // paint right inner border line g.drawLine(x + w - 2, y, x + w - 2, y + h + 1); // paint bottom inner border line g.drawLine(x + 2, y + h - 2, x + w - 2, y + h - 2); // draw right outer border line g.setColor(light); g.drawLine(x + w - 1, y, x + w - 1, y + h - 1); // draw bottom outer border line g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); // paint the lighter points g.setColor(middle); g.drawLine(x + w - 1, y, x + w - 1, y); g.drawLine(x + w - 2, y + 2, x + w - 2, y + 2); g.drawLine(x, y + h - 1, x, y + h - 1); g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); } } /** * A button border that is only visible when the mouse pointer is within * the button's bounds. */ public static class RolloverButtonBorder extends MetalBorders.ButtonBorder { /** * Creates a new border instance. */ public RolloverButtonBorder() { // Nothing to do here. } /** * Paints the border. * * @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) { boolean mouseIsOver = false; if (c instanceof AbstractButton) { ButtonModel bmodel = ((AbstractButton) c).getModel(); mouseIsOver = bmodel.isRollover(); } if (mouseIsOver) super.paintBorder(c, g, x, y, w, h); } } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -