KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > ListValue


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.value;
19
20 import org.w3c.dom.DOMException JavaDoc;
21 import org.w3c.dom.css.CSSValue;
22
23 /**
24  * This class represents a list of values.
25  *
26  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
27  * @version $Id: ListValue.java,v 1.5 2004/08/18 07:12:53 vhardy Exp $
28  */

29 public class ListValue extends AbstractValue {
30     
31     /**
32      * The length of the list.
33      */

34     protected int length;
35
36     /**
37      * The items.
38      */

39     protected Value[] items = new Value[5];
40
41     /**
42      * The list separator.
43      */

44     protected char separator = ',';
45
46     /**
47      * Creates a ListValue.
48      */

49     public ListValue() {
50     }
51
52     /**
53      * Creates a ListValue with the given separator.
54      */

55     public ListValue(char s) {
56         separator = s;
57     }
58
59     /**
60      * Returns the separator used for this list.
61      */

62     public char getSeparatorChar() {
63         return separator;
64     }
65
66     /**
67      * Implements {@link Value#getCssValueType()}.
68      */

69     public short getCssValueType() {
70         return CSSValue.CSS_VALUE_LIST;
71     }
72
73     /**
74      * A string representation of the current value.
75      */

76     public String JavaDoc getCssText() {
77         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
78         if (length > 0) {
79             sb.append(items[0].getCssText());
80         }
81         for (int i = 1; i < length; i++) {
82             sb.append(separator);
83             sb.append(items[i].getCssText());
84         }
85         return sb.toString();
86     }
87
88     /**
89      * Implements {@link Value#getLength()}.
90      */

91     public int getLength() throws DOMException JavaDoc {
92         return length;
93     }
94
95     /**
96      * Implements {@link Value#item(int)}.
97      */

98     public Value item(int index) throws DOMException JavaDoc {
99         return items[index];
100     }
101
102     /**
103      * Returns a printable representation of this value.
104      */

105     public String JavaDoc toString() {
106         return getCssText();
107     }
108
109     /**
110      * Appends an item to the list.
111      */

112     public void append(Value v) {
113         if (length == items.length) {
114             Value[] t = new Value[length * 2];
115             for (int i = 0; i < length; i++) {
116                 t[i] = items[i];
117             }
118             items = t;
119         }
120         items[length++] = v;
121     }
122 }
123
Popular Tags