本文整理汇总了Java中java.awt.geom.Rectangle2D.getCenterX方法的典型用法代码示例。如果您正苦于以下问题:Java Rectangle2D.getCenterX方法的具体用法?Java Rectangle2D.getCenterX怎么用?Java Rectangle2D.getCenterX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Rectangle2D
的用法示例。
在下文中一共展示了Rectangle2D.getCenterX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransX
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
private double getTransX(TransformType type, Rectangle2D focus) {
switch (type) {
case DOWN:
case UP:
return focus.getCenterX() - this.currentTransformRectSize / 2;
case LEFT:
case DOWNLEFT:
case UPLEFT:
return focus.getX() - this.currentTransformRectSize;
case RIGHT:
case DOWNRIGHT:
case UPRIGHT:
return focus.getMaxX();
default:
return 0;
}
}
示例2: zoomComponent
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Zoom component.
*/
private void zoomComponent() {
Set<GraphNode> nodesPicked = this.getVisualizationViewer().getPickedVertexState().getPicked();
if (nodesPicked.size()!=0) {
HashSet<NetworkComponent> components = this.graphController.getNetworkModelAdapter().getNetworkComponentsFullySelected(nodesPicked);
if (components!=null && components.size()!=0) {
// --- Get the dimension of the selected nodes ------
Rectangle2D areaSelected = GraphGlobals.getGraphSpreadDimension(nodesPicked);
Point2D areaCenter = new Point2D.Double(areaSelected.getCenterX(), areaSelected.getCenterY());
// --- Create temporary GraphNode -------------------
GraphNode tmpNode = new GraphNode("tmPCenter", areaCenter);
this.getVisualizationViewer().getGraphLayout().getGraph().addVertex(tmpNode);
// --- Get the needed positions ---------------------
Point2D tmpNodePos = this.getVisualizationViewer().getGraphLayout().transform(tmpNode);
Point2D visViewCenter = this.getVisualizationViewer().getRenderContext().getMultiLayerTransformer().inverseTransform(this.getVisualizationViewer().getCenter());
// --- Calculate movement ---------------------------
final double dx = (visViewCenter.getX() - tmpNodePos.getX());
final double dy = (visViewCenter.getY() - tmpNodePos.getY());
// --- Remove temporary GraphNode and move view -----
this.getVisualizationViewer().getGraphLayout().getGraph().removeVertex(tmpNode);
this.getVisualizationViewer().getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy);
}
}
}
示例3: drawValueLabel
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Draws the value label just below the center of the dial.
*
* @param g2 the graphics device.
* @param area the plot area.
*/
protected void drawValueLabel(Graphics2D g2, Rectangle2D area) {
g2.setFont(this.valueFont);
g2.setPaint(this.valuePaint);
String valueStr = "No value";
if (this.dataset != null) {
Number n = this.dataset.getValue();
if (n != null) {
valueStr = this.tickLabelFormat.format(n.doubleValue()) + " "
+ this.units;
}
}
float x = (float) area.getCenterX();
float y = (float) area.getCenterY() + DEFAULT_CIRCLE_SIZE;
TextUtilities.drawAlignedString(valueStr, g2, x, y,
TextAnchor.TOP_CENTER);
}
示例4: calculateFitRectangle
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
private Rectangle2D calculateFitRectangle(XSLFPictureData picture, Rectangle2D anchor) {
Dimension imageDimension = picture.getImageDimension();
double aspectImg = imageDimension.getWidth() / imageDimension.getHeight();
double aspectPh = anchor.getWidth() / anchor.getHeight();
double centerX = anchor.getCenterX();
double centerY = anchor.getCenterY();
double width, height;
if (aspectPh > aspectImg) {
height = anchor.getHeight();
width = aspectImg * anchor.getHeight();
} else {
width = anchor.getWidth();
height = aspectImg * anchor.getWidth();
}
double x = centerX - width/2;
double y = centerY - height/2;
return new Rectangle((int)x, (int)y, (int)width, (int)height);
}
示例5: draw
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/** Renders the rubber band on the given graphics object. */
public void draw(Graphics g) {
if (this.dragOrigVertex != null) {
Rectangle2D startBounds = getScreenBounds(this.dragOrigVertex);
int startX = (int) startBounds.getCenterX();
int startY = (int) startBounds.getCenterY();
int endX, endY;
if (this.dragCurrVertex != null
&& this.dragCurrVertex != this.dragOrigVertex) {
Rectangle2D endBounds =
getScreenBounds(this.dragCurrVertex);
endX = (int) endBounds.getCenterX();
endY = (int) endBounds.getCenterY();
} else {
endX = this.dragCurrPoint.x;
endY = this.dragCurrPoint.y;
}
g.setColor(Color.black);
g.drawLine(startX, startY, endX, endY);
}
}
示例6: draw
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Draws the pointer.
*
* @param g2 the graphics target.
* @param plot the plot.
* @param frame the dial's reference frame.
* @param view the dial's view.
*/
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
Rectangle2D view) {
g2.setPaint(this.paint);
g2.setStroke(this.stroke);
Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
this.radius, this.radius);
double value = plot.getValue(this.datasetIndex);
DialScale scale = plot.getScaleForDataset(this.datasetIndex);
double angle = scale.valueToAngle(value);
Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
Point2D pt = arc.getEndPoint();
Line2D line = new Line2D.Double(frame.getCenterX(),
frame.getCenterY(), pt.getX(), pt.getY());
g2.draw(line);
}
示例7: getDefaultScaleAtPoint
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Gets the default point to scale at for zooming.
* @return the default scale at point
*/
private Point2D getDefaultScaleAtPoint() {
Rectangle2D rectVis = this.getVisualizationViewer().getVisibleRect();
if (rectVis.isEmpty()==false) {
this.defaultScaleAtPoint = new Point2D.Double(rectVis.getCenterX(), rectVis.getCenterY());
}
return defaultScaleAtPoint;
}
示例8: calculateLabelLocation
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Returns the location for a label
*
* @param labelBounds the label bounds.
* @param ascent the ascent (height of font).
* @param plotArea the plot area
* @param startAngle the start angle for the pie series.
*
* @return The location for a label.
*/
protected Point2D calculateLabelLocation(Rectangle2D labelBounds,
double ascent,
Rectangle2D plotArea,
double startAngle)
{
Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
Point2D point1 = arc1.getEndPoint();
double deltaX = -(point1.getX() - plotArea.getCenterX())
* this.axisLabelGap;
double deltaY = -(point1.getY() - plotArea.getCenterY())
* this.axisLabelGap;
double labelX = point1.getX() - deltaX;
double labelY = point1.getY() - deltaY;
if (labelX < plotArea.getCenterX()) {
labelX -= labelBounds.getWidth();
}
if (labelX == plotArea.getCenterX()) {
labelX -= labelBounds.getWidth() / 2;
}
if (labelY > plotArea.getCenterY()) {
labelY += ascent;
}
return new Point2D.Double(labelX, labelY);
}
示例9: PolygonGraphics
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
public PolygonGraphics(Color color, Polygon polygon, Rectangle2D bounds) {
super((int)bounds.getHeight(), (int)bounds.getWidth());
this.polygon = polygon;
this.height = (int)bounds.getHeight();
this.width = (int)bounds.getWidth();
this.color = color;
position = new Position(bounds.getCenterX(), bounds.getCenterY());
}
示例10: createGradientTransform
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
private static AffineTransform createGradientTransform(Rectangle2D r) {
double cx = r.getCenterX();
double cy = r.getCenterY();
AffineTransform xform = AffineTransform.getTranslateInstance(cx, cy);
xform.scale(r.getWidth()/2, r.getHeight()/2);
xform.translate(-cx, -cy);
return xform;
}
示例11: getLabelEnclosure
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Returns a rectangle that encloses the axis label. This is typically used for layout
* purposes (it gives the maximum dimensions of the label).
*
* @param g2 the graphics device.
* @param edge the edge of the plot area along which the axis is measuring.
*
* @return The enclosing rectangle.
*/
protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) {
// calculate the width of the axis label...
Rectangle2D result = new Rectangle2D.Double();
String axisLabel = getLabel();
if (axisLabel != null) {
FontMetrics fm = g2.getFontMetrics(getLabelFont());
Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm);
Insets insets = getLabelInsets();
bounds.setRect(bounds.getX(), bounds.getY(),
bounds.getWidth() + insets.left + insets.right,
bounds.getHeight() + insets.top + insets.bottom);
double angle = getLabelAngle();
if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
angle = angle - Math.PI / 2.0;
}
double x = bounds.getCenterX();
double y = bounds.getCenterY();
AffineTransform transformer = AffineTransform.getRotateInstance(angle, x, y);
Shape labelBounds = transformer.createTransformedShape(bounds);
result = labelBounds.getBounds2D();
}
return result;
}
示例12: RadialGradientPaint
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Constructs a {@code RadialGradientPaint} with a default
* {@code SRGB} color space.
* The gradient circle of the {@code RadialGradientPaint} is defined
* by the given bounding box.
* <p>
* This constructor is a more convenient way to express the
* following (equivalent) code:<br>
*
* <pre>
* double gw = gradientBounds.getWidth();
* double gh = gradientBounds.getHeight();
* double cx = gradientBounds.getCenterX();
* double cy = gradientBounds.getCenterY();
* Point2D center = new Point2D.Double(cx, cy);
*
* AffineTransform gradientTransform = new AffineTransform();
* gradientTransform.translate(cx, cy);
* gradientTransform.scale(gw / 2, gh / 2);
* gradientTransform.translate(-cx, -cy);
*
* RadialGradientPaint gp =
* new RadialGradientPaint(center, 1.0f, center,
* fractions, colors,
* cycleMethod,
* ColorSpaceType.SRGB,
* gradientTransform);
* </pre>
*
* @param gradientBounds the bounding box, in user space, of the circle
* defining the outermost extent of the gradient
* @param fractions numbers ranging from 0.0 to 1.0 specifying the
* distribution of colors along the gradient
* @param colors array of colors to use in the gradient. The first color
* is used at the focus point, the last color around the
* perimeter of the circle.
* @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
* or {@code REPEAT}
*
* @throws NullPointerException
* if {@code gradientBounds} is null,
* or {@code fractions} array is null,
* or {@code colors} array is null,
* or {@code cycleMethod} is null
* @throws IllegalArgumentException
* if {@code gradientBounds} is empty,
* or {@code fractions.length != colors.length},
* or {@code colors} is less than 2 in size,
* or a {@code fractions} value is less than 0.0 or greater than 1.0,
* or the {@code fractions} are not provided in strictly increasing order
*/
public RadialGradientPaint(Rectangle2D gradientBounds,
float[] fractions, Color[] colors,
CycleMethod cycleMethod)
{
// gradient center/focal point is the center of the bounding box,
// radius is set to 1.0, and then we set a scale transform
// to achieve an elliptical gradient defined by the bounding box
this(new Point2D.Double(gradientBounds.getCenterX(),
gradientBounds.getCenterY()),
1.0f,
new Point2D.Double(gradientBounds.getCenterX(),
gradientBounds.getCenterY()),
fractions,
colors,
cycleMethod,
ColorSpaceType.SRGB,
createGradientTransform(gradientBounds));
if (gradientBounds.isEmpty()) {
throw new IllegalArgumentException("Gradient bounds must be " +
"non-empty");
}
}
示例13: isHitAt
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Returns whether a specified local point pL is a part of the connection
* widget.
* First it make a rough bounds check
* for Line Segments => use Super call (ConnectionWidget.isHitAt(pL)).
* for self-edges => its sufficent to return getBounds.contains(pL).
* for Splines => Interate over all Partitial segments of the curve and make
* a minmax check with the bezier points. If pL is inside the minmax
* rectangle of one segment the curve is constructed and subdivided until
* the distance d between center point pC (of the bounding rectangle)
* and pL is below HIT_DISTANCE_SQUARE, in this case it returns true.
* If no no minmax check was successful or the subdivision lead to an
* rectangle witch doesn`t contain pL return false.
* @param localLocation the local location
* @return true, if the location is a part of the connection widget
*/
@Override
public boolean isHitAt(Point localLocation) {
if(!isVisible() || !getBounds ().contains (localLocation))
return false;
List<Point> controlPoints = getControlPoints ();
if(controlPoints.size() <=2){
if(isReflexive()) return true;
return super.isHitAt(localLocation);
}
if(bezierPoints != null) {
for (int i = 0; i < bezierPoints.length-1; i+=3) {
Point2D b0 = bezierPoints[i];
Point2D b1 = bezierPoints[i+1];
Point2D b2 = bezierPoints[i+2];
Point2D b3 = bezierPoints[i+3];
CubicCurve2D left = new CubicCurve2D.Double(
b0.getX(), b0.getY(),
b1.getX(), b1.getY(),
b2.getX(), b2.getY(),
b3.getX(), b3.getY());
Rectangle2D bounds = left.getBounds2D();
while(bounds.contains(localLocation)) {
//calculate the center and use HIT_DISTANCE_SQUARE for a range check
Point2D test = new Point2D.Double(bounds.getCenterX(),bounds.getCenterY());
if(test.distance(localLocation) < HIT_DISTANCE_SQUARE){
return true;
}
CubicCurve2D right = new CubicCurve2D.Double();
left.subdivide(left, right);
Rectangle2D lb2d = left.getBounds2D();
Rectangle2D rb2d = right.getBounds2D();
if( lb2d.contains(localLocation)){
bounds = lb2d;
} else if (rb2d.contains(localLocation)) {
left = right;
bounds = rb2d;
} else {
return false;
}
}//end while
}//end for
}
return false;
}
示例14: drawTick
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Draws a tick on the dial.
*
* @param g2 the graphics device.
* @param meterArea the meter area.
* @param value the tick value.
* @param label a flag that controls whether or not a value label is drawn.
*/
protected void drawTick(Graphics2D g2, Rectangle2D meterArea,
double value, boolean label) {
double valueAngle = valueToAngle(value);
double meterMiddleX = meterArea.getCenterX();
double meterMiddleY = meterArea.getCenterY();
g2.setPaint(this.tickPaint);
g2.setStroke(new BasicStroke(2.0f));
double valueP2X = 0;
double valueP2Y = 0;
double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE;
double radius1 = radius - 15;
double valueP1X = meterMiddleX
+ (radius * Math.cos(Math.PI * (valueAngle / 180)));
double valueP1Y = meterMiddleY
- (radius * Math.sin(Math.PI * (valueAngle / 180)));
valueP2X = meterMiddleX
+ (radius1 * Math.cos(Math.PI * (valueAngle / 180)));
valueP2Y = meterMiddleY
- (radius1 * Math.sin(Math.PI * (valueAngle / 180)));
Line2D.Double line = new Line2D.Double(valueP1X, valueP1Y, valueP2X,
valueP2Y);
g2.draw(line);
if (this.tickLabelsVisible && label) {
String tickLabel = this.tickLabelFormat.format(value);
g2.setFont(this.tickLabelFont);
g2.setPaint(this.tickLabelPaint);
FontMetrics fm = g2.getFontMetrics();
Rectangle2D tickLabelBounds
= TextUtilities.getTextBounds(tickLabel, g2, fm);
double x = valueP2X;
double y = valueP2Y;
if (valueAngle == 90 || valueAngle == 270) {
x = x - tickLabelBounds.getWidth() / 2;
}
else if (valueAngle < 90 || valueAngle > 270) {
x = x - tickLabelBounds.getWidth();
}
if ((valueAngle > 135 && valueAngle < 225)
|| valueAngle > 315 || valueAngle < 45) {
y = y - tickLabelBounds.getHeight() / 2;
}
else {
y = y + tickLabelBounds.getHeight() / 2;
}
g2.drawString(tickLabel, (float) x, (float) y);
}
}
示例15: drawHorizontal
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Draws a the title horizontally within the specified area. This method will be called
* from the {@link #draw(Graphics2D, Rectangle2D) draw} method.
*
* @param g2 the graphics device.
* @param area the area for the title.
*/
protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
Rectangle2D titleArea = (Rectangle2D) area.clone();
getSpacer().trim(titleArea);
g2.setFont(this.font);
g2.setPaint(this.paint);
TextBlock title = TextUtilities.createTextBlock(
this.text, this.font, this.paint, (float) titleArea.getWidth(), new G2TextMeasurer(g2)
);
TextBlockAnchor anchor = null;
float x = 0.0f;
HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
x = (float) titleArea.getX();
anchor = TextBlockAnchor.TOP_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
x = (float) titleArea.getMaxX();
anchor = TextBlockAnchor.TOP_RIGHT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
x = (float) titleArea.getCenterX();
anchor = TextBlockAnchor.TOP_CENTER;
}
float y = 0.0f;
RectangleEdge position = getPosition();
if (position == RectangleEdge.TOP) {
y = (float) titleArea.getY();
}
else if (position == RectangleEdge.BOTTOM) {
y = (float) titleArea.getMaxY();
if (horizontalAlignment == HorizontalAlignment.LEFT) {
anchor = TextBlockAnchor.BOTTOM_LEFT;
}
else if (horizontalAlignment == HorizontalAlignment.CENTER) {
anchor = TextBlockAnchor.BOTTOM_CENTER;
}
else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
anchor = TextBlockAnchor.BOTTOM_RIGHT;
}
}
title.draw(g2, x, y, anchor);
}