01: /**
02: * ===========================================
03: * JFreeReport : a free Java reporting library
04: * ===========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
09: *
10: * This library is free software; you can redistribute it and/or modify it under the terms
11: * of the GNU Lesser General Public License as published by the Free Software Foundation;
12: * either version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16: * See the GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License along with this
19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: *
22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23: * in the United States and other countries.]
24: *
25: * ------------
26: * CacheStyleSheet.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.layout.text;
30:
31: import java.util.Arrays;
32:
33: import org.jfree.report.style.AbstractStyleSheet;
34: import org.jfree.report.style.StyleKey;
35: import org.jfree.report.style.StyleSheet;
36:
37: /**
38: * This stylesheet collects all style-properties that may be used during the text-creation.
39: *
40: * @author Thomas Morgner
41: */
42: public class CacheStyleSheet extends AbstractStyleSheet {
43: public static final Object UNDEFINED = new Object();
44: private Object[] cache;
45: private StyleSheet parent;
46: private boolean locked;
47:
48: public CacheStyleSheet(final StyleSheet parent,
49: final int styleKeyCount) {
50: this .parent = parent;
51: this .cache = new Object[styleKeyCount];
52: Arrays.fill(cache, UNDEFINED);
53: }
54:
55: public Object getStyleProperty(final StyleKey key,
56: final Object defaultValue) {
57: final Object value = parent.getStyleProperty(key, defaultValue);
58: if (!locked) {
59: cache[key.getIdentifier()] = value;
60: }
61: return value;
62: }
63:
64: public StyleSheet getParent() {
65: return parent;
66: }
67:
68: //
69: // public void setParent(final StyleSheet parent)
70: // {
71: // this.cache.clear();
72: // this.parent = parent;
73: // }
74:
75: public Object[] getEntries() {
76: return this .cache;
77: }
78:
79: public void lock() {
80: this .locked = true;
81: this.cache = null;
82: }
83: }
|