List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
private void updateLegend() { int width = DEFAULT_LEGEND_WIDTH; int height = DEFAULT_LEGENT_HEIGHT; legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); Graphics2D g = (Graphics2D) legend.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setPaint(UI.colorBlack2);/*www. j a v a 2s . c o m*/ g.fillRoundRect(0, 0, width, height - 12, 5, 5); g.setColor(barColorBelow); int boxNum = 10; g.setStroke(UI.stroke1_5); double value; for (int i = 0; i < boxNum; i++) { value = _minValue + (_maxValue - _minValue) / boxNum * i; if (value > disectBound) { g.setColor(barColorNormal); } int h = (height - 12) / boxNum * i; g.drawLine(i * width / boxNum, height - 12 - h, (i + 1) * width / boxNum, height - 12 - h); } g.setColor(Color.BLACK); g.setFont(UI.fontMono.deriveFont(10f)); DecimalFormat format = new DecimalFormat("#.##"); g.drawString(format.format(_minValue), 2, 23); g.setColor(Color.BLACK); String maxString = format.format(_maxValue); int swidth = g.getFontMetrics().stringWidth(maxString); g.drawString(maxString, width - 2 - swidth, 23); g.dispose(); }
From source file:org.squidy.designer.shape.ZoomShape.java
@Override protected void paintAfterChildren(PPaintContext paintContext) { super.paintAfterChildren(paintContext); Graphics2D g = paintContext.getGraphics(); if (multiSelection != null) { g.setColor(COLOR_MULTI_SELECTION); g.fill(globalToLocal((Rectangle2D) ((RectangularShape) multiSelection).clone())); g.setColor(Color.BLUE);// w w w . j a va 2s.co m // System.out.println(getGlobalScale()); g.setStroke(STROKE_MULTI_SELECTION); g.draw(globalToLocal((Rectangle2D) ((RectangularShape) multiSelection).clone())); } }
From source file:org.squidy.designer.shape.ZoomShape.java
/** * @param paintContext// w ww . j a va2s. c o m */ protected void paintShapeZoomedIn(PPaintContext paintContext) { Shape shapeZoomedIn = getZoomedInShape(); if (shapeZoomedIn != null) { Graphics2D g = paintContext.getGraphics(); Rectangle bounds = shapeZoomedIn.getBounds(); g.setPaint(getZoomedInFillPaint()); if (isRenderPrimitiveRect()) g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.fill(shapeZoomedIn); g.setStroke(STROKE_ZOOMED_IN); g.setPaint(getZoomedInDrawPaint()); if (isRenderPrimitiveRect()) g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.draw(shapeZoomedIn); } }
From source file:org.squidy.designer.shape.ZoomShape.java
/** * @param paintContext//from w ww . j a v a 2s . c o m */ protected void paintShapeZoomedOut(PPaintContext paintContext) { Shape shapeZoomedOut = getZoomedOutShape(); if (shapeZoomedOut != null) { Graphics2D g = paintContext.getGraphics(); Rectangle bounds = shapeZoomedOut.getBounds(); g.setPaint(getZoomedOutFillPaint()); if (isRenderPrimitiveRect()) g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.fill(shapeZoomedOut); g.setStroke(STROKE_ZOOMED_OUT); g.setPaint(getZoomedOutDrawPaint()); if (isRenderPrimitiveRect()) g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); else g.draw(shapeZoomedOut); } }
From source file:gda.plots.SimpleXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself.//from w ww. j a v a 2 s . c om * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @param plot * the plot (can be used to obtain standard color information etc). * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); // get the data point double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); // Test x1 = xValueTransformer.transformValue(x1); if (Double.isNaN(x1) || Double.isNaN(y1)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (sxys.isDrawLines()) { if (item > 0) { // get the previous data point... double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); // Test // System.out.print("tranformed " + x0); x0 = xValueTransformer.transformValue(x0); // Message.debug(" to " + x0); if (!Double.isNaN(x0) && !Double.isNaN(y0)) { boolean drawLine = true; if (getPlotDiscontinuous()) { // only draw a line if the gap between the current and // previous data // point is within the threshold int numX = dataset.getItemCount(series); double minX = dataset.getXValue(series, 0); double maxX = dataset.getXValue(series, numX - 1); drawLine = (x1 - x0) <= ((maxX - minX) / numX * getGapThreshold()); } if (drawLine) { double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { g2.draw(state.workingLine); } } } } } if (sxys.isDrawMarkers()) { Shape shape = sxys.getSymbol(); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { g2.setPaint(sxys.getSymbolPaint()); // Always use full stroke for drawing marker g2.setStroke(new BasicStroke()); if (sxys.getFilled()) { g2.fill(shape); } else { g2.draw(shape); } g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); } entityArea = shape; } if (getPlotImages()) { // use shape scale with transform?? // double scale = getShapeScale(plot, series, item, transX1, // transY1); Image image = getImage(plot, series, item, transX1, transY1); if (image != null) { Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image); g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null); entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null)); } } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, transX1, transY1, (y1 < 0.0)); } updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation); // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }
From source file:org.squidy.designer.zoom.ActionShape.java
@Override protected void paintShapeZoomedOut(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); RectangularShape r = (RectangularShape) getZoomedOutShape(); if (r instanceof RoundRectangle2D) { // g.setStroke(STROKE_ZOOMED_OUT); g.setColor(failure ? COLOR_FAILURE : started ? COLOR_STARTED : COLOR_STOPPED); g.setStroke(StrokeUtils.getBasicStroke(20f)); if (polygonRendering) { if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Polygon shadeHorizontal = new Polygon(); Polygon shadeVertical = new Polygon(); double shift = 1; shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); Rectangle bounds = shapeZoomedOut.getBounds(); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shift = 30;/*from w w w . j a v a2 s.c om*/ shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); bounds = shapeZoomedOut.getBounds(); shadeHorizontal.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeHorizontal.addPoint(bounds.x, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y + bounds.height); shadeVertical.addPoint(bounds.x + bounds.width, bounds.y); g.fillPolygon(shadeHorizontal); g.fillPolygon(shadeVertical); } } else { g.draw(shapeZoomedOut); } } else { for (double shift = 30.; shift >= 1.; shift -= 5.) { shapeZoomedOut.setFrame(r.getMinX() + shift, r.getMinY() + shift, r.getMaxX() + shift, r.getMaxY() + shift); if (isRenderPrimitiveRect()) { if (!isHierarchicalZoomInProgress()) { Rectangle bounds = shapeZoomedOut.getBounds(); // g.fillRect(bounds.x, bounds.y, bounds.width, // bounds.height); g.drawLine(bounds.x + 1, bounds.y + bounds.height, bounds.x + bounds.width - 3, bounds.y + bounds.height); g.drawLine(bounds.x + bounds.width, bounds.y + 1, bounds.x + bounds.width, bounds.y + bounds.height - 3); } } else { g.draw(shapeZoomedOut); } } } } super.paintShapeZoomedOut(paintContext); }
From source file:com.rapidminer.gui.plotter.charts.RapidBarPainter.java
/** * Paints a single bar instance.//w w w. j a va 2s. co m * * @param g2 * the graphics target. * @param renderer * the renderer. * @param row * the row index. * @param column * the column index. * @param bar * the bar * @param base * indicates which side of the rectangle is the base of the bar. */ @Override public void paintBar(final Graphics2D g2, final BarRenderer renderer, final int row, final int column, final RectangularShape bar, final RectangleEdge base) { Paint itemPaint = renderer.getItemPaint(row, column); Color c0 = null; if (itemPaint instanceof Color) { c0 = (Color) itemPaint; } else { c0 = SwingTools.DARK_BLUE; } // as a special case, if the bar color has alpha == 0, we draw // nothing. if (c0.getAlpha() == 0) { return; } g2.setPaint(c0); g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight())); // draw the outline... if (renderer.isDrawBarOutline()) { Stroke stroke = renderer.getItemOutlineStroke(row, column); Paint paint = renderer.getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } }
From source file:org.jfree.experimental.chart.plot.dial.StandardDialRange.java
/** * Draws the range.//from w ww . j a v a 2s .c o m * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame (in Java2D space). * @param view the dial's view rectangle (in Java2D space). */ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.innerRadius, this.innerRadius); Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.outerRadius, this.outerRadius); //double range = this.upperBound - this.lowerBound; DialScale scale = plot.getScaleForDataset(0); double angleMin = scale.valueToAngle(this.lowerBound); double angleMax = scale.valueToAngle(this.upperBound); Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN); Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN); g2.setPaint(this.paint); g2.setStroke(new BasicStroke(2.0f)); g2.draw(arcInner); g2.draw(arcOuter); }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * Paints the text decoration marks.//from w w w. ja va 2 s . c om * @param g2d Graphics2D instance to paint to * @param fm Current typeface * @param fontsize Current font size * @param inline inline area to paint the marks for * @param baseline position of the baseline * @param startx start IPD */ private static void renderTextDecoration(Graphics2D g2d, FontMetrics fm, int fontsize, InlineArea inline, int baseline, int startx) { boolean hasTextDeco = inline.hasUnderline() || inline.hasOverline() || inline.hasLineThrough(); if (hasTextDeco) { float descender = fm.getDescender(fontsize) / 1000f; float capHeight = fm.getCapHeight(fontsize) / 1000f; float lineWidth = (descender / -4f) / 1000f; float endx = (startx + inline.getIPD()) / 1000f; if (inline.hasUnderline()) { Color ct = (Color) inline.getTrait(Trait.UNDERLINE_COLOR); g2d.setColor(ct); float y = baseline - descender / 2f; g2d.setStroke(new BasicStroke(lineWidth)); g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f, endx, y / 1000f)); } if (inline.hasOverline()) { Color ct = (Color) inline.getTrait(Trait.OVERLINE_COLOR); g2d.setColor(ct); float y = (float) (baseline - (1.1 * capHeight)); g2d.setStroke(new BasicStroke(lineWidth)); g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f, endx, y / 1000f)); } if (inline.hasLineThrough()) { Color ct = (Color) inline.getTrait(Trait.LINETHROUGH_COLOR); g2d.setColor(ct); float y = (float) (baseline - (0.45 * capHeight)); g2d.setStroke(new BasicStroke(lineWidth)); g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f, endx, y / 1000f)); } } }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private static void drawArrowToDestination(final Graphics2D gfx, final Rectangle2D start, final Rectangle2D destination, final Stroke lineStroke, final Stroke arrowStroke, final float arrowSize) { final double startx = start.getCenterX(); final double starty = start.getCenterY(); final Point2D arrowPoint = Utils.findRectEdgeIntersection(destination, startx, starty); if (arrowPoint != null) { gfx.setStroke(arrowStroke); double angle = findLineAngle(arrowPoint.getX(), arrowPoint.getY(), startx, starty); final double arrowAngle = Math.PI / 12.0d; final double x1 = arrowSize * Math.cos(angle - arrowAngle); final double y1 = arrowSize * Math.sin(angle - arrowAngle); final double x2 = arrowSize * Math.cos(angle + arrowAngle); final double y2 = arrowSize * Math.sin(angle + arrowAngle); final double cx = (arrowSize / 2.0f) * Math.cos(angle); final double cy = (arrowSize / 2.0f) * Math.sin(angle); final GeneralPath polygon = new GeneralPath(); polygon.moveTo(arrowPoint.getX(), arrowPoint.getY()); polygon.lineTo(arrowPoint.getX() + x1, arrowPoint.getY() + y1); polygon.lineTo(arrowPoint.getX() + x2, arrowPoint.getY() + y2); polygon.closePath();//from w w w .j a va2 s. c om gfx.fill(polygon); gfx.setStroke(lineStroke); gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx), (int) (arrowPoint.getY() + cy)); } }