List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:de.erdesignerng.visual.jgraph.JGraphEditor.java
@Override public void commandCreateView(View aView, Point2D aLocation) { ViewCell theCell = new ViewCell(aView); theCell.transferPropertiesToAttributes(aView); Object theTargetCell = graph.getFirstCellForLocation(aLocation.getX(), aLocation.getY()); if (theTargetCell instanceof SubjectAreaCell) { SubjectAreaCell theSACell = (SubjectAreaCell) theTargetCell; SubjectArea theArea = (SubjectArea) theSACell.getUserObject(); theArea.getViews().add(aView);//w ww. j ava2s. c o m theSACell.add(theCell); } theCell.setBounds(new Rectangle2D.Double(aLocation.getX(), aLocation.getY(), -1, -1)); graph.getGraphLayoutCache().insert(theCell); theCell.transferAttributesToProperties(theCell.getAttributes()); graph.doLayout(); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void mouseDragged(MouseEvent event) { try {//from w ww . ja v a 2 s. c om if (this.panStartPoint != null) { Rectangle2D scaledDataArea = this.chartPanel.getScaledDataArea(); this.panStartPoint = RefineryUtilities.getPointInRectangle(this.panStartPoint.getX(), this.panStartPoint.getY(), scaledDataArea); Point2D panEndPoint = RefineryUtilities.getPointInRectangle(event.getX(), event.getY(), scaledDataArea); // horizontal pan Plot plot = this.chartPanel.getChart().getPlot(); if (plot instanceof XYPlot) { XYPlot hvp = (XYPlot) plot; ValueAxis xAxis = hvp.getDomainAxis(); if (xAxis != null) { double translatedStartPoint = xAxis.java2DToValue((float) panStartPoint.getX(), scaledDataArea, hvp.getDomainAxisEdge()); double translatedEndPoint = xAxis.java2DToValue((float) panEndPoint.getX(), scaledDataArea, hvp.getDomainAxisEdge()); double dX = translatedStartPoint - translatedEndPoint; double oldMin = xAxis.getLowerBound(); double newMin = oldMin + dX; double oldMax = xAxis.getUpperBound(); double newMax = oldMax + dX; // do not pan out of range if (newMin >= hvp.getDataRange(xAxis).getLowerBound() && newMax <= hvp.getDataRange(xAxis).getUpperBound()) { xAxis.setLowerBound(newMin); xAxis.setUpperBound(newMax); } } } // vertical pan (1. Y-Axis) if (plot instanceof XYPlot) { XYPlot vvp = (XYPlot) plot; ValueAxis yAxis = vvp.getRangeAxis(); if (yAxis != null) { double translatedStartPoint = yAxis.java2DToValue((float) panStartPoint.getY(), scaledDataArea, vvp.getRangeAxisEdge()); double translatedEndPoint = yAxis.java2DToValue((float) panEndPoint.getY(), scaledDataArea, vvp.getRangeAxisEdge()); double dY = translatedStartPoint - translatedEndPoint; double oldMin = yAxis.getLowerBound(); double newMin = oldMin + dY; double oldMax = yAxis.getUpperBound(); double newMax = oldMax + dY; // do not pan out of range if (newMin >= yMin && newMax <= yMax) { yAxis.setLowerBound(newMin); yAxis.setUpperBound(newMax); } } } // for the next time this.panStartPoint = panEndPoint; } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
From source file:org.mwc.cmap.grideditor.chart.DataPointsDragTracker.java
public void chartMouseMoved(final ChartMouseEvent event) { if (!myDragSubject.isEmpty()) { myChartPanel.forgetZoomPoints(); // Rectangle clientArea = myChartPanel.getClientArea(); // int screenX = event.getTrigger().getX() - clientArea.x; // int screenY = event.getTrigger().getY() - clientArea.y; // [IM] don't bother with sorting out the client area offset // - we've stopped using it in the FixedChartComposite calling method final int screenX = event.getTrigger().getX(); final int screenY = event.getTrigger().getY(); // deliberately switch axes for following line, now that we've switched // the axes to put time // down the LH side. final Point2D point2d = new Point2D.Double(screenY, screenX); final XYPlot xyplot = myChartPanel.getChart().getXYPlot(); final ChartRenderingInfo renderingInfo = myChartPanel.getChartRenderingInfo(); Rectangle2D dataArea = renderingInfo.getPlotInfo().getDataArea(); // WORKAROUND: when the grid graph gets really wide, the labels on the // y-axis get stretched. // but, the dataArea value doesn't reflect this. // So, get the width values from the getScreenDataArea method - which // does reflect the scaling applied to the y axis. // - and all works well now. final Rectangle dataArea2 = myChartPanel.getScreenDataArea(); dataArea = new Rectangle2D.Double(dataArea2.x, dataArea.getY(), dataArea2.width, dataArea.getHeight()); final ValueAxis domainAxis = xyplot.getDomainAxis(); final RectangleEdge domainEdge = xyplot.getDomainAxisEdge(); final ValueAxis valueAxis = xyplot.getRangeAxis(); final RectangleEdge valueEdge = xyplot.getRangeAxisEdge(); double domainX = domainAxis.java2DToValue(point2d.getX(), dataArea, domainEdge); final double domainY = valueAxis.java2DToValue(point2d.getY(), dataArea, valueEdge); if (myAllowVerticalMovesOnly) { domainX = myDragSubject.getDraggedItem().getXValue(); }// www .j a v a 2 s.c o m if (!myDragSubject.isEmpty()) myDragSubject.setProposedValues(domainX, domainY); myChartPanel.redrawCanvas(); } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java
@Override public Document createDiagram() { init();/* w w w .j a va2 s . 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:de.erdesignerng.visual.jgraph.JGraphEditor.java
@Override public void commandCreateComment(Comment aComment, Point2D aLocation) { CommentCell theCell = new CommentCell(aComment); theCell.transferPropertiesToAttributes(aComment); Object theTargetCell = graph.getFirstCellForLocation(aLocation.getX(), aLocation.getY()); if (theTargetCell instanceof SubjectAreaCell) { SubjectAreaCell theSACell = (SubjectAreaCell) theTargetCell; SubjectArea theArea = (SubjectArea) theSACell.getUserObject(); theArea.getComments().add(aComment); theSACell.add(theCell);/* ww w . j ava 2s .c om*/ } theCell.setBounds(new Rectangle2D.Double(aLocation.getX(), aLocation.getY(), -1, -1)); graph.getGraphLayoutCache().insert(theCell); theCell.transferAttributesToProperties(theCell.getAttributes()); graph.doLayout(); }
From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java
private void compute(final Mask selectedMask) { final RasterDataNode raster = getRaster(); final AttributeDescriptor dataField = scatterPlotModel.dataField; if (raster == null || dataField == null) { return;/*from w ww . ja v a2 s. c o m*/ } SwingWorker<ComputedData[], Object> swingWorker = new SwingWorker<ComputedData[], Object>() { @Override protected ComputedData[] doInBackground() throws Exception { BeamLogManager.getSystemLogger().finest("start computing scatter plot data"); final List<ComputedData> computedDataList = new ArrayList<>(); final FeatureCollection<SimpleFeatureType, SimpleFeature> collection = scatterPlotModel.pointDataSource .getFeatureCollection(); final SimpleFeature[] features = collection.toArray(new SimpleFeature[collection.size()]); final int boxSize = scatterPlotModel.boxSize; final Rectangle sceneRect = new Rectangle(raster.getSceneRasterWidth(), raster.getSceneRasterHeight()); final GeoCoding geoCoding = raster.getGeoCoding(); final AffineTransform imageToModelTransform; imageToModelTransform = ImageManager.getImageToModelTransform(geoCoding); for (SimpleFeature feature : features) { final Point point = (Point) feature.getDefaultGeometryProperty().getValue(); Point2D modelPos = new Point2D.Float((float) point.getX(), (float) point.getY()); final Point2D imagePos = imageToModelTransform.inverseTransform(modelPos, null); if (!sceneRect.contains(imagePos)) { continue; } final float imagePosX = (float) imagePos.getX(); final float imagePosY = (float) imagePos.getY(); final Rectangle imageRect = sceneRect.intersection(new Rectangle( ((int) imagePosX) - boxSize / 2, ((int) imagePosY) - boxSize / 2, boxSize, boxSize)); if (imageRect.isEmpty()) { continue; } final double[] rasterValues = new double[imageRect.width * imageRect.height]; raster.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height, rasterValues); final int[] maskBuffer = new int[imageRect.width * imageRect.height]; Arrays.fill(maskBuffer, 1); if (selectedMask != null) { selectedMask.readPixels(imageRect.x, imageRect.y, imageRect.width, imageRect.height, maskBuffer); } final int centerIndex = imageRect.width * (imageRect.height / 2) + (imageRect.width / 2); if (maskBuffer[centerIndex] == 0) { continue; } double sum = 0; double sumSqr = 0; int n = 0; boolean valid = false; for (int y = 0; y < imageRect.height; y++) { for (int x = 0; x < imageRect.width; x++) { final int index = y * imageRect.height + x; if (raster.isPixelValid(x + imageRect.x, y + imageRect.y) && maskBuffer[index] != 0) { final double rasterValue = rasterValues[index]; sum += rasterValue; sumSqr += rasterValue * rasterValue; n++; valid = true; } } } if (!valid) { continue; } double rasterMean = sum / n; double rasterSigma = n > 1 ? Math.sqrt((sumSqr - (sum * sum) / n) / (n - 1)) : 0.0; String localName = dataField.getLocalName(); Number attribute = (Number) feature.getAttribute(localName); final Collection<org.opengis.feature.Property> featureProperties = feature.getProperties(); final float correlativeData = attribute.floatValue(); final GeoPos geoPos = new GeoPos(); if (geoCoding.canGetGeoPos()) { final PixelPos pixelPos = new PixelPos(imagePosX, imagePosY); geoCoding.getGeoPos(pixelPos, geoPos); } else { geoPos.setInvalid(); } computedDataList.add(new ComputedData(imagePosX, imagePosY, geoPos.getLat(), geoPos.getLon(), (float) rasterMean, (float) rasterSigma, correlativeData, featureProperties)); } return computedDataList.toArray(new ComputedData[computedDataList.size()]); } @Override public void done() { try { final ValueAxis xAxis = getPlot().getDomainAxis(); final ValueAxis yAxis = getPlot().getRangeAxis(); xAxis.setAutoRange(false); yAxis.setAutoRange(false); scatterpointsDataset.removeAllSeries(); acceptableDeviationDataset.removeAllSeries(); regressionDataset.removeAllSeries(); getPlot().removeAnnotation(r2Annotation); computedDatas = null; final ComputedData[] data = get(); if (data.length == 0) { return; } computedDatas = data; final XYIntervalSeries scatterValues = new XYIntervalSeries(getCorrelativeDataName()); for (ComputedData computedData : computedDatas) { final float rasterMean = computedData.rasterMean; final float rasterSigma = computedData.rasterSigma; final float correlativeData = computedData.correlativeData; scatterValues.add(correlativeData, correlativeData, correlativeData, rasterMean, rasterMean - rasterSigma, rasterMean + rasterSigma); } computingData = true; scatterpointsDataset.addSeries(scatterValues); xAxis.setAutoRange(true); yAxis.setAutoRange(true); xAxis.setAutoRange(false); yAxis.setAutoRange(false); xAutoRangeAxisRange = new Range(xAxis.getLowerBound(), xAxis.getUpperBound()); yAutoRangeAxisRange = new Range(yAxis.getLowerBound(), yAxis.getUpperBound()); if (xAxisRangeControl.isAutoMinMax()) { xAxisRangeControl.adjustComponents(xAxis, 3); } else { xAxisRangeControl.adjustAxis(xAxis, 3); } if (yAxisRangeControl.isAutoMinMax()) { yAxisRangeControl.adjustComponents(yAxis, 3); } else { yAxisRangeControl.adjustAxis(yAxis, 3); } computeRegressionAndAcceptableDeviationData(); computingData = false; } catch (InterruptedException | CancellationException e) { BeamLogManager.getSystemLogger().log(Level.WARNING, "Failed to compute correlative plot.", e); JOptionPane.showMessageDialog(getParentDialogContentPane(), "Failed to compute correlative plot.\n" + "Calculation canceled.", /*I18N*/ CHART_TITLE, /*I18N*/ JOptionPane.ERROR_MESSAGE); } catch (ExecutionException e) { BeamLogManager.getSystemLogger().log(Level.WARNING, "Failed to compute correlative plot.", e); JOptionPane.showMessageDialog(getParentDialogContentPane(), "Failed to compute correlative plot.\n" + "An error occurred:\n" + e.getCause().getMessage(), CHART_TITLE, /*I18N*/ JOptionPane.ERROR_MESSAGE); } } }; swingWorker.execute(); }
From source file:de.erdesignerng.visual.jgraph.JGraphEditor.java
@Override public void commandCreateTable(Table aTable, Point2D aLocation) { TableCell theImportingCell = new TableCell(aTable); theImportingCell.transferPropertiesToAttributes(aTable); Object theTargetCell = graph.getFirstCellForLocation(aLocation.getX(), aLocation.getY()); if (theTargetCell instanceof SubjectAreaCell) { SubjectAreaCell theSACell = (SubjectAreaCell) theTargetCell; SubjectArea theArea = (SubjectArea) theSACell.getUserObject(); theArea.getTables().add(aTable); theSACell.add(theImportingCell); }/*w ww . ja va 2 s.c om*/ theImportingCell.setBounds(new Rectangle2D.Double(aLocation.getX(), aLocation.getY(), -1, -1)); graph.getGraphLayoutCache().insert(theImportingCell); theImportingCell.transferAttributesToProperties(theImportingCell.getAttributes()); graph.doLayout(); }
From source file:convcao.com.caoAgent.convcaoNeptusInteraction.java
@Override public void paint(Graphics2D g, StateRenderer2D renderer) { Point2D center = renderer.getScreenPosition(coords.squareCenter); double width = renderer.getZoom() * coords.cellWidth * coords.numCols; double height = renderer.getZoom() * coords.cellWidth * coords.numRows; g.setColor(new Color(0, 0, 255, 64)); g.translate(center.getX(), center.getY()); g.rotate(-renderer.getRotation());/*from w w w . jav a 2 s .c o m*/ g.fill(new Rectangle2D.Double(-width / 2, -height / 2, width, height)); g.rotate(renderer.getRotation()); g.translate(-center.getX(), -center.getY()); if (!active) return; g.setColor(Color.orange); int pos = 50; for (String v : nameTable.values()) { g.drawString(v + ": " + depths.get(v) + "m", 15, pos); pos += 20; } for (String vehicle : nameTable.values()) { LocationType src = positions.get(vehicle); LocationType dst = destinations.get(vehicle); if (!arrived.get(vehicle)) g.setColor(Color.red.darker()); else g.setColor(Color.green.darker()); float dash[] = { 4.0f }; g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash, 0.0f)); g.draw(new Line2D.Double(renderer.getScreenPosition(src), renderer.getScreenPosition(dst))); Point2D dstPt = renderer.getScreenPosition(dst); if (!arrived.get(vehicle)) g.setColor(Color.red.darker()); else g.setColor(Color.green.darker()); g.fill(new Ellipse2D.Double(dstPt.getX() - 4, dstPt.getY() - 4, 8, 8)); } }
From source file:at.tuwien.ifs.somtoolbox.apps.viewer.MapPNode.java
public GeneralUnitPNode getGeneralUnitPNodeAtPos(Point2D p) { if (unitsNode.getFullBounds().contains(p)) { int xPos = (int) Math.floor(p.getX() / getUnitWidth()); int yPos = (int) Math.floor(p.getY() / getUnitHeight()); return getUnit(xPos, yPos); } else {//from ww w.j a v a 2 s .c o m return null; } }
From source file:dk.dma.epd.common.prototype.notification.MsiNmNotification.java
/** * Returns if the MSI-NM is close the the new route * * NB: This code was from the old MsiLayer. Should be optimized! * * @param route the new route//from w w w . j a v a2s .c o m * @param mousePosition the mouse position * @param projection the projection * @return if the MSI-NM is close the the new route */ public boolean nearNewRoute(Route route, Position mousePosition, Projection projection) { double visibilityFromNewWaypoint = EPD.getInstance().getSettings().getEnavSettings() .getMsiVisibilityFromNewWaypoint(); // Check if MSI messages should be visible on route. boolean visibleOnRoute = false; // Go through each waypoint of the route to check if the MSI message should be visible. for (int i = 0; !visibleOnRoute && i < route.getWaypoints().size(); i++) { RouteWaypoint rWaypoint = route.getWaypoints().get(i); Point2D pointA = null; Point2D pointB = null; Point2D pnt; // If the waypoint is not the last placed waypoint compare it to the next in line. // Else compare it to the mouse location. if (rWaypoint == route.getWaypoints().getLast()) { pointA = projection.forward(rWaypoint.getPos().getLatitude(), rWaypoint.getPos().getLongitude()); pointB = projection.forward(mousePosition.getLatitude(), mousePosition.getLongitude()); } else if (rWaypoint != route.getWaypoints().getLast()) { RouteWaypoint nWaypoint = route.getWaypoints().get(i + 1); pointA = projection.forward(rWaypoint.getPos().getLatitude(), rWaypoint.getPos().getLongitude()); pointB = projection.forward(nWaypoint.getPos().getLatitude(), nWaypoint.getPos().getLongitude()); } // The slope of the line. double slope = Math.round(((pointB.getY() - pointA.getY()) / (pointB.getX() - pointA.getX())) * visibilityFromNewWaypoint); // If the value of slope is more than the value of visibilityFromNewWaypoint, // change the slop reverse the x and y axis. if (Math.abs(slope) > visibilityFromNewWaypoint) { double dy = Math.abs(pointB.getY() - pointA.getY()); slope = Math.round(((pointB.getX() - pointA.getX()) / (pointB.getY() - pointA.getY())) * visibilityFromNewWaypoint); for (int j = 0; j * visibilityFromNewWaypoint < dy; j++) { pnt = pointA; // The first point should be placed a point where the mouse was clicked. if (j == 0) { visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); continue; } //Mouse placed on the right side of the last placed waypoint. if (pointA.getX() <= pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() + slope, pointA.getY() + visibilityFromNewWaypoint); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() + posSlope, pointA.getY() - visibilityFromNewWaypoint); } // mouse placed on the left side. } else if (pointA.getX() > pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() - slope, pointA.getY() - visibilityFromNewWaypoint); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() - posSlope, pointA.getY() + visibilityFromNewWaypoint); } } // Handles placing of point on a vertical line. if (pointA.getY() < pointB.getY() && slope == 0) { pnt.setLocation(pointA.getX(), pointA.getY() + visibilityFromNewWaypoint); } else if (pointA.getY() > pointB.getY() && slope == 0) { pnt.setLocation(pointA.getX(), pointA.getY() - visibilityFromNewWaypoint); } visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); } } else { double dx = Math.abs(pointB.getX() - pointA.getX()); for (int j = 0; j * visibilityFromNewWaypoint < dx; j++) { pnt = pointA; if (j == 0) { visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); continue; } // Mouse placed on the right side of the last placed waypoint. if (pointA.getX() <= pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY() + slope); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY() - posSlope); } // Mouse placed on the left side of the last placed waypoint. } else if (pointA.getX() > pointB.getX()) { if (slope > 0) { pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY() - slope); } else if (slope < 0) { double posSlope = Math.abs(slope); pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY() + posSlope); } } if (pointA.getX() < pointB.getX() && slope == 0) { pnt.setLocation(pointA.getX() + visibilityFromNewWaypoint, pointA.getY()); } else if (pointA.getX() > pointB.getX() && slope == 0) { pnt.setLocation(pointA.getX() - visibilityFromNewWaypoint, pointA.getY()); } visibleOnRoute = setMessageVisible(visibilityFromNewWaypoint, visibleOnRoute, projection, pnt); } } } return visibleOnRoute; }