001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * DynamicReplacedContentStyleSheet.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.layout.style;
030:
031: import java.awt.geom.Point2D;
032:
033: import org.jfree.report.style.AbstractStyleSheet;
034: import org.jfree.report.style.ElementStyleKeys;
035: import org.jfree.report.style.StyleKey;
036: import org.jfree.report.style.StyleSheet;
037: import org.jfree.report.util.InstanceID;
038: import org.jfree.ui.FloatDimension;
039:
040: /**
041: * A replaced content element that is contained in a 'canvas' box (which is the default for all non-inline replaced
042: * content elements) must have a minimum width and height of 100% so that it fills the whole box.
043: *
044: * @author Thomas Morgner
045: */
046: public class DynamicReplacedContentStyleSheet extends
047: AbstractStyleSheet {
048: private static final Float SIZE = new Float(-100);
049: private static final Float POS = new Float(0);
050: private StyleSheet parent;
051:
052: public DynamicReplacedContentStyleSheet(final StyleSheet parent) {
053: this .parent = parent;
054: }
055:
056: public StyleSheet getParent() {
057: return parent;
058: }
059:
060: public Object getStyleProperty(final StyleKey key,
061: final Object defaultValue) {
062: // if (ElementStyleKeys.MAXIMUMSIZE.equals(key))
063: // {
064: // final Float maxHeight = (Float) parent.getStyleProperty(ElementStyleKeys.MAX_HEIGHT);
065: // return new FloatDimension(SIZE.floatValue(), maxHeight.floatValue());
066: // }
067: // if (ElementStyleKeys.MAX_WIDTH.equals(key))
068: // {
069: // return SIZE;
070: // }
071: //
072: if (ElementStyleKeys.MINIMUMSIZE.equals(key)) {
073: return new FloatDimension(-100, -100);
074: }
075: if (ElementStyleKeys.MIN_WIDTH.equals(key)) {
076: return SIZE;
077: }
078: if (ElementStyleKeys.MIN_HEIGHT.equals(key)) {
079: return SIZE;
080: }
081: if (ElementStyleKeys.POS_X.equals(key)) {
082: return POS;
083: }
084: if (ElementStyleKeys.POS_Y.equals(key)) {
085: return POS;
086: }
087: if (ElementStyleKeys.ABSOLUTE_POS.equals(key)) {
088: return new Point2D.Float(0, 0);
089: }
090: return parent.getStyleProperty(key, defaultValue);
091: }
092:
093: public Object[] toArray(final StyleKey[] keys) {
094: final Object[] objects = (Object[]) parent.toArray(keys)
095: .clone();
096: objects[ElementStyleKeys.MIN_WIDTH.getIdentifier()] = SIZE;
097: objects[ElementStyleKeys.MIN_HEIGHT.getIdentifier()] = SIZE;
098: objects[ElementStyleKeys.MINIMUMSIZE.getIdentifier()] = null;
099: objects[ElementStyleKeys.POS_X.getIdentifier()] = POS;
100: objects[ElementStyleKeys.POS_Y.getIdentifier()] = POS;
101: objects[ElementStyleKeys.ABSOLUTE_POS.getIdentifier()] = null;
102: // objects[ElementStyleKeys.MAXIMUMSIZE.getIdentifier()] = null;
103: // objects[ElementStyleKeys.MAX_WIDTH.getIdentifier()] = SIZE;
104: return objects;
105: }
106:
107: public InstanceID getId() {
108: return parent.getId();
109: }
110:
111: public long getChangeTracker() {
112: return parent.getChangeTracker();
113: }
114: }
|