List of usage examples for java.awt.geom GeneralPath lineTo
public abstract void lineTo(double x, double y);
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
/**<!====== drawItem ======================================================> Draws a 3D bar to represent one data item. <! Name Description> @param g2 the graphics device. @param state the renderer state. @param dataArea the area for plotting the data. @param plot the plot./* w ww . ja va 2s.c o m*/ @param domainAxis the domain axis. @param rangeAxis the range axis. @param dataset the dataset. @param row the row index (zero-based). @param column the column index (zero-based). @param pass the pass index. <!=======================================================================>*/ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } g2.setStroke(new BasicStroke(1)); double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof Color) { Color endColor = getFrontDark((Color) itemPaint); Color startColor = (Color) itemPaint; Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor, (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor); g2.setPaint(paint); } g2.fill(bar); double x0 = bar.getMinX(); // left double x1 = x0 + getXOffset(); // offset left double x2 = bar.getMaxX(); // right double x3 = x2 + getXOffset(); // offset right double y0 = bar.getMinY() - getYOffset(); // offset top double y1 = bar.getMinY(); // bar top double y2 = bar.getMaxY() - getYOffset(); // offset bottom double y3 = bar.getMaxY(); // bottom //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight()); Line2D.Double line = new Line2D.Double(x2, y1, x2, y3); g2.draw(line); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; g2.setPaint(itemPaint); // Draw the right side if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { Color startColor = getSideLight((Color) itemPaint); Color endColor = getSideDark((Color) itemPaint); Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3, endColor); g2.setPaint(paint); } g2.fill(bar3dRight); } // Draw the top bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); // bottom left bar3dTop.lineTo((float) x1, (float) y0); // top left bar3dTop.lineTo((float) x3, (float) y0); // top right bar3dTop.lineTo((float) x2, (float) y1); // bottom right bar3dTop.closePath(); if (itemPaint instanceof Color) { Color endColor = getTopDark((Color) itemPaint); Color startColor = getTopLight((Color) itemPaint); //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor); Point2D.Double topRight = new Point2D.Double(x3, y0); Point2D.Double bottomLeft = new Point2D.Double(x0, y1); //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2))); Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2))); Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor, (float) darkEnd.getX(), (float) darkEnd.getY(), endColor); g2.setPaint(paint); //drawMarker(topRight, g2, startColor); } g2.fill(bar3dTop); g2.setPaint(itemPaint); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:org.operamasks.faces.render.graph.XYCurveAndShapeRenderer.java
/** * Draws the item (first pass). This method draws the lines * connecting the items. Instead of drawing separate lines, * a GeneralPath is constructed and drawn at the end of * the series painting./* w ww . java 2 s . co m*/ * * @param g2 the graphics device. * @param state the renderer state. * @param plot the plot (can be used to obtain standard color information * etc). * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataArea the area within which the data is being drawn. */ protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item != 0) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); PlotOrientation orientation = plot.getOrientation(); int itemCount = dataset.getItemCount(series); double[][] points = new double[itemCount][2]; int count = 0; for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(series, i); double y = dataset.getYValue(series, i); double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation); if (!Double.isNaN(transX) && !Double.isNaN(transY)) { points[count][0] = transX; points[count][1] = transY; count++; } } if (count < 2) { return; } // sort points according to x axis Arrays.sort(points, new Comparator<double[]>() { public int compare(double[] a, double[] b) { return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0; } }); // draw curve CubicSplineFunction2D f = new CubicSplineFunction2D(points, count); GeneralPath path = new GeneralPath(); double startX = points[0][0]; double startY = points[0][1]; double endX = points[count - 1][0]; double endY = points[count - 1][1]; double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation); if (orientation == PlotOrientation.HORIZONTAL) { if (drawArea) { path.moveTo((float) yz, (float) startX); path.lineTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); path.lineTo((float) yz, (float) endX); path.closePath(); } else { path.moveTo((float) startY, (float) startX); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) f.getValue(x), (float) x); } path.lineTo((float) endY, (float) endX); } } else { if (drawArea) { path.moveTo((float) startX, (float) yz); path.lineTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); path.lineTo((float) endX, (float) yz); path.closePath(); } else { path.moveTo((float) startX, (float) startY); for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) { path.lineTo((float) x, (float) f.getValue(x)); } path.lineTo((float) endX, (float) endY); } } Paint paint = getItemPaint(series, item); Stroke stroke = getItemStroke(series, item); if (drawArea) { g2.setPaint(paint); g2.fill(path); // create paint for outline if (paint instanceof Color) { paint = ((Color) paint).darker(); } else if (paint instanceof GradientPaint) { paint = ((GradientPaint) paint).getColor1().darker(); } } g2.setPaint(paint); g2.setStroke(stroke); g2.draw(path); }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.java
/** * This chart uses the XYAnnotation as a glyph to represent * a single pca data point. Glyph shape is determined by survival time. * Survival of more than 10 months is represented by a circle. 10 months or less * is represented by a square. Component1 values are represented by X * Component2 values are represented by Y */// www .jav a 2 s .c o m private void createGlyphsAndAddToPlot(XYPlot plot, double glyphScaleFactor) { XYShapeAnnotation glyph; Shape glyphShape = null; Color glyphColor; double glyphSize = 8.0; //pixels double glyphIncrement = (glyphSize * glyphScaleFactor) / 2.0; float gi = (float) glyphIncrement; ISPYPCADataPoint pcaPoint; double x, y; for (Iterator i = dataPoints.iterator(); i.hasNext();) { pcaPoint = (ISPYPCADataPoint) i.next(); x = pcaPoint.getComponentValue(component1); y = pcaPoint.getComponentValue(component2); Double mriPctChange = pcaPoint.getTumorMRIpctChange(); if (mriPctChange == null) { //data is missing Rectangle2D.Double rect = new Rectangle2D.Double(); //rect.setFrameFromCenter(x,y, x+1.25,y+1.25); rect.setFrameFromCenter(x, y, x + glyphIncrement, y + glyphIncrement); glyphShape = rect; } else if (mriPctChange <= -30.0) { //tumor shrank by more than 30% (down arrow) GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf - gi, yf + gi); gp.lineTo(xf + gi, yf + gi); gp.closePath(); glyphShape = gp; } else if (mriPctChange > 0.0) { //tumor size increased (up arrow) GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf + gi, yf - gi); gp.lineTo(xf - gi, yf - gi); gp.closePath(); glyphShape = gp; // Ellipse2D.Double circle = new Ellipse2D.Double(); // circle.setFrameFromCenter(x,y, x+2, y+2); } else if ((mriPctChange > -30.0) && (mriPctChange <= 0.0)) { //no change or reduction in tumor size but less than 30% reduction Ellipse2D.Double circle = new Ellipse2D.Double(); //circle.setFrameFromCenter(x,y,x+1.25,y+1.25); circle.setFrameFromCenter(x, y, x + gi, y + gi); glyphShape = circle; } glyphColor = getColorForDataPoint(pcaPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); String tooltip = pcaPoint.toString(); glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java
/** * Build the legend// ww w. j a va 2 s. c om * */ protected void buildLegend() { LegendTitle legend = pcaChart.getLegend(); LegendItemSource[] sources = new LegendItemSource[1]; PcaLegendItemSource legendSrc = new PcaLegendItemSource(); LegendItem item = null; //Rect=survival less than 10 months item = new LegendItem("Survival less than 10 months", null, null, null, new Rectangle2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); //Circle=survival 10 months or more item = new LegendItem("Survival over 10 months", null, null, null, new Ellipse2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); //Triangle if data if survival data is missing GeneralPath triangle = new GeneralPath(); // triangle.moveTo(1.0f,0.0f); // triangle.moveTo(0.0f,1.0f); // triangle.moveTo(1.0f,1.0f); triangle.moveTo(0.0f, -4.0f); triangle.lineTo(4.0f, 4.0f); triangle.lineTo(-4.0f, 4.0f); triangle.closePath(); //triangle.closePath(); item = new LegendItem("Survival Unknown", null, null, null, triangle, Color.BLACK); legendSrc.addLegendItem(item); //Diamond=survival N/A, for non_tumor/normal Shape r = new Rectangle2D.Double(0, 0, 8, 8); Shape d = ShapeUtilities.rotateShape(r, new Double(0.785398163), new Float(0), new Float(0)); item = new LegendItem("Survival N/A", null, null, null, d, Color.BLACK); legendSrc.addLegendItem(item); if (colorBy == PCAcolorByType.Disease) { //go through the disease color map and add legend items String diseaseName = null; Color diseaseColor = null; DiseaseType[] diseases = DiseaseType.values(); for (int i = 0; i < diseases.length; i++) { diseaseName = diseases[i].name(); if (diseases[i].equals(DiseaseType.UNCLASSIFIED)) { continue; //remove unclassified from the legend } diseaseColor = diseases[i].getColor(); item = new LegendItem(diseaseName, null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), diseaseColor); //item = new LegendItem(diseaseName, null, null, null, new Rectangle2D.Double(0,0,6,6), diseaseColor); legendSrc.addLegendItem(item); } // item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.GRAY); // legendSrc.addLegendItem(item); } else if (colorBy == PCAcolorByType.Gender) { String genderName = null; Color genderColor = null; GenderType[] genderTypes = GenderType.values(); for (int i = 0; i < genderTypes.length; i++) { genderName = genderTypes[i].toString(); genderColor = genderTypes[i].getColor(); item = new LegendItem(genderName, null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), genderColor); legendSrc.addLegendItem(item); } // item = new LegendItem("Male", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.BLUE); // legendSrc.addLegendItem(item); // item = new LegendItem("Female", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.PINK); // legendSrc.addLegendItem(item); // item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f),Color.GRAY); // legendSrc.addLegendItem(item); } sources[0] = legendSrc; legend.setSources(sources); }
From source file:org.trade.ui.chart.renderer.PivotRenderer.java
/** * Draws the annotation./*from ww w .ja va2s . com*/ * * @param g2 * the graphics device. * @param plot * the plot. * @param dataArea * the data area. * @param domainAxis * the domain axis. * @param rangeAxis * the range axis. * @param rendererIndex * the renderer index. * @param info * the plot rendering info. * @param angle * double * @param x * double * @param y * double * @param ledgend * String */ public void drawPivotArrow(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info, double angle, double x, double y, String ledgend) { double tipRadius = DEFAULT_TIP_RADIUS; double baseRadius = DEFAULT_BASE_RADIUS; double arrowLength = DEFAULT_ARROW_LENGTH; double arrowWidth = DEFAULT_ARROW_WIDTH; double labelOffset = DEFAULT_LABEL_OFFSET; Font font = DEFAULT_FONT; Paint paint = DEFAULT_PAINT; boolean outlineVisible = false; Paint outlinePaint = Color.black; Stroke outlineStroke = new BasicStroke(0.5f); TextAnchor textAnchor = DEFAULT_TEXT_ANCHOR; TextAnchor rotationAnchor = DEFAULT_ROTATION_ANCHOR; double rotationAngle = DEFAULT_ROTATION_ANGLE; Stroke arrowStroke = new BasicStroke(1.0f); Paint arrowPaint = Color.black; PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); double j2DX = domainAxis.valueToJava2D(x, dataArea, domainEdge); double j2DY = rangeAxis.valueToJava2D(y, dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { double temp = j2DX; j2DX = j2DY; j2DY = temp; } double startX = j2DX + (Math.cos(angle) * baseRadius); double startY = j2DY + (Math.sin(angle) * baseRadius); double endX = j2DX + (Math.cos(angle) * tipRadius); double endY = j2DY + (Math.sin(angle) * tipRadius); double arrowBaseX = endX + (Math.cos(angle) * arrowLength); double arrowBaseY = endY + (Math.sin(angle) * arrowLength); double arrowLeftX = arrowBaseX + (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowLeftY = arrowBaseY + (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightX = arrowBaseX - (Math.cos(angle + (Math.PI / 2.0)) * arrowWidth); double arrowRightY = arrowBaseY - (Math.sin(angle + (Math.PI / 2.0)) * arrowWidth); GeneralPath arrow = new GeneralPath(); arrow.moveTo((float) endX, (float) endY); arrow.lineTo((float) arrowLeftX, (float) arrowLeftY); arrow.lineTo((float) arrowRightX, (float) arrowRightY); arrow.closePath(); g2.setStroke(arrowStroke); g2.setPaint(arrowPaint); Line2D line = new Line2D.Double(startX, startY, endX, endY); g2.draw(line); g2.fill(arrow); // draw the label double labelX = j2DX + (Math.cos(angle) * (baseRadius + labelOffset)); double labelY = j2DY + (Math.sin(angle) * (baseRadius + labelOffset)); g2.setFont(font); Shape hotspot = TextUtilities.calculateRotatedStringBounds(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); g2.setPaint(paint); TextUtilities.drawRotatedString(ledgend, g2, (float) labelX, (float) labelY, textAnchor, rotationAngle, rotationAnchor); if (outlineVisible) { g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(hotspot); } // String toolTip = getToolTipText(); // String url = getURL(); // if (toolTip != null || url != null) { // addEntity(info, hotspot, rendererIndex, toolTip, url); // } }
From source file:longMethod.jfreechart.draw.XYPolygonAnnotation.java
/** * Draws the annotation. This method is usually called by the * {@link XYPlot} class, you shouldn't need to call it directly. * * @param g2 the graphics device.// ww w .ja va 2 s.c o m * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info the plot rendering info. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { // if we don't have at least 2 (x, y) coordinates, just return if (this.polygon.length < 4) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); GeneralPath area = new GeneralPath(); double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, domainEdge); double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { area.moveTo((float) y, (float) x); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) y, (float) x); } area.closePath(); } else if (orientation == PlotOrientation.VERTICAL) { area.moveTo((float) x, (float) y); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) x, (float) y); } area.closePath(); } if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(area); } if (this.stroke != null && this.outlinePaint != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.stroke); g2.draw(area); } addEntity(info, area, rendererIndex, getToolTipText(), getURL()); }
From source file:com.cburch.draw.shapes.Poly.java
private GeneralPath getPath() { GeneralPath p = path; if (p == null) { p = new GeneralPath(); Handle[] hs = handles;/* w ww . ja va 2s .c o m*/ if (hs.length > 0) { boolean first = true; for (Handle h : hs) { if (first) { p.moveTo(h.getX(), h.getY()); first = false; } else { p.lineTo(h.getX(), h.getY()); } } } path = p; } return p; }
From source file:CustomStrokes.java
public Shape createStrokedShape(Shape shape) { GeneralPath newshape = new GeneralPath(); // Start with an empty shape // Iterate through the specified shape, perturb its coordinates, and // use them to build up the new shape. float[] coords = new float[6]; for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) { int type = i.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: perturb(coords, 2);/*from w w w . j a v a 2 s . c o m*/ newshape.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: perturb(coords, 2); newshape.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: perturb(coords, 4); newshape.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: perturb(coords, 6); newshape.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: newshape.closePath(); break; } } // Finally, stroke the perturbed shape and return the result return stroke.createStrokedShape(newshape); }
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);//w w w.java2s. c o m 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(); gfx.fill(polygon); gfx.setStroke(lineStroke); gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx), (int) (arrowPoint.getY() + cy)); } }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java
private void buildLegend() { LegendTitle legend = corrChart.getLegend(); LegendItemSource[] sources = new LegendItemSource[1]; CorrLegendItemSource legendSrc = new CorrLegendItemSource(); LegendItem item = null;//from w ww . j av a 2s . com //Rect=survival less than 10 months GeneralPath downtriangle = new GeneralPath(); downtriangle.moveTo(-4.0f, -4.0f); downtriangle.lineTo(4.0f, -4.0f); downtriangle.lineTo(0.0f, 4.0f); downtriangle.closePath(); item = new LegendItem("Tumor size reduced by 30% or more (MRI)", null, null, null, downtriangle, Color.BLACK); legendSrc.addLegendItem(item); item = new LegendItem("Tumor size reduced less than 30% or no change (MRI)", null, null, null, new Ellipse2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); GeneralPath uptriangle = new GeneralPath(); uptriangle.moveTo(0.0f, -4.0f); uptriangle.lineTo(4.0f, 4.0f); uptriangle.lineTo(-4.0f, 4.0f); uptriangle.closePath(); item = new LegendItem("Tumor size increased (MRI)", null, null, null, uptriangle, Color.BLACK); legendSrc.addLegendItem(item); item = new LegendItem("Tumor size change N/A", null, null, null, new Rectangle2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); if (colorBy == ColorByType.CLINICALRESPONSE) { for (ClinicalResponseType cr : ClinicalResponseType.values()) { item = new LegendItem(cr.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), cr.getColor()); legendSrc.addLegendItem(item); } } else if (colorBy == ColorByType.DISEASESTAGE) { for (ClinicalStageType ds : ClinicalStageType.values()) { if (!ds.name().endsWith("ALL")) { item = new LegendItem(ds.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ds.getColor()); legendSrc.addLegendItem(item); } } } else if (colorBy == ColorByType.TIMEPOINT) { for (TimepointType tp : TimepointType.values()) { item = new LegendItem(tp.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), tp.getColor()); legendSrc.addLegendItem(item); } } else if ((colorBy == ColorByType.IHC_EXPRESSION_X) || (colorBy == ColorByType.IHC_EXPRESSION_Y)) { // for (CorrScatterColorByIHCType ihcType : CorrScatterColorByIHCType.values()) { // item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), ihcType.getColor()); // legendSrc.addLegendItem(item); // } if (ihcBiomarkerType == IHCBiomarkerType.BCL2) { for (BCL2ihcType ihcType : BCL2ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.EGFR) { for (EGFRihcType ihcType : EGFRihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.FAK) { for (FAKihcType ihcType : FAKihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.HER2) { for (HER2ihcType ihcType : HER2ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.KI67) { for (Ki67ihcType ihcType : Ki67ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.P27) { for (P27ihcType ihcType : P27ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.P53) { for (P53ihcType ihcType : P53ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } else if (ihcBiomarkerType == IHCBiomarkerType.CYCLIN_D1) { for (CCND1ihcType ihcType : CCND1ihcType.values()) { item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6), new BasicStroke(3.0f), ihcType.getColor()); legendSrc.addLegendItem(item); } } } sources[0] = legendSrc; legend.setSources(sources); }