📄 bevelborder.java
字号:
* <code>right</code>, <code>top</code> and * <code>bottom</code> fields indicate the width of the * border at the respective edge. * * @return the same object that was passed for <code>insets</code>. * * @see #getBorderInsets() */ public Insets getBorderInsets(Component c, Insets insets) { insets.left = insets.right = insets.top = insets.bottom = 2; return insets; } /** * Determines the color that will be used for the outer side of * highlighted edges when painting the border. If a highlight color * has been specified upon constructing the border, that color is * returned. Otherwise, the inner highlight color is brightened. * * @param c the component enclosed by this border. * * @see #getHighlightInnerColor(java.awt.Component) * @see java.awt.Color#brighter() */ public Color getHighlightOuterColor(Component c) { if (highlightOuter != null) return highlightOuter; else return getHighlightInnerColor(c).brighter(); } /** * Determines the color that will be used for the inner side of * highlighted edges when painting the border. If a highlight color * has been specified upon constructing the border, that color is * returned. Otherwise, the background color of the enclosed * component is brightened. * * @param c the component enclosed by this border. * * @see java.awt.Component#getBackground() * @see java.awt.Color#brighter() */ public Color getHighlightInnerColor(Component c) { if (highlightInner != null) return highlightInner; else return c.getBackground().brighter(); } /** * Determines the color that will be used for the inner side of * shadowed edges when painting the border. If a shadow color has * been specified upon constructing the border, that color is * returned. Otherwise, the background color of the enclosed * component is darkened. * * @param c the component enclosed by this border. * * @see java.awt.Component#getBackground() * @see java.awt.Color#darker() */ public Color getShadowInnerColor(Component c) { if (shadowInner != null) return shadowInner; else return c.getBackground().darker(); } /** * Determines the color that will be used for the outer side of * shadowed edges when painting the border. If a shadow color * has been specified upon constructing the border, that color is * returned. Otherwise, the inner shadow color is darkened. * * @param c the component enclosed by this border. * * @see #getShadowInnerColor(java.awt.Component) * @see java.awt.Color#darker() */ public Color getShadowOuterColor(Component c) { if (shadowOuter != null) return shadowOuter; else return getShadowInnerColor(c).darker(); } /** * Returns the color that will be used for the outer side of * highlighted edges when painting the border, or <code>null</code> * if that color will be derived from the background of the enclosed * Component. */ public Color getHighlightOuterColor() { return highlightOuter; } /** * Returns the color that will be used for the inner side of * highlighted edges when painting the border, or <code>null</code> * if that color will be derived from the background of the enclosed * Component. */ public Color getHighlightInnerColor() { return highlightInner; } /** * Returns the color that will be used for the inner side of * shadowed edges when painting the border, or <code>null</code> if * that color will be derived from the background of the enclosed * Component. */ public Color getShadowInnerColor() { return shadowInner; } /** * Returns the color that will be used for the outer side of * shadowed edges when painting the border, or <code>null</code> if * that color will be derived from the background of the enclosed * Component. */ public Color getShadowOuterColor() { return shadowOuter; } /** * Returns the appearance of this border, which is either {@link * #RAISED} or {@link #LOWERED}. */ public int getBevelType() { return bevelType; } /** * Determines whether this border fills every pixel in its area * when painting. * * <p>If the border colors are derived from the background color of * the enclosed component, the result is <code>true</code> because * the derivation method always returns opaque colors. Otherwise, * the result depends on the opacity of the individual colors. * * @return <code>true</code> if the border is fully opaque, or * <code>false</code> if some pixels of the background * can shine through the border. */ public boolean isBorderOpaque() { /* If the colors are to be drived from the enclosed Component's * background color, the border is guaranteed to be fully opaque * because Color.brighten() and Color.darken() always return an * opaque color. */ return ((highlightOuter == null) || (highlightOuter.getAlpha() == 255)) && ((highlightInner == null) || (highlightInner.getAlpha() == 255)) && ((shadowInner == null) || (shadowInner.getAlpha() == 255)) && ((shadowOuter == null) ||(shadowOuter.getAlpha() == 255)); } /** * Paints a raised bevel border around a component. * * @param c the component whose border is to be painted. * @param g the graphics for painting. * @param x the horizontal position for painting the border. * @param y the vertical position for painting the border. * @param width the width of the available area for painting the border. * @param height the height of the available area for painting the border. */ protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) { paintBevel(g, x, y, width, height, getHighlightOuterColor(c), getHighlightInnerColor(c), getShadowInnerColor(c), getShadowOuterColor(c)); } /** * Paints a lowered bevel border around a component. * * @param c the component whose border is to be painted. * @param g the graphics for painting. * @param x the horizontal position for painting the border. * @param y the vertical position for painting the border. * @param width the width of the available area for painting the border. * @param height the height of the available area for painting the border. */ protected void paintLoweredBevel(Component c, Graphics g, int x, int y, int width, int height) { paintBevel(g, x, y, width, height, getShadowInnerColor(c), getShadowOuterColor(c), getHighlightInnerColor(c), getHighlightOuterColor(c)); } /** * Paints a two-pixel bevel in four colors. * * <pre> * @@@@@@@@@@@@ * @..........# @ = color a * @. X# . = color b * @. X# X = color c * @.XXXXXXXXX# # = color d * ############</pre> * * @param g the graphics for painting. * @param x the horizontal position for painting the border. * @param y the vertical position for painting the border. * @param width the width of the available area for painting the border. * @param height the height of the available area for painting the border. * @param a the color for the outer side of the top and left edges. * @param b the color for the inner side of the top and left edges. * @param c the color for the inner side of the bottom and right edges. * @param d the color for the outer side of the bottom and right edges. */ private static void paintBevel(Graphics g, int x, int y, int width, int height, Color a, Color b, Color c, Color d) { Color oldColor; oldColor = g.getColor(); g.translate(x, y); width = width - 1; height = height - 1; try { /* To understand this code, it might be helpful to look at the * images that are included with the JavaDoc. They are located * in the "doc-files" subdirectory. */ g.setColor(a); g.drawLine(0, 0, width, 0); // a, horizontal g.drawLine(0, 1, 0, height); // a, vertical g.setColor(b); g.drawLine(1, 1, width - 1, 1); // b, horizontal g.drawLine(1, 2, 1, height - 1); // b, vertical g.setColor(c); g.drawLine(2, height - 1, width - 1, height - 1); // c, horizontal g.drawLine(width - 1, 2, width - 1, height - 2); // c, vertical g.setColor(d); g.drawLine(1, height, width, height); // d, horizontal g.drawLine(width, 1, width, height - 1); // d, vertical } finally { g.translate(-x, -y); g.setColor(oldColor); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -