001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -------------------
028: * CompositeTitle.java
029: * -------------------
030: * (C) Copyright 2005, by David Gilbert and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: CompositeTitle.java,v 1.14.2.1 2005/10/25 20:58:34 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 19-Nov-2004 : Version 1 (DG);
040: * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG);
041: * 04-Feb-2005 : Implemented MAXIMUM_WIDTH in calculateSize (DG);
042: * 20-Apr-2005 : Added new draw() method (DG);
043: * 03-May-2005 : Implemented equals() method (DG);
044: *
045: */
046:
047: package org.jfree.chart.title;
048:
049: import java.awt.Graphics2D;
050: import java.awt.geom.Rectangle2D;
051: import java.io.Serializable;
052:
053: import org.jfree.chart.block.BlockContainer;
054: import org.jfree.chart.block.BorderArrangement;
055: import org.jfree.chart.block.RectangleConstraint;
056: import org.jfree.ui.Size2D;
057:
058: /**
059: * A title that contains multiple titles within a {@link BlockContainer}.
060: */
061: public class CompositeTitle extends Title implements Cloneable,
062: Serializable {
063:
064: /** For serialization. */
065: private static final long serialVersionUID = -6770854036232562290L;
066:
067: /** A container for the individual titles. */
068: private BlockContainer container;
069:
070: /**
071: * Creates a new composite title with a default border arrangement.
072: */
073: public CompositeTitle() {
074: this (new BlockContainer(new BorderArrangement()));
075: }
076:
077: /**
078: * Creates a new title using the specified container.
079: *
080: * @param container the container (<code>null</code> not permitted).
081: */
082: public CompositeTitle(BlockContainer container) {
083: if (container == null) {
084: throw new IllegalArgumentException(
085: "Null 'container' argument.");
086: }
087: this .container = container;
088: }
089:
090: /**
091: * Returns the container holding the titles.
092: *
093: * @return The title container (never <code>null</code>).
094: */
095: public BlockContainer getContainer() {
096: return this .container;
097: }
098:
099: /**
100: * Sets the title container.
101: *
102: * @param container the container (<code>null</code> not permitted).
103: */
104: public void setTitleContainer(BlockContainer container) {
105: if (container == null) {
106: throw new IllegalArgumentException(
107: "Null 'container' argument.");
108: }
109: this .container = container;
110: }
111:
112: /**
113: * Arranges the contents of the block, within the given constraints, and
114: * returns the block size.
115: *
116: * @param g2 the graphics device.
117: * @param constraint the constraint (<code>null</code> not permitted).
118: *
119: * @return The block size (in Java2D units, never <code>null</code>).
120: */
121: public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) {
122: RectangleConstraint contentConstraint = toContentConstraint(constraint);
123: Size2D contentSize = this .container.arrange(g2,
124: contentConstraint);
125: return new Size2D(calculateTotalWidth(contentSize.getWidth()),
126: calculateTotalHeight(contentSize.getHeight()));
127: }
128:
129: /**
130: * Draws the title on a Java 2D graphics device (such as the screen or a
131: * printer).
132: *
133: * @param g2 the graphics device.
134: * @param area the area allocated for the title.
135: */
136: public void draw(Graphics2D g2, Rectangle2D area) {
137: area = trimMargin(area);
138: drawBorder(g2, area);
139: area = trimBorder(area);
140: area = trimPadding(area);
141: this .container.draw(g2, area);
142: }
143:
144: /**
145: * Draws the block within the specified area.
146: *
147: * @param g2 the graphics device.
148: * @param area the area.
149: * @param params ignored (<code>null</code> permitted).
150: *
151: * @return Always <code>null</code>.
152: */
153: public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
154: draw(g2, area);
155: return null;
156: }
157:
158: /**
159: * Tests this title for equality with an arbitrary object.
160: *
161: * @param obj the object (<code>null</code> permitted).
162: *
163: * @return A boolean.
164: */
165: public boolean equals(Object obj) {
166: if (obj == this ) {
167: return true;
168: }
169: if (!(obj instanceof CompositeTitle)) {
170: return false;
171: }
172: if (!super .equals(obj)) {
173: return false;
174: }
175: CompositeTitle that = (CompositeTitle) obj;
176: if (!this .container.equals(that.container)) {
177: return false;
178: }
179: return true;
180: }
181:
182: }
|