下面列出了java.awt.Rectangle#Double ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void drawText(Graphics2D g, Rectangle2D area) {
float x, y;
for (ChartText text : this.texts) {
x = (float) (area.getWidth() * text.getX());
y = (float) (area.getHeight() * (1 - text.getY()));
Dimension dim = Draw.getStringDimension(text.getText(), g);
Rectangle.Double rect = new Rectangle.Double(x, y, dim.getWidth(), dim.getHeight());
if (text.isFill()) {
g.setColor(text.getBackground());
g.fill(rect);
}
if (text.isDrawNeatline()) {
g.setColor(text.getNeatlineColor());
Stroke oldStroke = g.getStroke();
g.setStroke(new BasicStroke(text.getNeatlineSize()));
g.draw(rect);
g.setStroke(oldStroke);
}
g.setFont(text.getFont());
g.setColor(text.getColor());
Draw.drawString(g, text.getText(), x, y);
}
}
private static Rectangle.Double getControlPoint(String controlPoints, String bbox) {
Rectangle.Double rect = null;
try {
//we need to adjust the bounding box to at least include the symbol
String bbox2 = getBoundingRectangle(controlPoints, bbox);
String[] bounds2 = bbox2.split(",");
double left = Double.valueOf(bounds2[0]).doubleValue();
double right = Double.valueOf(bounds2[2]).doubleValue();
double top = Double.valueOf(bounds2[3]).doubleValue();
double bottom = Double.valueOf(bounds2[1]).doubleValue();
double width = Math.abs(right - left);
double height = Math.abs(top - bottom);
rect = new Rectangle.Double(left, top, width, height);
} catch (Exception ex) {
System.out.println("Failed to create control point in MultiPointHandler.getControlPoint");
}
return rect;
}
/**
* Currently used by AddModifiers for greater accuracy on center labels
*
* @param geoPoints
* @return
*/
public static POINT2 geodesic_center(ArrayList<POINT2> geoPoints) {
POINT2 pt = null;
try {
if(geoPoints==null || geoPoints.isEmpty())
return pt;
Rectangle.Double rect2d=geodesic_mbr(geoPoints);
double deltax=rect2d.getWidth()/2;
double deltay=rect2d.getHeight()/2;
POINT2 ul=new POINT2(rect2d.x,rect2d.y);
//first walk east by deltax
POINT2 ptEast=geodesic_coordinate(ul,deltax,90);
//next walk south by deltay;
pt=geodesic_coordinate(ptEast,deltay,180);
} catch (Exception exc) {
ErrorLogger.LogException(_className, "geodesic_center",
new RendererException("Failed inside geodesic_center", exc));
}
return pt;
}
public void mouseClicked(MouseEvent e) {
if (!e.isControlDown()) {
setSelection(null);
}
//Rectangle made by single click is grown by couple pixels to make clicking easier.
//Growing should be done by screen pixels, and this is the latest point for that for now.
//If accurate single click detection is needed some day later, this should be moved to
//SelectionChangeListeners and implement needed methods or parameters.
Rectangle rect = new Rectangle((int)e.getPoint().getX(), (int)e.getPoint().getY(), 0 ,0);
rect.grow(3, 3);
Rectangle.Double translatedRect = translateToChart(rect);
setSelection(translatedRect);
}
@Override
public Rectangle2D getArea() {
if (area == null) {
area = new Rectangle.Double(getX(), getY(), getWidth(), getHeight());
} else {
area.x = getX();
area.y = getY();
area.width = getWidth();
area.height = getHeight();
}
return area;
}
/**
* Get the area the entity occupies.
*
* @return A rectange (in world coordinate units).
*/
@Override
public Rectangle2D getArea() {
// Hack for human like creatures
if ((Math.abs(getWidth() - 1.0) < 0.1)
&& (Math.abs(getHeight() - 2.0) < 0.1)) {
return new Rectangle.Double(getX(), getY() + 1.0, 1.0, 1.0);
}
return super.getArea();
}
/**
* calculates the geodesic MBR, intended for regular shaped areas
*
* @param geoPoints
* @return
*/
public static Rectangle.Double geodesic_mbr(ArrayList<POINT2> geoPoints) {
Rectangle.Double rect2d = null;
try {
if (geoPoints == null || geoPoints.isEmpty()) {
return rect2d;
}
ArrayList<POINT2>normalizedPts=normalize_points(geoPoints);
double ulx=normalizedPts.get(0).x;
double lrx=ulx;
double uly=normalizedPts.get(0).y;
double lry=uly;
int j=0;
POINT2 pt=null;
for(j=1;j<normalizedPts.size();j++)
{
pt=normalizedPts.get(j);
if(pt.x<ulx)
ulx=pt.x;
if(pt.x>lrx)
lrx=pt.x;
if(pt.y>uly)
uly=pt.y;
if(pt.y<lry)
lry=pt.y;
}
POINT2 ul=new POINT2(ulx,uly);
POINT2 ur=new POINT2(lrx,uly);
POINT2 lr=new POINT2(lrx,lry);
double width=geodesic_distance(ul,ur,null,null);
double height=geodesic_distance(ur,lr,null,null);
rect2d=new Rectangle.Double(ulx,uly,width,height);
} catch (Exception exc) {
ErrorLogger.LogException(_className, "geodesic_mbr",
new RendererException("Failed inside geodesic_mbr", exc));
}
return rect2d;
}
public Rectangle.Double translateToChart(Rectangle mouseCoords){
//Screen coordinates are integers
Point corner1 = new Point((int)mouseCoords.getMinX(), (int)mouseCoords.getMinY());
Point corner2 = new Point((int)mouseCoords.getMaxX(), (int)mouseCoords.getMaxY());
Point.Double translated1 = translateToChart(corner1);
Point.Double translated2 = translateToChart(corner2);
return createOrderedRectangle(translated1, translated2);
}
public SeprateMovabletype()
{
字 = new Vector<PlaneGeometry>();
原本字體 = new Vector<PlaneGeometry>();
字外殼 = null;
這馬 = new Rectangle.Double();
目標 = new Rectangle.Double();
}
public SeprateMovabletype(SeprateMovabletype 活字)
{
字 = new Vector<PlaneGeometry>();
for (PlaneGeometry 活字的字 : 活字.字)
字.add(new PlaneGeometry(活字的字));
原本字體 = new Vector<PlaneGeometry>(活字.原本字體);
字外殼 = null;
這馬 = new Rectangle.Double();
這馬.setRect(活字.這馬);
目標 = new Rectangle.Double();
目標.setRect(活字.目標);
}
public void 設字範圍(Rectangle2D 目標)
{
// TODO Auto-generated method stub
這馬 = new Rectangle.Double();
這馬.setRect(目標);
這馬字範圍();
return;
}
public void 重設字範圍()
{
// TODO Auto-generated method stub
這馬 = new Rectangle.Double();
這馬字範圍();
return;
}
/**
* Draw text
*
* @param g Graphics2D
* @param x X
* @param y Y
*/
public void draw(Graphics2D g, float x, float y) {
Dimension dim = this.getDimension(g);
x += this.xShift;
y += this.yShift;
AffineTransform tempTrans = g.getTransform();
if (this.angle != 0) {
//AffineTransform myTrans = new AffineTransform();
AffineTransform myTrans = (AffineTransform) tempTrans.clone();
myTrans.translate(x, y);
//myTrans.translate(tempTrans.getTranslateX() + x, tempTrans.getTranslateY() + y);
myTrans.rotate(-angle * Math.PI / 180);
g.setTransform(myTrans);
x = 0;
y = 0;
}
Rectangle.Double rect = new Rectangle.Double(x, y - dim.getHeight(), dim.getWidth(), dim.getHeight());
rect.setRect(rect.x - gap, rect.y - gap, rect.width + gap * 2,
rect.height + gap * 2);
if (this.drawBackground) {
g.setColor(this.background);
g.fill(rect);
}
if (this.drawNeatline) {
g.setColor(this.neatLineColor);
Stroke oldStroke = g.getStroke();
g.setStroke(new BasicStroke(neatLineSize));
g.draw(rect);
g.setStroke(oldStroke);
}
g.setColor(this.color);
g.setFont(font);
switch (this.yAlign) {
case BOTTOM:
y = y - dim.height;
break;
case CENTER:
y = y - dim.height * 0.5f;
break;
}
for (String str : this.text) {
dim = Draw.getStringDimension(str, g);
Draw.drawString(g, x, y, str, xAlign, YAlign.TOP, useExternalFont);
y += dim.height;
y += this.lineSpace;
}
if (this.angle != 0) {
g.setTransform(tempTrans);
}
}
/**
* Get the area the entity occupies.
*
* @return A rectange (in world coordinate units).
*/
@Override
public Rectangle2D getArea() {
return new Rectangle.Double(getX(), getY() + getHeight() - 1,
getWidth(), 1);
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
RECT r = getBounds();
Shape shp = new Rectangle.Double(r.Xmin, r.Ymin, r.getWidth(), r.getHeight());
return transformation.toTransform().createTransformedShape(shp); //TODO: match character shapes (?)
}
private Rectangle2D createRectangle2D(SWCRectangle swcRect)
{
return new Rectangle.Double(swcRect.getX(), swcRect.getY(), swcRect.getWidth(), swcRect.getHeight());
}
private void paintWords(Graphics2D g2, double screenWidth, double screenHeight)
{
//Area boundingShape = ImageOutline.getShape("resources/shapes/batman.gif", screenWidth, screenHeight);
//Area boundingShape = ImageOutline.getShape("resources/shapes/sherlock.png", screenWidth, screenHeight);
Area boundingShape = ImageOutline.getShape("resources/shapes/cloud.png", screenWidth, screenHeight);
Area screenArea = new Area(new Rectangle.Double(0, 0, screenWidth, screenHeight));
screenArea.subtract(boundingShape);
occupiedAreas.add(screenArea);
//g2.setColor(Color.BLACK);
//g2.draw(boundingShape);
List<String> words = getWords();
Map<String, Double> scales = new HashMap();
for (int i = 0; i < words.size(); i++)
{
scales.put(words.get(i), computeOriginalScale(words.get(i), screenWidth, screenHeight, g2));
}
int cntPlaced = 0;
int totalWords = 500;
for (int i = 0; i < totalWords; i++)
{
String word = words.get(rnd.nextInt(words.size()));
for (int r = 0; r < 50; r++)
{
double scale = scales.get(word);
if (placeWord(word, scale, screenWidth, screenHeight, g2))
{
cntPlaced++;
if (cntPlaced % 50 == 0)
System.out.println("placed " + cntPlaced + " words");
break;
}
else
{
scales.put(word, scale * 0.9);
}
}
}
System.out.println("placed " + cntPlaced + " out of " + totalWords);
}
protected Shape createShape(double startX, double startY, double size) {
return new Rectangle.Double(startX, startY, size, size);
}
public Rectangle2D.Double 字範圍()
{
Rectangle.Double 範圍 = new Rectangle.Double();
範圍.setRect(super.getBounds2D());
return 範圍;
}
/**
* Returns the area used by this entity.
*
* @param ex
* x
* @param ey
* y
* @return rectangle for the used area
*/
public Rectangle2D getArea(final double ex, final double ey) {
final Rectangle2D tempRect = new Rectangle.Double();
tempRect.setRect(ex, ey, area.getWidth(), area.getHeight());
return tempRect;
}