List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:org.owasp.benchmark.score.report.Scatter.java
private void makeDataLabels(OverallResults or, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(or); for (Entry<Point2D, String> e : map.entrySet()) { if (e.getValue() != null) { Point2D p = e.getKey(); String label = sort(e.getValue()); XYTextAnnotation annotation = new XYTextAnnotation(label, p.getX(), p.getY()); annotation.setTextAnchor(p.getX() < 3 ? TextAnchor.TOP_LEFT : TextAnchor.TOP_CENTER); annotation.setBackgroundPaint(Color.white); annotation.setPaint(Color.blue); annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); }/* w ww. ja v a 2s .co m*/ } }
From source file:org.apache.fop.render.pdf.PDFDocumentHandler.java
/** {@inheritDoc} */ public void startPage(int index, String name, String pageMasterName, Dimension size) throws IFException { this.pdfResources = this.pdfDoc.getResources(); PageBoundaries boundaries = new PageBoundaries(size, getContext().getForeignAttributes()); Rectangle trimBox = boundaries.getTrimBox(); Rectangle bleedBox = boundaries.getBleedBox(); Rectangle mediaBox = boundaries.getMediaBox(); Rectangle cropBox = boundaries.getCropBox(); // set scale attributes double scaleX = 1; double scaleY = 1; String scale = (String) getContext().getForeignAttribute(PageScale.EXT_PAGE_SCALE); Point2D scales = PageScale.getScale(scale); if (scales != null) { scaleX = scales.getX(); scaleY = scales.getY();//from ww w . j a v a 2 s .c o m } //PDF uses the lower left as origin, need to transform from FOP's internal coord system AffineTransform boxTransform = new AffineTransform(scaleX / 1000, 0, 0, -scaleY / 1000, 0, scaleY * size.getHeight() / 1000); this.currentPage = this.pdfDoc.getFactory().makePage(this.pdfResources, index, toPDFCoordSystem(mediaBox, boxTransform), toPDFCoordSystem(cropBox, boxTransform), toPDFCoordSystem(bleedBox, boxTransform), toPDFCoordSystem(trimBox, boxTransform)); if (accessEnabled) { logicalStructureHandler.startPage(currentPage); } pdfUtil.generatePageLabel(index, name); currentPageRef = new PageReference(currentPage, size); this.pageReferences.put(Integer.valueOf(index), currentPageRef); this.generator = new PDFContentGenerator(this.pdfDoc, this.outputStream, this.currentPage); // Transform the PDF's default coordinate system (0,0 at lower left) to the PDFPainter's AffineTransform basicPageTransform = new AffineTransform(1, 0, 0, -1, 0, (scaleY * size.height) / 1000f); basicPageTransform.scale(scaleX, scaleY); generator.saveGraphicsState(); generator.concatenate(basicPageTransform); }
From source file:inet.CalculationNetworkEditor.visual.control.listener.BothGraphActions.java
public void relocateVertexes() { Layout<V, E> layout = visViewBoth.getGraphLayout(); Collection<V> physical = logic.getAllVertOfType(IStorage.Type.PHYSICAL); for (V phy : physical) { Collection<V> mapping = logic.getVertexStack(phy); for (V visual : visualPhysicalV.keySet()) { if (visualPhysicalV.get(visual) == phy) { mapping.add(visual);/* w ww. j a v a 2 s . c om*/ } } Point2D pAct = layout.transform(phy); for (V mapped : mapping) { if (!mapped.equals(phy)) { // all vertices of mapping but the phisical vertex pAct.setLocation(pAct.getX() + mapDistance, pAct.getY() + mapDistance); layout.setLocation(mapped, pAct); } } } //printLocationOfAllVertices(); }
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
/** * Convert display to world-coordinates. * // ww w . j a va2s. co m * @param dc * @param wc * @return world coordinates */ public Point2D dc2wc(final Point2D dc, Point2D wc) { try { wc = wc_mat.inverseTransform(dc, wc); wc.setLocation(wc.getX() / SCALE, wc.getY() / SCALE); return wc; } catch (NoninvertibleTransformException e) { throw new RuntimeException("Why uninvertible?", e); } }
From source file:org.jfree.chart.demo.ScatterPlotDemo3.java
/** * Callback method for receiving notification of a mouse click on a chart. * * @param event information about the event. *//* w ww . ja v a 2 s . com*/ public void chartMouseClicked(ChartMouseEvent event) { int x = event.getTrigger().getX(); int y = event.getTrigger().getY(); // the following translation takes account of the fact that the chart image may // have been scaled up or down to fit the panel... Point2D p = chartPanel.translateScreenToJava2D(new Point(x, y)); // now convert the Java2D coordinate to axis coordinates... XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); double xx = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge()); double yy = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge()); // just for fun, lets convert the axis coordinates back to component coordinates... double xxx = plot.getDomainAxis().valueToJava2D(xx, dataArea, plot.getDomainAxisEdge()); double yyy = plot.getRangeAxis().valueToJava2D(yy, dataArea, plot.getRangeAxisEdge()); Point2D p2 = chartPanel.translateJava2DToScreen(new Point2D.Double(xxx, yyy)); System.out .println("Mouse coordinates are (" + x + ", " + y + "), in data space = (" + xx + ", " + yy + ")."); System.out.println("--> (" + p2.getX() + ", " + p2.getY() + ")"); }
From source file:ru.jcorp.smartstreets.gui.map.MapEditor.java
public void saveMap() { Dimension size = graphLayout.getSize(); mapContext.getMap().setHeight(size.height); mapContext.getMap().setWidth(size.width); // preprocess positions for (GraphNode node : graphModel.getVertices()) { Point2D point = graphLayout.transform(node); node.getMapNode().setX(point.getX()); node.getMapNode().setY(point.getY()); }//from ww w.ja va2 s . com mapContext.commit(); }
From source file:net.sf.mzmine.modules.visualization.scatterplot.scatterplotchart.ScatterPlotRenderer.java
/** * Draws an item label./*from w ww. ja v a 2s . c o m*/ * * @param g2 * the graphics device. * @param orientation * the orientation. * @param dataset * the dataset. * @param series * the series index (zero-based). * @param item * the item index (zero-based). * @param x * the x coordinate (in Java2D space). * @param y * the y coordinate (in Java2D space). * @param negative * indicates a negative value (which affects the item label * position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); String label = generator.generateLabel(dataset, series, item); if ((label == null) || (label.length() == 0)) return; // get the label position.. 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(), x, y, orientation); FontMetrics metrics = g2.getFontMetrics(labelFont); int width = SwingUtilities.computeStringWidth(metrics, label) + 2; int height = metrics.getHeight(); int X = (int) (anchorPoint.getX() - (width / 2)); int Y = (int) (anchorPoint.getY() - (height)); g2.setPaint(searchColor); g2.fillRect(X, Y, width, height); super.drawItemLabel(g2, orientation, dataset, series, item, x, y, negative); }
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
/** * Convert world- to display coordinates. * // w w w. j a v a 2 s .c om * @param wc * @param dc * @return display coordinates */ public Point2D wc2dc(final Point2D wc, Point2D dc) { if (dc == null) dc = new Point2D.Float(); dc.setLocation(wc.getX() * SCALE, wc.getY() * SCALE); return wc_mat.transform(dc, dc); }
From source file:edu.uci.ics.jung.visualization.VisualizationViewer.java
/** * called by the superclass to display tooltips */// www .j av a2s. co m public String getToolTipText(MouseEvent event) { Layout<V, E> layout = getGraphLayout(); Point2D p = null; if (vertexToolTipTransformer != null) { p = event.getPoint(); //renderContext.getBasicTransformer().inverseViewTransform(event.getPoint()); V vertex = getPickSupport().getVertex(layout, p.getX(), p.getY()); if (vertex != null) { return vertexToolTipTransformer.transform(vertex); } } if (edgeToolTipTransformer != null) { if (p == null) p = renderContext.getMultiLayerTransformer().inverseTransform(Layer.VIEW, event.getPoint()); E edge = getPickSupport().getEdge(layout, p.getX(), p.getY()); if (edge != null) { return edgeToolTipTransformer.transform(edge); } } if (mouseEventToolTipTransformer != null) { return mouseEventToolTipTransformer.transform(event); } return super.getToolTipText(event); }
From source file:org.nuxeo.pdf.service.PDFTransformationServiceImpl.java
@Override public Blob applyImageWatermark(Blob input, Blob watermark, WatermarkProperties properties) { // Set up the graphic state to handle transparency // Define a new extended graphic state PDExtendedGraphicsState extendedGraphicsState = new PDExtendedGraphicsState(); // Set the transparency/opacity extendedGraphicsState.setNonStrokingAlphaConstant((float) properties.getAlphaColor()); try (PDDocument pdfDoc = PDDocument.load(input.getStream())) { BufferedImage image = ImageIO.read(watermark.getStream()); PDXObjectImage ximage = new PDPixelMap(pdfDoc, image); for (Object o : pdfDoc.getDocumentCatalog().getAllPages()) { PDPage page = (PDPage) o;// www .j a v a2 s. c om PDRectangle pageSize = page.findMediaBox(); PDResources resources = page.findResources(); // Get the defined graphic states. HashMap<String, PDExtendedGraphicsState> graphicsStateDictionary = (HashMap<String, PDExtendedGraphicsState>) resources .getGraphicsStates(); if (graphicsStateDictionary != null) { graphicsStateDictionary.put("TransparentState", extendedGraphicsState); resources.setGraphicsStates(graphicsStateDictionary); } else { Map<String, PDExtendedGraphicsState> m = new HashMap<>(); m.put("TransparentState", extendedGraphicsState); resources.setGraphicsStates(m); } try (PDPageContentStream contentStream = new PDPageContentStream(pdfDoc, page, true, true)) { contentStream.appendRawCommands("/TransparentState gs\n"); contentStream.endMarkedContentSequence(); double watermarkWidth = ximage.getWidth() * properties.getScale(); double watermarkHeight = ximage.getHeight() * properties.getScale(); Point2D position = computeTranslationVector(pageSize.getWidth(), watermarkWidth, pageSize.getHeight(), watermarkHeight, properties); contentStream.drawXObject(ximage, (float) position.getX(), (float) position.getY(), (float) watermarkWidth, (float) watermarkHeight); } } return saveInTempFile(pdfDoc); } catch (COSVisitorException | IOException e) { throw new NuxeoException(e); } }