KickJava   Java API By Example, From Geeks To Geeks.

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


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  * LineReportElement.java
28  *
29  * Created on 28 febbraio 2003, 20.02
30  *
31  */

32
33 package it.businesslogic.ireport;
34
35 import it.businesslogic.ireport.gui.*;
36 import it.businesslogic.ireport.util.*;
37 import java.awt.*;
38 import java.awt.image.*;
39 import java.awt.geom.*;
40
41 public class LineReportElement extends GraphicReportElement
42 {
43
44     public String JavaDoc direction;
45     
46     public LineReportElement(int x, int y, int width, int height)
47     {
48         //this(x,y,width,height,"TopDown");
49
// I expect the delta width and height to be passed
50
// so with + or - sign.
51
this(x, y , width, height, "whatever");
52
53         if (width * height >= 0) {
54             setDirection( "TopDown" );
55         } else {
56             setDirection( "BottomUp" );
57         }
58     }
59     
60     public LineReportElement(int x, int y, int width, int height, String JavaDoc direction)
61     {
62         super(x, y, Math.abs(width) , Math.abs(height) );
63         //graphicElementPen = "Thin";
64
//this.bgcolor = Color.WHITE;
65
//this.fgcolor = Color.BLACK;
66
this.direction = direction;
67         setKey("line");
68     }
69     
70     public void drawObject(Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin)
71     {
72         this.zoom_factor = zoom_factor;
73         int height_draw = 0;
74                 if (height <= 1) height_draw = 0;
75                 else height_draw = height-1;
76                 int width_draw = 0;
77                 if (width <= 1) width_draw = 0;
78                 else width_draw = width-1;
79         
80                 //g.fill( position.x,position.y,width,height,new Brush(bgcolor, BrushStyle.SOLID));
81
Point a = new Point( getZoomedDim( position.x-10) +10-x_shift_origin, getZoomedDim( position.y-10) +10-y_shift_origin );
82         Point b = new Point( getZoomedDim(position.x+width_draw-10)+10-x_shift_origin,getZoomedDim( position.y+height_draw-10)+10-y_shift_origin);
83         
84                 if (!direction.equalsIgnoreCase("TopDown"))
85         {
86             b.y = getZoomedDim( position.y-10) +10-y_shift_origin;
87             a.y = getZoomedDim( position.y+height-10)+10-y_shift_origin;
88         }
89         
90                 Stroke stroke = this.getPenStroke( getGraphicElementPen() ,zoom_factor );
91         if(stroke != null){
92                     Stroke oldStroke = g.getStroke();
93                     g.setStroke(stroke);
94                 
95             g.setColor( getFgcolor() );
96             g.drawLine(a.x,a.y,b.x,b.y);
97                     g.setStroke(oldStroke);
98         }
99     }
100     
101     public ReportElement cloneMe()
102     {
103         LineReportElement newReportElement = new LineReportElement(position.x, position.y, width, height);
104         copyBaseReportElement(newReportElement, this);
105         
106         return newReportElement;
107     }
108         
109         /** Getter for property direction.
110          * @return Value of property direction.
111          *
112          */

113         public java.lang.String JavaDoc getDirection() {
114             return direction;
115         }
116         
117         /** Setter for property direction.
118          * @param direction New value of property direction.
119          *
120          */

121         public void setDirection(java.lang.String JavaDoc direction) {
122             this.direction = direction;
123         }
124         
125         public void copyBaseReportElement(ReportElement destination, ReportElement source)
126         {
127                 super.copyBaseReportElement(destination, source);
128                 
129                 if (destination instanceof LineReportElement &&
130                     source instanceof LineReportElement )
131                 {
132                     ((LineReportElement)destination).setDirection( new String JavaDoc( ((LineReportElement)source).getDirection()));
133                 }
134         }
135         
136          public boolean insideBand()
137         {
138
139             int r_height = (height == 0) ? 1 : height;
140             if (band == null)
141             {
142
143                 return false;
144             }
145
146             int yband = band.getBandYLocation();
147
148             if (position.y - yband + r_height > band.getHeight())
149             {
150                 return false;
151             }
152             return super.insideBand();
153         }
154 }
155
Popular Tags