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: * SimpleStyleSheet.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.layout.style;
30:
31: import org.jfree.report.style.AbstractStyleSheet;
32: import org.jfree.report.style.BandDefaultStyleSheet;
33: import org.jfree.report.style.StyleKey;
34: import org.jfree.report.style.StyleSheet;
35: import org.jfree.report.util.InstanceID;
36:
37: /**
38: * A simple, read-only stylesheet.
39: *
40: * @author Thomas Morgner
41: */
42: public final class SimpleStyleSheet extends AbstractStyleSheet {
43: public static final StyleSheet EMPTY_STYLE = new SimpleStyleSheet(
44: BandDefaultStyleSheet.getBandDefaultStyle(), StyleKey
45: .getDefinedStyleKeys());
46:
47: private Object[] properties;
48: private InstanceID parentId;
49:
50: public SimpleStyleSheet(final StyleSheet parent,
51: final StyleKey[] definedStyleKeys) {
52: if (parent == null) {
53: throw new NullPointerException();
54: }
55: if (definedStyleKeys == null) {
56: throw new NullPointerException();
57: }
58: this .parentId = parent.getId();
59: this .properties = parent.toArray(definedStyleKeys);
60: }
61:
62: /**
63: * Returns the value of a style. If the style is not found in this style-sheet, the code looks in the parent
64: * style-sheets. If the style is not found in any of the parent style-sheets, then the default value (possibly
65: * <code>null</code>) is returned.
66: *
67: * @param key the style key.
68: * @param defaultValue the default value (<code>null</code> permitted).
69: * @return the value.
70: */
71: public Object getStyleProperty(final StyleKey key,
72: final Object defaultValue) {
73: final int identifier = key.getIdentifier();
74: if (properties.length > identifier) {
75: final Object property = properties[identifier];
76: if (property != null) {
77: return property;
78: }
79: }
80: return defaultValue;
81: }
82:
83: public InstanceID getParentId() {
84: return parentId;
85: }
86:
87: }
|