List of usage examples for java.awt.geom Area Area
public Area(Shape s)
From source file:dk.dma.epd.common.prototype.gui.voct.VOCTAdditionalInfoPanel.java
/** * {@inheritDoc}/*from w w w . j av a 2 s.c o m*/ */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); }
From source file:org.apache.pdfbox.pdfviewer.PageDrawer.java
/** * Set the clipping Path.//from w ww. j a v a2s . c om * * @param windingRule The winding rule this path will use. * */ public void setClippingPath(int windingRule) { PDGraphicsState graphicsState = getGraphicsState(); GeneralPath clippingPath = (GeneralPath) getLinePath().clone(); clippingPath.setWindingRule(windingRule); // If there is already set a clipping path, we have to intersect the new with the existing one if (graphicsState.getCurrentClippingPath() != null) { Area currentArea = new Area(getGraphicsState().getCurrentClippingPath()); Area newArea = new Area(clippingPath); currentArea.intersect(newArea); graphicsState.setCurrentClippingPath(currentArea); } else { graphicsState.setCurrentClippingPath(clippingPath); } getLinePath().reset(); }
From source file:org.opensha.commons.geo.RegionUtils.java
/** * Returns the {@code Region} spanned by a node centered at the supplied * location with the given width and height. * @param p {@code Location} at center of a grid node * @param w node width/*from w w w . ja v a2 s. c om*/ * @param h node height * @return the node's {@code Region} */ public static Area getNodeShape(Location p, double w, double h) { double halfW = w / 2; double halfH = h / 2; double nodeLat = p.getLatitude(); double nodeLon = p.getLongitude(); LocationList locs = new LocationList(); locs.add(new Location(nodeLat + halfH, nodeLon + halfW)); // top right locs.add(new Location(nodeLat - halfH, nodeLon + halfW)); // bot right locs.add(new Location(nodeLat - halfH, nodeLon - halfW)); // bot left locs.add(new Location(nodeLat + halfH, nodeLon - halfW)); // top left return new Area(locs.toPath()); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics2D#hit(Rectangle, Shape, boolean) *//* www.j a v a2 s . c o m*/ @Override public boolean hit(final Rectangle rect, Shape s, final boolean onStroke) { if (onStroke) { s = stroke.createStrokedShape(s); } s = transform.createTransformedShape(s); final Area area = new Area(s); if (clip != null) { area.intersect(clip); } return area.intersects(rect.x, rect.y, rect.width, rect.height); }
From source file:VASSAL.counters.Labeler.java
/** * Return the Shape of the counter by adding the shape of this label to the shape of all inner traits. * Minimize generation of new Area objects. *//* w w w . j ava 2s . c o m*/ public Shape getShape() { Shape innerShape = piece.getShape(); // If the label has a Control key, then the image of the label is NOT included in the selectable area of the // counter if (!labelKey.isNull()) { return innerShape; } else { final Rectangle r = new Rectangle(getLabelPosition(), imagePainter.getImageSize()); // If the label is completely enclosed in the current counter shape, then we can just return // the current shape if (innerShape.contains(r.x, r.y, r.width, r.height)) { return innerShape; } else { final Area a = new Area(innerShape); // Cache the Area object generated. Only recreate if the label position or size has changed if (!r.equals(lastRect)) { lastShape = new Area(r); lastRect = new Rectangle(r); } a.add(lastShape); return a; } } }
From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java
@Override public void fillRectangle(RectangleRenderEvent rre) throws ChartException { if (iv != null) { iv.modifyEvent(rre);//from ww w . j av a 2 s . com } final Fill flBackground = validateMultipleFill(rre.getBackground()); if (isFullTransparent(flBackground)) { return; } final Bounds bo = normalizeBounds(rre.getBounds()); final Rectangle2D.Double r2d = new Rectangle2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth(), bo.getHeight()); if (flBackground instanceof ColorDefinition) { final ColorDefinition cd = (ColorDefinition) flBackground; _g2d.setColor((Color) _ids.getColor(cd)); _g2d.fill(r2d); } else if (flBackground instanceof Gradient) { final Gradient g = (Gradient) flBackground; final ColorDefinition cdStart = g.getStartColor(); final ColorDefinition cdEnd = g.getEndColor(); // boolean bCyclic = g.isCyclic(); double dAngleInDegrees = g.getDirection(); final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0); // int iAlpha = g.getTransparency(); if (dAngleInDegrees < -90 || dAngleInDegrees > 90) { throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING, "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$ new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale())); } Point2D.Double p2dStart, p2dEnd; if (dAngleInDegrees == 90) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees == -90) { p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); } else if (dAngleInDegrees > 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getHeight() - bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else if (dAngleInDegrees < 0) { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop() + bo.getWidth() * Math.abs(Math.tan(dAngleInRadians))); } else { p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop()); p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop()); } _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd, (Color) _ids.getColor(cdEnd))); _g2d.fill(r2d); } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) { if (flBackground instanceof PatternImage) { fillWithPatternImage(new Area(r2d), flBackground); return; } java.awt.Image img = createImageFromModel(flBackground); if (img != null) { final Shape shClip = _g2d.getClip(); Area ar2 = new Area(r2d); if (shClip != null) { Area ar1 = new Area(shClip); ar2.intersect(ar1); } _g2d.setClip(ar2); img = scaleImage(img); final Size szImage = _ids.getSize(img); int iXRepeat = (int) (Math.ceil(r2d.width / szImage.getWidth())); int iYRepeat = (int) (Math.ceil(r2d.height / szImage.getHeight())); ImageObserver io = (ImageObserver) _ids.getObserver(); for (int i = 0; i < iXRepeat; i++) { for (int j = 0; j < iYRepeat; j++) { _g2d.drawImage(img, (int) (r2d.x + i * szImage.getWidth()), (int) (r2d.y + j * szImage.getHeight()), io); } } _g2d.setClip(shClip); // RESTORE } } }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * {@inheritDoc}//from w w w . ja v a 2 s . c om */ @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(GraphicsUtil.ANTIALIAS_HINT); // Define the content rectangle int x0 = pointerLeft ? pad + pointerWidth : pad; RoundRectangle2D.Double content = new RoundRectangle2D.Double(x0, pad, width - 2 * pad - pointerWidth, height - 2 * pad, cornerRadius, cornerRadius); // Define the pointer triangle int xp = pointerLeft ? pad + pointerWidth : width - pad - pointerWidth; int yp = pad + height - pointerFromBottom; Polygon pointer = new Polygon(); pointer.addPoint(xp, yp); pointer.addPoint(xp, yp - pointerHeight); pointer.addPoint(xp + pointerWidth * (pointerLeft ? -1 : 1), yp - pointerHeight / 2); // Combine content rectangle and pointer into one area Area area = new Area(content); area.add(new Area(pointer)); // Fill the pop-up background Color col = pointerLeft ? c.getBackground().darker() : c.getBackground().brighter(); g2.setColor(col); g2.fill(area); if (message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING || message.getSeverity() == MaritimeTextingNotificationSeverity.ALERT || message.getSeverity() == MaritimeTextingNotificationSeverity.SAFETY) { g2.setStroke(new BasicStroke(2.0f)); switch (message.getSeverity()) { case WARNING: g2.setColor(WARN_COLOR); case ALERT: g2.setColor(ALERT_COLOR); case SAFETY: g2.setColor(SAFETY_COLOR); default: g2.setColor(WARN_COLOR); } // g2.setColor(message.getSeverity() == MaritimeTextingNotificationSeverity.WARNING ? WARN_COLOR : ALERT_COLOR); g2.draw(area); } }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
@Override public void fillPath(int windingRule) throws IOException { graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite()); graphics.setPaint(getNonStrokingPaint()); setClip();//w ww . j a v a 2s.c o m linePath.setWindingRule(windingRule); // disable anti-aliasing for rectangular paths, this is a workaround to avoid small stripes // which occur when solid fills are used to simulate piecewise gradients, see PDFBOX-2302 // note that we ignore paths with a width/height under 1 as these are fills used as strokes, // see PDFBOX-1658 for an example Rectangle2D bounds = linePath.getBounds2D(); boolean noAntiAlias = isRectangular(linePath) && bounds.getWidth() > 1 && bounds.getHeight() > 1; if (noAntiAlias) { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if (!(graphics.getPaint() instanceof Color)) { // apply clip to path to avoid oversized device bounds in shading contexts (PDFBOX-2901) Area area = new Area(linePath); area.intersect(new Area(graphics.getClip())); graphics.fill(area); } else { graphics.fill(linePath); } linePath.reset(); if (noAntiAlias) { // JDK 1.7 has a bug where rendering hints are reset by the above call to // the setRenderingHint method, so we re-set all hints, see PDFBOX-2302 setRenderingHints(); } }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Shape createShape(double x, double y, Rectangle2D hotspot) { Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(), hotspot.getHeight(), 8, 8)); boolean right = hotspot.getMinX() > x; Polygon po = new Polygon(); po.addPoint(0, 0);//from w w w . jav a 2s .c o m po.addPoint(0, 10); po.addPoint(10, 0); AffineTransform af = new AffineTransform(); if (right) { af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(-Math.PI / 4); } else { af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(Math.PI * 3 / 4); } Shape shape = af.createTransformedShape(po); result.add(new Area(shape)); return result; }
From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java
public static ArrayList<GeneralPath> assemblePathList(GeoPos[] geoPoints) { final GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO, geoPoints.length + 8); final ArrayList<GeneralPath> pathList = new ArrayList<>(16); if (geoPoints.length > 1) { double lon, lat; double minLon = 0, maxLon = 0; boolean first = true; for (GeoPos gp : geoPoints) { lon = gp.getLon();/*from w w w . ja va2 s .c o m*/ lat = gp.getLat(); if (first) { minLon = lon; maxLon = lon; path.moveTo(lon, lat); first = false; } if (lon < minLon) { minLon = lon; } if (lon > maxLon) { maxLon = lon; } path.lineTo(lon, lat); } path.closePath(); int runIndexMin = (int) Math.floor((minLon + 180) / 360); int runIndexMax = (int) Math.floor((maxLon + 180) / 360); if (runIndexMin == 0 && runIndexMax == 0) { // the path is completely within [-180, 180] longitude pathList.add(path); return pathList; } final Area pathArea = new Area(path); final GeneralPath pixelPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); for (int k = runIndexMin; k <= runIndexMax; k++) { final Area currentArea = new Area( new Rectangle2D.Float(k * 360.0f - 180.0f, -90.0f, 360.0f, 180.0f)); currentArea.intersect(pathArea); if (!currentArea.isEmpty()) { pathList.add(areaToPath(currentArea, -k * 360.0, pixelPath)); } } } return pathList; }