📄 reportelement.java
字号:
/*
* ReportElement.java
*
* iReport -- Visual designer for generating JasperReports Documents
* Copyright (C) 2002 Giulio Toffoli gt@businesslogic.it
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Giulio Toffoli
* Via T.Aspetti, 233
* 35100 Padova ITALY
* gt@businesslogic.it
*
*
* Created on 22 febbraio 2003, 15.03
*
* Updated 3 July 2003, 2004 by Robert Lamping
* - Added: adjustBand()
Moving a element will trigger iReports to see whether
* an element is entirely within another band
* If so, the element's band is modified to the band it is placed in.
* - Modified: trasform()
* Included adjustBand() at the end.
* Updated 3 July 2003, 2004 by Robert Lamping
* - added updateBounds in setHeight() and setWidth()
*/
package it.businesslogic.ireport;
import it.businesslogic.ireport.gui.*;
import it.businesslogic.ireport.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.util.Iterator;
import java.util.Vector;
public class ReportElement {
static int id_gen=1;
public String name;
public Point position;
public int width;
public int height;
Rectangle bounds;
public static BufferedImage hached=null;
public Band band;
public String transparent;
public String printWhenExpression="";
public String positionType="FixRelativeToTop";
public boolean isPrintRepeatedValues=true;
public boolean isRemoveLineWhenBlank=false;
public boolean isPrintInFirstWholeBand=false;
public boolean isPrintWhenDetailOverflows=false;
public static Color lightcolor;
public String printWhenGroupChanges="";
double zoom_factor=1.0;
public Color bgcolor = null;
public Color fgcolor = null;
protected String stretchType;
protected String elementGroup = "";
public Vector intersections = new Vector();
public ReportElement(int x, int y, int width, int height) {
if (hached == null){
hached = Misc.loadBufferedImageFromResources(new java.awt.Panel() ,"it/businesslogic/ireport/icons/layout/hached.gif");
}
this.position = new Point(x,y);
this.width= Math.abs(width);
this.height=Math.abs(height);
bounds = new Rectangle(position.x,position.y,width,height);
name = "element-"+id_gen;
id_gen++;
this.hached = hached;
bgcolor = Color.WHITE;
fgcolor = Color.BLACK;
if (lightcolor == null) {
lightcolor = Color.LIGHT_GRAY;
}
transparent = "Opaque";
stretchType = "NoStretch";
}
public void drawObject(Graphics2D g, double zoom_factor, int x_shift_origin, int y_shift_origin) {
position.x -= 10;
position.y -= 10;
x_shift_origin -= 10;
y_shift_origin -= 10;
this.zoom_factor = zoom_factor;
//g.setPaint( new TexturePaint( red, new Rectangle2D.Double( zoomed_width+10-horizontal_scroll,9-vertical_scroll,9,9)));
g.fillRect( getZoomedDim(position.x)-x_shift_origin,
getZoomedDim(position.y)-y_shift_origin,
getZoomedDim(width),
getZoomedDim(height));
//g.drawRect(getZoomedDim(position.x)-x_shift_origin, getZoomedDim(position.y)-y_shift_origin, getZoomedDim(width), getZoomedDim(height));
position.x += 10;
position.y += 10;
x_shift_origin += 10;
y_shift_origin += 10;
drawGraphicsElement(g,"2Point", zoom_factor, x_shift_origin,y_shift_origin);
drawBorder(g, zoom_factor, x_shift_origin,y_shift_origin);
}
public void drawGraphicsElement(Graphics2D g, String pen, double zoom_factor, int x_shift_origin, int y_shift_origin) {
drawGraphicsElement( g, pen, zoom_factor, x_shift_origin, y_shift_origin,0);
}
public void drawGraphicsElement(Graphics2D g, String pen, double zoom_factor, int x_shift_origin, int y_shift_origin,int radius) {
int correction = (zoom_factor <= 1 && (pen.equals("Thin") || pen.equals("1Point") || pen.equals("Dotted") ) ) ? -1 : 0;
int xy_correction = (zoom_factor <= 1 && pen.equals("Dotted")) ? 1 : 0;
Stroke stroke = getPenStroke( pen,zoom_factor );
g.setColor( this.fgcolor );
this.zoom_factor = zoom_factor;
if (stroke==null || pen.equalsIgnoreCase("None")) return;
position.x -= 10;
position.y -= 10;
x_shift_origin -= 10;
y_shift_origin -= 10;
Stroke oldStroke = g.getStroke();
g.setStroke(stroke);
if (radius != 0) {
g.drawRoundRect(
getZoomedDim(position.x)-x_shift_origin+xy_correction,
getZoomedDim(position.y)-y_shift_origin+xy_correction,
getZoomedDim(width)+correction,getZoomedDim(height)+correction,radius,radius);
}
else {
g.drawRect(
getZoomedDim(position.x)-x_shift_origin+xy_correction,
getZoomedDim(position.y)-y_shift_origin+xy_correction,
getZoomedDim(width) + correction,getZoomedDim(height)+correction);
}
position.x += 10;
position.y += 10;
g.setStroke(oldStroke);
}
public void drawBorder(Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin)
{
drawBorder(g, zoom_factor, x_shift_origin, y_shift_origin, null );
}
public void drawBorder(Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin, Box box)
{
this.zoom_factor = zoom_factor;
int correction = (zoom_factor <= 1 ) ? -1 : 0;
position.x -= 10;
position.y -= 10;
x_shift_origin -= 10;
y_shift_origin -= 10;
Stroke oldStroke = g.getStroke();
if (box == null || !insideBand())
{
if ( insideBand() ) {
g.setColor( lightcolor);
} else {
g.setColor( Color.RED);
}
g.drawRect(
getZoomedDim(position.x)-x_shift_origin,
getZoomedDim(position.y)-y_shift_origin,
getZoomedDim(width) + correction,getZoomedDim(height)+correction);
}
else
{
// Left side
boolean insideBand = insideBand();
int ax = getZoomedDim(position.x)-x_shift_origin;
int ay = getZoomedDim(position.y)-y_shift_origin;
int bx = ax+getZoomedDim(width)+correction;
int by = ay+getZoomedDim(height)+correction;
Stroke newBoxStroke = null;
if (box.getLeftBorderColor() != null) { g.setColor( box.getLeftBorderColor() ); }
else g.setColor( lightcolor );
if ((newBoxStroke = getPenStroke(box.getLeftBorder(),zoom_factor )) != null)
{
g.setStroke( newBoxStroke );
g.drawLine(ax, ay, ax, by);
}
//else g.setStroke(oldStroke);
if (box.getTopBorderColor() != null) { g.setColor( box.getTopBorderColor() ); }
else g.setColor( lightcolor );
if ((newBoxStroke = getPenStroke(box.getTopBorder(),zoom_factor )) != null)
{
g.setStroke( newBoxStroke );
g.drawLine(ax, ay, bx, ay);
}
if (box.getRightBorderColor() != null) { g.setColor( box.getRightBorderColor() ); }
else g.setColor( lightcolor );
if ((newBoxStroke = getPenStroke(box.getRightBorder(),zoom_factor )) != null)
{
g.setStroke( newBoxStroke );
g.drawLine(bx, ay, bx, by);
}
if (box.getBottomBorderColor() != null) { g.setColor( box.getBottomBorderColor() ); }
else g.setColor( lightcolor );
if ((newBoxStroke = getPenStroke(box.getBottomBorder(),zoom_factor )) != null)
{
g.setStroke( newBoxStroke );
g.drawLine(ax, by, bx, by);
}
g.setStroke(oldStroke);
}
position.x += 10;
position.y += 10;
x_shift_origin += 10;
y_shift_origin += 10;
}
public void drawCorona(Graphics2D g, double zoom_factor, int x_shift_origin, int y_shift_origin, boolean selected) {
this.zoom_factor = zoom_factor;
// draw a corona...
position.x -= 10;
position.y -= 10;
x_shift_origin -= 10;
y_shift_origin -= 10;
Rectangle2D r = new Rectangle2D.Double(getZoomedDim(position.x)-5-x_shift_origin,
getZoomedDim(position.y)-5-y_shift_origin,
getZoomedDim(width)+10,
getZoomedDim(height)+10);
Rectangle2D r2 = new Rectangle2D.Double( getZoomedDim(position.x)-x_shift_origin,
getZoomedDim(position.y)-y_shift_origin,
getZoomedDim(width),
getZoomedDim(height));
java.awt.geom.Area area = new Area(r);
area.exclusiveOr( new Area(r2));
if (hached == null) {
g.fill(area);
}
else {
g.setPaint( new java.awt.TexturePaint( hached, new Rectangle2D.Double(0,0,2,2 ) ));
g.fill(area);
}
// draw grips...
g.setPaint(Color.BLUE);
if (!selected) {
g.setPaint(Color.GRAY);
}
// checking overlaps slows down the repainting
if (intersectsElements() ) {
if ( enclosesOtherElement() ) {
g.setPaint(Color.PINK);
} else {
g.setPaint(Color.GREEN);
}
}
if ( !insideBand()) {
g.setPaint(Color.RED);
}
g.fillRect(getZoomedDim(position.x)-5-x_shift_origin, getZoomedDim(position.y)-5-y_shift_origin,5,5);
g.fillRect(getZoomedDim(position.x+width)-x_shift_origin, getZoomedDim(position.y)-5-y_shift_origin,5,5);
g.fillRect(getZoomedDim(position.x+width)-x_shift_origin, getZoomedDim(position.y+height)-y_shift_origin,5,5);
g.fillRect(getZoomedDim(position.x)-5-x_shift_origin, getZoomedDim(position.y+height)-y_shift_origin,5,5);
g.fillRect(getZoomedDim(position.x+(width/2))-2-x_shift_origin, getZoomedDim(position.y)-5-y_shift_origin,5,5);
g.fillRect(getZoomedDim(position.x+(width/2))-2-x_shift_origin, getZoomedDim(position.y+height)-y_shift_origin,5,5);
g.fillRect(getZoomedDim(position.x)-5-x_shift_origin, getZoomedDim(position.y+(height/2))-2-y_shift_origin,5,5);
g.fillRect(getZoomedDim(position.x+width)-x_shift_origin, getZoomedDim(position.y+(height/2))-2-y_shift_origin,5,5);
position.x += 10;
position.y += 10;
}
public boolean enclosesOtherElement() {
for (Iterator i = intersections.iterator(); i.hasNext(); ) {
ReportElement e = (ReportElement) i.next();
if (bounds.contains(e.bounds) ) {
return true;
}
}
return false;
}
public boolean intersectsElements() {
int oldHeight = 0;
boolean result = false;
// do not stop after you found an intersection
// list them all so that
// later on you can see whether one is hidden or enclosed by the
// current element.
for (Iterator i = band.getParent().getElements().iterator(); i.hasNext(); ) {
ReportElement e = (ReportElement) i.next();
// do not compare with 'this' reportElement
if ( ! this.equals( e ) ) {
oldHeight = e.height;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -