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: * PageBackgroundDrawable.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.base.internal;
030:
031: import java.awt.Color;
032: import java.awt.Dimension;
033: import java.awt.Graphics2D;
034: import java.awt.RenderingHints;
035: import java.awt.geom.AffineTransform;
036: import java.awt.geom.Rectangle2D;
037: import java.awt.print.PageFormat;
038: import javax.swing.UIManager;
039:
040: import org.jfree.report.modules.output.pageable.graphics.PageDrawable;
041: import org.jfree.ui.ExtendedDrawable;
042:
043: /**
044: * Creation-Date: 17.11.2006, 20:31:36
045: *
046: * @author Thomas Morgner
047: */
048: public class PageBackgroundDrawable implements ExtendedDrawable {
049: private int defaultWidth;
050: private int defaultHeight;
051: private PageDrawable backend;
052: private boolean borderPainted;
053: private float shadowSize;
054: private double zoom;
055:
056: public PageBackgroundDrawable() {
057: this .shadowSize = 6;
058: this .borderPainted = false;
059: this .zoom = 1;
060: }
061:
062: public PageDrawable getBackend() {
063: return backend;
064: }
065:
066: public void setBackend(final PageDrawable backend) {
067: this .backend = backend;
068: }
069:
070: public boolean isBorderPainted() {
071: return borderPainted;
072: }
073:
074: public void setBorderPainted(final boolean borderPainted) {
075: this .borderPainted = borderPainted;
076: }
077:
078: public double getZoom() {
079: return zoom;
080: }
081:
082: public void setZoom(final double zoom) {
083: this .zoom = zoom;
084: }
085:
086: public int getDefaultWidth() {
087: return defaultWidth;
088: }
089:
090: public void setDefaultWidth(final int defaultWidth) {
091: this .defaultWidth = defaultWidth;
092: }
093:
094: public int getDefaultHeight() {
095: return defaultHeight;
096: }
097:
098: public void setDefaultHeight(final int defaultHeight) {
099: this .defaultHeight = defaultHeight;
100: }
101:
102: public Dimension getPreferredSize() {
103: if (backend == null) {
104: return new Dimension(
105: (int) ((defaultWidth + shadowSize) * zoom),
106: (int) ((defaultHeight + shadowSize) * zoom));
107: }
108: final Dimension preferredSize = backend.getPreferredSize();
109:
110: return new Dimension(
111: (int) ((preferredSize.width + shadowSize) * zoom),
112: (int) ((preferredSize.height + shadowSize) * zoom));
113: }
114:
115: public boolean isPreserveAspectRatio() {
116: return true;
117: }
118:
119: public float getShadowSize() {
120: return shadowSize;
121: }
122:
123: public void setShadowSize(final float shadowSize) {
124: this .shadowSize = shadowSize;
125: }
126:
127: /**
128: * Draws the object.
129: *
130: * @param g2 the graphics device.
131: * @param area the area inside which the object should be drawn.
132: */
133: public void draw(final Graphics2D g2, final Rectangle2D area) {
134: if (backend == null) {
135: return;
136: }
137:
138: final PageFormat pageFormat = backend.getPageFormat();
139: final float outerW = (float) pageFormat.getWidth();
140: final float outerH = (float) pageFormat.getHeight();
141:
142: final float innerX = (float) pageFormat.getImageableX();
143: final float innerY = (float) pageFormat.getImageableY();
144: final float innerW = (float) pageFormat.getImageableWidth();
145: final float innerH = (float) pageFormat.getImageableHeight();
146:
147: //double paperBorder = paperBorderPixel * zoomFactor;
148:
149: /** Prepare background **/
150: g2.transform(AffineTransform.getScaleInstance(getZoom(),
151: getZoom()));
152: g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
153: RenderingHints.VALUE_FRACTIONALMETRICS_ON);
154:
155: /** Prepare background **/
156: final Rectangle2D pageArea = new Rectangle2D.Float(0, 0,
157: outerW, outerH);
158:
159: g2.setPaint(Color.white);
160: g2.fill(pageArea);
161:
162: final Graphics2D g22 = (Graphics2D) g2.create();
163: backend.draw(g22, new Rectangle2D.Double(0, 0, pageFormat
164: .getImageableWidth(), pageFormat.getImageableHeight()));
165: g22.dispose();
166:
167: /**
168: * The border around the printable area is painted when the corresponding property is
169: * set to true.
170: */
171: final Rectangle2D printingArea = new Rectangle2D.Float(innerX,
172: innerY, innerW, innerH);
173:
174: /** Paint Page Shadow */
175: final Rectangle2D southborder = new Rectangle2D.Float(
176: getShadowSize(), outerH, outerW, getShadowSize());
177:
178: g2.setPaint(UIManager.getColor("controlShadow")); //$NON-NLS-1$
179:
180: g2.fill(southborder);
181:
182: final Rectangle2D eastborder = new Rectangle2D.Float(outerW,
183: getShadowSize(), getShadowSize(), outerH);
184:
185: g2.fill(eastborder);
186: final Rectangle2D transPageArea = new Rectangle2D.Float(0, 0,
187: outerW, outerH);
188:
189: g2.setPaint(Color.black);
190: g2.draw(transPageArea);
191: if (isBorderPainted()) {
192: g2.setPaint(Color.gray);
193: g2.draw(printingArea);
194: }
195:
196: }
197: }
|