下面列出了java.awt.Rectangle#Float ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Draw legend
*
* @param g Graphics2D
* @param point Start point
*/
@Override
public void draw(Graphics2D g, PointF point) {
AffineTransform oldMatrix = g.getTransform();
g.translate(point.X + this.xshift, point.Y + this.yshift);
//Draw background color
if (this.drawBackground) {
g.setColor(this.background);
g.fill(new Rectangle.Float(0, 0, this.width, this.height));
}
//Draw legend
g.setStroke(new BasicStroke(1));
switch (this.orientation) {
case HORIZONTAL:
this.drawHorizontalBarLegend(g, legendScheme);
break;
case VERTICAL:
this.drawVerticalBarLegend(g, legendScheme);
break;
}
//Draw neatline
if (drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(0, 0, this.width, this.height);
g.setColor(neatLineColor);
g.setStroke(new BasicStroke(neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
AffineTransform oldMatrix = g.getTransform();
g.translate(x, y);
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawScaleBar(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, 1);
g.translate(aP.X, aP.Y);
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawScaleBar(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
AffineTransform oldMatrix = g.getTransform();
g.translate(x, y);
if (_angle != 0) {
g.rotate(_angle);
}
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth(), this.getHeight()));
}
drawNorthArrow(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize), (this.getHeight() - _neatLineSize));
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getX(), this.getY(), pageLocation, zoom);
g.translate(aP.X, aP.Y);
g.scale(zoom, zoom);
if (_angle != 0) {
g.rotate(_angle);
}
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackground());
g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
}
drawNorthArrow(g);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Draw legend
*
* @param g Graphics2D
* @param point Start point
*/
public void draw(Graphics2D g, PointF point) {
AffineTransform oldMatrix = g.getTransform();
g.translate(point.X + this.xshift, point.Y + this.yshift);
//Draw background color
if (this.drawBackground) {
g.setColor(this.background);
g.fill(new Rectangle.Float(0, 0, this.width, this.height));
}
//Draw legend
g.setStroke(new BasicStroke(1));
switch (this.orientation) {
case HORIZONTAL:
drawHorizontalLegend(g, legendScheme);
break;
case VERTICAL:
this.drawVerticalLegend(g, legendScheme);
break;
}
//Draw neatline
if (drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(0, 0, this.width, this.height);
g.setColor(neatLineColor);
g.setStroke(new BasicStroke(neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Draw arraw
*
* @param g Graphics2D
* @param sP Start point
* @param angle Angle
*/
public static void drawArraw(Graphics2D g, PointF sP, double angle) {
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5);
Rectangle.Float rect = new Rectangle.Float(-4, -4, 8, 8);
PointF[] pt = new PointF[5];
pt[0] = new PointF(rect.x, rect.y);
pt[1] = new PointF(rect.x + rect.width, rect.y + (rect.height / 2));
pt[2] = new PointF(rect.x, rect.y + rect.height);
pt[3] = new PointF(rect.x + rect.width / 2, pt[1].Y);
pt[4] = pt[0];
path.moveTo(pt[0].X, pt[0].Y);
for (int i = 1; i < 5; i++) {
path.lineTo(pt[i].X, pt[i].Y);
}
AffineTransform tempTrans = g.getTransform();
if (angle != 0) {
//AffineTransform myTrans = new AffineTransform();
AffineTransform myTrans = (AffineTransform) tempTrans.clone();
//myTrans.translate(tempTrans.getTranslateX() + sP.X, tempTrans.getTranslateY() + sP.Y);
myTrans.translate(sP.X, sP.Y);
double angle1 = angle - 90;
myTrans.rotate(angle1 * Math.PI / 180);
g.setTransform(myTrans);
}
path.closePath();
g.fill(path);
if (angle != 0) {
g.setTransform(tempTrans);
}
}
/**
* Draw arraw
*
* @param g Graphics2D
* @param sP Start point
* @param angle Angle
* @param size Arrow size
*/
public static void drawArraw(Graphics2D g, PointF sP, double angle, int size) {
GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5);
Rectangle.Float rect = new Rectangle.Float(-size, -size, size * 2, size * 2);
PointF[] pt = new PointF[5];
pt[0] = new PointF(rect.x, rect.y);
pt[1] = new PointF(rect.x + rect.width, rect.y + (rect.height / 2));
pt[2] = new PointF(rect.x, rect.y + rect.height);
pt[3] = new PointF(rect.x + rect.width / 2, pt[1].Y);
pt[4] = pt[0];
path.moveTo(pt[0].X, pt[0].Y);
for (int i = 1; i < 5; i++) {
path.lineTo(pt[i].X, pt[i].Y);
}
AffineTransform tempTrans = g.getTransform();
if (angle != 0) {
//AffineTransform myTrans = new AffineTransform();
AffineTransform myTrans = (AffineTransform) tempTrans.clone();
//myTrans.translate(tempTrans.getTranslateX() + sP.X, tempTrans.getTranslateY() + sP.Y);
myTrans.translate(sP.X, sP.Y);
double angle1 = angle - 90;
myTrans.rotate(angle1 * Math.PI / 180);
g.setTransform(myTrans);
}
path.closePath();
g.fill(path);
if (angle != 0) {
g.setTransform(tempTrans);
}
}
/**
* Draw selected vertices rectangles
*
* @param g Graphics2D
* @param points The points
* @param size The size
* @param outlineColor Outline coloe
* @param fillColor Fill color
*/
public static void drawSelectedVertices(Graphics2D g, PointF[] points, float size, Color outlineColor, Color fillColor) {
Rectangle.Float rect = new Rectangle.Float(0, 0, size, size);
for (PointF aPoint : points) {
rect.x = aPoint.X - size / 2;
rect.y = aPoint.Y - size / 2;
g.setColor(fillColor);
g.fill(rect);
g.setColor(outlineColor);
g.setStroke(new BasicStroke(1));
g.draw(rect);
}
}
/**
* Draw selected vertice rectangles
*
* @param g Graphics2D
* @param point The point
* @param size The size
* @param outlineColor Outline coloe
* @param fillColor Fill color
*/
public static void drawSelectedVertice(Graphics2D g, PointF point, float size, Color outlineColor, Color fillColor) {
Rectangle.Float rect = new Rectangle.Float(0, 0, size, size);
rect.x = point.X - size / 2;
rect.y = point.Y - size / 2;
g.setColor(fillColor);
g.fill(rect);
g.setColor(outlineColor);
g.setStroke(new BasicStroke(1));
g.draw(rect);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getLeft(), this.getTop(), pageLocation, zoom);
g.translate(aP.X, aP.Y);
g.scale(zoom, zoom);
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackColor());
g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
}
drawScaleBar(g, zoom);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getLeft(), this.getTop(), pageLocation, zoom);
g.translate(aP.X, aP.Y);
g.scale(zoom, zoom);
if (_angle != 0) {
g.rotate(_angle);
}
if (_antiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()){
g.setColor(this.getBackColor());
g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
}
drawNorthArrow(g, zoom);
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
/**
* Paint graphics
*
* @param g Graphics2D
* @param pageLocation Page location
* @param zoom Zoom
*/
public void paintGraphics(Graphics2D g, PointF pageLocation, float zoom) {
if (_legendLayer == null) {
return;
}
if (_legendLayer.getLayerType() == LayerTypes.ImageLayer) {
return;
}
AffineTransform oldMatrix = g.getTransform();
PointF aP = pageToScreen(this.getLeft(), this.getTop(), pageLocation, zoom);
g.translate(aP.X, aP.Y);
g.scale(zoom, zoom);
if (this._isAntiAlias) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
} else {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
//Draw background color
if (this.isDrawBackColor()) {
g.setColor(this.getBackColor());
g.fill(new Rectangle.Float(0, 0, this.getWidth() * zoom, this.getHeight() * zoom));
}
int gap = this.getTickGap(g);
switch (_legendStyle) {
case Bar_Horizontal:
if (gap > 1) {
drawHorizontalBarLegend_Ex(g, zoom);
} else {
drawHorizontalBarLegend(g, zoom);
}
break;
case Bar_Vertical:
if (gap > 1) {
drawVerticalBarLegend_Ex(g, zoom);
} else {
drawVerticalBarLegend(g, zoom);
}
break;
case Normal:
drawNormalLegend(g, zoom);
break;
}
//Draw neatline
if (_drawNeatLine) {
Rectangle.Float mapRect = new Rectangle.Float(_neatLineSize - 1, _neatLineSize - 1,
(this.getWidth() - _neatLineSize) * zoom, (this.getHeight() - _neatLineSize) * zoom);
g.setColor(_neatLineColor);
g.setStroke(new BasicStroke(_neatLineSize));
g.draw(mapRect);
}
g.setTransform(oldMatrix);
}
private static native void getNativeGlyphOutlineBounds(long nativeStrikePtr,
int glyphCode,
Rectangle.Float result,
double x, double y);
private void updateXYParams(GeoPos geoPos1, GeoPos geoPos2) {
GeoCoding geoCoding;
if(product.isMultiSize()) {
geoCoding = product.getBand((String) referenceCombo.getSelectedItem()).getGeoCoding();
} else {
geoCoding = product.getSceneGeoCoding();
}
final PixelPos pixelPos1 = geoCoding.getPixelPos(geoPos1, null);
if (!pixelPos1.isValid()) {
pixelPos1.setLocation(0, 0);
}
final PixelPos pixelPos2 = geoCoding.getPixelPos(geoPos2, null);
if (!pixelPos2.isValid()) {
if(product.isMultiSize()) {
pixelPos2.setLocation(product.getBand((String) referenceCombo.getSelectedItem()).getRasterWidth(),
product.getBand((String) referenceCombo.getSelectedItem()).getRasterHeight());
} else {
pixelPos2.setLocation(product.getSceneRasterWidth(),
product.getSceneRasterHeight());
}
}
final Rectangle.Float region = new Rectangle.Float();
region.setFrameFromDiagonal(pixelPos1.x, pixelPos1.y, pixelPos2.x, pixelPos2.y);
final Rectangle.Float productBounds;
if(product.isMultiSize()) {
productBounds = new Rectangle.Float(0, 0,
product.getBand((String) referenceCombo.getSelectedItem()).getRasterWidth(),
product.getBand((String) referenceCombo.getSelectedItem()).getRasterHeight());
} else {
productBounds = new Rectangle.Float(0, 0,
product.getSceneRasterWidth(),
product.getSceneRasterHeight());
}
Rectangle2D finalRegion = productBounds.createIntersection(region);
paramX1.setValue((int) finalRegion.getMinX(), ex -> true);
paramY1.setValue((int) finalRegion.getMinY(), ex -> true);
paramX2.setValue((int) finalRegion.getMaxX() - 1, ex -> true);
paramY2.setValue((int) finalRegion.getMaxY() - 1, ex -> true);
}
/**
* Get bounds rectangle
*
* @return Bounds rectangle
*/
public Rectangle.Float getBounds() {
return new Rectangle.Float(x, y, width, height);
}