001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * RectangleReportElement.java
028: *
029: * Created on 28 febbraio 2003, 19.20
030: *
031: */
032:
033: package it.businesslogic.ireport;
034:
035: import it.businesslogic.ireport.gui.*;
036: import it.businesslogic.ireport.util.*;
037: import java.awt.*;
038: import java.awt.image.*;
039: import java.awt.geom.*;
040:
041: public class RectangleReportElement extends GraphicReportElement {
042:
043: //public int radius = 0;
044: /**
045: * Key for element properties handled using the IReportHashMapBean
046: */
047: public static final String RADIUS = "RADIUS";
048:
049: /**
050: * Default values. If a value can change for different elements,
051: * it is not listed here (i.e. MODE).
052: */
053: public static final int DEFAULT_RADIUS = 0;
054:
055: public RectangleReportElement(int x, int y, int width, int height) {
056: super (x, y, width, height);
057: //setGraphicElementPen ("Thin");
058: //this.bgcolor = Color.WHITE;
059: //this.fgcolor = Color.BLACK;
060: setKey("rectangle");
061: }
062:
063: public RectangleReportElement(int x, int y, int width, int height,
064: int radius) {
065: this (x, y, width, height);
066: this .setPropertyValue(RADIUS, "" + radius);
067: //this.radius = radius;
068: //setKey("rectangle");
069: }
070:
071: public void drawObject(Graphics2D g, double zoom_factor,
072: int x_shift_origin, int y_shift_origin) {
073: position.x -= 10;
074: position.y -= 10;
075: x_shift_origin -= 10;
076: y_shift_origin -= 10;
077:
078: this .zoom_factor = zoom_factor;
079:
080: g.setColor(getBgcolor());
081: if (!getTransparent().equalsIgnoreCase("Transparent"))
082: g.fillRoundRect(getZoomedDim(position.x) - x_shift_origin,
083: getZoomedDim(position.y) - y_shift_origin,
084: getZoomedDim(width), getZoomedDim(height),
085: (int) (2 * this .getRadius() * zoom_factor),
086: (int) (2 * this .getRadius() * zoom_factor));
087: g.setColor(getFgcolor());
088:
089: position.x += 10;
090: position.y += 10;
091: x_shift_origin += 10;
092: y_shift_origin += 10;
093:
094: drawGraphicsElement(g, this .getGraphicElementPen(),
095: zoom_factor, x_shift_origin, y_shift_origin,
096: (int) (2 * this .getRadius() * zoom_factor));
097: }
098:
099: public ReportElement cloneMe() {
100: RectangleReportElement newReportElement = new RectangleReportElement(
101: position.x, position.y, width, height);
102: copyBaseReportElement(newReportElement, this );
103: return newReportElement;
104: }
105:
106: public void drawGraphicsElement(Graphics2D g, String pen,
107: double zoom_factor, int x_shift_origin, int y_shift_origin) {
108:
109: Stroke stroke = getPenStroke(pen, zoom_factor);
110: g.setColor(getFgcolor());
111:
112: this .zoom_factor = zoom_factor;
113: if (stroke == null || pen.equalsIgnoreCase("None"))
114: return;
115:
116: position.x -= 10;
117: position.y -= 10;
118: x_shift_origin -= 10;
119: y_shift_origin -= 10;
120:
121: Stroke oldStroke = g.getStroke();
122: g.setStroke(stroke);
123: g.drawRoundRect(getZoomedDim(position.x) - x_shift_origin,
124: getZoomedDim(position.y) - y_shift_origin,
125: getZoomedDim(width), getZoomedDim(height),
126: (int) (2 * this .getRadius() * zoom_factor),
127: (int) (2 * this .getRadius() * zoom_factor));
128:
129: position.x += 10;
130: position.y += 10;
131:
132: g.setStroke(oldStroke);
133: }
134:
135: /** Getter for property radius.
136: * @return Value of property radius.
137: *
138: */
139: public int getRadius() {
140: if (getPropertyValue(RADIUS) == null) {
141: // Look for a fgcolor in the stylesheet...
142: if (getStyle() != null) {
143: return getStyle().getAttributeInteger(
144: getStyle().ATTRIBUTE_radius, DEFAULT_RADIUS,
145: true);
146: }
147: }
148: return getIntValue(RADIUS, DEFAULT_RADIUS);
149: }
150:
151: /** Setter for property radius.
152: * @param radius New value of property radius.
153: *
154: */
155: public void setRadius(int radius) {
156: setPropertyValue(RADIUS, radius + "");
157: }
158:
159: public void copyBaseReportElement(ReportElement destination,
160: ReportElement source) {
161: super .copyBaseReportElement(destination, source);
162:
163: if (destination instanceof RectangleReportElement
164: && source instanceof RectangleReportElement) {
165: //((RectangleReportElement)destination).setRadius ( ((RectangleReportElement)source).getRadius ());
166: destination.setPropertyValue(RADIUS, source
167: .getPropertyValue(RADIUS));
168: }
169: }
170:
171: public void setStyle(Style style) {
172:
173: super.setStyle(style);
174: }
175:
176: }
|