java.awt.Shape Java Examples
The following examples show how to use
java.awt.Shape.
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: SunGraphics2D.java From jdk8u-jdk with GNU General Public License v2.0 | 7 votes |
protected static Shape transformShape(int tx, int ty, Shape s) { if (s == null) { return null; } if (s instanceof Rectangle) { Rectangle r = s.getBounds(); r.translate(tx, ty); return r; } if (s instanceof Rectangle2D) { Rectangle2D rect = (Rectangle2D) s; return new Rectangle2D.Double(rect.getX() + tx, rect.getY() + ty, rect.getWidth(), rect.getHeight()); } if (tx == 0 && ty == 0) { return cloneShape(s); } AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty); return mat.createTransformedShape(s); }
Example #2
Source File: AddRulesTest.java From pumpernickel with MIT License | 7 votes |
public BufferedImage render() { Rectangle2D bounds = getBounds(); Rectangle r = bounds.getBounds(); BufferedImage bi = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.translate(-r.x, -r.y); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (int a = 0; a < shapes.size(); a++) { float hue = (a) / 11f; float bri = .75f + .25f * a / ((shapes.size())); Shape shape = shapes.get(a); g.setColor(new Color(Color.HSBtoRGB(hue, .75f, bri))); g.fill(shape); } g.dispose(); return bi; }
Example #3
Source File: SymbolAxis.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Draws the grid bands. Alternate bands are colored using * <CODE>gridBandPaint<CODE> (<CODE>DEFAULT_GRID_BAND_PAINT</CODE> by * default). * * @param g2 the graphics device. * @param plotArea the area within which the chart should be drawn. * @param dataArea the area within which the plot should be drawn (a * subset of the drawArea). * @param edge the axis location. * @param ticks the ticks. */ protected void drawGridBands(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, List ticks) { Shape savedClip = g2.getClip(); g2.clip(dataArea); if (RectangleEdge.isTopOrBottom(edge)) { drawGridBandsHorizontal(g2, plotArea, dataArea, true, ticks); } else if (RectangleEdge.isLeftOrRight(edge)) { drawGridBandsVertical(g2, plotArea, dataArea, true, ticks); } g2.setClip(savedClip); }
Example #4
Source File: ShapeUtilities.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Translates a shape to a new location such that the anchor point * (relative to the rectangular bounds of the shape) aligns with the * specified (x, y) coordinate in Java2D space. * * @param shape the shape (<code>null</code> not permitted). * @param anchor the anchor (<code>null</code> not permitted). * @param locationX the x-coordinate (in Java2D space). * @param locationY the y-coordinate (in Java2D space). * * @return A new and translated shape. */ public static Shape createTranslatedShape(final Shape shape, final RectangleAnchor anchor, final double locationX, final double locationY) { if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } Point2D anchorPoint = RectangleAnchor.coordinates( shape.getBounds2D(), anchor); final AffineTransform transform = AffineTransform.getTranslateInstance( locationX - anchorPoint.getX(), locationY - anchorPoint.getY()); return transform.createTransformedShape(shape); }
Example #5
Source File: SpanShapeRenderer.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void fill(SunGraphics2D sg, Shape s) { if (s instanceof Rectangle2D && (sg.transform.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0) { renderRect(sg, (Rectangle2D) s); return; } Region clipRegion = sg.getCompClip(); ShapeSpanIterator sr = LoopPipe.getFillSSI(sg); try { sr.setOutputArea(clipRegion); sr.appendPath(s.getPathIterator(sg.transform)); renderSpans(sg, clipRegion, s, sr); } finally { sr.dispose(); } }
Example #6
Source File: NpcHighlightOverlay.java From plugins with GNU General Public License v3.0 | 5 votes |
private void renderHullOverlay(Graphics2D graphics, NPC npc, Color color) { Shape objectClickbox = npc.getConvexHull(); if (objectClickbox != null) { graphics.setColor(color); graphics.setStroke(new BasicStroke(2)); graphics.draw(objectClickbox); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20)); graphics.fill(objectClickbox); } }
Example #7
Source File: DrawableShapeLoader.java From osp with GNU General Public License v3.0 | 5 votes |
/** * Saves a DrawableShape by saving the general path. * @param control XMLControl * @param obj Object */ public void saveObject(XMLControl control, Object obj) { DrawableShape drawableShape = (DrawableShape) obj; control.setValue("geometry", drawableShape.shapeClass); //$NON-NLS-1$ control.setValue("x", drawableShape.x); //$NON-NLS-1$ control.setValue("y", drawableShape.y); //$NON-NLS-1$ control.setValue("theta", drawableShape.theta); //$NON-NLS-1$ control.setValue("fill color", drawableShape.color); //$NON-NLS-1$ control.setValue("edge color", drawableShape.edgeColor); //$NON-NLS-1$ Shape shape = AffineTransform.getRotateInstance(-drawableShape.theta, drawableShape.x, drawableShape.y).createTransformedShape(drawableShape.shape); control.setValue("general path", shape); //$NON-NLS-1$ }
Example #8
Source File: TextMeasureTests.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { GVContext gvctx = (GVContext)ctx; GlyphVector gv = gvctx.gv; Shape s; do { for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) { s = gv.getGlyphOutline(i); } } while (--numReps >= 0); }
Example #9
Source File: ZoomSliderPanel.java From mars-sim with GNU General Public License v3.0 | 5 votes |
private void initShapes() { shapes = new Shape[3]; int w = getWidth(); int h = getHeight(); shapes[0] = new Rectangle2D.Double(w/16, h/16, w*7/8, h*7/8); shapes[1] = new Line2D.Double(w/16, h*15/16, w*15/16, h/16); shapes[2] = new Ellipse2D.Double(w/4, h/4, w/2, h/2); size.width = w; size.height = h; }
Example #10
Source File: TextMeasureTests.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { GVContext gvctx = (GVContext)ctx; GlyphVector gv = gvctx.gv; Shape s; do { for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) { s = gv.getGlyphLogicalBounds(i); } } while (--numReps >= 0); }
Example #11
Source File: LegendGraphic.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Creates a new legend graphic. * * @param shape the shape (<code>null</code> not permitted). * @param fillPaint the fill paint (<code>null</code> not permitted). */ public LegendGraphic(Shape shape, Paint fillPaint) { ParamChecks.nullNotPermitted(shape, "shape"); ParamChecks.nullNotPermitted(fillPaint, "fillPaint"); this.shapeVisible = true; this.shape = shape; this.shapeAnchor = RectangleAnchor.CENTER; this.shapeLocation = RectangleAnchor.CENTER; this.shapeFilled = true; this.fillPaint = fillPaint; this.fillPaintTransformer = new StandardGradientPaintTransformer(); setPadding(2.0, 2.0, 2.0, 2.0); }
Example #12
Source File: SessionOfStandardView.java From ET_Redux with Apache License 2.0 | 5 votes |
private void paintFractionVerticalTicRed(Graphics2D g2d, int chosenDatumIndex) { Shape redDatumLine = new Line2D.Double(// mapX(zeroBasedFractionAquireTimes.get(chosenDatumIndex)),// mapY(minY),// mapX(zeroBasedFractionAquireTimes.get(chosenDatumIndex)),// mapY(maxY)); Paint savedPaint = g2d.getPaint(); Stroke savedStroke = g2d.getStroke(); g2d.setPaint(EXCLUDED_COLOR); g2d.setStroke(new BasicStroke(0.5f)); g2d.draw(redDatumLine); g2d.setPaint(savedPaint); g2d.setStroke(savedStroke); }
Example #13
Source File: PathGraphics.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Redraw a rectanglular area using a proxy graphics */ public abstract void redrawRegion(Rectangle2D region, double scaleX, double scaleY, Shape clip, AffineTransform devTransform) throws PrinterException ;
Example #14
Source File: Underline.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
Shape getUnderlineShape(float thickness, float x1, float x2, float y) { Stroke ulStroke = getStroke(thickness); Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift); return ulStroke.createStrokedShape(line); }
Example #15
Source File: FXGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Returns the user clipping region. The initial default value is * {@code null}. * * @return The user clipping region (possibly {@code null}). * * @see #setClip(java.awt.Shape) */ @Override public Shape getClip() { if (this.clip == null) { return null; } AffineTransform inv; try { inv = this.transform.createInverse(); return inv.createTransformedShape(this.clip); } catch (NoninvertibleTransformException ex) { return null; } }
Example #16
Source File: BufferedRenderPipe.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void draw(SunGraphics2D sg2d, Shape s) { if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) { if (s instanceof Polygon) { if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE) { Polygon p = (Polygon)s; drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints); return; } } Path2D.Float p2df; int transx, transy; if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) { if (s instanceof Path2D.Float) { p2df = (Path2D.Float)s; } else { p2df = new Path2D.Float(s); } transx = sg2d.transX; transy = sg2d.transY; } else { p2df = new Path2D.Float(s, sg2d.transform); transx = 0; transy = 0; } drawPath(sg2d, p2df, transx, transy); } else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) { ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s); try { fillSpans(sg2d, si, 0, 0); } finally { si.dispose(); } } else { fill(sg2d, sg2d.stroke.createStrokedShape(s)); } }
Example #17
Source File: TranslucentShapedFrameTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void shapedCbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shapedCbActionPerformed if (testFrame != null) { Shape s = null; if (shapedCb.isSelected()) { s = new Ellipse2D.Double(0, 0, testFrame.getWidth(), testFrame.getHeight()); } testFrame.setShape(s); } }
Example #18
Source File: BoxAndWhiskerRenderer.java From opensim-gui with Apache License 2.0 | 5 votes |
/** * Returns a legend item for a series. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return The legend item. */ public LegendItem getLegendItem(int datasetIndex, int series) { CategoryPlot cp = getPlot(); if (cp == null) { return null; } CategoryDataset dataset; dataset = cp.getDataset(datasetIndex); String label = getLegendItemLabelGenerator().generateLabel(dataset, series); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel(dataset, series); } Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0); Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke outlineStroke = getSeriesOutlineStroke(series); return new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); }
Example #19
Source File: Test6657026.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public void setClip(Shape clip) { // TODO: check }
Example #20
Source File: Graphics2DStore.java From RipplePower with Apache License 2.0 | 4 votes |
public Shape getClip() { return clip; }
Example #21
Source File: DefaultDrawingSupplier.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Creates an array of standard shapes to display for the items in series * on charts. * * @return The array of shapes. */ public static Shape[] createStandardSeriesShapes() { Shape[] result = new Shape[10]; double size = 6.0; double delta = size / 2.0; int[] xpoints; int[] ypoints; // square result[0] = new Rectangle2D.Double(-delta, -delta, size, size); // circle result[1] = new Ellipse2D.Double(-delta, -delta, size, size); // up-pointing triangle xpoints = intArray(0.0, delta, -delta); ypoints = intArray(-delta, delta, delta); result[2] = new Polygon(xpoints, ypoints, 3); // diamond xpoints = intArray(0.0, delta, 0.0, -delta); ypoints = intArray(-delta, 0.0, delta, 0.0); result[3] = new Polygon(xpoints, ypoints, 4); // horizontal rectangle result[4] = new Rectangle2D.Double(-delta, -delta / 2, size, size / 2); // down-pointing triangle xpoints = intArray(-delta, +delta, 0.0); ypoints = intArray(-delta, -delta, delta); result[5] = new Polygon(xpoints, ypoints, 3); // horizontal ellipse result[6] = new Ellipse2D.Double(-delta, -delta / 2, size, size / 2); // right-pointing triangle xpoints = intArray(-delta, delta, -delta); ypoints = intArray(-delta, 0.0, delta); result[7] = new Polygon(xpoints, ypoints, 3); // vertical rectangle result[8] = new Rectangle2D.Double(-delta / 2, -delta, size / 2, size); // left-pointing triangle xpoints = intArray(-delta, delta, delta); ypoints = intArray(0.0, -delta, +delta); result[9] = new Polygon(xpoints, ypoints, 3); return result; }
Example #22
Source File: TableHeaderPainter.java From seaglass with Apache License 2.0 | 4 votes |
private void paintAscending(Graphics2D g) { Shape s = shapeGenerator.createArrowUp(1, 0, 6, 6); g.setPaint(tableHeaderSortIndicator); g.fill(s); }
Example #23
Source File: CollapsedView.java From netbeans with Apache License 2.0 | 4 votes |
public @Override String getToolTipText(float x, float y, Shape allocation){ ToolTipSupport tts = getEditorUI().getToolTipSupport(); JComponent toolTip = new FoldingToolTip(getExpandedView(), getEditorUI()); tts.setToolTip(toolTip, PopupManager.ScrollBarBounds, PopupManager.Largest, -FoldingToolTip.BORDER_WIDTH, 0); return ""; //NOI18N }
Example #24
Source File: ExtendedTextSourceLabel.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public Shape handleGetOutline(float x, float y) { return getGV().getOutline(x, y); }
Example #25
Source File: Arja_00112_s.java From coming with MIT License | 4 votes |
/** * Returns a legend item for a series. This default implementation will * return <code>null</code> if {@link #isSeriesVisible(int)} or * {@link #isSeriesVisibleInLegend(int)} returns <code>false</code>. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return The legend item (possibly <code>null</code>). * * @see #getLegendItems() */ public LegendItem getLegendItem(int datasetIndex, int series) { CategoryPlot p = getPlot(); if (p == null) { return null; } // check that a legend item needs to be displayed... if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) { return null; } CategoryDataset dataset = p.getDataset(datasetIndex); String label = this.legendItemLabelGenerator.generateLabel(dataset, series); String description = label; String toolTipText = null; if (this.legendItemToolTipGenerator != null) { toolTipText = this.legendItemToolTipGenerator.generateLabel( dataset, series); } String urlText = null; if (this.legendItemURLGenerator != null) { urlText = this.legendItemURLGenerator.generateLabel(dataset, series); } Shape shape = lookupLegendShape(series); Paint paint = lookupSeriesPaint(series); Paint outlinePaint = lookupSeriesOutlinePaint(series); Stroke outlineStroke = lookupSeriesOutlineStroke(series); LegendItem item = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint); item.setLabelFont(lookupLegendTextFont(series)); Paint labelPaint = lookupLegendTextPaint(series); if (labelPaint != null) { item.setLabelPaint(labelPaint); } item.setSeriesKey(dataset.getRowKey(series)); item.setSeriesIndex(series); item.setDataset(dataset); item.setDatasetIndex(datasetIndex); return item; }
Example #26
Source File: LivreBase.java From brModelo with GNU General Public License v3.0 | 4 votes |
public Shape getRegiaoRecArred() { if (Regiao == null) { Regiao = new RoundRectangle2D.Float(getLeft(), getTop(), getWidth(), getHeight(), getWidth() / 3, getHeight()); } return Regiao; }
Example #27
Source File: FakeLayoutMapper.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Shape getComponentVisibilityClip(String componentId) { return null; }
Example #28
Source File: HexDrawUtilities.java From megamek with GNU General Public License v2.0 | 4 votes |
private static Shape getHBLU(int hexFace) { return getHRU(hexFace).createTransformedShape(getHBLU()); }
Example #29
Source File: GisFeatureRendererMulti.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private ArrayList makeShapes(Iterator featList) { Shape shape; ArrayList shapeList = new ArrayList(); ProjectionImpl dataProject = getDataProjection(); if (Debug.isSet("GisFeature/MapDraw")) { System.out.println("GisFeature/MapDraw: makeShapes with " + displayProject); } /* * if (Debug.isSet("bug.drawShapes")) { * int count =0; * // make each GisPart a seperate shape for debugging * feats:while (featList.hasNext()) { * AbstractGisFeature feature = (AbstractGisFeature) featList.next(); * java.util.Iterator pi = feature.getGisParts(); * while (pi.hasNext()) { * GisPart gp = (GisPart) pi.next(); * int np = gp.getNumPoints(); * GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, np); * double[] xx = gp.getX(); * double[] yy = gp.getY(); * path.moveTo((float) xx[0], (float) yy[0]); * if (count == 63) * System.out.println("moveTo x ="+xx[0]+" y= "+yy[0]); * for(int i = 1; i < np; i++) { * path.lineTo((float) xx[i], (float) yy[i]); * if (count == 63) * System.out.println("lineTo x ="+xx[i]+" y= "+yy[i]); * } * shapeList.add(path); * if (count == 63) * break feats; * count++; * } * } * System.out.println("bug.drawShapes: #shapes =" +shapeList.size()); * return shapeList; * } */ while (featList.hasNext()) { AbstractGisFeature feature = (AbstractGisFeature) featList.next(); if (dataProject.isLatLon()) // always got to run it through if its lat/lon shape = feature.getProjectedShape(displayProject); else if (dataProject == displayProject) shape = feature.getShape(); else shape = feature.getProjectedShape(dataProject, displayProject); shapeList.add(shape); } return shapeList; }
Example #30
Source File: BufferedRenderPipe.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void fill(SunGraphics2D sg2d, Shape s) { int transx, transy; if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) { // Here we are able to use fillPath() for // high-quality fills. Path2D.Float p2df; if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) { if (s instanceof Path2D.Float) { p2df = (Path2D.Float)s; } else { p2df = new Path2D.Float(s); } transx = sg2d.transX; transy = sg2d.transY; } else { p2df = new Path2D.Float(s, sg2d.transform); transx = 0; transy = 0; } fillPath(sg2d, p2df, transx, transy); return; } AffineTransform at; if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) { // Transform (translation) will be done by FillSpans (we could // delegate to fillPolygon() here, but most hardware accelerated // libraries cannot handle non-convex polygons, so we will use // the FillSpans approach by default) at = null; transx = sg2d.transX; transy = sg2d.transY; } else { // Transform will be done by the PathIterator at = sg2d.transform; transx = transy = 0; } ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d); try { // Subtract transx/y from the SSI clip to match the // (potentially untranslated) geometry fed to it Region clip = sg2d.getCompClip(); ssi.setOutputAreaXYXY(clip.getLoX() - transx, clip.getLoY() - transy, clip.getHiX() - transx, clip.getHiY() - transy); ssi.appendPath(s.getPathIterator(at)); fillSpans(sg2d, ssi, transx, transy); } finally { ssi.dispose(); } }