KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > border > SAbstractBorder


1 /*
2  * $Id: SAbstractBorder.java,v 1.8 2005/05/27 09:17:33 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.border;
15
16 import org.wings.style.CSSAttributeSet;
17 import org.wings.style.CSSStyleSheet;
18 import org.wings.style.CSSProperty;
19
20 import java.awt.*;
21
22 /**
23  * This is a an abstract implementation of the <code>SBorder</code>
24  * interface.
25  *
26  * @author <a HREF="mailto:engels@mercatis.de">Holger Engels</a>
27  * @version $Revision: 1.8 $
28  */

29 public abstract class SAbstractBorder
30         implements SBorder {
31     /**
32      * the insets
33      */

34     private Insets insets;
35
36     /**
37      * border color
38      */

39     private Color color;
40
41     /**
42      * border thickness
43      */

44     private int thickness;
45
46     protected CSSAttributeSet attributes = new CSSAttributeSet();
47
48     public SAbstractBorder() {
49         this(Color.black, 2, new Insets(0, 0, 0, 0));
50     }
51
52     public SAbstractBorder(Color c, int thickness, Insets insets) {
53         setInsets(insets);
54         setColor(c);
55         setThickness(thickness);
56     }
57
58     public SAbstractBorder(Insets insets) {
59         this(null, 0, insets);
60     }
61
62     public SAbstractBorder(Color c) {
63         this(c, 2, new Insets(0, 0, 0, 0));
64     }
65
66     public SAbstractBorder(int thickness) {
67         this(Color.black, thickness, new Insets(0, 0, 0, 0));
68     }
69
70     /**
71      * set the insets of the border
72      */

73     public void setInsets(Insets insets) {
74         this.insets = insets;
75         if (insets != null) {
76             attributes.put(CSSProperty.PADDING_TOP, insets.top + "px");
77             attributes.put(CSSProperty.PADDING_LEFT, insets.left + "px");
78             attributes.put(CSSProperty.PADDING_RIGHT, insets.right + "px");
79             attributes.put(CSSProperty.PADDING_BOTTOM, insets.bottom + "px");
80         }
81         else {
82             attributes.remove(CSSProperty.PADDING_TOP);
83             attributes.remove(CSSProperty.PADDING_LEFT);
84             attributes.remove(CSSProperty.PADDING_RIGHT);
85             attributes.remove(CSSProperty.PADDING_BOTTOM);
86         }
87     }
88
89     /**
90      * @return the insets of the border
91      */

92     public final Insets getInsets() {
93         return insets;
94     }
95
96     /**
97      * sets the foreground color of the border
98      */

99     public Color getColor() {
100         return color;
101     }
102
103     /**
104      * sets the foreground color of the border
105      */

106     public void setColor(Color color) {
107         this.color = color;
108         attributes.put(CSSProperty.BORDER_COLOR, CSSStyleSheet.getAttribute(color));
109     }
110
111     /**
112      * set the thickness of the border
113      * thickness must be > 0
114      */

115     public void setThickness(int thickness) {
116         this.thickness = thickness;
117         attributes.put(CSSProperty.BORDER_WIDTH, thickness + "px");
118     }
119
120     public CSSAttributeSet getAttributes() {
121         return attributes;
122     }
123
124     /**
125      * @return thickness in pixels
126      */

127     public final int getThickness() {
128         return thickness;
129     }
130
131 }
132
Popular Tags