📄 reportelement.java
字号:
// make lines a little heigher,so that they can intersect
// with a rectangle
if (e.height == 0 ) {
e.height = 10;
}
if (e.bounds.intersects(bounds) ) {
// store the intersecting rectangle
this.intersections.add( e );
result = true;
}
e.height = oldHeight;
}
}
return result;
}
public boolean intersects(Point p) {
Rectangle r = new Rectangle(bounds);
if (height == 0) {
r.height = 10;
r.y -= 5;
}
if (width == 0) {
r.width = 10;
r.x -= 5;
}
return r.intersects(p.x,p.y,1,1);
}
public boolean insideBandReal() {
position.x -= 10;
position.y -= 10;
boolean result = insideBand();
position.x += 10;
position.y += 10;
return result;
}
public boolean insideBand() {
if ( band == null )
return false; // no parent ?????
int yband = band.getBandYLocation();
// lower left corner of element is below the band.
if ( position.y - yband < 0 )
return false;
// lower left corner of element is left from the left margin
if ( position.x - band.getParent().getLeftMargin() < 0 )
return false;
// with element on the bottom the element is too high for the band
if ( position.y - yband + height > band.getHeight() )
return false;
// with element on the left margin, the width is larger than usable width of page.
if ( position.x - band.getParent().getLeftMargin() + width > band.getUsableWidth() )
return false ;
return true;
}
public boolean intersects(Rectangle r2) {
Rectangle r = new Rectangle(bounds);
if (height == 0) {
r.height = 10;
r.y -= 5;
}
if (width == 0) {
r.width = 10;
r.x -= 5;
}
return r.intersects(r2);
}
public void setPosition(Point p) {
if (p == null) return;
if (p.x == position.x && p.y == position.y) return;
position.x = p.x;
position.y = p.y;
bounds = new Rectangle(position.x,position.y,width,height);
}
public Point trasform(Point delta, int type) {
if (delta == null) return null;
Point result = new Point(delta);
int old_x = 0;
int old_y = 0;
if (type == TransformationType.TRANSFORMATION_MOVE) {
position.x += delta.x;
position.y += delta.y;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_E) {
old_x = width;
width += delta.x;
if (width <0) width=0;
result.x = width - old_x;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_W) {
old_x = width;
int d = Math.min(delta.x,width);
width -= d;
position.x += d;
result.x = d;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_N) {
int d = Math.min(delta.y,height);
height -= d;
position.y += d;
result.y = d;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_S) {
old_y = height;
height += delta.y;
if (height <0) height=0;
result.y = height - old_y;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_SE) {
old_y = height;
old_x = width;
height += delta.y;
if (height <0) height=0;
width += delta.x;
if (width <0) width=0;
result.x = width - old_x;
result.y = height - old_y;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_SW) {
old_y = height;
height += delta.y;
if (height <0) height=0;
int d = Math.min(delta.x,width);
width -= d;
position.x += d;
result.x = d;
result.y = height - old_y;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_NE) {
old_x = width;
int d = Math.min(delta.y,height);
height -= d;
position.y += d;
width += delta.x;
if (width <0) width=0;
result.x = width - old_x;
result.y = d;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_NW) {
int d = Math.min(delta.y,height);
height -= d;
position.y += d;
result.y = d;
d = Math.min(delta.x,width);
width -= d;
position.x += d;
result.x = d;
}
bounds = new Rectangle(position.x,position.y,width,height);
return result;
}
/**
* Try to move the element to another band if the element is placed entirely
* within the band.
*
* @author RFL
*/
public void adjustBand() {
position.x -= 10;
position.y -= 10;
for (Iterator i = band.getParent().getBands().iterator(); i.hasNext(); ) {
Band b = (Band) i.next();
if ( position.y - band.getParent().getBandYLocation(b) >= 0) {
if ( position.y - band.getParent().getBandYLocation(b) + height <= b.getHeight() ) {
// element is within this band.
band = b;
break;
}
}
}
position.x += 10;
position.y += 10;
}
/*
* This method should be called when you modify height, width,
* or position manually.
*/
public void updateBounds() {
bounds = new Rectangle(position.x,position.y,width,height);
}
public Point trasformTest(Point delta, int type) {
if (delta == null) return null;
Point result = new Point(delta);
int old_x = 0;
int old_y = 0;
if (type == TransformationType.TRANSFORMATION_MOVE) {
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_E) {
old_x = width;
old_x += delta.x;
if (old_x <0) old_x=0;
result.x = old_x-width;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_W) {
result.x = Math.min(delta.x,width);
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_N) {
result.y = Math.min(delta.y,height);
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_S) {
old_y = height;
old_y += delta.y;
if (old_y <0) old_y=0;
result.y = old_y - height;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_SE) {
old_y = height;
old_x = width;
old_y += delta.y;
if (old_y <0) old_y=0;
old_x += delta.x;
if (old_x <0) old_x=0;
result.x = old_x - width;
result.y = old_y - height;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_SW) {
old_y = height;
old_y += delta.y;
if (old_y <0) old_y=0;
result.x = Math.min(delta.x,width);
result.y =old_y - height;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_NE) {
old_x = width;
result.y = Math.min(delta.y,height);
old_x += delta.x;
if (old_x <0) old_x=0;
result.x = old_x - width;
}
else if (type == TransformationType.TRANSFORMATION_RESIZE_NW) {
result.y = Math.min(delta.y,height);
result.x = Math.min(delta.x,width);
}
return result;
}
public String toString() {
return name+" ["+(position.x-band.getParent().getRightMargin()-10)+","+ (position.y-band.getBandYLocation()-10) + "]";
}
public int getZoomedDim(int dim) {
if (zoom_factor == 1.0) return dim;
//if (((double)dim*(double)zoom_factor)<0.5) return 1;
// Truncate, don't round!!
return (int)((double)dim*zoom_factor);
//return (int)Math.ceil((double)dim*zoom_factor);
}
public double getZoomedDim(double dim) {
if (zoom_factor == 1.0) return dim;
//if (((double)dim*(double)zoom_factor)<0.5) return 1;
// Truncate, don't round!!
return ((double)dim*zoom_factor);
//return (int)Math.ceil((double)dim*zoom_factor);
}
public int getLogicalDim(int dim) {
if (zoom_factor == 1.0) return dim;
//if (Math.abs( ((double)dim/(double)zoom_factor)) < 1 &&
// Math.abs( ((double)dim/(double)zoom_factor)) > 0) return 1;
// Truncate, don't round!!
return (int)((double)dim/zoom_factor);
//return (int)Math.ceil((double)dim/zoom_factor);
}
public ReportElement cloneMe() {
ReportElement newReportElement = new ReportElement(position.x, position.y, width, height);
newReportElement.name = new String(name);
newReportElement.band = band;
newReportElement.transparent = transparent;
copyElementPropertiesTo(newReportElement);
return newReportElement;
}
public void copyElementPropertiesTo(ReportElement newReportElement) {
newReportElement.printWhenExpression = printWhenExpression;
newReportElement.positionType = positionType;
newReportElement.isPrintRepeatedValues = isPrintRepeatedValues;
newReportElement.isRemoveLineWhenBlank = isRemoveLineWhenBlank;
newReportElement.isPrintInFirstWholeBand = isPrintInFirstWholeBand;
newReportElement.isPrintWhenDetailOverflows = isPrintWhenDetailOverflows;
}
public static String string_replace(String s1, String s2, String s3) {
String string="";
string = "";
if (s2 == null || s3 == null || s2.length() == 0) return s3;
int pos_i = 0; // posizione corrente.
int pos_f = 0; // posizione corrente finale
int len = s2.length();
while ( (pos_f = s3.indexOf(s2, pos_i)) >= 0) {
string += s3.substring(pos_i,pos_f)+s1;
//+string.substring(pos+ s2.length());
pos_f = pos_i = pos_f + len;
}
string += s3.substring(pos_i);
return string;
}
public static Stroke getPenStroke(String pen, double zoom_factor) {
if (pen == null || pen.equals("None")) return null;
if (pen.equals("Dotted")) {
return (Stroke)new BasicStroke(
(float)(1f * zoom_factor),
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL,
0f,
new float[]{5f, 3f},
0f
);
}
else if (pen.equals("2Point")) {
return (Stroke)new BasicStroke((float)(2f*zoom_factor));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -