KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > RectangleReportElement


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * RectangleReportElement.java
28  *
29  * Created on 28 febbraio 2003, 19.20
30  *
31  */

32
33 package it.businesslogic.ireport;
34 import it.businesslogic.ireport.gui.*;
35 import it.businesslogic.ireport.util.*;
36 import java.awt.*;
37 import java.awt.image.*;
38 import java.awt.geom.*;
39
40 public class RectangleReportElement extends GraphicReportElement {
41     
42     //public int radius = 0;
43
/**
44       * Key for element properties handled using the IReportHashMapBean
45       */

46      public static final String JavaDoc RADIUS = "RADIUS";
47         
48     /**
49      * Default values. If a value can change for different elements,
50      * it is not listed here (i.e. MODE).
51      */

52     public static final int DEFAULT_RADIUS = 0;
53     
54     public RectangleReportElement (int x, int y, int width, int height) {
55         super (x,y, width, height);
56         //setGraphicElementPen ("Thin");
57
//this.bgcolor = Color.WHITE;
58
//this.fgcolor = Color.BLACK;
59
setKey ("rectangle");
60     }
61     
62     public RectangleReportElement (int x, int y, int width, int height, int radius) {
63         this (x,y,width,height);
64         this.setPropertyValue(RADIUS, ""+radius);
65         //this.radius = radius;
66
//setKey("rectangle");
67
}
68     
69     public void drawObject (Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin) {
70         position.x -= 10;
71         position.y -= 10;
72         x_shift_origin -= 10;
73         y_shift_origin -= 10;
74         
75         this.zoom_factor = zoom_factor;
76         
77         g.setColor ( getBgcolor() );
78         if (!getTransparent ().equalsIgnoreCase ("Transparent"))
79             g.fillRoundRect ( getZoomedDim (position.x)-x_shift_origin,
80             getZoomedDim (position.y)-y_shift_origin,
81             getZoomedDim (width),
82             getZoomedDim (height),
83             (int)(2*this.getRadius()*zoom_factor),
84             (int)(2*this.getRadius()*zoom_factor));
85         g.setColor ( getFgcolor());
86         
87         position.x += 10;
88         position.y += 10;
89         x_shift_origin += 10;
90         y_shift_origin += 10;
91         
92         drawGraphicsElement (g,this.getGraphicElementPen (), zoom_factor, x_shift_origin,y_shift_origin, (int)(2*this.getRadius()*zoom_factor));
93     }
94     
95     public ReportElement cloneMe () {
96         RectangleReportElement newReportElement = new RectangleReportElement (position.x, position.y, width, height);
97         copyBaseReportElement (newReportElement, this);
98         return newReportElement;
99     }
100     
101     public void drawGraphicsElement (Graphics2D g, String JavaDoc pen, double zoom_factor, int x_shift_origin, int y_shift_origin) {
102         
103         Stroke stroke = getPenStroke ( pen,zoom_factor );
104         g.setColor ( getFgcolor() );
105         
106         this.zoom_factor = zoom_factor;
107         if (stroke==null || pen.equalsIgnoreCase ("None")) return;
108         
109         position.x -= 10;
110         position.y -= 10;
111         x_shift_origin -= 10;
112         y_shift_origin -= 10;
113         
114         Stroke oldStroke = g.getStroke ();
115         g.setStroke (stroke);
116         g.drawRoundRect (
117         getZoomedDim (position.x)-x_shift_origin,
118         getZoomedDim (position.y)-y_shift_origin,
119         getZoomedDim (width),getZoomedDim (height),
120         (int)(2*this.getRadius()*zoom_factor),
121         (int)(2*this.getRadius()*zoom_factor));
122         
123         position.x += 10;
124         position.y += 10;
125         
126         g.setStroke (oldStroke);
127     }
128     
129     /** Getter for property radius.
130      * @return Value of property radius.
131      *
132      */

133     public int getRadius () {
134         if (getPropertyValue(RADIUS) == null)
135             {
136                 // Look for a fgcolor in the stylesheet...
137
if (getStyle() != null)
138                 {
139                    return getStyle().getAttributeInteger( getStyle().ATTRIBUTE_radius, DEFAULT_RADIUS, true);
140                 }
141             }
142             return getIntValue(RADIUS, DEFAULT_RADIUS );
143     }
144     
145     /** Setter for property radius.
146      * @param radius New value of property radius.
147      *
148      */

149     public void setRadius (int radius) {
150         setPropertyValue(RADIUS, radius+"");
151     }
152     
153     public void copyBaseReportElement (ReportElement destination, ReportElement source) {
154         super.copyBaseReportElement (destination, source);
155         
156         if (destination instanceof RectangleReportElement &&
157         source instanceof RectangleReportElement ) {
158             //((RectangleReportElement)destination).setRadius ( ((RectangleReportElement)source).getRadius ());
159
destination.setPropertyValue(RADIUS, source.getPropertyValue(RADIUS));
160         }
161     }
162     
163      public void setStyle(Style style) {
164      
165         super.setStyle(style);
166      }
167     
168 }
169
Popular Tags