List of usage examples for java.awt.geom Rectangle2D getX
public abstract double getX();
From source file:KIDLYRenderer.java
/** * Calculates the item label anchor point. * * @param anchor the anchor./* w w w . j ava2s . c o m*/ * @param bar the bar. * @param orientation the plot orientation. * * @return The anchor point. */ private Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor, Rectangle2D bar, PlotOrientation orientation) { Point2D result = null; double offset = getItemLabelAnchorOffset(); double x0 = bar.getX() - offset; double x1 = bar.getX(); double x2 = bar.getX() + offset; double x3 = bar.getCenterX(); double x4 = bar.getMaxX() - offset; double x5 = bar.getMaxX(); double x6 = bar.getMaxX() + offset; double y0 = bar.getMaxY() + offset; double y1 = bar.getMaxY(); double y2 = bar.getMaxY() - offset; double y3 = bar.getCenterY(); double y4 = bar.getMinY() + offset; double y5 = bar.getMinY(); double y6 = bar.getMinY() - offset; if (anchor == ItemLabelAnchor.CENTER) { result = new Point2D.Double(x3, y3); } else if (anchor == ItemLabelAnchor.INSIDE1) { result = new Point2D.Double(x4, y4); } else if (anchor == ItemLabelAnchor.INSIDE2) { result = new Point2D.Double(x4, y4); } else if (anchor == ItemLabelAnchor.INSIDE3) { result = new Point2D.Double(x4, y3); } else if (anchor == ItemLabelAnchor.INSIDE4) { result = new Point2D.Double(x4, y2); } else if (anchor == ItemLabelAnchor.INSIDE5) { result = new Point2D.Double(x4, y2); } else if (anchor == ItemLabelAnchor.INSIDE6) { result = new Point2D.Double(x3, y2); } else if (anchor == ItemLabelAnchor.INSIDE7) { result = new Point2D.Double(x2, y2); } else if (anchor == ItemLabelAnchor.INSIDE8) { result = new Point2D.Double(x2, y2); } else if (anchor == ItemLabelAnchor.INSIDE9) { result = new Point2D.Double(x2, y3); } else if (anchor == ItemLabelAnchor.INSIDE10) { result = new Point2D.Double(x2, y4); } else if (anchor == ItemLabelAnchor.INSIDE11) { result = new Point2D.Double(x2, y4); } else if (anchor == ItemLabelAnchor.INSIDE12) { result = new Point2D.Double(x3, y4); } else if (anchor == ItemLabelAnchor.OUTSIDE1) { result = new Point2D.Double(x5, y6); } else if (anchor == ItemLabelAnchor.OUTSIDE2) { result = new Point2D.Double(x6, y5); } else if (anchor == ItemLabelAnchor.OUTSIDE3) { result = new Point2D.Double(x6, y3); } else if (anchor == ItemLabelAnchor.OUTSIDE4) { result = new Point2D.Double(x6, y1); } else if (anchor == ItemLabelAnchor.OUTSIDE5) { result = new Point2D.Double(x5, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE6) { result = new Point2D.Double(x3, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE7) { result = new Point2D.Double(x1, y0); } else if (anchor == ItemLabelAnchor.OUTSIDE8) { result = new Point2D.Double(x0, y1); } else if (anchor == ItemLabelAnchor.OUTSIDE9) { result = new Point2D.Double(x0, y3); } else if (anchor == ItemLabelAnchor.OUTSIDE10) { result = new Point2D.Double(x0, y5); } else if (anchor == ItemLabelAnchor.OUTSIDE11) { result = new Point2D.Double(x1, y6); } else if (anchor == ItemLabelAnchor.OUTSIDE12) { result = new Point2D.Double(x3, y6); } return result; }
From source file:ec.ui.view.RevisionSaSeriesView.java
private void showSelectionPopup(Rectangle2D rectangle) { XYPlot plot = chartpanel_.getChart().getXYPlot(); Rectangle2D dataArea = chartpanel_.getScreenDataArea(); DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); double minX = domainAxis.java2DToValue(rectangle.getMinX(), dataArea, plot.getDomainAxisEdge()); double maxX = domainAxis.java2DToValue(rectangle.getMaxX(), dataArea, plot.getDomainAxisEdge()); Date startDate = new Date((long) minX); Date endDate = new Date((long) maxX); TsPeriod start = new TsPeriod(firstPeriod.getFrequency(), startDate); TsPeriod end = new TsPeriod(firstPeriod.getFrequency(), endDate); if (end.minus(start) == 0) { return;/*w w w . j a v a 2s .co m*/ } TsPeriodSelector sel = new TsPeriodSelector(); sel.between(start.firstday(), end.lastday()); List<TsData> listSeries = history_.Select(info_, startDate, endDate); List<TsData> revSeries = new ArrayList<>(); for (TsData t : listSeries) { revSeries.add(t.select(sel)); } Point pt = new Point((int) rectangle.getX(), (int) rectangle.getY()); pt.translate(3, 3); SwingUtilities.convertPointToScreen(pt, chartpanel_); popup.setLocation(pt); popup.setChartTitle(info_.toUpperCase() + " First estimations"); popup.setTsData(sRef.select(sel), revSeries); popup.setVisible(true); chartpanel_.repaint(); }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * @param selection ./* w ww.jav a 2s. c om*/ * @return range[] rangos del rectangulo */ public Range[] getRange(Rectangle2D selection) { Range[] rangos = new Range[2]; // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D( new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY()); if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) { double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight(); double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight(); Plot p = this.chart.getPlot(); if (p instanceof ScatterPlotChart) { ScatterPlotChart z = (ScatterPlotChart) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { rangos[0] = z.getRangeX(vLower, vUpper, plotInfo, selectOrigin); rangos[1] = z.getRangeY(hLower, hUpper, plotInfo, selectOrigin); } else { // devolver las coordenadas del rectangulo. rangos[0] = z.getRangeX(hLower, hUpper, plotInfo, selectOrigin); rangos[1] = z.getRangeY(vLower, vUpper, plotInfo, selectOrigin); } } } return rangos; }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * Draw an image at the indicated location. * @param uri the URI/URL of the image/*from w w w . j a va 2s . c om*/ * @param pos the position of the image * @param foreignAttributes an optional Map with foreign attributes, may be null */ protected void drawImage(String uri, Rectangle2D pos, Map foreignAttributes) { uri = URISpecification.getURL(uri); Rectangle posInt = new Rectangle((int) pos.getX(), (int) pos.getY(), (int) pos.getWidth(), (int) pos.getHeight()); Point origin = new Point(currentIPPosition, currentBPPosition); int x = origin.x + posInt.x; int y = origin.y + posInt.y; ImageManager manager = getUserAgent().getFactory().getImageManager(); ImageInfo info = null; try { ImageSessionContext sessionContext = getUserAgent().getImageSessionContext(); info = manager.getImageInfo(uri, sessionContext); //Only now fully load/prepare the image Map hints = ImageUtil.getDefaultHints(sessionContext); org.apache.xmlgraphics.image.loader.Image img = manager.getImage(info, FLAVORS, hints, sessionContext); //...and process the image if (img instanceof ImageGraphics2D) { ImageGraphics2D imageG2D = (ImageGraphics2D) img; RendererContext context = createRendererContext(posInt.x, posInt.y, posInt.width, posInt.height, foreignAttributes); getGraphics2DAdapter().paintImage(imageG2D.getGraphics2DImagePainter(), context, x, y, posInt.width, posInt.height); } else if (img instanceof ImageRendered) { ImageRendered imgRend = (ImageRendered) img; RenderedImage ri = imgRend.getRenderedImage(); setCursorPos(x, y); gen.paintBitmap(ri, new Dimension(posInt.width, posInt.height), false); } else if (img instanceof ImageXMLDOM) { ImageXMLDOM imgXML = (ImageXMLDOM) img; renderDocument(imgXML.getDocument(), imgXML.getRootNamespace(), pos, foreignAttributes); } else { throw new UnsupportedOperationException("Unsupported image type: " + img); } } catch (ImageException ie) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageError(this, (info != null ? info.toString() : uri), ie, null); } catch (FileNotFoundException fe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageNotFound(this, (info != null ? info.toString() : uri), fe, null); } catch (IOException ioe) { ResourceEventProducer eventProducer = ResourceEventProducer.Provider .get(getUserAgent().getEventBroadcaster()); eventProducer.imageIOError(this, (info != null ? info.toString() : uri), ioe, null); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java
@Override public Document createDiagram() { init();/*from ww w .j ava2s .c o m*/ if (informationFlowOptions.isUseNamesLegend()) { setVisioNamesLegend(new VisioNamesLegend(this.getTargetPage())); } setColorDimension(createColorDimension(informationFlowOptions.getColorOptionsBean(), TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE)); lineDimension = createLineDimension(informationFlowOptions.getLineOptionsBean(), TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE); lineCaptionSelected = informationFlowOptions.getSelectionType(); lineCaptionAttributeId = informationFlowOptions.getLineCaptionSelectedAttributeId(); addMissingParentNodes(); addResultNodes(); groupNodes(); for (GXLNode node : GXLUtil.getNodes(graph)) { setIsrNodeTexts(node); } addEdges(); try { LOGGER.debug("trying to add graph to gxl2visio converter"); List<LayoutOperation> layoutOperations = determineLayoutOperations(); Rectangle2D graphAreaBounds = visioDocumentCreator.addGraph(graph, layoutOperations); // correct the position of the bounding box, since it's returned incorrectly by the "addGraph"-method graphAreaBounds.setRect(0, 0, graphAreaBounds.getWidth(), graphAreaBounds.getHeight()); Shape title = createDiagramTitle( MessageAccess.getStringOrNull("graphicalExport.informationflow.title", getLocale())); List<Shape> queryInfo = createQueryInfo(graphAreaBounds); Rectangle2D legendsBox = createLegends(graphAreaBounds); setTitlePos(graphAreaBounds, title, queryInfo); setQueryInfoPos(queryInfo, title.getPinX(), title.getPinY() - getQueryInfoHeight(queryInfo)); Point2D adjustment = adjustPage(graphAreaBounds, title, queryInfo, legendsBox); legendsBox = new Rectangle2D.Double(legendsBox.getX() + adjustment.getX(), legendsBox.getY() + adjustment.getY(), legendsBox.getWidth(), legendsBox.getHeight()); createGeneratedInformation(this.getTargetPage().getWidth()); createLogos(0, 0, this.getTargetPage().getWidth(), this.getTargetPage().getHeight()); if (informationFlowOptions.isUseNamesLegend()) { createNamesLegend(legendsBox); } } catch (GraphStructureException gex) { throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR, gex); } catch (MasterNotFoundException e) { throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR, e); } return visioDocumentCreator.getDocument(); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
/** * Draws the object.// w ww . j a va2s. c o m * * @param graphics * the graphics device. * @param area * the area inside which the object should be drawn. */ public void draw(final Graphics2D graphics, final Rectangle2D area) { final Graphics2D g2 = (Graphics2D) graphics.create(); if (isDrawPageBackground()) { g2.setPaint(Color.white); g2.fill(area); } g2.translate(-area.getX(), -area.getY()); try { final StrictBounds pageBounds = StrictGeomUtility.createBounds(area.getX(), area.getY(), area.getWidth(), area.getHeight()); this.pageArea = pageBounds; this.drawArea = pageBounds; this.graphics = g2; if (startBlockBox(rootBox)) { processRootBand(pageBounds); } finishBlockBox(rootBox); } finally { this.graphics = null; this.drawArea = null; g2.dispose(); } }
From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java
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;/*from www . j a v a2s . c om*/ } 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 GradientPaint) { itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); double x0 = bar.getMinX(); double x1 = x0 + getXOffset(); double x2 = bar.getMaxX(); double x3 = x2 + getXOffset(); double y0 = bar.getMinY() - getYOffset(); double y1 = bar.getMinY(); double y2 = bar.getMaxY() - getYOffset(); double y3 = bar.getMaxY(); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; 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) { g2.setPaint(((Color) itemPaint).darker()); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(), gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()), bar3dRight)); } g2.fill(bar3dRight); } bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); bar3dTop.lineTo((float) x1, (float) y0); bar3dTop.lineTo((float) x3, (float) y0); bar3dTop.lineTo((float) x2, (float) y1); bar3dTop.closePath(); 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 (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:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java
@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;//from w w w .j a v a 2 s . com } 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 GradientPaint) { itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar); } g2.setPaint(itemPaint); g2.fill(bar); double x0 = bar.getMinX(); double x1 = x0 + getXOffset(); double x2 = bar.getMaxX(); double x3 = x2 + getXOffset(); double y0 = bar.getMinY() - getYOffset(); double y1 = bar.getMinY(); double y2 = bar.getMaxY() - getYOffset(); double y3 = bar.getMaxY(); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; 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) { g2.setPaint(((Color) itemPaint).darker()); } else if (itemPaint instanceof GradientPaint) { GradientPaint gp = (GradientPaint) itemPaint; g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(), gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()), bar3dRight)); } g2.fill(bar3dRight); } bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); bar3dTop.lineTo((float) x1, (float) y0); bar3dTop.lineTo((float) x3, (float) y0); bar3dTop.lineTo((float) x2, (float) y1); bar3dTop.closePath(); 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 (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:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Is mouse on top axis//ww w . j av a 2 s . c om * * @param mouseEvent the event * * @return On top axis */ private boolean isOnTopDomainAxis(MouseEvent mouseEvent) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); if (mouseEvent.getX() < dataArea.getX()) { return false; } if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) { return false; } double top = dataArea.getY(); return mouseEvent.getY() <= top + 20; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Is mouse on bottom axis/* ww w . j ava 2 s . c o m*/ * * @param mouseEvent the event * * @return on bottom axis */ private boolean isOnBottomDomainAxis(MouseEvent mouseEvent) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); if (mouseEvent.getX() < dataArea.getX()) { return false; } if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) { return false; } double bottom = dataArea.getY() + dataArea.getHeight(); return mouseEvent.getY() >= bottom - 20; }