Java Code Examples for java.awt.geom.Rectangle2D#Double
The following examples show how to use
java.awt.geom.Rectangle2D#Double .
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: RenderParameters.java From render with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("UnusedDeclaration") public void deriveMinimalBoundingBox(final boolean force, final double... padding) throws IllegalStateException { final double paddingTop, paddingRight, paddingBottom, paddingLeft; if (padding.length > 3) { paddingTop = padding[0]; paddingRight = padding[1]; paddingBottom = padding[2]; paddingLeft = padding[3]; } else if (padding.length > 1) { paddingLeft = paddingRight = padding[0]; paddingTop = paddingBottom = padding[1]; } else if (padding.length > 0) { paddingLeft = paddingRight = paddingTop = paddingBottom = padding[0]; } else { paddingLeft = paddingRight = paddingTop = paddingBottom = 0; } if (force || !isMinBoundsDefined()) { final Rectangle2D.Double minBounds = TileSpec.deriveBoundingBox(tileSpecs, meshCellSize, force, null); minBoundsMinX = minBounds.x - paddingLeft; minBoundsMinY = minBounds.y - paddingTop; minBoundsMaxX = minBounds.x + minBounds.width + paddingRight; minBoundsMaxY = minBounds.y + minBounds.height + paddingBottom; minBoundsMeshCellSize = meshCellSize; } }
Example 2
Source File: ImageGenerator.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public void drawImage( Graphics2D g2d, ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer ) { checkMapContent(); if (buffer > 0.0) ref.expandBy(buffer, buffer); Rectangle2D refRect = new Rectangle2D.Double(ref.getMinX(), ref.getMinY(), ref.getWidth(), ref.getHeight()); Rectangle2D imageRect = new Rectangle2D.Double(0, 0, imageWidth, imageHeight); GeometryUtilities.scaleToRatio(imageRect, refRect, false); ReferencedEnvelope newRef = new ReferencedEnvelope(refRect, ref.getCoordinateReferenceSystem()); Rectangle imageBounds = new Rectangle(0, 0, imageWidth, imageHeight); Color white = Color.white; g2d.setColor(new Color(white.getRed(), white.getGreen(), white.getBlue(), 0)); g2d.fillRect(0, 0, imageWidth, imageHeight); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); synchronized (renderer) { content.getViewport().setBounds(newRef); renderer.paint(g2d, imageBounds, newRef); } }
Example 3
Source File: BoundsTree.java From ReactionDecoder with GNU Lesser General Public License v3.0 | 6 votes |
/** * Adds a rectangular bounds to the tree and updates the root bounds. * * @param label * @param bounds the bounding box of the */ public void add(String label, Rectangle2D bounds) { // don't add empty bounding boxes to the root boolean isEmpty = (bounds.getCenterX() == 0 && bounds.getCenterY() == 0 && bounds.getWidth() == 0 && bounds.getHeight() == 0); childMap.put(label, bounds); if (root == null && !isEmpty) { root = new Rectangle2D.Double( bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()); childMap.put(rootLabel, root); } else if (!isEmpty) { root.add(bounds); } if (root != null) { // System.out.println("root " + BoundsPrinter.toString(root) + " added " + BoundsPrinter.toString(bounds) + " " + label); } }
Example 4
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 5
Source File: TickLabelEntityTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { TickLabelEntity e1 = new TickLabelEntity(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), "ToolTip", "URL"); TickLabelEntity e2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(e1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); e2 = (TickLabelEntity) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(e1, e2); }
Example 6
Source File: GradientXYBarPainter.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitHorizontalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double y0 = bar.getMinY(); double y1 = Math.rint(y0 + (bar.getHeight() * a)); double y2 = Math.rint(y0 + (bar.getHeight() * b)); double y3 = Math.rint(y0 + (bar.getHeight() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), y1 - y0); result[1] = new Rectangle2D.Double(bar.getMinX(), y1, bar.getWidth(), y2 - y1); result[2] = new Rectangle2D.Double(bar.getMinX(), y2, bar.getWidth(), y3 - y2); result[3] = new Rectangle2D.Double(bar.getMinX(), y3, bar.getWidth(), bar.getMaxY() - y3); return result; }
Example 7
Source File: GradientXYBarPainter.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Splits a bar into subregions (elsewhere, these subregions will have * different gradients applied to them). * * @param bar the bar shape. * @param a the first division. * @param b the second division. * @param c the third division. * * @return An array containing four subregions. */ private Rectangle2D[] splitVerticalBar(RectangularShape bar, double a, double b, double c) { Rectangle2D[] result = new Rectangle2D[4]; double x0 = bar.getMinX(); double x1 = Math.rint(x0 + (bar.getWidth() * a)); double x2 = Math.rint(x0 + (bar.getWidth() * b)); double x3 = Math.rint(x0 + (bar.getWidth() * c)); result[0] = new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), x1 - x0, bar.getHeight()); result[1] = new Rectangle2D.Double(x1, bar.getMinY(), x2 - x1, bar.getHeight()); result[2] = new Rectangle2D.Double(x2, bar.getMinY(), x3 - x2, bar.getHeight()); result[3] = new Rectangle2D.Double(x3, bar.getMinY(), bar.getMaxX() - x3, bar.getHeight()); return result; }
Example 8
Source File: Plot.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Draws the background image (if there is one) aligned within the * specified area. * * @param g2 the graphics device. * @param area the area. * * @see #getBackgroundImage() * @see #getBackgroundImageAlignment() * @see #getBackgroundImageAlpha() */ public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) { if (this.backgroundImage == null) { return; // nothing to do } Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.backgroundImageAlpha)); Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0, this.backgroundImage.getWidth(null), this.backgroundImage.getHeight(null)); Align.align(dest, area, this.backgroundImageAlignment); Shape savedClip = g2.getClip(); g2.clip(area); g2.drawImage(this.backgroundImage, (int) dest.getX(), (int) dest.getY(), (int) dest.getWidth() + 1, (int) dest.getHeight() + 1, null); g2.setClip(savedClip); g2.setComposite(savedComposite); }
Example 9
Source File: StandardXYItemRendererTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { StandardXYItemRenderer r1 = new StandardXYItemRenderer(); Rectangle2D rect1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0); r1.setLegendLine(rect1); StandardXYItemRenderer r2 = (StandardXYItemRenderer) r1.clone(); assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); // check independence rect1.setRect(4.0, 3.0, 2.0, 1.0); assertFalse(r1.equals(r2)); r2.setLegendLine(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0)); assertTrue(r1.equals(r2)); r1.setSeriesShapesFilled(1, Boolean.TRUE); assertFalse(r1.equals(r2)); r2.setSeriesShapesFilled(1, Boolean.TRUE); assertTrue(r1.equals(r2)); }
Example 10
Source File: Test.java From IntelliJDeodorant with MIT License | 5 votes |
public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { if (row < dataset.getRowCount() - 1) { return; } Comparable category = dataset.getColumnKey(column); List values = testProduct.createStackedValueList(dataset, dataset.getColumnKey(column), state.getVisibleSeriesArray(), getBase(), this.renderAsPercentages); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { drawStackHorizontal(values, category, g2, state, adjusted, plot, domainAxis, rangeAxis, dataset); } else { drawStackVertical(values, category, g2, state, adjusted, plot, domainAxis, rangeAxis, dataset); } }
Example 11
Source File: Rectangle.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * @since 1.2 */ public Rectangle2D createUnion(Rectangle2D r) { if (r instanceof Rectangle) { return union((Rectangle) r); } Rectangle2D dest = new Rectangle2D.Double(); Rectangle2D.union(this, r, dest); return dest; }
Example 12
Source File: RouterVisualiser.java From workcraft with MIT License | 5 votes |
private static void drawObstacleRectangles(Router router, Graphics2D g) { float width = 0.2f * (float) CircuitSettings.getBorderWidth(); float[] pattern = {0.05f, 0.05f}; g.setStroke(new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, pattern, 0.0f)); g.setColor(Color.GRAY); double margin = CircuitLayoutSettings.getMarginObstacleBusy(); for (Rectangle rect: router.getObstacles().getRectangles()) { Shape shape = new Rectangle2D.Double(rect.getX() - margin, rect.getY() - margin, rect.getWidth() + 2 * margin, rect.getHeight() + 2 * margin); g.draw(shape); } }
Example 13
Source File: AxisSpace.java From opensim-gui with Apache License 2.0 | 5 votes |
/** * Expands an area by the amount of space represented by this object. * * @param area the area to expand. * @param result an optional carrier for the result. * * @return The result. */ public Rectangle2D expand(Rectangle2D area, Rectangle2D result) { if (result == null) { result = new Rectangle2D.Double(); } result.setRect( area.getX() - this.left, area.getY() - this.top, area.getWidth() + this.left + this.right, area.getHeight() + this.top + this.bottom ); return result; }
Example 14
Source File: TestSVGGraphics2D.java From jfreesvg with GNU General Public License v3.0 | 5 votes |
@Test public void checkHitForOutline() { Shape shape = new Rectangle2D.Double(0.0, 0.0, 3.0, 3.0); Rectangle r = new Rectangle(1, 1, 1, 1); assertFalse(this.g2.hit(r, shape, true)); this.g2.scale(0.5, 0.5); // now the rectangle is entirely inside the shape, but does not touch // the outline... assertTrue(this.g2.hit(r, shape, true)); }
Example 15
Source File: ContainsTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { CubicCurve2D c = new CubicCurve2D.Double(0, 0, 4, -4, -2, -4, 2, 0); Rectangle2D r = new Rectangle2D.Double(0.75, -2.5, 0.5, 2); if (c.contains(r)) { throw new Exception("The rectangle should not be contained in the curve"); } }
Example 16
Source File: Paper.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * Creates a letter sized piece of paper * with one inch margins. */ public Paper() { mHeight = LETTER_HEIGHT; mWidth = LETTER_WIDTH; mImageableArea = new Rectangle2D.Double(INCH, INCH, mWidth - 2 * INCH, mHeight - 2 * INCH); }
Example 17
Source File: XYDotRenderer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Constructs a new renderer. */ public XYDotRenderer() { super(); this.dotWidth = 1; this.dotHeight = 1; this.legendShape = new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0); }
Example 18
Source File: jKali_0031_s.java From coming with MIT License | 4 votes |
/** * Draws a marker for the domain axis. * * @param g2 the graphics device (not <code>null</code>). * @param plot the plot (not <code>null</code>). * @param axis the range axis (not <code>null</code>). * @param marker the marker to be drawn (not <code>null</code>). * @param dataArea the area inside the axes (not <code>null</code>). * * @see #drawRangeMarker(Graphics2D, CategoryPlot, ValueAxis, Marker, * Rectangle2D) */ public void drawDomainMarker(Graphics2D g2, CategoryPlot plot, CategoryAxis axis, CategoryMarker marker, Rectangle2D dataArea) { Comparable category = marker.getKey(); CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this)); int columnIndex = dataset.getColumnIndex(category); if (columnIndex < 0) { return; } final Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, marker.getAlpha())); PlotOrientation orientation = plot.getOrientation(); Rectangle2D bounds = null; if (marker.getDrawAsLine()) { double v = axis.getCategoryMiddle(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Line2D line = null; if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } g2.setPaint(marker.getPaint()); g2.setStroke(marker.getStroke()); g2.draw(line); bounds = line.getBounds2D(); } else { double v0 = axis.getCategoryStart(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); double v1 = axis.getCategoryEnd(columnIndex, dataset.getColumnCount(), dataArea, plot.getDomainAxisEdge()); Rectangle2D area = null; if (orientation == PlotOrientation.HORIZONTAL) { area = new Rectangle2D.Double(dataArea.getMinX(), v0, dataArea.getWidth(), (v1 - v0)); } else if (orientation == PlotOrientation.VERTICAL) { area = new Rectangle2D.Double(v0, dataArea.getMinY(), (v1 - v0), dataArea.getHeight()); } g2.setPaint(marker.getPaint()); g2.fill(area); bounds = area; } String label = marker.getLabel(); RectangleAnchor anchor = marker.getLabelAnchor(); if (label != null) { Font labelFont = marker.getLabelFont(); g2.setFont(labelFont); g2.setPaint(marker.getLabelPaint()); Point2D coordinates = calculateDomainMarkerTextAnchorPoint( g2, orientation, dataArea, bounds, marker.getLabelOffset(), marker.getLabelOffsetType(), anchor); TextUtilities.drawAlignedString(label, g2, (float) coordinates.getX(), (float) coordinates.getY(), marker.getLabelTextAnchor()); } g2.setComposite(savedComposite); }
Example 19
Source File: AnnotationEventHook.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override public void processMouseEvent(final ExecutionUnit process, final MouseEventType type, final MouseEvent e) { if (!visualizer.isActive()) { return; } Point point = rendererModel.getMousePositionRelativeToProcess(); if (point == null) { point = e.getPoint(); } switch (type) { case MOUSE_CLICKED: if (!SwingUtilities.isLeftMouseButton(e)) { break; } if (process != null && e.getClickCount() >= 2) { if (!AnnotationDrawer.isProcessInteractionHappening(rendererModel)) { double x = Math.max(WorkflowAnnotation.MIN_X, point.getX()); double y = Math.max(WorkflowAnnotation.MIN_Y, point.getY()); ProcessAnnotation anno = new ProcessAnnotation( I18N.getGUILabel("workflow.annotation.default_text.label"), new AnnotationStyle(), process, false, false, new Rectangle2D.Double(x, y, ProcessAnnotation.DEFAULT_WIDTH, ProcessAnnotation.DEFAULT_HEIGHT)); model.addProcessAnnotation(anno); decorator.editSelected(); e.consume(); } } break; case MOUSE_ENTERED: case MOUSE_MOVED: if (process != null) { WorkflowAnnotations annotations = rendererModel.getProcessAnnotations(process); if (updateHoveredStatus(point, process, annotations)) { updateHyperlinkHoverStatus(point); e.consume(); } else { model.setHovered(null, null); } } break; case MOUSE_EXITED: if (!SwingTools.isMouseEventExitedToChildComponents(view, e)) { model.setHovered(null, null); } break; case MOUSE_DRAGGED: model.setHovered(null, null); break; case MOUSE_PRESSED: if ((SwingTools.isControlOrMetaDown(e) || e.isShiftDown()) && e.getButton() == 1) { return; } if (SwingUtilities.isLeftMouseButton(e) || SwingUtilities.isRightMouseButton(e)) { handleMousePressedForUnselectedAnnotations(e, point); } break; case MOUSE_RELEASED: default: break; } }
Example 20
Source File: ChartRenderingInfo.java From ECG-Viewer with GNU General Public License v2.0 | 2 votes |
/** * Constructs a new instance. If an entity collection is supplied, it will * be populated with information about the entities in a chart. If it is * <code>null</code>, no entity information (including tool tips) will * be collected. * * @param entities an entity collection (<code>null</code> permitted). */ public ChartRenderingInfo(EntityCollection entities) { this.chartArea = new Rectangle2D.Double(); this.plotInfo = new PlotRenderingInfo(this); this.entities = entities; }