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: * ElementLayoutInformation.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.util;
030:
031: import org.jfree.report.util.geom.StrictBounds;
032: import org.jfree.report.util.geom.StrictDimension;
033: import org.jfree.report.util.geom.StrictPoint;
034:
035: /**
036: * A small carrier class to encapsulate the common layout parameters. This information is
037: * a utility class, don't expect to find one bound to an element.
038: *
039: * @author Thomas Morgner
040: * @deprecated Is no longer needed. Remove it.
041: */
042: public class ElementLayoutInformation {
043: /**
044: * The absolute position of the element.
045: */
046: private StrictPoint absolutePosition;
047:
048: /**
049: * The current minimum size for the element.
050: */
051: private StrictDimension minimumSize;
052:
053: /**
054: * The current maximum size for the element.
055: */
056: private StrictDimension maximumSize;
057:
058: /**
059: * The current preferred size for the element.
060: */
061: private StrictDimension preferredSize;
062:
063: /**
064: * Creates a new instance.
065: * <p/>
066: * The position will be <code>rect.x, rect.y</code> and all dimensions are set to
067: * <code>rect.width, rect.height</code>.
068: *
069: * @param rect the rectangle that will be the base for this ElementLayoutInformation.
070: * @throws java.lang.NullPointerException if the given rectangle is null.
071: */
072: public ElementLayoutInformation(final StrictBounds rect) {
073: if (rect == null) {
074: throw new NullPointerException();
075: }
076: absolutePosition = new StrictPoint(rect.getX(), rect.getY());
077: final StrictDimension fdim = new StrictDimension(rect
078: .getWidth(), rect.getHeight());
079: maximumSize = fdim;
080: minimumSize = fdim;
081: preferredSize = fdim;
082: }
083:
084: /**
085: * Creates a new instance.
086: * <p/>
087: * The preferred size will be undefined (<code>null</code>).
088: *
089: * @param absolutePosition the absolute position for the element.
090: * @param minimumSize the minimum size for the element.
091: * @param maximumSize the maximum size for the element.
092: * @throws java.lang.NullPointerException if one of the parameters is <code>null</code>.
093: */
094: public ElementLayoutInformation(final StrictPoint absolutePosition,
095: final StrictDimension minimumSize,
096: final StrictDimension maximumSize) {
097: this (absolutePosition, minimumSize, maximumSize, null);
098: }
099:
100: /**
101: * Creates a new instance.
102: * <p/>
103: * If the preferred size is <code>null</code>, then it is left undefined.
104: *
105: * @param absolutePosition the absolute position for the element
106: * @param minimumSize the minimum size for the element
107: * @param maximumSize the maximum size for the element
108: * @param preferredSize the preferred size or <code>null</code> if not known.
109: * @throws java.lang.NullPointerException if the position or max/min size is
110: * <code>null</code>.
111: */
112: public ElementLayoutInformation(final StrictPoint absolutePosition,
113: final StrictDimension minimumSize,
114: final StrictDimension maximumSize,
115: final StrictDimension preferredSize) {
116: if (absolutePosition == null) {
117: throw new NullPointerException();
118: }
119: if (minimumSize == null) {
120: throw new NullPointerException();
121: }
122: if (maximumSize == null) {
123: throw new NullPointerException();
124: }
125: this .absolutePosition = (StrictPoint) absolutePosition.clone();
126: // the minsize cannot be greater than the max size ...
127: this .minimumSize = unionMin(maximumSize, minimumSize);
128: this .maximumSize = (StrictDimension) maximumSize.clone();
129: if (preferredSize != null) {
130: this .preferredSize = (StrictDimension) preferredSize
131: .clone();
132: }
133: }
134:
135: /**
136: * Gets the absolute positon defined in this LayoutInformation.
137: *
138: * @return a clone of the absolute position.
139: */
140: public StrictPoint getAbsolutePosition() {
141: return (StrictPoint) absolutePosition.clone();
142: }
143:
144: /**
145: * Gets the minimum size defined in this LayoutInformation.
146: *
147: * @return a clone of the minimum size.
148: */
149: public StrictDimension getMinimumSize() {
150: return (StrictDimension) minimumSize.clone();
151: }
152:
153: /**
154: * Gets the maximum size defined in this LayoutInformation.
155: *
156: * @return a clone of the maximum size.
157: */
158: public StrictDimension getMaximumSize() {
159: return (StrictDimension) maximumSize.clone();
160: }
161:
162: /**
163: * Gets the preferred size defined in this LayoutInformation.
164: *
165: * @return a clone of the preferred size.
166: */
167: public StrictDimension getPreferredSize() {
168: if (preferredSize == null) {
169: return null;
170: }
171: return (StrictDimension) preferredSize.clone();
172: }
173:
174: /**
175: * Create a minimum dimension of the given 2 dimension objects. If pref is not given,
176: * the max parameter is returned unchanged.
177: * <p/>
178: * This is used to limit the element bounds to the preferred size or the maximum size
179: * (in case the user misconfigured anything).
180: *
181: * @param max the maximum size as retrieved from the element.
182: * @param pref the preferred size.
183: * @return the minimum dimension.
184: */
185: public static StrictDimension unionMin(final StrictDimension max,
186: final StrictDimension pref) {
187: if (pref == null) {
188: return max;
189: }
190: return new StrictDimension(Math.min(pref.getWidth(), max
191: .getWidth()), Math.min(pref.getHeight(), max
192: .getHeight()));
193: }
194:
195: /**
196: * Returns a string representing the object (useful for debugging).
197: *
198: * @return A string.
199: */
200: public String toString() {
201: final StringBuffer b = new StringBuffer();
202: b.append("ElementLayoutInformation: \n");
203: b.append(" AbsolutePos: ");
204: b.append(absolutePosition);
205: b.append("\n MinSize: ");
206: b.append(minimumSize);
207: b.append("\n PrefSize: ");
208: b.append(preferredSize);
209: b.append("\n MaxSize: ");
210: b.append(maximumSize);
211: b.append('\n');
212: return b.toString();
213: }
214: }
|