List of usage examples for java.awt.geom Rectangle2D setRect
public abstract void setRect(double x, double y, double w, double h);
From source file:SWTUtils.java
/** * Transform a swt Rectangle instance into an awt one. * @param rect the swt <code>Rectangle</code> * @return a Rectangle2D.Double instance with * the eappropriate location and size./*from w w w . j a v a 2 s .c o m*/ */ public static Rectangle2D toAwtRectangle(Rectangle rect) { Rectangle2D rect2d = new Rectangle2D.Double(); rect2d.setRect(rect.x, rect.y, rect.width, rect.height); return rect2d; }
From source file:ShapeTransform.java
/** * Clips the given shape to the given bounds. If the shape is a Line2D, manual * clipping is performed, as the built in Area does not handle lines. * //from w w w.ja v a 2 s . c om * @param s * the shape to be clipped * @param bounds * the bounds to which the shape should be clipped * @return the clipped shape. */ public static Shape performCliping(final Shape s, final Rectangle2D bounds) { if (s instanceof Line2D) { final Line2D line = (Line2D) s; final Point2D[] clipped = getClipped(line.getX1(), line.getY1(), line.getX2(), line.getY2(), -DELTA, DELTA + bounds.getWidth(), -DELTA, DELTA + bounds.getHeight()); if (clipped == null) { return new GeneralPath(); } return new Line2D.Float(clipped[0], clipped[1]); } final Rectangle2D boundsCorrected = bounds.getBounds2D(); boundsCorrected.setRect(-DELTA, -DELTA, DELTA + boundsCorrected.getWidth(), DELTA + boundsCorrected.getHeight()); final Area a = new Area(boundsCorrected); if (a.isEmpty()) { // don't clip ... Area does not like lines // operations with lines always result in an empty Bounds:(0,0,0,0) area return new GeneralPath(); } final Area clipArea = new Area(s); a.intersect(clipArea); return a; }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static void drawMaskBoarder(Graphics2D g2, Rectangle2D frame) { g2.setPaint(Color.orange);/*from ww w . j a va2 s . c o m*/ g2.setStroke(new BasicStroke(1)); g2.draw(frame); Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(frame); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
private static void drawMaskBoarder(Graphics2D g2, Abstract2DMask mask) { g2.setPaint(Color.orange);/*from ww w. ja v a 2s.co m*/ g2.setStroke(new BasicStroke(1)); Rectangle2D frame = mask.getRectangleFrame(); g2.draw(frame); Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth); g2.fill(dragPoint); Color fillColor = new Color(250, 250, 50, 10); g2.setPaint(fillColor); g2.fill(mask.getShape()); }
From source file:org.talend.dataprofiler.chart.util.ToolTipChartComposite.java
/** * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a * data point in a data set that lies inside a hotspot around that value. * /*from w w w .ja va2 s.c o m*/ * @param point The Java 2D point * @return A string for the data at the point or null if no data is found. */ protected String getTooltipAtPoint(Point point) { String result = null; Point2D translatedPoint = this.translateScreenToJava2D(point); Plot plot = this.getChart().getPlot(); PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo(); if (plot instanceof CombinedDomainXYPlot) { int index = info.getSubplotIndex(translatedPoint); if (index < 0) { index = 0; } plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index); info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index); } if (plot != null && plot instanceof XYPlot) { XYPlot xyPlot = (XYPlot) plot; ValueAxis domainAxis = xyPlot.getDomainAxis(); ValueAxis rangeAxis = xyPlot.getRangeAxis(); // had to switch to SWT's rectangle here. Rectangle screenArea = this.scale(info.getDataArea()); double hotspotSizeX = hotspontsize * this.getScaleX(); double hotspotSizeY = hotspontsize * this.getScaleY(); double x0 = point.getX(); double y0 = point.getY(); double x1 = x0 - hotspotSizeX; double y1 = y0 + hotspotSizeY; double x2 = x0 + hotspotSizeX; double y2 = y0 - hotspotSizeY; RectangleEdge xEdge = RectangleEdge.BOTTOM; RectangleEdge yEdge = RectangleEdge.LEFT; // Switch everything for horizontal charts if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) { hotspotSizeX = hotspontsize * this.getScaleY(); hotspotSizeY = hotspontsize * this.getScaleX(); x0 = point.getY(); y0 = point.getX(); x1 = x0 + hotspotSizeX; y1 = y0 - hotspotSizeY; x2 = x0 - hotspotSizeX; y2 = y0 + hotspotSizeY; xEdge = RectangleEdge.LEFT; yEdge = RectangleEdge.BOTTOM; } // OK, here we have to get ourselves back into AWT land... Rectangle2D r2d = new Rectangle2D.Double(); r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height); double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge); double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge); double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge); double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge); double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge); int datasetCount = xyPlot.getDatasetCount(); for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) { XYDataset dataset = xyPlot.getDataset(datasetIndex); int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); if (dataset instanceof OHLCDataset) { // This could be optimized to use a binary search for x first for (int item = 0; item < itemCount; item++) { double xValue = dataset.getXValue(series, item); double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item); double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item); // Check hi lo and swap if needed if (yValueHi < yValueLo) { double temp = yValueHi; yValueHi = yValueLo; yValueLo = temp; } // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2) if (tx1 < xValue && xValue < tx2) { // Check if the cursor 'y' value lies between the high and low (low < ty0 < high) if (yValueLo < ty0 && ty0 < yValueHi) { return hiLoTips.generateToolTip(dataset, series, item); } } } } else { // This could be optimized to use a binary search for x first for (int item = 0; item < itemCount; item++) { double xValue = dataset.getXValue(series, item); double yValue = dataset.getYValue(series, item); // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2) if (tx1 < xValue && xValue < tx2) { // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2) if (ty1 < yValue && yValue < ty2) { return xyTips.generateToolTip(dataset, series, item); } } } } } } } return result; }
From source file:org.jfree.experimental.chart.annotations.XYTitleAnnotation.java
/** * Draws the annotation. This method is called by the drawing code in the * {@link XYPlot} class, you don't normally need to call this method * directly./* w w w. j ava 2 s . c om*/ * * @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 if supplied, this info object will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation); Range xRange = domainAxis.getRange(); Range yRange = rangeAxis.getRange(); double anchorX = 0.0; double anchorY = 0.0; if (this.coordinateType == XYCoordinateType.RELATIVE) { anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); } else { anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); } float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } double maxW = dataArea.getWidth(); double maxH = dataArea.getHeight(); if (this.coordinateType == XYCoordinateType.RELATIVE) { if (this.maxWidth > 0.0) { maxW = maxW * this.maxWidth; } if (this.maxHeight > 0.0) { maxH = maxH * this.maxHeight; } } if (this.coordinateType == XYCoordinateType.DATA) { maxW = this.maxWidth; maxH = this.maxHeight; } RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH)); Size2D size = this.title.arrange(g2, rc); Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height); Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor); xx = xx - (float) anchorPoint.getX(); yy = yy - (float) anchorPoint.getY(); titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight()); BlockParams p = new BlockParams(); if (info != null) { if (info.getOwner().getEntityCollection() != null) { p.setGenerateEntities(true); } } Object result = this.title.draw(g2, titleRect, p); if (result instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) result; info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection()); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url); } }
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen * or a printer)./* ww w . java 2 s . com*/ * @param g2 The graphics device. * @param plotArea The area within which the plot should be drawn. */ @Override public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D anchor, PlotState state, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); if (insets != null) { plotArea.setRect(plotArea.getX() + insets.getLeft(), plotArea.getY() + insets.getTop(), plotArea.getWidth() - insets.getLeft() - insets.getRight(), plotArea.getHeight() - insets.getTop() - insets.getBottom()); } if (info != null) { info.setPlotArea(plotArea); info.setDataArea(plotArea); } drawBackground(g2, plotArea); drawOutline(g2, plotArea); Shape savedClip = g2.getClip(); g2.clip(plotArea); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (this.dataset != null) { drawRadar(g2, plotArea, info, 0, this.dataset); } else { drawNoDataMessage(g2, plotArea); } g2.clip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, plotArea); }
From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the screen or * a printer).//from w w w . jav a2 s. c o m * * @param g2 the graphics device. * @param plotArea the area within which the plot (including axis labels) should be drawn. * @param info collects chart drawing information (<code>null</code> permitted). */ public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo info) { // if (data == null) // return; // set up info collection... if (info != null) { info.setPlotArea(plotArea); } // adjust the drawing area for plot insets (if any)... Insets insets = getInsets(); if (insets != null) { plotArea.setRect(plotArea.getX() + insets.left, plotArea.getY() + insets.top, plotArea.getWidth() - insets.left - insets.right, plotArea.getHeight() - insets.top - insets.bottom); } AxisSpace space = new AxisSpace(); space = this.domainAxis.reserveSpace(g2, this, plotArea, RectangleEdge.BOTTOM, space); space = this.rangeAxis.reserveSpace(g2, this, plotArea, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(plotArea, null); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); /* if automatic bounds... */ if (!isNoData()) { if (this instanceof DmcRenderablePlot) { DmcPlotRenderer renderer; renderer = ((DmcRenderablePlot) this).getPlotRenderer(); if (renderer != null) { renderer.initialize(); if (renderer.getState() == DmcPlotRenderer.STATE_STOPPED) { return; } } } } AxisState domainAxisState = null, rangeAxisState = null; if (this.domainAxis != null) { double cursor; cursor = dataArea.getMaxY(); domainAxisState = this.domainAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM, info); // cursor = info.getCursor(); } if (this.rangeAxis != null) { double cursor; cursor = dataArea.getMinX(); rangeAxisState = this.rangeAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT, info); } if (drawGridlines == true && domainAxisState != null && rangeAxisState != null) { drawGridlines(g2, dataArea, domainAxisState.getTicks(), rangeAxisState.getTicks()); } Shape originalClip = g2.getClip(); g2.clip(dataArea); // Composite originalComposite = g2.getComposite(); // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, // getForegroundAlpha())); // g2.setStroke(new BasicStroke(12.0F)); if (isNoData()) { drawNoDataMessage(g2, plotArea); } else { drawPlot(g2, dataArea, info); } g2.setClip(originalClip); drawOutline(g2, dataArea); }
From source file:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java
private int getPosAt(long timestamp) { if (chartFrame != null && plot != null) { org.eclipse.swt.graphics.Rectangle swtRect = chartFrame.getScreenDataArea(); Rectangle2D screenDataArea = new Rectangle(); screenDataArea.setRect(swtRect.x, swtRect.y, swtRect.width, swtRect.height); int pos = (int) plot.getDomainAxis().valueToJava2D(timestamp, screenDataArea, plot.getDomainAxisEdge()); return pos; }/*from w w w.j a v a 2 s. co m*/ return 0; }
From source file:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java
private long getTimestampAt(int pos) { if (chartFrame != null && plot != null && loadedInterval != null) { org.eclipse.swt.graphics.Rectangle swtRect = chartFrame.getScreenDataArea(); Rectangle2D screenDataArea = new Rectangle(); screenDataArea.setRect(swtRect.x, swtRect.y, swtRect.width, swtRect.height); long v = (long) plot.getDomainAxis().java2DToValue(pos, screenDataArea, plot.getDomainAxisEdge()); if (v < loadedInterval.startTimestamp) { v = loadedInterval.startTimestamp; } else if (v > loadedInterval.endTimestamp) { v = loadedInterval.endTimestamp; }//from www . j ava 2 s . c o m return v; } return 0; }