本文整理汇总了Java中java.awt.geom.Rectangle2D.getCenterY方法的典型用法代码示例。如果您正苦于以下问题:Java Rectangle2D.getCenterY方法的具体用法?Java Rectangle2D.getCenterY怎么用?Java Rectangle2D.getCenterY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.Rectangle2D
的用法示例。
在下文中一共展示了Rectangle2D.getCenterY方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransY
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
private double getTransY(TransformType type, Rectangle2D focus) {
switch (type) {
case DOWN:
case DOWNLEFT:
case DOWNRIGHT:
return focus.getMaxY();
case UP:
case UPLEFT:
case UPRIGHT:
return focus.getY() - this.currentTransformRectSize;
case LEFT:
case RIGHT:
return focus.getCenterY() - this.currentTransformRectSize / 2;
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: appendTargetNode
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Checks whether the given source node is in a proper position with
* respect to the given target node and appends the target node to the
* string builder, together with a node anchor that keeps the edge
* horizontal or vertical.
*/
private void appendTargetNode(JVertex<G> srcNode, JVertex<G> tgtNode) {
if (this.layoutMap != null) {
JVertexLayout srcLayout = this.layoutMap.getLayout(srcNode.getNode());
JVertexLayout tgtLayout = this.layoutMap.getLayout(tgtNode.getNode());
if (srcLayout != null && tgtLayout != null) {
Rectangle2D tgtBounds = tgtLayout.getBounds();
Point2D tgtCenter =
new Point2D.Double(tgtBounds.getCenterX(), tgtBounds.getCenterY());
int side = getSide(srcNode, tgtCenter);
if (side == 0) {
Rectangle2D srcBounds = srcLayout.getBounds();
Point2D srcCenter =
new Point2D.Double(srcBounds.getCenterX(), srcBounds.getCenterY());
appendNode(tgtNode, srcCenter);
} else {
appendNode(tgtNode);
}
}
} else {
appendNode(tgtNode);
}
}
示例7: 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);
}
示例8: 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());
}
示例9: 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;
}
示例10: createAlignedRectangle2D
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Creates a rectangle that is aligned to the frame.
*
* @param dimensions
* @param frame
* @param hAlign
* @param vAlign
*
* @return A rectangle.
*/
private Rectangle2D createAlignedRectangle2D(Size2D dimensions,
Rectangle2D frame, HorizontalAlignment hAlign,
VerticalAlignment vAlign) {
double x = Double.NaN;
double y = Double.NaN;
if (hAlign == HorizontalAlignment.LEFT) {
x = frame.getX();
}
else if (hAlign == HorizontalAlignment.CENTER) {
x = frame.getCenterX() - (dimensions.width / 2.0);
}
else if (hAlign == HorizontalAlignment.RIGHT) {
x = frame.getMaxX() - dimensions.width;
}
if (vAlign == VerticalAlignment.TOP) {
y = frame.getY();
}
else if (vAlign == VerticalAlignment.CENTER) {
y = frame.getCenterY() - (dimensions.height / 2.0);
}
else if (vAlign == VerticalAlignment.BOTTOM) {
y = frame.getMaxY() - dimensions.height;
}
return new Rectangle2D.Double(x, y, dimensions.width,
dimensions.height);
}
示例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: draw
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a
* printer).
* <P>
* This plot relies on a {@link PolarItemRenderer} to draw each
* item in the plot. This allows the visual representation of the data to
* be changed easily.
* <P>
* The optional info argument collects information about the rendering of
* the plot (dimensions, tooltip information etc). Just pass in
* <code>null</code> if you do not need this information.
*
* @param g2 the graphics device.
* @param area the area within which the plot (including axes and
* labels) should be drawn.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState ignored.
* @param info collects chart drawing information (<code>null</code>
* permitted).
*/
public void draw(Graphics2D g2,
Rectangle2D area,
Point2D anchor,
PlotState parentState,
PlotRenderingInfo info) {
// if the plot area is too small, just return...
boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (info != null) {
info.setPlotArea(area);
}
// adjust the drawing area for the plot insets (if any)...
RectangleInsets insets = getInsets();
insets.trim(area);
Rectangle2D dataArea = area;
if (info != null) {
info.setDataArea(dataArea);
}
// draw the plot background and axes...
drawBackground(g2, dataArea);
double h = Math.min(dataArea.getWidth() / 2.0,
dataArea.getHeight() / 2.0) - MARGIN;
Rectangle2D quadrant = new Rectangle2D.Double(dataArea.getCenterX(),
dataArea.getCenterY(), h, h);
AxisState state = drawAxis(g2, area, quadrant);
if (this.renderer != null) {
Shape originalClip = g2.getClip();
Composite originalComposite = g2.getComposite();
g2.clip(dataArea);
g2.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, getForegroundAlpha()));
drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());
// draw...
render(g2, dataArea, info);
g2.setClip(originalClip);
g2.setComposite(originalComposite);
}
drawOutline(g2, dataArea);
drawCornerTextItems(g2, dataArea);
}
示例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: getCenterPoint
import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类
/** Computes and returns the centre point of a rectangle. */
private Point2D getCenterPoint(Rectangle2D bounds) {
return new Point2D.Double(bounds.getCenterX(), bounds.getCenterY());
}
示例15: 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");
}
}