37 import javax.swing.border.AbstractBorder; 38 import javax.swing.text.AttributeSet; 39 import javax.swing.text.View; 40 import javax.swing.text.html.CSS.Attribute; 41 import javax.swing.text.html.CSS.BorderStyle; 42 import javax.swing.text.html.CSS.BorderWidthValue; 43 import javax.swing.text.html.CSS.ColorValue; 44 import javax.swing.text.html.CSS.CssValue; 45 import javax.swing.text.html.CSS.LengthValue; 46 import javax.swing.text.html.CSS.Value; 47 48 /** 49 * CSS-style borders for HTML elements. 50 * 51 * @author Sergey Groznyh 52 */ 53 @SuppressWarnings("serial") // Superclass is not serializable across versions 54 class CSSBorder extends AbstractBorder { 55 56 /** Indices for the attribute groups. */ 57 final static int COLOR = 0, STYLE = 1, WIDTH = 2; 58 59 /** Indices for the box sides within the attribute group. */ 60 final static int TOP = 0, RIGHT = 1, BOTTOM = 2, LEFT = 3; 61 62 /** The attribute groups. */ 63 final static Attribute[][] ATTRIBUTES = { 64 { Attribute.BORDER_TOP_COLOR, Attribute.BORDER_RIGHT_COLOR, 65 Attribute.BORDER_BOTTOM_COLOR, Attribute.BORDER_LEFT_COLOR, }, 66 { Attribute.BORDER_TOP_STYLE, Attribute.BORDER_RIGHT_STYLE, 67 Attribute.BORDER_BOTTOM_STYLE, Attribute.BORDER_LEFT_STYLE, }, 68 { Attribute.BORDER_TOP_WIDTH, Attribute.BORDER_RIGHT_WIDTH, 69 Attribute.BORDER_BOTTOM_WIDTH, Attribute.BORDER_LEFT_WIDTH, }, 70 }; 71 72 /** Parsers for the border properties. */ 73 final static CssValue PARSERS[] = { 74 new ColorValue(), new BorderStyle(), new BorderWidthValue(null, 0), 75 }; 76 77 /** Default values for the border properties. */ 78 final static Object[] DEFAULTS = { 79 Attribute.BORDER_COLOR, // marker: value will be computed on request 80 PARSERS[1].parseCssValue(Attribute.BORDER_STYLE.getDefaultValue()), 81 PARSERS[2].parseCssValue(Attribute.BORDER_WIDTH.getDefaultValue()), 82 }; 83 84 /** Attribute set containing border properties. */ 85 final AttributeSet attrs; 86 87 /** 88 * Initialize the attribute set. 89 */ 90 CSSBorder(AttributeSet attrs) { 91 this.attrs = attrs; 92 } 93 94 /** 95 * Return the border color for the given side. 96 */ 97 private Color getBorderColor(int side) { 98 Object o = attrs.getAttribute(ATTRIBUTES[COLOR][side]); | 37 import javax.swing.border.AbstractBorder; 38 import javax.swing.text.AttributeSet; 39 import javax.swing.text.View; 40 import javax.swing.text.html.CSS.Attribute; 41 import javax.swing.text.html.CSS.BorderStyle; 42 import javax.swing.text.html.CSS.BorderWidthValue; 43 import javax.swing.text.html.CSS.ColorValue; 44 import javax.swing.text.html.CSS.CssValue; 45 import javax.swing.text.html.CSS.LengthValue; 46 import javax.swing.text.html.CSS.Value; 47 48 /** 49 * CSS-style borders for HTML elements. 50 * 51 * @author Sergey Groznyh 52 */ 53 @SuppressWarnings("serial") // Superclass is not serializable across versions 54 class CSSBorder extends AbstractBorder { 55 56 /** Indices for the attribute groups. */ 57 static final int COLOR = 0, STYLE = 1, WIDTH = 2; 58 59 /** Indices for the box sides within the attribute group. */ 60 static final int TOP = 0, RIGHT = 1, BOTTOM = 2, LEFT = 3; 61 62 /** The attribute groups. */ 63 static final Attribute[][] ATTRIBUTES = { 64 { Attribute.BORDER_TOP_COLOR, Attribute.BORDER_RIGHT_COLOR, 65 Attribute.BORDER_BOTTOM_COLOR, Attribute.BORDER_LEFT_COLOR, }, 66 { Attribute.BORDER_TOP_STYLE, Attribute.BORDER_RIGHT_STYLE, 67 Attribute.BORDER_BOTTOM_STYLE, Attribute.BORDER_LEFT_STYLE, }, 68 { Attribute.BORDER_TOP_WIDTH, Attribute.BORDER_RIGHT_WIDTH, 69 Attribute.BORDER_BOTTOM_WIDTH, Attribute.BORDER_LEFT_WIDTH, }, 70 }; 71 72 /** Parsers for the border properties. */ 73 static final CssValue PARSERS[] = { 74 new ColorValue(), new BorderStyle(), new BorderWidthValue(null, 0), 75 }; 76 77 /** Default values for the border properties. */ 78 static final Object[] DEFAULTS = { 79 Attribute.BORDER_COLOR, // marker: value will be computed on request 80 PARSERS[1].parseCssValue(Attribute.BORDER_STYLE.getDefaultValue()), 81 PARSERS[2].parseCssValue(Attribute.BORDER_WIDTH.getDefaultValue()), 82 }; 83 84 /** Attribute set containing border properties. */ 85 final AttributeSet attrs; 86 87 /** 88 * Initialize the attribute set. 89 */ 90 CSSBorder(AttributeSet attrs) { 91 this.attrs = attrs; 92 } 93 94 /** 95 * Return the border color for the given side. 96 */ 97 private Color getBorderColor(int side) { 98 Object o = attrs.getAttribute(ATTRIBUTES[COLOR][side]); |