List of usage examples for java.awt.geom Rectangle2D getCenterY
public double getCenterY()
From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java
/** * * @param s/*from w ww .j a va2 s . c o m*/ * @return */ public Point2D getCenter(Shape s) { Rectangle2D r2 = s.getBounds2D(); Point2D.Double p = new Point2D.Double(r2.getCenterX(), r2.getCenterY()); return p; }
From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java
/** * Iterates over Vertices, checking to see if x,y is contained in the * Vertex's Shape. If (x,y) is contained in more than one vertex, use * the vertex whose center is closest to the pick point. * @see edu.uci.ics.jung.visualization.picking.PickSupport#getVertex(double, double) *//*ww w . ja va 2s. co m*/ public V getVertex(Layout<V, E> layout, double x, double y) { V closest = null; double minDistance = Double.MAX_VALUE; Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, new Point2D.Double(x, y)); x = ip.getX(); y = ip.getY(); while (true) { try { for (V v : getFilteredVertices(layout)) { Shape shape = vv.getRenderContext().getVertexShapeTransformer().transform(v); // get the vertex location Point2D p = layout.transform(v); if (p == null) continue; // transform the vertex location to screen coords p = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p); double ox = x - p.getX(); double oy = y - p.getY(); if (shape.contains(ox, oy)) { if (style == Style.LOWEST) { // return the first match return v; } else if (style == Style.HIGHEST) { // will return the last match closest = v; } else { // return the vertex closest to the // center of a vertex shape Rectangle2D bounds = shape.getBounds2D(); double dx = bounds.getCenterX() - ox; double dy = bounds.getCenterY() - oy; double dist = dx * dx + dy * dy; if (dist < minDistance) { minDistance = dist; closest = v; } } } } break; } catch (ConcurrentModificationException cme) { } } return closest; }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();/* w ww . j a va 2 s.co m*/ Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Rectangle2D entityBounds = entity.getBounds2D(); double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge); double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge); double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge); double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge); PlotOrientation orientation = plot.getOrientation(); //transform model to origin (0,0) in model coordinates AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(), -entityBounds.getCenterY()); //transform from origin (0,0) to model location AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(), entityBounds.getCenterY()); //transform from model scale to view scale double scaleX = viewW / entityBounds.getWidth(); double scaleY = viewH / entityBounds.getHeight(); Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}", new Object[] { scaleX, scaleY }); AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY); AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f); AffineTransform modelToView = new AffineTransform(toOrigin); modelToView.preConcatenate(flipTransform); modelToView.preConcatenate(toViewScale); modelToView.preConcatenate(toViewLocation); // // if (orientation == PlotOrientation.HORIZONTAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewY, // viewX); // } else if (orientation == PlotOrientation.VERTICAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewX, // viewY); // } FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity) .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
/** * Draws the visual representation of a single wind arrow. *//* w w w .j a va 2 s .com*/ @Override public void drawItem(Graphics2D g2d, XYItemRendererState state, Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { resizeArrowByPlotHeight((int) plotArea.getHeight()); // Needs a new graphics object to use translate() and rotate() Graphics2D g2 = (Graphics2D) g2d.create(); g2.setRenderingHints(renderHints); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); double middleY = plotArea.getCenterY(); WindDataset windData = (WindDataset) dataset; Number x = windData.getX(series, item); Number windDir = windData.getWindDirection(series, item); Number wforce = windData.getWindForce(series, item); double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, domainAxisLocation); g2.translate((int) middleX, (int) middleY); g2.setColor(Color.BLACK); if (wforce.doubleValue() <= zeroWindLimit) { drawCircle(g2); } else { g2.rotate(Math.toRadians(windDir.doubleValue() - 180)); drawArrow(g2, wforce.doubleValue()); if (useArrowHead) { g2.fill(getPolygonHead(arrowHeadSize, arrowHeight)); } else { g2.draw(getCircleHead(arrowHeadSize, arrowHeight)); } } }
From source file:org.csa.rstb.dat.toolviews.HaAlphaPlotPanel.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//from ww w . j a v a 2 s .c om 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(sqr((%s - %s)/%s) + sqr((%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:edu.ucla.stat.SOCR.chart.gui.CircleDrawer.java
/** * Draws the circle./*from w w w. j a v a 2 s .c o m*/ * * @param g2 the graphics device. * @param area the area in which to draw. */ public void draw(Graphics2D g2, Rectangle2D area) { Ellipse2D ellipse = new Ellipse2D.Double(area.getX(), area.getY(), area.getWidth(), area.getHeight()); if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(ellipse); } if (this.outlinePaint != null && this.outlineStroke != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(ellipse); } g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1.0f)); Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY()); Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY()); g2.draw(line1); g2.draw(line2); }
From source file:com.rapidminer.gui.plotter.charts.ParallelPlotter2.java
@Override public void updatePlotter() { prepareData();/*from w w w .j a v a 2s .co m*/ JFreeChart chart = createChart(this.dataset); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // general plot settings XYPlot plot = chart.getXYPlot(); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // domain axis SymbolAxis axis = null; if (this.dataTable.isSupportingColumnWeights()) { List<Double> weightList = new LinkedList<>(); for (int column = 0; column < dataTable.getNumberOfColumns(); column++) { if ((!dataTable.isSpecial(column)) && (column != colorColumn)) { weightList.add(this.dataTable.getColumnWeight(column)); } } double[] weights = new double[weightList.size()]; int index = 0; for (Double d : weightList) { weights[index++] = d; } axis = new WeightBasedSymbolAxis(null, domainAxisMap, weights); } else { axis = new SymbolAxis(null, domainAxisMap); } axis.setTickLabelFont(LABEL_FONT); axis.setLabelFont(LABEL_FONT_BOLD); // rotate labels if (isLabelRotating()) { axis.setTickLabelsVisible(true); axis.setVerticalTickLabels(true); } chart.getXYPlot().setDomainAxis(axis); // renderer final ColorizedLineAndShapeRenderer renderer = new ColorizedLineAndShapeRenderer(this.colorMap); plot.setRenderer(renderer); // legend settings if ((colorColumn >= 0) && (this.dataTable.isNominal(colorColumn))) { final LegendItemCollection legendItemCollection = new LegendItemCollection(); for (int i = 0; i < this.dataTable.getNumberOfValues(colorColumn); i++) { legendItemCollection.add(new LegendItem(this.dataTable.mapIndex(colorColumn, i), null, null, null, new Rectangle2D.Double(0, 0, 7, 7), getColorProvider() .getPointColor(i / (double) (this.dataTable.getNumberOfValues(colorColumn) - 1)), new BasicStroke(0.75f), Color.GRAY)); } chart.addLegend(new LegendTitle(new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { return legendItemCollection; } })); LegendTitle legend = chart.getLegend(); if (legend != null) { legend.setPosition(RectangleEdge.TOP); legend.setFrame(BlockBorder.NONE); legend.setHorizontalAlignment(HorizontalAlignment.LEFT); legend.setItemFont(LABEL_FONT); } } else if (colorColumn >= 0) { chart.addLegend(new LegendTitle(new LegendItemSource() { @Override public LegendItemCollection getLegendItems() { LegendItemCollection itemCollection = new LegendItemCollection(); itemCollection.add(new LegendItem("Dummy")); return itemCollection; } }) { private static final long serialVersionUID = 1288380309936848376L; @Override public Object draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area, java.lang.Object params) { if (dataTable.isDate(colorColumn) || dataTable.isTime(colorColumn) || dataTable.isDateTime(colorColumn)) { drawSimpleDateLegend(g2, (int) (area.getCenterX() - 170), (int) (area.getCenterY() + 7), dataTable, colorColumn, renderer.getMinColorValue(), renderer.getMaxColorValue()); return new BlockResult(); } else { final String minColorString = Tools.formatNumber(renderer.getMinColorValue()); final String maxColorString = Tools.formatNumber(renderer.getMaxColorValue()); drawSimpleNumericalLegend(g2, (int) (area.getCenterX() - 90), (int) (area.getCenterY() + 7), dataTable.getColumnName(colorColumn), minColorString, maxColorString); return new BlockResult(); } } @Override public void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area) { draw(g2, area, null); } }); } // chart panel if (panel instanceof AbstractChartPanel) { panel.setChart(chart); } else { panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN); final ChartPanelShiftController controller = new ChartPanelShiftController(panel); panel.addMouseListener(controller); panel.addMouseMotionListener(controller); } // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!! panel.getChartRenderingInfo().setEntityCollection(null); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
/** * Handles an action event./*from w w w. j a v a 2 s. c om*/ * * @param evt * the event. */ public void actionPerformed(ActionEvent evt) { try { String acmd = evt.getActionCommand(); if (acmd.equals(ACTION_CHART_ZOOM_BOX)) { setPanMode(false); } else if (acmd.equals(ACTION_CHART_PAN)) { setPanMode(true); } else if (acmd.equals(ACTION_CHART_ZOOM_IN)) { ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); Rectangle2D rect = info.getPlotInfo().getDataArea(); zoomBoth(rect.getCenterX(), rect.getCenterY(), ZOOM_FACTOR); } else if (acmd.equals(ACTION_CHART_ZOOM_OUT)) { ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo(); Rectangle2D rect = info.getPlotInfo().getDataArea(); zoomBoth(rect.getCenterX(), rect.getCenterY(), 1 / ZOOM_FACTOR); } else if (acmd.equals(ACTION_CHART_ZOOM_TO_FIT)) { // X-axis (has no fixed borders) chartPanel.autoRangeHorizontal(); Plot plot = chartPanel.getChart().getPlot(); if (plot instanceof ValueAxisPlot) { XYPlot vvPlot = (XYPlot) plot; ValueAxis axis = vvPlot.getRangeAxis(); if (axis != null) { axis.setLowerBound(yMin); axis.setUpperBound(yMax); } } } else if (acmd.equals(ACTION_CHART_EXPORT)) { try { chartPanel.doSaveAs(); } catch (IOException i) { MsgBox.error(i.getMessage()); } } else if (acmd.equals(ACTION_CHART_PRINT)) { chartPanel.createChartPrintJob(); } else if (acmd.equals(ACTION_CHART_PROPERTIES)) { ChartPropertyEditPanel panel = new ChartPropertyEditPanel(jFreeChart); int result = JOptionPane.showConfirmDialog(this, panel, localizationResources.getString("Chart_Properties"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { panel.updateChartProperties(jFreeChart); } } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
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//from w w w. ja va 2 s. c o m 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:org.jfree.chart.demo.CircleDrawer.java
/** * Draws the circle./*w w w . j a v a 2s . c o m*/ * * @param g2 the graphics device. * @param area the area in which to draw. */ public void draw(final Graphics2D g2, final Rectangle2D area) { final Ellipse2D ellipse = new Ellipse2D.Double(area.getX(), area.getY(), area.getWidth(), area.getHeight()); if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(ellipse); } if (this.outlinePaint != null && this.outlineStroke != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(ellipse); } g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1.0f)); final Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY()); final Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY()); g2.draw(line1); g2.draw(line2); }