List of usage examples for java.awt.geom GeneralPath closePath
public final synchronized void closePath()
From source file:ro.nextreports.engine.util.chart.CylinderRenderer.java
/** * Draws a cylinder to represent one data item. * // w w w . j a v a 2s . co m * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area for plotting the data. * @param plot the plot. * @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. */ 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; } 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(); float transL0 = (float) rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); float transL1 = (float) rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); float barL0 = Math.min(transL0, transL1); float barLength = Math.abs(transL1 - transL0); // draw the bar... GeneralPath bar = new GeneralPath(); if (orientation == PlotOrientation.HORIZONTAL) { bar.moveTo(barL0, (float) barW0); bar.lineTo(barL0, (float) (barW0 + state.getBarWidth())); bar.lineTo(barL0 + barLength, (float) (barW0 + state.getBarWidth())); bar.lineTo(barL0 + barLength, (float) barW0); bar.closePath(); } else { bar.moveTo((float) barW0, (float) (barL0 - getYOffset() / 2)); bar.lineTo((float) barW0, (float) (barL0 + barLength - getYOffset() / 2)); Arc2D arc = new Arc2D.Double(barW0, (barL0 + barLength - getYOffset()), state.getBarWidth(), getYOffset(), 180, 180, Arc2D.OPEN); bar.append(arc, true); bar.lineTo((float) (barW0 + state.getBarWidth()), (float) (barL0 - getYOffset() / 2)); arc = new Arc2D.Double(barW0, (barL0 - getYOffset()), state.getBarWidth(), getYOffset(), 0, -180, Arc2D.OPEN); bar.append(arc, true); bar.closePath(); } Paint itemPaint = getItemPaint(row, column); if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; itemPaint = getGradientPaintTransformer().transform(gp, bar); } g2.setPaint(itemPaint); g2.fill(bar); Shape bar3dTop = new Ellipse2D.Double(barW0, barL0 - getYOffset(), state.getBarWidth(), getYOffset()); if (itemPaint instanceof GradientPaint) { g2.setPaint(((GradientPaint) itemPaint).getColor2()); } g2.fill(bar3dTop); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); 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.getBounds2D(), (value < 0.0)); } // collect entity and tool tip information... if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; if (getItemURLGenerator(row, column) != null) { url = getItemURLGenerator(row, column).generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(bar.getBounds2D(), tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); } } }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private VisualPeakAnnotation generateTriangle(double startX, double startY, double apexX, double apexY, double stopX, double stopY) { GeneralPath path = new GeneralPath(); path.moveTo(startX, startY);/*from w ww .j a va 2s. c o m*/ path.lineTo(apexX, apexY); path.lineTo(stopX, stopY); path.closePath(); Rectangle2D r = path.getBounds2D(); return new VisualPeakAnnotation(path, new Point2D.Double(r.getCenterX(), r.getMaxY()), PeakAnnotationType.POINTER); }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.java
/** * Build the legend//from w w w. jav a 2s .c om * */ private 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("Tumor size change (MRI): Unknown", null, null, null, new Rectangle2D.Double(0, 0, 8, 8), Color.BLACK); legendSrc.addLegendItem(item); 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); 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); } } sources[0] = legendSrc; legend.setSources(sources); }
From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java
/** * Returns the shape for the window for this dial. Some dial layers will * request that their drawing be clipped within this window. * * @param frame the reference frame (<code>null</code> not permitted). * * @return The shape of the dial's window. *//* w w w . ja v a2s . c o m*/ public Shape getWindow(Rectangle2D frame) { Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius, this.innerRadius); Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius, this.outerRadius); Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle, this.extent, Arc2D.OPEN); Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + this.extent, -this.extent, Arc2D.OPEN); GeneralPath p = new GeneralPath(); Point2D point1 = inner.getStartPoint(); p.moveTo((float) point1.getX(), (float) point1.getY()); p.append(inner, true); p.append(outer, true); p.closePath(); return p; }
From source file:com.gargoylesoftware.htmlunit.html.HtmlArea.java
private GeneralPath parsePoly() { final String[] coords = StringUtils.split(getCoordsAttribute(), ','); final GeneralPath path = new GeneralPath(); for (int i = 0; i + 1 < coords.length; i += 2) { if (i == 0) { path.moveTo(Float.parseFloat(coords[i]), Float.parseFloat(coords[i + 1])); } else {//from w w w. jav a2s.c o m path.lineTo(Float.parseFloat(coords[i]), Float.parseFloat(coords[i + 1])); } } path.closePath(); return path; }
From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java
protected Shape getOuterWindow(Rectangle2D frame) { double radiusMargin = 0.02; double angleMargin = 1.5; Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius - radiusMargin, this.innerRadius - radiusMargin); Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius + radiusMargin, this.outerRadius + radiusMargin); Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN);/*from w w w. jav a 2 s . c om*/ Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + angleMargin + this.extent, -this.extent - 2 * angleMargin, Arc2D.OPEN); GeneralPath p = new GeneralPath(); Point2D point1 = inner.getStartPoint(); p.moveTo((float) point1.getX(), (float) point1.getY()); p.append(inner, true); p.append(outer, true); p.closePath(); return p; }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.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 *//*from w w w. j a va 2 s .c om*/ protected void createGlyphsAndAddToPlot(XYPlot plot) { XYShapeAnnotation glyph; Shape glyphShape; Color glyphColor; PrincipalComponentAnalysisDataPoint pcaPoint; double x, y; for (Iterator i = dataPoints.iterator(); i.hasNext();) { pcaPoint = (PrincipalComponentAnalysisDataPoint) i.next(); x = pcaPoint.getComponentValue(component1); y = pcaPoint.getComponentValue(component2); double survival = pcaPoint.getSurvivalInMonths(); if ((survival > 0) && (survival < 10.0)) { Rectangle2D.Double rect = new Rectangle2D.Double(); rect.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = rect; } else if ((survival > 0) && (survival >= 10.0)) { Ellipse2D.Double circle = new Ellipse2D.Double(); circle.setFrameFromCenter(x, y, x + 2, y + 2); glyphShape = circle; } else { //Rectangle2D.Double rect = new Rectangle2D.Double(); //rect.setFrameFromCenter(x,y, x+2,y+2); GeneralPath gp = new GeneralPath(); float xf = (float) x; float yf = (float) y; //make a triangle gp.moveTo(xf, yf); gp.lineTo(xf + 3.0f, yf - 3.0f); gp.lineTo(xf - 3.0f, yf - 3.0f); gp.closePath(); glyphShape = gp; } glyphColor = getColorForDataPoint(pcaPoint); glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor); String tooltip = ""; if (pcaPoint.getSurvivalInMonths() <= 0.0) { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName(); } else { tooltip = pcaPoint.getSampleId() + " " + pcaPoint.getDiseaseName() + " survivalMonths=" + nf.format(pcaPoint.getSurvivalInMonths()); } glyph.setToolTipText(tooltip); plot.addAnnotation(glyph); } }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java
/** * Build the legend//from w ww . ja v a 2s. c o m * */ 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: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 *///from ww w. j a va 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:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param f//from w w w . j a va2 s . com * @param useScanAcquisitionTime * @param outline * @param fill * @param valueVar * @return */ public static List<XYAnnotation> generatePeakShapes(IFileFragment f, boolean useScanAcquisitionTime, Color outline, Color fill, String valueVar) { List<XYAnnotation> l = new ArrayList<>(); try { IVariableFragment peakNames = f.getChild("peak_name"); IVariableFragment peakRT = f.getChild("peak_retention_time"); IVariableFragment peakStartRT = f.getChild("peak_start_time"); IVariableFragment peakStopRT = f.getChild("peak_end_time"); int peaks = peakRT.getArray().getShape()[0]; boolean baselineAvailable = true; IVariableFragment blStartRT = null; IVariableFragment blStopRT = null; IVariableFragment blStartValue = null; IVariableFragment blStopValue = null; try { blStartRT = f.getChild("baseline_start_time"); blStopRT = f.getChild("baseline_stop_time"); blStartValue = f.getChild("baseline_start_value"); blStopValue = f.getChild("baseline_stop_value"); } catch (ResourceNotAvailableException e) { baselineAvailable = false; } boolean andichromMode = valueVar.equals("ordinate_values"); Array ordinateValues = null; try { ordinateValues = f.getChild(valueVar).getArray(); } catch (ResourceNotAvailableException rne) { ordinateValues = f.getChild("total_intensity").getArray(); andichromMode = false; } Collection<String> peaknames = ArrayTools.getStringsFromArray(peakNames.getArray()); IndexIterator ii = peakRT.getArray().getIndexIterator(); Iterator<String> peaknamesIter = peaknames.iterator(); for (int i = 0; i < peaks; i++) { double sat = ii.getDoubleNext(); double peakStartTime = peakStartRT.getArray().getDouble(i); double peakStopTime = peakStopRT.getArray().getDouble(i); int scan = 0; int startIdx, stopIdx; if (andichromMode) { double delay = f.getChild("actual_delay_time").getArray().getDouble(0); double samplingRate = f.getChild("actual_sampling_interval").getArray().getDouble(0); scan = (int) (Math.floor(((sat - delay) / samplingRate))); startIdx = (int) (Math.floor(((peakStartTime - delay) / samplingRate))); stopIdx = (int) (Math.floor(((peakStopTime - delay) / samplingRate))); } else { Array satA = f.getChild("scan_acquisition_time").getArray(); double[] d = (double[]) satA.get1DJavaArray(double.class); scan = Arrays.binarySearch(d, sat); if (scan < 0) { scan = ((-1) * (scan + 1)); } startIdx = Arrays.binarySearch(d, peakStartTime); stopIdx = Arrays.binarySearch(d, peakStopTime); if (startIdx < 0) { startIdx = ((-1) * (startIdx + 1)); } if (stopIdx < 0) { stopIdx = ((-1) * (stopIdx + 1)); } } String name = peaknamesIter.next(); double blStartTime, blStopTime, blStartVal, blStopVal; if (baselineAvailable) { blStartTime = blStartRT.getArray().getDouble(i); blStopTime = blStopRT.getArray().getDouble(i); blStartVal = blStartValue.getArray().getDouble(i); blStopVal = blStopValue.getArray().getDouble(i); } else { blStartTime = peakStartTime; blStopTime = peakStopTime; blStartVal = ordinateValues.getDouble(startIdx); blStopVal = ordinateValues.getDouble(stopIdx); } if (name.trim().isEmpty()) { name = "NN"; } GeneralPath gp = new GeneralPath(); if (useScanAcquisitionTime) { Array sat2 = f.getChild("scan_acquisition_time").getArray(); gp.moveTo(peakStartTime, ordinateValues.getDouble(startIdx)); for (int j = startIdx + 1; j <= stopIdx + 1; j++) { gp.lineTo(sat2.getDouble(j), ordinateValues.getDouble(j)); } gp.lineTo(Math.max(blStopTime, peakStopTime), blStopVal); gp.lineTo(Math.min(blStartTime, peakStartTime), blStartVal); gp.closePath(); //gp.closePath(); Rectangle2D.Double bbox = new Rectangle2D.Double(peakStartTime, 0, peakStopTime - peakStartTime, ordinateValues.getDouble(scan)); Area a = new Area(bbox); a.intersect(new Area(gp)); XYShapeAnnotation xypa = new XYShapeAnnotation(a, new BasicStroke(), outline, fill); XYLineAnnotation xyla = new XYLineAnnotation(blStartTime, blStartVal, blStopTime, blStopVal, new BasicStroke(), Color.BLACK); l.add(xypa); l.add(xyla); // XYLineAnnotation baseline = new XYLineAnnotation(); } else { gp.moveTo(startIdx, ordinateValues.getDouble(startIdx)); for (int j = startIdx + 1; j <= stopIdx + 1; j++) { gp.lineTo(j, ordinateValues.getDouble(j)); } gp.closePath(); XYShapeAnnotation xypa = new XYShapeAnnotation(gp, new BasicStroke(), outline, fill); l.add(xypa); } } } catch (ResourceNotAvailableException rnae) { Logger.getLogger(Chromatogram1DChartProvider.class.getName()).info(rnae.getLocalizedMessage()); } return l; }