List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override public void mouseMoved(MouseEvent e) { Insets insets = getInsets();//w w w . ja v a2 s. c o m int x = (int) ((e.getX() - insets.left) / getScaleX()); int y = (int) ((e.getY() - insets.top) / getScaleY()); ChartEntity entity = null; if (getChartRenderingInfo() != null) { EntityCollection entities = getChartRenderingInfo().getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); // boolean isDirty = false; int seriesIndex = -1; if (selectedSeriesIndex >= 0) { // double xInChart = ChartMaskingUtilities.translateScreenX(x, // getScreenDataArea(), getChart()); // XYDataset dataset = getChart().getXYPlot().getDataset(); // PatternDataset patternDataset = (PatternDataset) dataset; // int itemIndex = patternDataset.getItemFromX(selectedSeriesIndex, xInChart); // if (itemIndex < patternDataset.getItemCount(selectedSeriesIndex)) { // chartX = patternDataset.getXValue(selectedSeriesIndex, itemIndex); // chartY = patternDataset.getYValue(selectedSeriesIndex, itemIndex); // Point2D axisTrace = ChartMaskingUtilities.translateChartPoint( // new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart()); // horizontalTraceLocation = (int) axisTrace.getX(); // verticalTraceLocation = (int) axisTrace.getY(); // if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) { // repaint(); // } // seriesIndex = selectedSeriesIndex; // isDirty = true; // } seriesIndex = followDomainTrace(selectedSeriesIndex, x); if (seriesIndex >= 0 && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) { repaint(); } } else if (getChart().getXYPlot().getSeriesCount() == 1) { // int seriesIndex0 = 0; // double xInChart = ChartMaskingUtilities.translateScreenX(x, // getScreenDataArea(), getChart()); // XYDataset dataset = getChart().getXYPlot().getDataset(); // PatternDataset patternDataset = (PatternDataset) dataset; // int itemIndex = patternDataset.getItemFromX(seriesIndex0, xInChart); // if (itemIndex < patternDataset.getItemCount(seriesIndex0)) { // chartX = patternDataset.getXValue(seriesIndex0, itemIndex); // chartY = patternDataset.getYValue(seriesIndex0, itemIndex); // Point2D axisTrace = ChartMaskingUtilities.translateChartPoint( // new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart()); //// if (getScreenDataArea().contains(axisTrace)) { // horizontalTraceLocation = (int) axisTrace.getX(); // verticalTraceLocation = (int) axisTrace.getY(); // if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) { // repaint(); // } // seriesIndex = seriesIndex0; // isDirty = true; //// } // } seriesIndex = followDomainTrace(0, x); if (seriesIndex >= 0 && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) { repaint(); } } else if (entity instanceof XYItemEntity) { XYItemEntity xyEntity = (XYItemEntity) entity; XYDataset dataset = xyEntity.getDataset(); int item = ((XYItemEntity) entity).getItem(); seriesIndex = xyEntity.getSeriesIndex(); double chartX = dataset.getXValue(seriesIndex, item); double chartY = dataset.getYValue(seriesIndex, item); Point2D screenPoint = ChartMaskingUtilities.translateChartPoint( new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart()); setChartX(chartX); setChartY(chartY); setSeriesIndex(seriesIndex); setItemIndex(item); if (dataset instanceof IXYErrorDataset) { setChartError(((IXYErrorDataset) dataset).getYError(seriesIndex, item)); } if (getHorizontalAxisTrace()) { setHorizontalTraceLocation((int) screenPoint.getX()); } if (getVerticalAxisTrace()) { setVerticalTraceLocation((int) screenPoint.getY()); } if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled()) { repaint(); } // isDirty = true; } if (seriesIndex >= 0) { Object[] listeners = getListeners(ChartMouseListener.class); if (getChart() != null) { XYChartMouseEvent event = new XYChartMouseEvent(getChart(), e, entity); event.setXY(getChartX(), getChartY()); event.setSeriesIndex(seriesIndex); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseMoved(event); } } } } // getChart().handleClick(x, y, getChartRenderingInfo()); } if (isInternalLegendEnabled && isInternalLegendSelected) { int cursorType = findCursorOnSelectedItem(e.getX(), e.getY()); setCursor(Cursor.getPredefinedCursor(cursorType)); } else if (getCursor() != defaultCursor) { setCursor(defaultCursor); } super.mouseMoved(e); // we can only generate events if the panel's chart is not null // (see bug report 1556951) }
From source file:org.gumtree.vis.awt.JChartPanel.java
private void drawTextInputBox(Graphics2D g2) { if (textInputFlag && textInputPoint != null) { // g2.drawChars("Input Text Here".toCharArray(), 1, 60, (int) textInputPoint.getX(), (int) textInputPoint.getY()); Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); String inputText = textInputContent == null ? "" : textInputContent; FontMetrics fm = g2.getFontMetrics(); // int sWidth; // if (textInputCursorIndex == 0 || inputText.length() == 0) { // sWidth = 0; // } else if (textInputCursorIndex < inputText.length()){ // sWidth = fm.stringWidth(inputText.substring(0, textInputCursorIndex)); // } else { // sWidth = fm.stringWidth(inputText); // } String[] lines = inputText.split("\n", 100); int cursorY = 0; int cursorX = 0; int charCount = 0; int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3 + i * 15); // charCount += lines[i].length() + 1; if (textInputCursorIndex > charCount && textInputCursorIndex < charCount + lines[i].length() + 1) { cursorY = i;/* w w w . j a va 2 s . co m*/ cursorX = fm.stringWidth(lines[i].substring(0, textInputCursorIndex - charCount)); } else if (textInputCursorIndex == charCount + lines[i].length() + 1) { cursorY = i + 1; cursorX = 0; } charCount += lines[i].length() + 1; int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; // g2.drawString(inputText, (int) textInputPoint.getX() + 3, (int) textInputPoint.getY() - 3); g2.setColor(Color.MAGENTA); // g2.drawString("|", (float) textInputPoint.getX() + 2 + sWidth, (float) textInputPoint.getY() - 3); g2.drawLine((int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + (cursorY - 1) * 15, (int) textInputPoint.getX() + 3 + cursorX, (int) textInputPoint.getY() + cursorY * 15); g2.setColor(Color.BLACK); g2.setColor(oldColor); // int boxWidth = fm.stringWidth(inputText) + 10; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(textInputPoint.getX(), textInputPoint.getY() - 15, maxWidth + 8, maxHeight); // ChartMaskingUtilities.drawMaskBoarder(g2, inputBox); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) textInputPoint.getX(), (int) textInputPoint.getY() - 15, maxWidth + 8, maxHeight); } if (textContentMap.size() > 0) { Color oldColor = g2.getColor(); g2.setColor(Color.BLACK); Rectangle2D imageArea = getScreenDataArea(); for (Entry<Rectangle2D, String> entry : textContentMap.entrySet()) { Rectangle2D rect = entry.getKey(); Point2D screenPoint = ChartMaskingUtilities .translateChartPoint(new Point2D.Double(rect.getX(), rect.getY()), imageArea, getChart()); String text = entry.getValue(); if (text == null) { continue; } String[] lines = text.split("\n"); g2.setColor(Color.BLACK); for (int i = 0; i < lines.length; i++) { g2.drawString(lines[i], (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3 + i * 15); } if (rect == selectedTextWrapper) { FontMetrics fm = g2.getFontMetrics(); int maxWidth = 0; int maxHeight = 0; for (int i = 0; i < lines.length; i++) { int lineWidth = fm.stringWidth(lines[i]); if (lineWidth > maxWidth) { maxWidth = lineWidth; } } maxHeight = 15 * lines.length; if (maxWidth < 100) { maxWidth = 100; } Rectangle2D inputBox = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15, maxWidth + 8, maxHeight); Color fillColor = new Color(250, 250, 50, 30); g2.setPaint(fillColor); g2.fill(inputBox); g2.setColor(Color.ORANGE); g2.drawRect((int) screenPoint.getX(), (int) screenPoint.getY() - 15, maxWidth + 8, maxHeight); } // g2.drawString(text == null ? "" : text, (int) screenPoint.getX() + 3, (int) screenPoint.getY() - 3); } g2.setColor(oldColor); } }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void mouseDragged(MouseEvent event) { try {//from www .jav a 2 s . co m 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:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java
/** * Finds the chart entity at the given co-ordinates. If the co-ordinates are * not within a given entity scrolls down(vertical plot) or left(plot * horizontal) until it is within the entity or outside the plot area. * /* w w w . j av a 2s . c om*/ * @param x * @param y * @return The entity at the co-ordinates. Returns null if no entity found */ private ChartEntity getEntityForLocation(double x, double y) { if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { ChartEntity entity = null; Rectangle rect = getScreenDataArea(); int count = 0; // //logger.debug(rect.x + "," + rect.y +"," + rect.width + "," // + rect.height); Point2D javaPoint = translateScreenToJava2D(new Point(rect.x, rect.y)); if (this.orientation == PlotOrientation.HORIZONTAL) { while (entity == null && x > javaPoint.getX()) { entity = entities.getEntity(x, y); // if(entity!=null) // //logger.debug("found in " + count + " attempts"); x--; count++; } } else { while (entity == null && y < (javaPoint.getY() + (rect.height * scaleY))) { entity = entities.getEntity(x, y); // if(entity!=null) // //logger.debug("found in " + count + " attempts"); y++; count++; } } return entity; } } return null; }
From source file:lcmc.common.ui.ResourceGraph.java
protected final ViewScalingControl getScalingControl() { return new ViewScalingControl() { void superScale(final VisualizationServer thisVV, final float amount, final Point2D from) { super.scale(thisVV, amount, from); }//from w ww . j a v a 2 s.c om @Override public void scale(final VisualizationServer vv, final float amount, final Point2D from) { final JScrollBar sbV = getScrollPane().getVerticalScrollBar(); final JScrollBar sbH = getScrollPane().getHorizontalScrollBar(); swingUtils.invokeLater(new Runnable() { @Override public void run() { final Point2D prevPoint = getVisualizationViewer().getRenderContext() .getMultiLayerTransformer().inverseTransform(Layer.VIEW, from); final double scaledSoFar0 = getScaledSoFar(); float am = amount; if (am < 1) { if (scaledSoFar0 < 0.3) { am = 1; } else { superScale(vv, 1 / am, new Point2D.Double(0, 0)); } } else if (am > 1) { if (scaledSoFar0 > 5) { am = 1; } else { superScale(vv, 1 / am, new Point2D.Double(0, 0)); } } setScaledSoFar(scaledSoFar0 * am); final Point2D p2 = getVisualizationViewer().getRenderContext().getMultiLayerTransformer() .inverseTransform(Layer.VIEW, from); final int valueY = (int) (sbV.getValue() + prevPoint.getY() - p2.getY()); sbV.setValue(valueY); sbV.repaint(); final int valueX = (int) (sbH.getValue() + prevPoint.getX() - p2.getX()); sbH.setValue(valueX); sbH.repaint(); vv.repaint(); } }); } }; }
From source file:org.squidy.designer.zoom.impl.PortShape.java
public PortShape() { setBounds(Constants.DEFAULT_PORT_BOUNDS); addInputEventListener(new PBasicInputEventHandler() { /*/*from w w w. ja v a2 s . c o m*/ * (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()) { isCreatingEdge = true; Rectangle2D bounds = localToGlobal(getBounds()); startX = bounds.getX() + bounds.getWidth() / 2;// .getCenterX(); startY = bounds.getY() + bounds.getWidth() / 2;// .getCenterY(); currentX = startX; currentY = startY; // moveToFront(); event.setHandled(true); } } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseReleased * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseReleased(PInputEvent event) { super.mouseReleased(event); isCreatingEdge = false; ConnectionManager connectionManager = ShapeUtils.getConnectionManager(PortShape.this); Point2D point = event.getPosition(); if (connectionManager.hasConnectionAtDifferentNodeAtPoint(PortShape.this, point)) { if (LOG.isDebugEnabled()) { LOG.debug("Connection port found at " + point); } ConnectorShape<?, ?> source = (ConnectorShape<?, ?>) getParent(); ConnectorShape<?, ?> target = (ConnectorShape<?, ?>) connectionManager .getConnectionAtPoint(point).getParent(); if (!source.getParent().equals(target.getParent())) { // ConnectorShape<?, ?> tmp = source; // source = target; // target = tmp; } PipeShape pipeShape; try { pipeShape = PipeShape.create(source, target); } catch (Exception e) { publishNotification(new TemporaryNotification(e.getMessage())); return; } VisualShape<VisualShape<?>> parentShape; if (!source.getParent().equals(target.getParent())) { if (target.getParent().equals(source)) { parentShape = (VisualShape<VisualShape<?>>) source; } else { parentShape = (VisualShape<VisualShape<?>>) target; } } else { parentShape = (VisualShape<VisualShape<?>>) source.getParent(); } parentShape.addVisualShape(pipeShape); pipeShape.invalidateFullBounds(); } else { // TODO [RR]: Repaint from bounds (do not repaint full node bounds) getParent().getParent().invalidatePaint(); } } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PBasicInputEventHandler#mouseDragged * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override public void mouseDragged(PInputEvent event) { super.mouseDragged(event); Point2D point = event.getPosition(); currentX = point.getX(); currentY = point.getY(); event.getCamera().invalidatePaint(); event.setHandled(true); } /* * (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); innerColor = Color.GRAY; } /* * (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); innerColor = Color.LIGHT_GRAY; } }); }
From source file:spinworld.gui.RadarPlot.java
/** * Draws the label for one axis./*from w w w. j av a2 s . com*/ * * @param g2 the graphics device. * @param plotArea whole plot drawing area (e.g. including space for labels) * @param plotDrawingArea the plot drawing area (just spanning of axis) * @param value the value of the label (ignored). * @param cat the category (zero-based index). * @param startAngle the starting angle. * @param extent the extent of the arc. */ protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, Rectangle2D plotDrawingArea, double value, int cat, double startAngle, double extent) { FontRenderContext frc = g2.getFontRenderContext(); String label = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { // if series are in rows, then the categories are the column keys label = this.labelGenerator.generateColumnLabel(this.dataset, cat); } else { // if series are in columns, then the categories are the row keys label = this.labelGenerator.generateRowLabel(this.dataset, cat); } double angle = normalize(startAngle); Font font = getLabelFont(); Point2D labelLocation; do { Rectangle2D labelBounds = font.getStringBounds(label, frc); LineMetrics lm = font.getLineMetrics(label, frc); double ascent = lm.getAscent(); labelLocation = calculateLabelLocation(labelBounds, ascent, plotDrawingArea, startAngle); boolean leftOut = angle > 90 && angle < 270 && labelLocation.getX() < plotArea.getX(); boolean rightOut = (angle < 90 || angle > 270) && labelLocation.getX() + labelBounds.getWidth() > plotArea.getX() + plotArea.getWidth(); if (leftOut || rightOut) { font = font.deriveFont(font.getSize2D() - 1); } else { break; } } while (font.getSize() > 8); Composite saveComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.setPaint(getLabelPaint()); g2.setFont(font); g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY()); g2.setComposite(saveComposite); }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Translates a Java2D point on the chart to a screen location. * // w w w . j a v a 2s.c o m * @param java2DPoint * the Java2D point. * * @return The screen location. */ @Override public Point translateJava2DToScreen(Point2D java2DPoint) { Insets insets = getInsets(); int x = (int) (java2DPoint.getX() * this.scaleX + insets.left); int y = (int) (java2DPoint.getY() * this.scaleY + insets.top); return new Point(x, y); }
From source file:com.ah.ui.actions.monitor.MapsAction.java
protected boolean validatePerimeter(Point2D l1p1, Point2D l1p2, Point2D l2p1, Point2D l2p2, boolean hasPageId, Collection<JSONObject> jsonNodes) throws Exception { Point2D ip = BoMgmt.getLocationTracking().lli(l1p1, l1p2, l2p1, l2p2); if (ip != null) { JSONObject ipo = new JSONObject(); if (!hasPageId) { ipo.put("pageId", pageId); hasPageId = true;//w ww.j av a2s . c o m } ipo.put("x", ip.getX()); ipo.put("y", ip.getY()); jsonNodes.add(ipo); } return hasPageId; }
From source file:com.peterbochs.instrument.InstrumentPanel.java
@Override public void chartMouseClicked(ChartMouseEvent event) { try {/* ww w .j a v a2 s . c o m*/ // System.out.println(event.getTrigger().getX()); JFreeChart chart = event.getChart(); XYPlot xyplot = chart.getXYPlot(); MyXYBlockRenderer renderer = (MyXYBlockRenderer) xyplot.getRenderer(); XYZDataset dataset = (XYZDataset) xyplot.getDataset(); XYItemEntity entity = (XYItemEntity) event.getEntity(); int series = entity.getSeriesIndex(); int item = entity.getItem(); int i = event.getTrigger().getX(); int j = event.getTrigger().getY(); Point2D point2d = jMemoryChartPanel.translateScreenToJava2D(new Point(i, j)); ChartRenderingInfo chartrenderinginfo = jMemoryChartPanel.getChartRenderingInfo(); Rectangle2D rectangle2d = chartrenderinginfo.getPlotInfo().getDataArea(); double x = xyplot.getDomainAxis().java2DToValue(point2d.getX(), rectangle2d, xyplot.getDomainAxisEdge()); double y = xyplot.getRangeAxis().java2DToValue(point2d.getY(), rectangle2d, xyplot.getRangeAxisEdge()); int realX = (int) Math.round(x); int realY = (int) Math.round(y); renderer.setSelectedXY(realX, realY); long blockSize = CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem()); long columnCount = Data.getColumnCount( CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()), CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()), blockSize); Long address = ((realY * columnCount) + realX) * blockSize; updateHotestTable(address, blockSize); this.jAddressLabel.setText("Address=0x" + Long.toHexString(address)); this.jRWCountLabel.setText("R/W count=" + (int) dataset.getZValue(series, item)); } catch (Exception ex) { } }