Java Code Examples for java.awt.geom.Area#transform()
The following examples show how to use
java.awt.geom.Area#transform() .
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: BalloonManager.java From netbeans with Apache License 2.0 | 7 votes |
private Shape getShadowMask( Shape parentMask ) { Area area = new Area(parentMask); AffineTransform tx = new AffineTransform(); tx.translate(SHADOW_SIZE, SHADOW_SIZE );//Math.sin(ANGLE)*(getHeight()+SHADOW_SIZE), 0); area.transform(tx); area.subtract(new Area(parentMask)); return area; }
Example 2
Source File: AbstractGraphics2D.java From pumpernickel with MIT License | 6 votes |
@Override public void clip(Shape s) { if (s == null) return; if (clipping == null) { setClip(s); return; } Area a1 = new Area(clipping); Area a2 = new Area(s); a2.transform(transform); a1.intersect(a2); if (a1.isRectangular()) { clipping = a1.getBounds2D(); } else { clipping = a1; } }
Example 3
Source File: ImageOutline.java From swcv with MIT License | 6 votes |
public static Area getShape(String shapeFile, double screenWidth, double screenHeight) { try { System.out.print("reading shape..."); BufferedImage outline = ImageIO.read(new File(shapeFile)); Area boundingShape = ImageOutline.getOutline(outline, Color.BLACK, true, 10); System.out.println("done"); Rectangle2D bb = boundingShape.getBounds2D(); double scaleX = screenWidth / bb.getWidth(); double scaleY = screenHeight / bb.getHeight(); double scale = Math.min(scaleX, scaleY) * 0.95; AffineTransform at = new AffineTransform(scale, 0, 0, scale, 0, 0); boundingShape.transform(at); return boundingShape; } catch (IOException e) { throw new RuntimeException(e); } }
Example 4
Source File: PlumNeedle.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Draws the needle. * * @param g2 the graphics device. * @param plotArea the plot area. * @param rotate the rotation point. * @param angle the angle. */ protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) { Arc2D shape = new Arc2D.Double(Arc2D.PIE); double radius = plotArea.getHeight(); double halfX = plotArea.getWidth() / 2; double diameter = 2 * radius; shape.setFrame(plotArea.getMinX() + halfX - radius , plotArea.getMinY() - radius, diameter, diameter); radius = Math.toDegrees(Math.asin(halfX / radius)); shape.setAngleStart(270 - radius); shape.setAngleExtent(2 * radius); Area s = new Area(shape); if ((rotate != null) && (angle != 0)) { /// we have rotation houston, please spin me getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); s.transform(getTransform()); } defaultDisplay(g2, s); }
Example 5
Source File: AbstractShapeTransition2D.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
/** * Calculating the scaling ratio for the shape to fit the dimensions provided. */ protected float calculateMultiplier(Dimension size) { Shape shape = getShape(); Area base = new Area(shape); AffineTransform transform = new AffineTransform(); Rectangle2D r = ShapeBounds.getBounds(base); transform.translate(size.width / 2.0f - r.getCenterX(), size.height / 2.0f - r.getCenterY()); base.transform(transform); // r = ShapeBounds.getBounds(base, r); float min = 0; float max = 1; Rectangle2D boundsRect = new Rectangle2D.Float(0, 0, size.width, size.height); while (!isOK(base, boundsRect, max)) { min = max; max *= 1.2f; } float f = calculateMultiplier(base, boundsRect, min, max); isOK(base, boundsRect, f); return f; }
Example 6
Source File: AbstractGraphics2D.java From pumpernickel with MIT License | 6 votes |
@Override public Shape getClip() { if (clipping == null) return null; try { Area area = new Area(clipping); area.transform(transform.createInverse()); if (area.isRectangular()) return area.getBounds2D(); return area; } catch (NoninvertibleTransformException t) { RuntimeException e2 = new RuntimeException(); e2.initCause(t); throw e2; } }
Example 7
Source File: InfiniteProgressPanel.java From qmcflactomp3 with GNU General Public License v3.0 | 6 votes |
private Area[] buildTicker() { Area[] ticker = new Area[barsCount]; Point2D.Double center = new Point2D.Double((double) getWidth() / 2, (double) getHeight() / 2); double fixedAngle = 2.0 * Math.PI / (barsCount); for (double i = 0.0; i < barsCount; i++) { Area primitive = buildPrimitive(); AffineTransform toCenter = AffineTransform.getTranslateInstance(center.getX(), center.getY()); AffineTransform toBorder = AffineTransform.getTranslateInstance(45.0, -6.0); AffineTransform toCircle = AffineTransform.getRotateInstance(-i * fixedAngle, center.getX(), center.getY()); AffineTransform toWheel = new AffineTransform(); toWheel.concatenate(toCenter); toWheel.concatenate(toBorder); primitive.transform(toWheel); primitive.transform(toCircle); ticker[(int) i] = primitive; } return ticker; }
Example 8
Source File: InfiniteProgressPanel.java From ghidra with Apache License 2.0 | 6 votes |
private Area[] buildTicker( int barCount ) { Area[] newTicker = new Area[barCount]; Point2D.Double center = new Point2D.Double( (double) getWidth() / 2, (double) getHeight() / 2 ); double fixedAngle = 2.0 * Math.PI / (barCount); for ( double i = 0.0; i < barCount; i++ ) { Area primitive = buildPrimitive(); AffineTransform toCenter = AffineTransform.getTranslateInstance(center.getX(), center.getY() ); AffineTransform toBorder = AffineTransform.getTranslateInstance(45.0, -6.0 ); AffineTransform toCircle = AffineTransform.getRotateInstance(-i * fixedAngle, center.getX(), center.getY() ); AffineTransform toWheel = new AffineTransform(); toWheel.concatenate(toCenter); toWheel.concatenate(toBorder); primitive.transform(toWheel); primitive.transform(toCircle); newTicker[(int) i] = primitive; } return newTicker; }
Example 9
Source File: Dissector.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
@Override synchronized public Area getAreaAt(final Layer layer) { final Area a = new Area(); for (final Item item : al_items) { for (int i=0; i<item.n_points; i++) { if (item.p_layer[i] != layer.getId()) continue; a.add(new Area(new Rectangle2D.Float((float)(item.p[0][i] - item.radius), (float)(item.p[1][i] - item.radius), item.radius, item.radius))); } } a.transform(this.at); return a; }
Example 10
Source File: InfiniteProgressPanel.java From ghidra with Apache License 2.0 | 5 votes |
protected void transformTicker() { if ( inRampUpPeriod ) { return; } for ( Area element : ticker ) { element.transform( transformToCircle ); } }
Example 11
Source File: PlumNeedle.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Draws the needle. * * @param g2 the graphics device. * @param plotArea the plot area. * @param rotate the rotation point. * @param angle the angle. */ @Override protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) { Arc2D shape = new Arc2D.Double(Arc2D.PIE); double radius = plotArea.getHeight(); double halfX = plotArea.getWidth() / 2; double diameter = 2 * radius; shape.setFrame(plotArea.getMinX() + halfX - radius , plotArea.getMinY() - radius, diameter, diameter); radius = Math.toDegrees(Math.asin(halfX / radius)); shape.setAngleStart(270 - radius); shape.setAngleExtent(2 * radius); Area s = new Area(shape); if ((rotate != null) && (angle != 0)) { /// we have rotation houston, please spin me getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); s.transform(getTransform()); } defaultDisplay(g2, s); }
Example 12
Source File: Heliostat.java From energy2d with GNU Lesser General Public License v3.0 | 5 votes |
public static Area getShape(Rectangle2D.Float r, float angle) { // the positions and sizes of the circles must ensure that r is the bounding box Area a = new Area(new Rectangle2D.Float(r.x + r.width * 0.45f, r.y + r.height * 0.5f, r.width * 0.1f, r.height * 0.5f)); Area mirror = new Area(new Rectangle2D.Float(r.x, r.y + r.height * 0.45f, r.width, r.height * 0.1f)); mirror.add(new Area(new Rectangle2D.Float(r.x + 0.3f * r.width, r.y + r.height * 0.54f, r.width * 0.4f, r.height * 0.05f))); mirror.transform(AffineTransform.getRotateInstance(angle, r.x + r.width * 0.5, r.y + r.height * 0.5)); a.add(mirror); return a; }
Example 13
Source File: Polyline.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** A little square for each pixel in @param layer.*/ @Override synchronized public Area getAreaAt(final Layer layer) { final Area a = new Area(); for (int i=0; i<n_points; i++) { if (p_layer[i] != layer.getId()) continue; a.add(new Area(new Rectangle2D.Float((float)p[0][i], (float)p[1][i], 1, 1))); } a.transform(this.at); return a; }
Example 14
Source File: AbstractShapeTransition2D.java From pumpernickel with MIT License | 5 votes |
/** Determine if a particular scaling ratio works */ private boolean isOK(Area shape, Rectangle2D shapeBounds, Rectangle2D bounds, float ratio) { Area area = new Area(shape); area.transform(AffineTransform.getScaleInstance(ratio, ratio)); Rectangle2D r = ShapeBounds.getBounds(area); area.transform(AffineTransform.getTranslateInstance(-r.getCenterX() + bounds.getCenterX(), -r.getCenterY() + bounds.getCenterY())); Area boundsArea = new Area(bounds); boundsArea.subtract(area); return boundsArea.isEmpty(); }
Example 15
Source File: Ball.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
@Override synchronized public Area getAreaAt(final Layer layer) { final Area a = new Area(); for (int i=0; i<n_points; i++) { if (p_layer[i] != layer.getId()) continue; a.add(new Area(new Ellipse2D.Float((float)(p[0][i] - p_width[i]/2), (float)(p[1][i] - p_width[i]/2), (float)p_width[i], (float)p_width[i]))); } a.transform(this.at); return a; }
Example 16
Source File: PlumNeedle.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Draws the needle. * * @param g2 the graphics device. * @param plotArea the plot area. * @param rotate the rotation point. * @param angle the angle. */ @Override protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) { Arc2D shape = new Arc2D.Double(Arc2D.PIE); double radius = plotArea.getHeight(); double halfX = plotArea.getWidth() / 2; double diameter = 2 * radius; shape.setFrame(plotArea.getMinX() + halfX - radius , plotArea.getMinY() - radius, diameter, diameter); radius = Math.toDegrees(Math.asin(halfX / radius)); shape.setAngleStart(270 - radius); shape.setAngleExtent(2 * radius); Area s = new Area(shape); if ((rotate != null) && (angle != 0)) { /// we have rotation houston, please spin me getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); s.transform(getTransform()); } defaultDisplay(g2, s); }
Example 17
Source File: Connector.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Whether the area of the root node intersects the world coordinates {@code wx}, {@code wy} at {@link Layer} {@code la}. */ public boolean intersectsOrigin(final double wx, final double wy, final Layer la) { if (null == root || root.la != la) return false; final Area a = root.getArea(); a.transform(this.at); return a.contains(wx, wy); }
Example 18
Source File: JFreeChartReportDrawable.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public void draw( final Graphics2D graphics2D, final Rectangle2D bounds ) { this.bounds = (Rectangle2D) bounds.clone(); if ( chartRenderingInfo != null ) { this.chartRenderingInfo.clear(); } final Graphics2D g2 = (Graphics2D) graphics2D.create(); this.chart.draw( g2, bounds, chartRenderingInfo ); g2.dispose(); if ( chartRenderingInfo == null || debugRendering == false ) { return; } graphics2D.setColor( Color.RED ); final Rectangle2D dataArea = getDataAreaOffset(); final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection(); for ( int i = 0; i < entityCollection.getEntityCount(); i++ ) { final ChartEntity chartEntity = entityCollection.getEntity( i ); if ( chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity || chartEntity instanceof PieSectionEntity ) { final Area a = new Area( chartEntity.getArea() ); if ( buggyDrawArea ) { a.transform( AffineTransform.getTranslateInstance( dataArea.getX(), dataArea.getY() ) ); } a.intersect( new Area( dataArea ) ); graphics2D.draw( a ); } else { graphics2D.draw( chartEntity.getArea() ); } } }
Example 19
Source File: InfiniteProgressPanel.java From ghidra with Apache License 2.0 | 4 votes |
protected void transformTicker() { for ( Area element : ticker ) { element.transform( transformToCircle ); } }
Example 20
Source File: DefaultTransformModel.java From darklaf with MIT License | 4 votes |
/** * Return the currently active {@link AffineTransform}. Recalculate if needed. * * @return the currently active {@link AffineTransform} */ @Override public AffineTransform getTransform(final JXLayer<? extends JComponent> layer) { JComponent view = layer == null ? null : layer.getView(); /* * Set the current actual program values in addition to the user options. */ setValue(Type.LayerWidth, layer == null ? 0 : layer.getWidth()); setValue(Type.LayerHeight, layer == null ? 0 : layer.getHeight()); setValue(Type.ViewWidth, view == null ? 0 : view.getWidth()); setValue(Type.ViewHeight, view == null ? 0 : view.getHeight()); /* * If any change to previous values, recompute the transform. */ if (!Arrays.equals(prevValues, values) || !valid) { System.arraycopy(values, 0, prevValues, 0, values.length); transform.setToIdentity(); if (view != null) { Point2D p = getRotationCenter(layer.getSize()); double centerX = p.getX(); double centerY = p.getY(); AffineTransform nonScaledTransform = transformNoScale(centerX, centerY); double scaleX; double scaleY; if (isScaleToPreferredSize()) { scaleX = getScale(); scaleY = scaleX; } else { Area area = new Area(new Rectangle2D.Double(0, 0, view.getWidth(), view.getHeight())); area.transform(nonScaledTransform); Rectangle2D bounds = area.getBounds2D(); scaleX = layer.getWidth() / bounds.getWidth(); scaleY = layer.getHeight() / bounds.getHeight(); if (isPreserveAspectRatio()) { scaleX = Math.min(scaleX, scaleY); scaleY = scaleX; } } transform.translate(centerX, centerY); transform.scale(isMirror() ? -scaleX : scaleX, scaleY); transform.translate(-centerX, -centerY); transform.concatenate(nonScaledTransform); } } valid = true; return transform; }