List of usage examples for java.awt Shape getBounds2D
public Rectangle2D getBounds2D();
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Get the border shape for the given label shape * @param labelShape/* w w w. j a v a 2 s. co m*/ * the label shape that we're going to draw a border around * @return * the border shape */ private Shape getLabelBorder(Shape labelShape) { Rectangle2D labelBounds = labelShape.getBounds2D(); return new RoundRectangle2D.Double(labelBounds.getX() - LABEL_BORDER_ROUNDING_ARC_SIZE, labelBounds.getY() - LABEL_BORDER_ROUNDING_ARC_SIZE, labelBounds.getWidth() + (LABEL_BORDER_ROUNDING_ARC_SIZE * 2), labelBounds.getHeight() + (LABEL_BORDER_ROUNDING_ARC_SIZE * 2), LABEL_BORDER_ROUNDING_ARC_SIZE, LABEL_BORDER_ROUNDING_ARC_SIZE); }
From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java
/** * Get a collection of entities with the area shape equal to the bounding rectangle * for the shape of original entity. This is necessary because the Javascript for the sample * selection lasso can only handle rect objects. * @param entities/* w w w. ja v a 2s . co m*/ * @return a collection of entities containing the bounding rectangles of the original entities */ protected Collection<ChartEntity> getBoundingEntities(Collection entities) { ChartEntity entity; ChartEntity boundingEntity; Shape shape; Rectangle2D boundingRect; Collection<ChartEntity> boundingEntities = new ArrayList<ChartEntity>(); for (Iterator i = entities.iterator(); i.hasNext();) { entity = (ChartEntity) i.next(); shape = entity.getArea(); boundingRect = shape.getBounds2D(); boundingEntity = new ChartEntity(boundingRect, entity.getToolTipText(), entity.getURLText()); boundingEntities.add(boundingEntity); } return boundingEntities; }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
public void generatePeakShape(IChromatogramDescriptor chromatogram, IPeakAnnotationDescriptor peakDescr, ADataset1D<IChromatogram1D, IScan> dataset, int seriesIndex, List<VisualPeakAnnotation> l) { int scan = chromatogram.getChromatogram().getIndexFor(peakDescr.getApexTime()); double yValue = dataset.getYValue(seriesIndex, scan); if (dataset instanceof TopViewDataset) { if (drawShapes) { VisualPeakAnnotation pointer = generateTriangle(peakDescr.getApexTime() - 5, yValue - 10, peakDescr.getApexTime(), yValue, peakDescr.getApexTime() + 5, yValue - 10); l.add(pointer);/*from w ww .j a v a 2 s. c o m*/ } } else { if (drawOutlines) { VisualPeakAnnotation outline = generateOutline(chromatogram, peakDescr, dataset, seriesIndex); if (outline != null) { l.add(outline); } } if (drawLines) { Shape line2d = new Rectangle2D.Double(peakDescr.getApexTime() - 0.5, dataset.getMaxY(), 1, dataset.getMaxY() - dataset.getMinY()); VisualPeakAnnotation vpa = new VisualPeakAnnotation(line2d, new Point2D.Double(line2d.getBounds2D().getCenterX(), line2d.getBounds2D().getCenterY()), PeakAnnotationType.LINE); l.add(vpa); } if (drawShapes) { VisualPeakAnnotation pointer = generateTriangle(peakDescr.getApexTime() - 5, yValue - 10, peakDescr.getApexTime(), yValue, peakDescr.getApexTime() + 5, yValue - 10); l.add(pointer); } } }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * A recursive version of/*from w w w.j av a 2 s . c o m*/ * {@link #calculateMaximalNodeDimension(VisualTreeNode, FontRenderContext)} * @param maximalNodeDimension * the biggest width and height * @param treeLayout * the tree layout * @param frc * the {@link FontRenderContext} */ private void calculateMaximalNodeDimensionRecursive(Dimension2DDouble maximalNodeDimension, VisualTreeNode treeLayout, FontRenderContext frc) { Shape textShape = this.getLabelShape(treeLayout, frc); Shape borderShape = this.getLabelBorder(textShape); Rectangle2D borderBounds = borderShape.getBounds2D(); if (borderBounds.getWidth() > maximalNodeDimension.getWidth()) { maximalNodeDimension.setWidth(borderBounds.getWidth()); } if (borderBounds.getHeight() > maximalNodeDimension.getHeight()) { maximalNodeDimension.setHeight(borderBounds.getHeight()); } for (VisualTreeNode childNode : treeLayout.getChildNodes()) { this.calculateMaximalNodeDimensionRecursive(maximalNodeDimension, childNode, frc); } }
From source file:org.esa.snap.rcp.statistics.DensityPlotPanel.java
private ChartPanel createChartPanel(JFreeChart chart) { densityPlotDisplay = new ChartPanel(chart); MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, densityPlotDisplay, "scatter_plot_area", "Mask generated from selected scatter plot area", Color.RED, PlotAreaSelectionTool.AreaType.ELLIPSE) { @Override/* w w w .j av a 2 s . com*/ protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) { Rectangle2D bounds = shape.getBounds2D(); return createMaskExpression(bounds.getCenterX(), bounds.getCenterY(), 0.5 * bounds.getWidth(), 0.5 * bounds.getHeight()); } protected String createMaskExpression(double x0, double y0, double dx, double dy) { return String.format("sqrt(sq((%s - %s)/%s) + sq((%s - %s)/%s)) < 1.0", BandArithmetic.createExternalName(dataSourceConfig.xBand.getName()), x0, dx, BandArithmetic.createExternalName(dataSourceConfig.yBand.getName()), y0, dy); } }; densityPlotDisplay.getPopupMenu().addSeparator(); densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem()); densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem()); densityPlotDisplay.getPopupMenu().addSeparator(); densityPlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return densityPlotDisplay; }
From source file:hudson.util.NoOverlapCategoryAxis.java
@Override protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) { if (state == null) { throw new IllegalArgumentException("Null 'state' argument."); }//from w ww . j a v a2 s .c o m if (isTickLabelsVisible()) { java.util.List ticks = refreshTicks(g2, state, plotArea, edge); state.setTicks(ticks); // remember the last drawn label so that we can avoid drawing overlapping labels. Rectangle2D r = null; int categoryIndex = 0; Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { CategoryTick tick = (CategoryTick) iterator.next(); g2.setFont(getTickLabelFont(tick.getCategory())); g2.setPaint(getTickLabelPaint(tick.getCategory())); CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge); double x0 = 0.0; double x1 = 0.0; double y0 = 0.0; double y1 = 0.0; if (edge == RectangleEdge.TOP) { x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); y1 = state.getCursor() - this.getCategoryLabelPositionOffset(); y0 = y1 - state.getMax(); } else if (edge == RectangleEdge.BOTTOM) { x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); y0 = state.getCursor() + this.getCategoryLabelPositionOffset(); y1 = y0 + state.getMax(); } else if (edge == RectangleEdge.LEFT) { y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); x1 = state.getCursor() - this.getCategoryLabelPositionOffset(); x0 = x1 - state.getMax(); } else if (edge == RectangleEdge.RIGHT) { y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); x0 = state.getCursor() + this.getCategoryLabelPositionOffset(); x1 = x0 - state.getMax(); } Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); if (r == null || !r.intersects(area)) { Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor()); TextBlock block = tick.getLabel(); block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); if (plotState != null && plotState.getOwner() != null) { EntityCollection entities = plotState.getOwner().getEntityCollection(); if (entities != null) { String tooltip = getCategoryLabelToolTip(tick.getCategory()); entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null)); } } r = bounds.getBounds2D(); } categoryIndex++; } if (edge.equals(RectangleEdge.TOP)) { double h = state.getMax(); state.cursorUp(h); } else if (edge.equals(RectangleEdge.BOTTOM)) { double h = state.getMax(); state.cursorDown(h); } else if (edge == RectangleEdge.LEFT) { double w = state.getMax(); state.cursorLeft(w); } else if (edge == RectangleEdge.RIGHT) { double w = state.getMax(); state.cursorRight(w); } } return state; }
From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java
private ChartPanel createChartPanel(final JFreeChart chart) { scatterPlotDisplay = new ChartPanel(chart) { @Override//from ww w . j a va 2 s .com public void restoreAutoBounds() { // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... final XYPlot plot = chart.getXYPlot(); boolean savedNotify = plot.isNotify(); plot.setNotify(false); xAxisRangeControl.adjustAxis(plot.getDomainAxis(), 3); yAxisRangeControl.adjustAxis(plot.getRangeAxis(), 3); plot.setNotify(savedNotify); } }; MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, scatterPlotDisplay, "correlative_plot_area", "Mask generated from selected correlative plot area", Color.RED, PlotAreaSelectionTool.AreaType.Y_RANGE) { @Override protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) { Rectangle2D bounds = shape.getBounds2D(); return createMaskExpression(bounds.getMinY(), bounds.getMaxY()); } protected String createMaskExpression(double x1, double x2) { String bandName = BandArithmetic.createExternalName(getRaster().getName()); return String.format("%s >= %s && %s <= %s", bandName, x1, bandName, x2); } }; scatterPlotDisplay.getPopupMenu().addSeparator(); scatterPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem()); scatterPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem()); scatterPlotDisplay.getPopupMenu().addSeparator(); scatterPlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return scatterPlotDisplay; }
From source file:net.sf.maltcms.common.charts.api.overlay.SelectionOverlay.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, ChartPanel chartPanel, boolean scale) { if (entity != null) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();//from w w w . j av a2 s . com Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; if (scale) { transformed = scaleAtOrigin(entity, hoverScaleX, hoverScaleY).createTransformedShape(entity); } transformed = getTranslateInstance( entity.getBounds2D().getCenterX() - transformed.getBounds2D().getCenterX(), entity.getBounds2D().getCenterY() - transformed.getBounds2D().getCenterY()) .createTransformedShape(transformed); g2.setComposite(getInstance(AlphaComposite.SRC_OVER, fillAlpha)); g2.fill(transformed); g2.setColor(Color.DARK_GRAY); g2.draw(transformed); g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } }
From source file:edu.dlnu.liuwenpeng.render.XYBarRenderer.java
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. /*from w w w.j a v a2 s.co m*/ * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
From source file:edu.dlnu.liuwenpeng.render.NewXYBarRenderer.java
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. // w ww . ja v a 2 s. c o m * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }