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