List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:gov.nih.nci.caintegrator.application.graphing.BoxAndWhiskerDotsRenderer.java
/** * Draws two dots to represent the average value of more than one outlier. * //from w ww . j a va2s.co m * @param point the location * @param boxWidth the box width. * @param oRadius the radius. * @param g2 the graphics device. */ private void drawMultipleEllipse(Point2D point, double boxWidth, double oRadius, Graphics2D g2) { Ellipse2D dot1 = new Ellipse2D.Double(point.getX() - (boxWidth / 2) + oRadius, point.getY(), oRadius, oRadius); Ellipse2D dot2 = new Ellipse2D.Double(point.getX() + (boxWidth / 2), point.getY(), oRadius, oRadius); g2.draw(dot1); g2.draw(dot2); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphAction.java
/** * Add the action listener to the graph. *///from w ww . j a v a 2 s. com private void setAction() { gui.pnlGraph.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(final ChartMouseEvent e) { if (e.getEntity() instanceof PlotEntity) { Point2D p = gui.pnlGraph.translateScreenToJava2D(e.getTrigger().getPoint()); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); DateAxis rangeAxis = (DateAxis) plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); CategoryAxis catAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); double chartY = rangeAxis.java2DToValue(p.getX(), plotArea, rangeAxisEdge); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int categoryCount = categories.getColumnCount(); for (int i = 0; i < categoryCount; i++) { double catStart = catAxis.getCategoryStart(i, categoryCount, plotArea, domainAxisEdge); double catEnd = catAxis.getCategoryEnd(i, categoryCount, plotArea, domainAxisEdge); if (e.getTrigger().getY() >= catStart && e.getTrigger().getY() < catEnd) { new EditAvailabilityController(gui.function, gui.function.getWorkers().get(i), new Day(new Date((long) chartY)), parent); } } } else { CategoryItemEntity item = (CategoryItemEntity) e.getEntity(); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); DateAxis dateAxis = (DateAxis) plot.getRangeAxis(); double d = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX(), plotArea, rangeAxisEdge); double d2 = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX() + e.getEntity().getArea().getBounds2D().getWidth(), plotArea, rangeAxisEdge); Date startDate = new Date((long) d); Date endDate = new Date((long) d2); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int workerIndex = categories.getColumnIndex(item.getColumnKey()); Worker worker = gui.function.getWorkers().get(workerIndex); Set<Availability> found = CalendarService.getAllWorkerAvailability(worker.getId(), startDate, endDate); Availability foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { found = CalendarService.getProjectAvailability(startDate, endDate); foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { JOptionPane.showMessageDialog( new JFrame(LocalizedStrings.getGeneralStrings().warning()), LocalizedStrings.getErrorMessages().availabilityCanNotBeChanged()); } } } } @Override public void chartMouseMoved(final ChartMouseEvent arg0) { } }); /** * ActionListener */ gui.btnNext.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.increment(); } }); /** * ActionListener */ gui.btnPrev.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.decrement(); } }); for (int i = 0; i < gui.buttons.length; i++) { addButtonListener(i); } /** * ActionListener */ gui.btnManualAv.addItemListener(new ItemListener() { @Override public void itemStateChanged(final ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { gui.function.setManualAv(true); } else { gui.function.setManualAv(false); } } }); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void mouseDragged(MouseEvent e) { // when not allowed to zoom / select, return if (blockSelectionOrZoom) { return;// ww w .ja va 2 s. c o m } // if the popup menu has already been triggered, then ignore dragging... if (getChartFieldValueByName("popup") != null && ((JPopupMenu) getChartFieldValueByName("popup")).isShowing()) { return; } // handle panning if we have a start point if (getChartFieldValueByName("panLast") != null) { double dx = e.getX() - ((Point) getChartFieldValueByName("panLast")).getX(); double dy = e.getY() - ((Point) getChartFieldValueByName("panLast")).getY(); if (dx == 0.0 && dy == 0.0) { return; } double wPercent = -dx / ((Double) getChartFieldValueByName("panW")); double hPercent = dy / ((Double) getChartFieldValueByName("panH")); boolean old = getChart().getPlot().isNotify(); getChart().getPlot().setNotify(false); Pannable p = (Pannable) getChart().getPlot(); if (p.getOrientation() == PlotOrientation.VERTICAL) { p.panDomainAxes(wPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); p.panRangeAxes(hPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); } else { p.panDomainAxes(hPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); p.panRangeAxes(wPercent, getChartRenderingInfo().getPlotInfo(), (Point) getChartFieldValueByName("panLast")); } setChartFieldValue((getChartFieldByName("panLast")), e.getPoint()); getChart().getPlot().setNotify(old); return; } // if no initial zoom point was set, ignore dragging... if (getChartFieldValueByName("zoomPoint") == null) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // erase the previous zoom rectangle (if any). We only need to do // this is we are using XOR mode, which we do when we're not using // the buffer (if there is a buffer, then at the end of this method we // just trigger a repaint) if (!(Boolean) getChartFieldValueByName("useBuffer")) { drawZoomRectangle(g2, true); } boolean hZoom = false; boolean vZoom = false; if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) { hZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); vZoom = (Boolean) getChartFieldValueByName("domainZoomable"); } else { hZoom = (Boolean) getChartFieldValueByName("domainZoomable"); vZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); } Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint"); Rectangle2D scaledDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY()); if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(), zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY())); } else if (hZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(), scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight())); } else if (vZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(), ymax - zoomPoint.getY())); } // Draw the new zoom rectangle... if ((Boolean) getChartFieldValueByName("useBuffer")) { repaint(); } else { // with no buffer, we use XOR to draw the rectangle "over" the // chart... drawZoomRectangle(g2, true); } g2.dispose(); }
From source file:org.squidy.designer.model.PipeShape.java
public void initialize() { if (pipe == null) { if (LOG.isErrorEnabled()) { LOG.error("Could not initialize PipeShape without a pipe instance. Removing from parent."); }/*from ww w .j a va2s.c om*/ return; } visualization = new VisualizationShape(this); visualization.setScale(0.5); addChild(visualization); // ShapeUtils.setApparent(visualization, false); pipe.addProcessingFeedback(visualization); flowIncoming = new DataTypeShape(pipe.getInputTypes()); flowIncoming.setScale(0.1); addChild(flowIncoming); // ShapeUtils.setApparent(flowIncoming, false); flowOutgoing = new DataTypeShape(pipe.getOutputTypes()); flowOutgoing.setScale(0.1); addChild(flowOutgoing); // ShapeUtils.setApparent(flowOutgoing, false); final PropertyChangeListener changeListener = new PropertyChangeListener() { /* * (non-Javadoc) * * * @seejava.beans.PropertyChangeListener#propertyChange(java. * beans. PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() != null) { setBounds(computeBounds()); positionVisualization(); } } }; addPropertyChangeListener(PNode.PROPERTY_PARENT, changeListener); source.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, changeListener); target.addPropertyChangeListener(PNode.PROPERTY_FULL_BOUNDS, changeListener); pipe.addStatusChangeListener(Processable.STATUS_PROCESSABLE_DELETED, new PropertyChangeListener() { /* * (non-Javadoc) * * @see * java.beans.PropertyChangeListener#propertyChange(java * .beans.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent evt) { if (source != null) { source.removePropertyChangeListener(changeListener); } if (target != null) { target.removePropertyChangeListener(changeListener); } removeFromParent(); } }); addInputEventListener(new PBasicInputEventHandler() { /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseEntered * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseEntered(PInputEvent event) { super.mouseEntered(event); // ShapeUtils.setApparent(visualization, true); // ShapeUtils.setApparent(flowIncoming, true); // ShapeUtils.setApparent(flowOutgoing, true); } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseExited( * edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseExited(PInputEvent event) { super.mouseExited(event); // ShapeUtils.setApparent(visualization, false); // ShapeUtils.setApparent(flowIncoming, false); // ShapeUtils.setApparent(flowOutgoing, false); } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mousePressed * (edu.umd.cs.piccolo. event.PInputEvent) */ @Override public void mousePressed(PInputEvent event) { super.mousePressed(event); if (!event.isHandled()) { Point2D p = event.getPosition(); double x = p.getX(); double y = p.getY(); // Check intersection based on mouse position (5 pixel // around // position) // Rectangle2D rectangle = globalToLocal(new // Rectangle2D.Double(x, y, 100 * getGlobalScale(), // 100 * getGlobalScale())); // if (shape.intersects(rectangle)) { event.getInputManager().setKeyboardFocus(event.getPath()); // // if (event.isRightMouseButton()) { // globalToLocal(p); // System.out.println("Do you wan't to create a bendpoint at x=" // + p.getX() + " / y=" // + p.getY() + "?"); // } event.setHandled(true); // } } // PNode nextNode = event.getPath().nextPickedNode(); // if (nextNode != null) { // EventListenerList listenerList = nextNode.getListenerList(); // // if (listenerList != null) { // PBasicInputEventHandler[] listeners = // listenerList.getListeners(PBasicInputEventHandler.class); // for (PBasicInputEventHandler listener : listeners) { // listener.mousePressed(event); // } // } // } } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#keyboardFocusGained * (edu.umd.cs.piccolo .event.PInputEvent) */ @Override public void keyboardFocusGained(PInputEvent event) { super.keyboardFocusGained(event); selected = true; moveToFront(); invalidatePaint(); } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#keyboardFocusLost * (edu.umd.cs.piccolo .event.PInputEvent) */ @Override public void keyboardFocusLost(PInputEvent event) { super.keyboardFocusLost(event); selected = false; invalidatePaint(); } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#keyPressed(edu * .umd.cs.piccolo.event .PInputEvent) */ @Override public void keyPressed(PInputEvent event) { super.keyPressed(event); if (KeyEvent.VK_DELETE == event.getKeyCode()) { // DrawingArea drawingArea = (DrawingArea) // event.getCamera().getComponent(); // drawingArea.removeEdge(Edge.this); if (LOG.isDebugEnabled()) { LOG.debug("Backspace has been pressed. Trigger deletion of edge?"); } pipe.delete(); Manager.get().notify(getPipe(), Action.DELETE); } } }); }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private static void drawArrowToDestination(final Graphics2D gfx, final Rectangle2D start, final Rectangle2D destination, final Stroke lineStroke, final Stroke arrowStroke, final float arrowSize) { final double startx = start.getCenterX(); final double starty = start.getCenterY(); final Point2D arrowPoint = Utils.findRectEdgeIntersection(destination, startx, starty); if (arrowPoint != null) { gfx.setStroke(arrowStroke);// w w w . j a v a 2s . co m double angle = findLineAngle(arrowPoint.getX(), arrowPoint.getY(), startx, starty); final double arrowAngle = Math.PI / 12.0d; final double x1 = arrowSize * Math.cos(angle - arrowAngle); final double y1 = arrowSize * Math.sin(angle - arrowAngle); final double x2 = arrowSize * Math.cos(angle + arrowAngle); final double y2 = arrowSize * Math.sin(angle + arrowAngle); final double cx = (arrowSize / 2.0f) * Math.cos(angle); final double cy = (arrowSize / 2.0f) * Math.sin(angle); final GeneralPath polygon = new GeneralPath(); polygon.moveTo(arrowPoint.getX(), arrowPoint.getY()); polygon.lineTo(arrowPoint.getX() + x1, arrowPoint.getY() + y1); polygon.lineTo(arrowPoint.getX() + x2, arrowPoint.getY() + y2); polygon.closePath(); gfx.fill(polygon); gfx.setStroke(lineStroke); gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx), (int) (arrowPoint.getY() + cy)); } }
From source file:sc.fiji.kappa.gui.KappaMenuBar.java
public void saveCurveFile(File file) { try {/*from w ww. j a v a 2 s. c o m*/ PrintWriter out = new PrintWriter(new FileWriter(file)); out.println(frame.getCurves().size()); for (Curve c : frame.getCurves()) { // Outputs the curve properties: it's type, the number of keyframes, the number // of control points, etc. if (c instanceof BSpline) { out.println(KappaFrame.B_SPLINE); } else { out.println(KappaFrame.BEZIER_CURVE); } out.println(c.getNoKeyframes()); // Print out the correct number of control points depending on the curve type. if (c instanceof BSpline && !((BSpline) c).isOpen()) { out.println(c.getNoCtrlPts() - BSpline.B_SPLINE_DEGREE); } else { out.println(c.getNoCtrlPts()); } if (c instanceof BSpline) { if (((BSpline) c).isOpen()) { out.println(BSpline.OPEN); } else { out.println(BSpline.CLOSED); } } // Writes the control points and what keyframe they are at for each curve. for (Curve.BControlPoints b : c.getKeyframes()) { out.println(b.t); // If it's a closed B-Spline, we don't output the last redundant points that // make it closed if (c instanceof BSpline && !((BSpline) c).isOpen()) { for (int i = 0; i < b.defPoints.length - BSpline.B_SPLINE_DEGREE; i++) { Point2D p = b.defPoints[i]; out.println(p.getX()); out.println(p.getY()); } } // Otherwise, we output all the points else { for (Point2D p : b.defPoints) { out.println(p.getX()); out.println(p.getY()); } } } } out.close(); } catch (Exception err) { frame.getOverlay().setVisible(true); frame.getOverlay().drawNotification("There was an error saving the curve data", frame.getScrollPane().getVisibleRect()); } }
From source file:com.projity.pm.graphic.xbs.XbsLayout.java
protected void updateBounds(int level, Point2D origin, Rectangle2D ref) {//cache in current version isn't a tree double y = origin.getY() + ref.getHeight() / 2 + ref.getMaxY() * (level - 1); Point2D childCenter, center; double x0, x1; GraphicNode node, child;//w w w.jav a2 s.c o m boolean hasChild; for (ListIterator i = cache.getIterator(); i.hasNext();) { node = (GraphicNode) i.next(); if (node.getLevel() == level) { x0 = -1; x1 = -1; hasChild = false; while (i.hasNext()) { child = (GraphicNode) i.next(); if (child.getLevel() <= level) { i.previous(); break; } else if (child.getLevel() == level + 1) { hasChild = true; childCenter = child.getXbsCenter(); if (x0 == -1 || childCenter.getX() < x0) x0 = childCenter.getX(); if (x1 == -1 || childCenter.getX() > x1) x1 = childCenter.getX(); dependencies.add(new GraphicDependency(node, child, null)); } } if (hasChild) setShape(node, ref, (x0 + x1) / 2, y); } } }
From source file:pipeline.parameter_cell_views.FloatRangeSlider.java
void moveIntervalEdgeToMousePosition(MouseEvent e) { if (!trackingChartMouseDrag) return; // is this necessary? if (silenceUpdate) return;/*from w ww . j a v a 2 s . c o m*/ Point2D chartCoordinates = getChartCoordinates(e); if (chartCoordinates == null) { return; } if (markerIntervalEdgeSelected == 0) { // prevent the minimum and maximum from sliding past each other if (chartCoordinates.getX() > selectionRange.getEndValue()) return; currentValue0 = (float) chartCoordinates.getX(); } else { // prevent the minimum and maximum from sliding past each other if (chartCoordinates.getX() < selectionRange.getStartValue()) return; currentValue1 = (float) chartCoordinates.getX(); } }
From source file:de.fhg.igd.mapviewer.BasicMapKit.java
private Rectangle2D generateBoundingRect(double minX, double minY, double maxX, double maxY, int epsg, int zoom) throws IllegalGeoPositionException { java.awt.geom.Point2D p1 = getMainMap().getTileFactory().getTileProvider().getConverter() .geoToPixel(new GeoPosition(minX, minY, epsg), zoom); java.awt.geom.Point2D p2 = getMainMap().getTileFactory().getTileProvider().getConverter() .geoToPixel(new GeoPosition(maxX, maxY, epsg), zoom); return new Rectangle2D.Double((p1.getX() < p2.getX()) ? (p1.getX()) : (p2.getX()), (p1.getY() < p2.getY()) ? (p1.getY()) : (p2.getY()), Math.abs(p2.getX() - p1.getX()), Math.abs(p2.getY() - p1.getY())); }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java
public void createSignatureRectangle(PDSignatureField signatureField, PDFAsVisualSignatureDesigner properties, float degrees) throws IOException { PDRectangle rect = new PDRectangle(); Point2D upSrc = new Point2D.Float(); upSrc.setLocation(properties.getxAxis() + properties.getWidth(), properties.getPageHeight() - properties.getyAxis()); Point2D llSrc = new Point2D.Float(); llSrc.setLocation(properties.getxAxis(), properties.getPageHeight() - properties.getyAxis() - properties.getHeight()); rect.setUpperRightX((float) upSrc.getX()); rect.setUpperRightY((float) upSrc.getY()); rect.setLowerLeftY((float) llSrc.getY()); rect.setLowerLeftX((float) llSrc.getX()); logger.debug("orig rectangle of signature has been created: {}", rect.toString()); AffineTransform transform = new AffineTransform(); transform.setToIdentity();/* w w w. ja va2s. c o m*/ if (degrees % 360 != 0) { transform.setToRotation(Math.toRadians(degrees), llSrc.getX(), llSrc.getY()); } Point2D upDst = new Point2D.Float(); transform.transform(upSrc, upDst); Point2D llDst = new Point2D.Float(); transform.transform(llSrc, llDst); float xPos = properties.getxAxis(); float yPos = properties.getPageHeight() - properties.getyAxis(); logger.debug("POS {} x {}", xPos, yPos); logger.debug("SIZE {} x {}", properties.getWidth(), properties.getHeight()); // translate according to page! rotation int pageRotation = properties.getPageRotation(); AffineTransform translate = new AffineTransform(); switch (pageRotation) { case 90: translate.setToTranslation( properties.getPageHeight() - (properties.getPageHeight() - properties.getyAxis()) - properties.getxAxis() + properties.getHeight(), properties.getxAxis() + properties.getHeight() - (properties.getPageHeight() - properties.getyAxis())); break; case 180: // translate.setToTranslation(properties.getPageWidth() - // properties.getxAxis() - properties.getxAxis(), // properties.getPageHeight() - properties.getyAxis() + // properties.getHeight()); translate.setToTranslation(properties.getPageWidth() - 2 * xPos, properties.getPageHeight() - 2 * (yPos - properties.getHeight())); break; case 270: translate.setToTranslation(-properties.getHeight() + yPos - xPos, properties.getPageWidth() - (yPos - properties.getHeight()) - xPos); break; } translate.transform(upDst, upDst); translate.transform(llDst, llDst); rect.setUpperRightX((float) upDst.getX()); rect.setUpperRightY((float) upDst.getY()); rect.setLowerLeftY((float) llDst.getY()); rect.setLowerLeftX((float) llDst.getX()); logger.debug("rectangle of signature has been created: {}", rect.toString()); signatureField.getWidget().setRectangle(rect); getStructure().setSignatureRectangle(rect); logger.debug("rectangle of signature has been created"); }