diff options
Diffstat (limited to 'libjava/classpath/javax/swing/plaf/metal/MetalBorders.java')
| -rw-r--r-- | libjava/classpath/javax/swing/plaf/metal/MetalBorders.java | 392 |
1 files changed, 390 insertions, 2 deletions
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java b/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java index f260ef6e34c..f55510684c6 100644 --- a/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java +++ b/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java @@ -45,14 +45,18 @@ import java.awt.Insets; import javax.swing.AbstractButton; import javax.swing.ButtonModel; -import javax.swing.JButton; +import javax.swing.JInternalFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JTextField; import javax.swing.border.AbstractBorder; import javax.swing.border.Border; import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.UIResource; -import javax.swing.plaf.basic.BasicGraphicsUtils; import javax.swing.plaf.basic.BasicBorders; + /** * This factory class creates borders for the different Swing components * UI. @@ -68,6 +72,9 @@ public class MetalBorders /** The shared instance for getRolloverButtonBorder(). */ private static Border toolbarButtonBorder; + /** The shared instance for getTextFieldBorder(). */ + private static Border textFieldBorder; + /** * A MarginBorder that gets shared by multiple components. * Created on demand by the private helper function {@link @@ -184,6 +191,373 @@ public class MetalBorders } /** + * A simple 3D border. + */ + public static class Flush3DBorder extends AbstractBorder + implements UIResource + { + /** + * Creates a new border instance. + */ + public Flush3DBorder() + { + } + + /** + * 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(2, 2, 2, 2); + else + { + newInsets.top = 2; + newInsets.left = 2; + newInsets.bottom = 2; + newInsets.right = 2; + } + return newInsets; + } + + /** + * Paints the border for the specified component. + * + * @param c the component (ignored). + * @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) + { + Color savedColor = g.getColor(); + g.setColor(MetalLookAndFeel.getControlDarkShadow()); + g.drawRect(x, y, w - 2, h - 2); + g.setColor(MetalLookAndFeel.getControlHighlight()); + g.drawRect(x + 1, y + 1, w - 2, h - 2); + g.setColor(MetalLookAndFeel.getControl()); + g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); + g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); + g.setColor(savedColor); + } + + } + + /** + * A border used for the {@link JTextField} component. + */ + public static class TextFieldBorder extends Flush3DBorder + implements UIResource + { + /** + * Creates a new border instance. + */ + public TextFieldBorder() + { + } + + /** + * Paints the border for the specified component. + * + * @param c the component (ignored). + * @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) + { + if (c.isEnabled()) + 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 when painting {@link JInternalFrame} instances. + */ + public static class InternalFrameBorder extends AbstractBorder + implements UIResource + { + /** + * Creates a new border instance. + */ + public InternalFrameBorder() + { + } + + /** + * 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 + g.setColor(MetalLookAndFeel.getControl()); + 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 JMenu} and {@link JMenuItem} components. + */ + public static class MenuItemBorder + extends AbstractBorder + implements UIResource + { + /** The border insets. */ + protected static Insets borderInsets = new Insets(2, 2, 2, 2); + + // TODO: find where the real colors come from + private static Color borderColorDark = new Color(102, 102, 153); + private static Color borderColorLight = new Color(255, 255, 255); + + /** + * Creates a new border instance. + */ + public MenuItemBorder() + { + } + + /** + * 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) + { + if (c instanceof JMenu) { + JMenu menu = (JMenu) c; + if (menu.isSelected()) + { + g.setColor(borderColorDark); + 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(borderColorLight); + 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(borderColorDark); + g.drawLine(x, y, x + w, y); + g.setColor(borderColorLight); + 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 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() + { + } + + /** + * 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 JScrollPanes. */ public static class ScrollPaneBorder @@ -413,6 +787,20 @@ public class MetalBorders } /** + * Returns a border for use by the {@link JTextField} component. + * + * @return A border. + * + * @since 1.3 + */ + public static Border getTextFieldBorder() + { + if (textFieldBorder == null) + textFieldBorder = new TextFieldBorder(); + return textFieldBorder; + } + + /** * Returns a border for Toolbar buttons in the Metal Look & Feel. * * @return a border for Toolbar buttons in the Metal Look & Feel |
