List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.Invoke.java
/** * process : Do : Paint the specified XObject (section 4.7). * * @param operator The operator that is being executed. * @param arguments List//from www.jav a 2s. co m * @throws IOException If there is an error invoking the sub object. */ @Override public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context; PDPage page = extractor.getPage(); COSName objectName = (COSName) arguments.get(0); Map<String, PDXObject> xobjects = extractor.getResources().getXObjects(); PDXObject xobject = (PDXObject) xobjects.get(objectName.getName()); if (xobject == null) { LOG.warn("Can't find the XObject for '" + objectName.getName() + "'"); } else if (xobject instanceof PDXObjectImage) { PDXObjectImage image = (PDXObjectImage) xobject; try { if (image.getImageMask()) { // set the current non stroking colorstate, so that it can // be used to create a stencil masked image image.setStencilColor(extractor.getGraphicsState().getNonStrokingColor()); } BufferedImage awtImage = image.getRGBImage(); if (awtImage == null) { LOG.warn("getRGBImage returned NULL"); return;//TODO PKOCH } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = extractor.getPageSize().getHeight(); LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight); Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix(); float yScaling = ctm.getYScale(); float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale()); if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) { angle = (-1) * angle; } ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling)); ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling)); // because of the moved 0,0-reference, we have to shear in the opposite direction ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1)); ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0)); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); extractor.drawImage(awtImage, ctmAT); } catch (Exception e) { LOG.error(e, e); } } else if (xobject instanceof PDXObjectForm) { // save the graphics state context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone()); PDXObjectForm form = (PDXObjectForm) xobject; COSStream formContentstream = form.getCOSStream(); // find some optional resources, instead of using the current resources PDResources pdResources = form.getResources(); // if there is an optional form matrix, we have to map the form space to the user space Matrix matrix = form.getMatrix(); if (matrix != null) { Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix()); context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM); } if (form.getBBox() != null) { PDGraphicsState graphicsState = context.getGraphicsState(); PDRectangle bBox = form.getBBox(); float x1 = bBox.getLowerLeftX(); float y1 = bBox.getLowerLeftY(); float x2 = bBox.getUpperRightX(); float y2 = bBox.getUpperRightY(); Point2D p0 = extractor.transformedPoint(x1, y1); Point2D p1 = extractor.transformedPoint(x2, y1); Point2D p2 = extractor.transformedPoint(x2, y2); Point2D p3 = extractor.transformedPoint(x1, y2); GeneralPath bboxPath = new GeneralPath(); bboxPath.moveTo((float) p0.getX(), (float) p0.getY()); bboxPath.lineTo((float) p1.getX(), (float) p1.getY()); bboxPath.lineTo((float) p2.getX(), (float) p2.getY()); bboxPath.lineTo((float) p3.getX(), (float) p3.getY()); bboxPath.closePath(); Area resultClippingArea = new Area(graphicsState.getCurrentClippingPath()); Area newArea = new Area(bboxPath); resultClippingArea.intersect(newArea); graphicsState.setCurrentClippingPath(resultClippingArea); } getContext().processSubStream(page, pdResources, formContentstream); // restore the graphics state context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop()); } }
From source file:net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler.java
/** * Handle PRESSED, DRAGGED, RELEASED events to generate drag diff events * // w ww .j a va 2s.c o m * @return */ private Consumer<ChartGestureEvent> createConsumer() { return new Consumer<ChartGestureEvent>() { // variables boolean wasMouseZoomable = false; Point2D last = null, first = null; ChartGestureEvent startEvent = null, lastEvent = null; @Override public void accept(ChartGestureEvent event) { ChartViewWrapper chartPanel = event.getChartWrapper(); JFreeChart chart = chartPanel.getChart(); MouseEventWrapper e = event.getMouseEvent(); // released? if (event.checkEvent(Event.RELEASED)) { chartPanel.setMouseZoomable(wasMouseZoomable); last = null; } else if (event.checkEvent(Event.PRESSED)) { // get data space coordinates last = chartPanel.mouseXYToPlotXY(e.getX(), e.getY()); first = last; startEvent = event; lastEvent = event; if (last != null) { wasMouseZoomable = chartPanel.isMouseZoomable(); chartPanel.setMouseZoomable(false); } } else if (event.checkEvent(Event.DRAGGED)) { if (last != null) { // get data space coordinates Point2D released = chartPanel.mouseXYToPlotXY(e.getX(), e.getY()); if (released != null) { double offset = 0; double start = 0; // scroll x if (getOrientation(event).equals(Orientation.HORIZONTAL)) { offset = -(released.getX() - last.getX()); start = first.getX(); } // scroll y else { offset = -(released.getY() - last.getY()); start = first.getY(); } // new dragdiff event ChartGestureDragDiffEvent dragEvent = new ChartGestureDragDiffEvent(startEvent, lastEvent, event, start, offset, orient); // scroll / zoom / do anything with this new event // choose handler by key filter for (int i = 0; i < dragDiffHandler.length; i++) if (key[i].filter(event.getMouseEvent())) dragDiffHandler[i].accept(dragEvent); // set last event lastEvent = event; // save updated last last = chartPanel.mouseXYToPlotXY(e.getX(), e.getY()); } } } } }; }
From source file:org.jax.maanova.plot.MaanovaChartPanel.java
/** * Convert the given point in java2d coordinates to chart coordinates. * @param java2DPoint the point to convert * @return the converted point/*from w w w . ja v a 2 s . c om*/ * @throws ClassCastException the plot isn't an XYPlot */ public Point2D toChartPoint(Point2D java2DPoint) throws ClassCastException { XYPlot plot = this.getChart().getXYPlot(); Rectangle2D dataArea = this.chartRenderingInfo.getPlotInfo().getDataArea(); double graphX = plot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea, plot.getDomainAxisEdge()); double graphY = plot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea, plot.getRangeAxisEdge()); return new Point2D.Double(graphX, graphY); }
From source file:util.ModSpringLayout.java
protected void calculateRepulsion() { try {//from w w w . j a va 2 s . c o m for (V v : getGraph().getVertices()) { if (isLocked(v)) { continue; } SpringVertexData svd = springVertexData.get(v); if (svd == null) { continue; } double dx = 0, dy = 0; for (V v2 : getGraph().getVertices()) { if (v == v2) { continue; } Point2D p = transform(v); Point2D p2 = transform(v2); if (p == null || p2 == null) { continue; } double vx = p.getX() - p2.getX(); double vy = p.getY() - p2.getY(); double distanceSq = p.distanceSq(p2); if (distanceSq == 0) { dx += Math.random(); dy += Math.random(); } else if (distanceSq < repulsion_range_sq) { double factor = 1; dx += factor * vx / distanceSq; dy += factor * vy / distanceSq; } } double dlen = dx * dx + dy * dy; if (dlen > 0) { dlen = Math.sqrt(dlen) / 2; svd.repulsiondx += dx / dlen; svd.repulsiondy += dy / dlen; } } } catch (ConcurrentModificationException cme) { calculateRepulsion(); } }
From source file:org.owasp.benchmark.score.report.ScatterVulns.java
private void makeDataLabels(String category, Set<Report> toolResults, XYPlot xyplot) { HashMap<Point2D, String> map = makePointList(category, toolResults); 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); if (label.toCharArray()[0] == averageLabel) { annotation.setPaint(Color.magenta); } else { annotation.setPaint(Color.blue); }//from w ww .j av a2 s. c o m annotation.setFont(theme.getRegularFont()); xyplot.addAnnotation(annotation); } } }
From source file:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java
/** * {@inheritDoc}/*w w w . j av a 2 s . c o m*/ * Mode.PICKING : Move node & edge * Mode.EDITING : Add node & edge * Mode.TRANSFORMING : Move graph layout */ @Override public void mousePressed(MouseEvent e) { before.clear(); //System.out.println("Before map cleared"); if (!mode.equals(Mode.EDITING)) { @SuppressWarnings("unchecked") final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource(); final Point2D p = e.getPoint(); final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout(); final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport(); if (pickSupport != null) { final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY()); final CEdge edge = pickSupport.getEdge(layout, p.getX(), p.getY()); if (mode.equals(Mode.TRANSFORMING)) { if (vertex != null || edge != null) { setMode(Mode.PICKING); vv.setCursor(Cursor.getPredefinedCursor(12)); } if ((vertex == null && edge == null) && (e.isShiftDown())) { setMode(Mode.PICKING); vv.setCursor(Cursor.getPredefinedCursor(12)); } } else if (mode.equals(Mode.PICKING) && !e.isShiftDown()) { if (vertex == null && edge == null) { setMode(Mode.TRANSFORMING); } } //Final choosen mode is transforming ! -> Deselect all nodes if (mode.equals(Mode.TRANSFORMING)) { commandDispatcher.dispatch(new DeselectAllCommand()); } //Save initial positions if (mode.equals(Mode.PICKING)) { if (vertex != null) { saveInitialPositionOfPickedNodes(vv); } } } } //will call either : // - CadralEditingGraphMousePlugin.mousePressed(e) // - CadralPickingGraphMousePlugin.mousePressed(e) super.mousePressed(e); //System.out.println("Coords clicked : " + e.getPoint()); }
From source file:org.kalypso.model.wspm.tuhh.ui.chart.layers.PointMarkerLayer.java
@Override public final void executeDrop(final Point point, final EditInfo dragStartData) { final IProfilePointMarker draggedDevider = (IProfilePointMarker) dragStartData.getData(); if (draggedDevider == null) return;//from w ww.j av a 2s.c o m final IProfile profil = getProfil(); final Point2D numPoint = ProfilLayerUtils.toNumeric(getCoordinateMapper(), point); if (numPoint == null) return; final IProfileRecord profilPoint = draggedDevider.getPoint(); final IProfileRecord newPoint = ProfileVisitors.findNearestPoint(profil, numPoint.getX()); if (newPoint == profilPoint) return; final IProfilePointMarker[] deviders = profil.getPointMarkerFor(profilPoint); final IProfilePointMarker[] targetDeviders = profil.getPointMarkerFor(newPoint); for (final IProfilePointMarker devider : deviders) { // BUGIFX: prohibit that a marker is moved on another marker of the same type, which // will incidentally remove it if (movesOnSameDeviderType(devider, targetDeviders)) { continue; } if (devider.getComponent().getId().equals(getTargetComponent().getId())) { moveDevider(devider, newPoint); } } }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartCanvas.java
public void dispatchMouseMovedEvent(Point2D point, MouseEvent e) { double x = point.getX(); double y = point.getY(); ChartEntity entity = this.info.getEntityCollection().getEntity(x, y); ChartMouseEventFX event = new ChartMouseEventFX(this.chart, e, entity); for (ChartMouseListenerFX listener : this.chartMouseListeners) { listener.chartMouseMoved(event); }//from www.ja va 2 s . c om }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartCanvas.java
public void dispatchMouseClickedEvent(Point2D point, MouseEvent e) { double x = point.getX(); double y = point.getY(); ChartEntity entity = this.info.getEntityCollection().getEntity(x, y); ChartMouseEventFX event = new ChartMouseEventFX(this.chart, e, entity); for (ChartMouseListenerFX listener : this.chartMouseListeners) { listener.chartMouseClicked(event); }/*from ww w.j a v a2 s . c o m*/ }
From source file:edu.uci.ics.jung.algorithms.layout.SpringLayout.java
protected void moveNodes() { synchronized (getSize()) { try {/*from w ww . j a v a2s .c o m*/ for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = springVertexData.get(v); if (vd == null) continue; Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY()); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }