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: * DynamicHeightWrapperStyleSheet.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.ElementStyleKeys;
33: import org.jfree.report.style.StyleKey;
34: import org.jfree.report.style.StyleSheet;
35: import org.jfree.report.util.InstanceID;
36: import org.jfree.ui.FloatDimension;
37:
38: /**
39: * An element, that has the dynamic flag set to true, must restrict its maximum width to the minimum width (unless
40: * it explicitly defines the maximum-width). This strange behavior is a legacy of our old sloopy layouting definition,
41: * where the minimum-size provided the defaults for all other sizes.
42: *
43: * @author Thomas Morgner
44: */
45: public class DynamicHeightWrapperStyleSheet extends AbstractStyleSheet {
46: private StyleSheet parent;
47: private Float minWidth;
48:
49: public DynamicHeightWrapperStyleSheet(final StyleSheet parent) {
50: this .parent = parent;
51: this .minWidth = (Float) parent
52: .getStyleProperty(ElementStyleKeys.MIN_WIDTH);
53: }
54:
55: public StyleSheet getParent() {
56: return parent;
57: }
58:
59: public Object getStyleProperty(final StyleKey key,
60: final Object defaultValue) {
61: if (ElementStyleKeys.MAXIMUMSIZE.equals(key)) {
62: final Float maxHeight = (Float) parent
63: .getStyleProperty(ElementStyleKeys.MAX_HEIGHT);
64: return new FloatDimension(minWidth.floatValue(), maxHeight
65: .floatValue());
66: }
67: if (ElementStyleKeys.MAX_WIDTH.equals(key)) {
68: return parent.getStyleProperty(ElementStyleKeys.MIN_WIDTH,
69: defaultValue);
70: }
71: return parent.getStyleProperty(key, defaultValue);
72: }
73:
74: public Object[] toArray(final StyleKey[] keys) {
75: final Object[] objects = (Object[]) parent.toArray(keys)
76: .clone();
77: objects[ElementStyleKeys.MAXIMUMSIZE.getIdentifier()] = null;
78: objects[ElementStyleKeys.MAX_WIDTH.getIdentifier()] = objects[ElementStyleKeys.MIN_WIDTH
79: .getIdentifier()];
80: return objects;
81: }
82:
83: public InstanceID getId() {
84: return parent.getId();
85: }
86:
87: public long getChangeTracker() {
88: return parent.getChangeTracker();
89: }
90: }
|