Java Code Examples for java.awt.geom.Rectangle2D#getCenterX()
The following examples show how to use
java.awt.geom.Rectangle2D#getCenterX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cardumen_007_s.java From coming with MIT License | 6 votes |
/** * 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) { Rectangle2D result = new Rectangle2D.Double(); String axisLabel = getLabel(); if (axisLabel != null && !axisLabel.equals("")) { FontMetrics fm = g2.getFontMetrics(getLabelFont()); Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm); RectangleInsets insets = getLabelInsets(); bounds = insets.createOutsetRectangle(bounds); 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; }
Example 2
Source File: JGenProg2017_0082_s.java From coming with MIT License | 6 votes |
/** * 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) { Rectangle2D result = new Rectangle2D.Double(); String axisLabel = getLabel(); if (axisLabel != null && !axisLabel.equals("")) { FontMetrics fm = g2.getFontMetrics(getLabelFont()); Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm); RectangleInsets insets = getLabelInsets(); bounds = insets.createOutsetRectangle(bounds); 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; }
Example 3
Source File: JGenProg2017_006_t.java From coming with MIT License | 6 votes |
/** * 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) { Rectangle2D result = new Rectangle2D.Double(); String axisLabel = getLabel(); if (axisLabel != null && !axisLabel.equals("")) { FontMetrics fm = g2.getFontMetrics(getLabelFont()); Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm); RectangleInsets insets = getLabelInsets(); bounds = insets.createOutsetRectangle(bounds); 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; }
Example 4
Source File: Cardumen_00195_t.java From coming with MIT License | 6 votes |
/** * 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) { Rectangle2D result = new Rectangle2D.Double(); String axisLabel = getLabel(); if (axisLabel != null && !axisLabel.equals("")) { FontMetrics fm = g2.getFontMetrics(getLabelFont()); Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm); RectangleInsets insets = getLabelInsets(); bounds = insets.createOutsetRectangle(bounds); 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; }
Example 5
Source File: PropertyEditor.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
private void setOffsetMarker(MouseEvent e) { Rectangle2D tmp = null; for (Shape s : lastmatch) { if ((int) indexVal.getValue() == lastmatch.indexOf(s)) { tmp = s.getBounds2D(); break; } } if (tmp != null) { Rectangle2D r2d = tmp; int x = (int) (e.getX() - r2d.getCenterX()); int y = (int) (e.getY() - r2d.getCenterY()); tempObject.setOffset(x + "," + y); offestVal.setText(getOffsetText(tempObject.getOffset())); referenceLabel.repaint(); } }
Example 6
Source File: MeterPlot.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * 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); }
Example 7
Source File: AnnotationEventHook.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Updates the positions of all operator annotations for the given operators. * * @param operators * the operators for which to reposition the annotations * @return the list of annotations that have actually changed position */ private List<WorkflowAnnotation> positionOperatorAnnotations(final Collection<Operator> operators) { List<WorkflowAnnotation> movedAnnos = new LinkedList<>(); for (Operator op : operators) { WorkflowAnnotations annotations = rendererModel.getOperatorAnnotations(op); if (annotations != null) { Rectangle2D opRect = rendererModel.getOperatorRect(op); for (WorkflowAnnotation anno : annotations.getAnnotationsDrawOrder()) { Rectangle2D loc = anno.getLocation(); double annoCenter = loc.getCenterX(); double opCenter = opRect.getCenterX(); double newX = loc.getX() + (opCenter - annoCenter); double newY = opRect.getMaxY() + OperatorAnnotation.Y_OFFSET; // move if they really changed if (loc.getX() != newX || loc.getY() != newY) { anno.setLocation(new Rectangle2D.Double(newX, newY, loc.getWidth(), loc.getHeight())); movedAnnos.add(anno); } } } } return movedAnnos; }
Example 8
Source File: Axis.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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) { Rectangle2D result = new Rectangle2D.Double(); String axisLabel = getLabel(); if (axisLabel != null && !axisLabel.equals("")) { FontMetrics fm = g2.getFontMetrics(getLabelFont()); Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm); RectangleInsets insets = getLabelInsets(); bounds = insets.createOutsetRectangle(bounds); 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; }
Example 9
Source File: Axis.java From openstock with GNU General Public License v3.0 | 5 votes |
protected double labelLocationX(AxisLabelLocation location, Rectangle2D dataArea) { if (location.equals(AxisLabelLocation.HIGH_END)) { return dataArea.getMaxX(); } if (location.equals(AxisLabelLocation.MIDDLE)) { return dataArea.getCenterX(); } if (location.equals(AxisLabelLocation.LOW_END)) { return dataArea.getMinX(); } throw new RuntimeException("Unexpected AxisLabelLocation: " + location); }
Example 10
Source File: SpiderWebPlot.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 11
Source File: RenderedText.java From workcraft with MIT License | 5 votes |
public RenderedText(String text, Font font, Positioning positioning, Point2D offset) { this.text = text; this.font = font; this.positioning = positioning; this.xOffset = offset.getX(); this.yOffset = offset.getY(); Rectangle2D textBounds = null; glyphVectors = new LinkedList<>(); String[] lines = {""}; if (text != null) { lines = text.split("\\|"); } for (String line: lines) { final FontRenderContext context = new FontRenderContext(AffineTransform.getScaleInstance(1000.0, 1000.0), true, true); final GlyphVector glyphVector = font.createGlyphVector(context, line.trim()); glyphVectors.add(glyphVector); Rectangle2D lineBounds = glyphVector.getVisualBounds(); if (textBounds != null) { textBounds = BoundingBoxHelper.move(textBounds, 0.0, -lineBounds.getHeight()); } textBounds = BoundingBoxHelper.union(textBounds, lineBounds); } int lineCount = lines.length; spacing = (lineCount < 2) ? 0.0 : (spacingRatio * textBounds.getHeight() / (lineCount - 1)); textBounds = BoundingBoxHelper.transform(textBounds, AffineTransform.getScaleInstance(1.0, 1.0 + spacingRatio)); double x = xOffset + positioning.xOffset + 0.5 * positioning.xSign * textBounds.getWidth() - textBounds.getCenterX(); double y = yOffset + positioning.yOffset + 0.5 * positioning.ySign * textBounds.getHeight() - textBounds.getCenterY(); boundingBox = BoundingBoxHelper.move(textBounds, x, y); }
Example 12
Source File: RadialGradientPaint.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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; }
Example 13
Source File: JFreeChart.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Creates a rectangle that is aligned to the frame. * * @param dimensions the dimensions for the rectangle. * @param frame the frame to align to. * @param hAlign the horizontal alignment. * @param vAlign the vertical alignment. * * @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); }
Example 14
Source File: DialPlot.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * A utility method that computes a rectangle using relative radius values. * * @param rect the reference rectangle ({@code null} not permitted). * @param radiusW the width radius (must be > 0.0) * @param radiusH the height radius. * * @return A new rectangle. */ public static Rectangle2D rectangleByRadius(Rectangle2D rect, double radiusW, double radiusH) { ParamChecks.nullNotPermitted(rect, "rect"); double x = rect.getCenterX(); double y = rect.getCenterY(); double w = rect.getWidth() * radiusW; double h = rect.getHeight() * radiusH; return new Rectangle2D.Double(x - w / 2.0, y - h / 2.0, w, h); }
Example 15
Source File: DialPlot.java From astor with GNU General Public License v2.0 | 5 votes |
/** * A utility method that computes a rectangle using relative radius values. * * @param rect the reference rectangle (<code>null</code> not permitted). * @param radiusW the width radius (must be > 0.0) * @param radiusH the height radius. * * @return A new rectangle. */ public static Rectangle2D rectangleByRadius(Rectangle2D rect, double radiusW, double radiusH) { if (rect == null) { throw new IllegalArgumentException("Null 'rect' argument."); } double x = rect.getCenterX(); double y = rect.getCenterY(); double w = rect.getWidth() * radiusW; double h = rect.getHeight() * radiusH; return new Rectangle2D.Double(x - w / 2.0, y - h / 2.0, w, h); }
Example 16
Source File: JFreeChart.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Creates a rectangle that is aligned to the frame. * * @param dimensions the dimensions for the rectangle. * @param frame the frame to align to. * @param hAlign the horizontal alignment. * @param vAlign the vertical alignment. * * @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); }
Example 17
Source File: RadialGradientPaint.java From Java8CN with Apache License 2.0 | 5 votes |
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; }
Example 18
Source File: SpiderWebPlot.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 19
Source File: BblToRegion.java From data-polygamy with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void readBblData(FSDataInputStream fis) throws IOException { try { BufferedReader buff = new BufferedReader(new InputStreamReader(fis)); String line = buff.readLine(); ArrayList<Double> xPoints = new ArrayList<Double>(); ArrayList<Double> yPoints = new ArrayList<Double>(); while (line != null) { String region = line.trim(); buff.readLine(); Integer nbPoints = Integer.parseInt(buff.readLine()); xPoints = new ArrayList<Double>(nbPoints); yPoints = new ArrayList<Double>(nbPoints); for (int i = 0; i < nbPoints; i++) { String[] points = buff.readLine().split(" "); xPoints.add(Double.parseDouble(points[0])); yPoints.add(Double.parseDouble(points[1])); } // creating polygon Path2D polygon = new Path2D.Double(); polygon.moveTo(xPoints.get(0), yPoints.get(0)); for (int i = 1; i < xPoints.size(); ++i) { polygon.lineTo(xPoints.get(i), yPoints.get(i)); } polygon.closePath(); Rectangle2D rect = polygon.getBounds2D(); double x = rect.getCenterX(); double y = rect.getCenterY(); int r = grid.getRegion(x, y); if(r != -1) { bblRegions.put(Long.parseLong(region), regionNames.get(r)); } line = buff.readLine(); } buff.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { fis.close(); } }
Example 20
Source File: VisualComponent.java From workcraft with MIT License | 4 votes |
public Point2D getOffset(Positioning positioning) { Rectangle2D bb = getInternalBoundingBoxInLocalSpace(); double xOffset = (positioning.xSign < 0) ? bb.getMinX() : (positioning.xSign > 0) ? bb.getMaxX() : bb.getCenterX(); double yOffset = (positioning.ySign < 0) ? bb.getMinY() : (positioning.ySign > 0) ? bb.getMaxY() : bb.getCenterY(); return new Point2D.Double(xOffset, yOffset); }