KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > StyleSheet


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.css.engine;
19
20 import org.w3c.css.sac.SACMediaList;
21
22 /**
23  * This class represents a list of rules.
24  *
25  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
26  * @version $Id: StyleSheet.java,v 1.4 2004/08/18 07:12:48 vhardy Exp $
27  */

28 public class StyleSheet {
29     
30     /**
31      * The rules.
32      */

33     protected Rule[] rules = new Rule[16];
34     
35     /**
36      * The number of rules.
37      */

38     protected int size;
39
40     /**
41      * The parent sheet, if any.
42      */

43     protected StyleSheet parent;
44
45     /**
46      * Whether or not this stylesheet is alternate.
47      */

48     protected boolean alternate;
49
50     /**
51      * The media to use to cascade properties.
52      */

53     protected SACMediaList media;
54
55     /**
56      * The style sheet title.
57      */

58     protected String JavaDoc title;
59
60     /**
61      * Sets the media to use to compute the styles.
62      */

63     public void setMedia(SACMediaList m) {
64         media = m;
65     }
66
67     /**
68      * Returns the media to use to compute the styles.
69      */

70     public SACMediaList getMedia() {
71         return media;
72     }
73
74     /**
75      * Returns the parent sheet.
76      */

77     public StyleSheet getParent() {
78         return parent;
79     }
80
81     /**
82      * Sets the parent sheet.
83      */

84     public void setParent(StyleSheet ss) {
85         parent = ss;
86     }
87
88     /**
89      * Sets the 'alternate' attribute of this style-sheet.
90      */

91     public void setAlternate(boolean b) {
92         alternate = b;
93     }
94
95     /**
96      * Tells whether or not this stylesheet is alternate.
97      */

98     public boolean isAlternate() {
99         return alternate;
100     }
101
102     /**
103      * Sets the 'title' attribute of this style-sheet.
104      */

105     public void setTitle(String JavaDoc t) {
106         title = t;
107     }
108
109     /**
110      * Returns the title of this style-sheet.
111      */

112     public String JavaDoc getTitle() {
113         return title;
114     }
115
116     /**
117      * Returns the number of rules.
118      */

119     public int getSize() {
120         return size;
121     }
122
123     /**
124      * Returns the rule at the given index.
125      */

126     public Rule getRule(int i) {
127         return rules[i];
128     }
129
130     /**
131      * Clears the content.
132      */

133     public void clear() {
134         size = 0;
135         rules = new Rule[10];
136     }
137
138     /**
139      * Appends a rule to the stylesheet.
140      */

141     public void append(Rule r) {
142         if (size == rules.length) {
143             Rule[] t = new Rule[size * 2];
144             for (int i = 0; i < size; i++) {
145                 t[i] = rules[i];
146             }
147             rules = t;
148         }
149         rules[size++] = r;
150     }
151
152     /**
153      * Returns a printable representation of this style-sheet.
154      */

155     public String JavaDoc toString(CSSEngine eng) {
156         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
157         for (int i = 0; i < size; i++) {
158             sb.append(rules[i].toString(eng));
159         }
160         return sb.toString();
161     }
162 }
163
Popular Tags