List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
private boolean updateMainTraceInfo(Point2D point) { if (point == null) { return false; }/*from w w w . j a v a 2s.c o m*/ final ChartPanel chartPanel = this.chartJDialog.getChartPanel(); // Top most plot. final XYPlot plot = this.chartJDialog.getPlot(); if (plot.getDataset() instanceof org.jfree.data.xy.DefaultHighLowDataset) { return this._updateMainTraceInfoForCandlestick(point); } final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(); // 0 are the main chart. 1, 2, 3... are TA. final TimeSeries timeSeries = timeSeriesCollection.getSeries(0); // I also not sure why. This is what are being done in Mouse Listener Demo 4. // // Don't use it. It will cause us to lose precision. //final Point2D p2 = chartPanel.translateScreenToJava2D((Point)point); /* Try to get correct main chart area. */ final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0) .getDataArea(); final ValueAxis domainAxis = plot.getDomainAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); // Don't use it. It will cause us to lose precision. //final double coordinateX = domainAxis.java2DToValue(p2.getX(), _plotArea, // domainAxisEdge); final double coordinateX = domainAxis.java2DToValue(point.getX(), _plotArea, domainAxisEdge); //double coordinateY = rangeAxis.java2DToValue(mousePoint2.getY(), plotArea, // rangeAxisEdge); int low = 0; int high = timeSeries.getItemCount() - 1; Date date = new Date((long) coordinateX); final long time = date.getTime(); long bestDistance = Long.MAX_VALUE; int bestMid = 0; while (low <= high) { int mid = (low + high) >>> 1; final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(mid); final Day day = (Day) timeSeriesDataItem.getPeriod(); final long search = day.getFirstMillisecond(); final long cmp = search - time; if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { bestDistance = 0; bestMid = mid; break; } final long abs_cmp = Math.abs(cmp); if (abs_cmp < bestDistance) { bestDistance = abs_cmp; bestMid = mid; } } final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(bestMid); final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond(); final double yValue = timeSeriesDataItem.getValue().doubleValue(); final double xJava2D = domainAxis.valueToJava2D(xValue, _plotArea, domainAxisEdge); final double yJava2D = rangeAxis.valueToJava2D(yValue, _plotArea, rangeAxisEdge); final int tmpIndex = bestMid; // translateJava2DToScreen will internally convert Point2D.Double to Point. final Point2D tmpPoint = chartPanel.translateJava2DToScreen(new Point2D.Double(xJava2D, yJava2D)); this.mainDrawArea.setRect(_plotArea); if (this.mainDrawArea.contains(tmpPoint)) { // 0 indicates main plot. this.mainTraceInfo = TraceInfo.newInstance(tmpPoint, 0, 0, tmpIndex); return true; } return false; }
From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java
/** * Bounds the selection rectangle between the first and the last chart * entity bounds. and between the top and bottom bounds of the chart area. *///from w w w. ja v a 2 s . c o m private void boundSelectionRectangle() { int FIRSTENTITYERROR = 2; if (selectedEntities.size() > 0) { ChartEntity first = selectedEntities.get(0); ChartEntity last = selectedEntities.get(selectedEntities.size() - 1); Point firstp = first.getArea().getBounds().getLocation(); Point lastp = last.getArea().getBounds().getLocation(); Rectangle screenArea = getScreenDataArea(); Point2D screenPoint = translateScreenToJava2D(new Point(screenArea.x, screenArea.y)); if (this.orientation == PlotOrientation.VERTICAL) { selectionRectangle = new Rectangle(firstp.x - FIRSTENTITYERROR, (int) screenPoint.getY(), lastp.x + last.getArea().getBounds().width - firstp.x, (int) (screenArea.height / scaleY)); } else { selectionRectangle = new Rectangle((int) screenPoint.getX(), firstp.y, (int) (screenArea.width / scaleX), lastp.y + last.getArea().getBounds().height - firstp.y); } } }
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;//from w ww .j a va2s . 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:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private boolean updateInvestPoint(Point2D _investPoint) { if (_investPoint == null) { return false; }//from w w w . j a v a2s . com final ChartPanel chartPanel = this.investmentFlowChartJDialog.getChartPanel(); final JFreeChart chart = chartPanel.getChart(); final XYPlot plot = (XYPlot) chart.getPlot(); final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(); final TimeSeries timeSeries = timeSeriesCollection.getSeries(0); // I also not sure why. This is what are being done in Mouse Listener Demo 4. // // Don't use it. It will cause us to lose precision. //final Point2D p2 = chartPanel.translateScreenToJava2D((Point)_investPoint); /* Try to get correct main chart area. */ final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); /* Believe it? When there is another thread keep updateing time series data, * and keep calling setDirty, _plotArea can be 0 size sometimes. Ignore it. * Just assume we had processed it. */ if (_plotArea.getWidth() == 0.0 && _plotArea.getHeight() == 0.0) { /* Cheat the caller. */ return true; } final ValueAxis domainAxis = plot.getDomainAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); final double coordinateX = domainAxis.java2DToValue(_investPoint.getX(), _plotArea, domainAxisEdge); int low = 0; int high = timeSeries.getItemCount() - 1; Date date = new Date((long) coordinateX); final long time = date.getTime(); long bestDistance = Long.MAX_VALUE; int bestMid = 0; while (low <= high) { int mid = (low + high) >>> 1; final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(mid); final Day day = (Day) timeSeriesDataItem.getPeriod(); final long search = day.getFirstMillisecond(); final long cmp = search - time; if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { bestDistance = 0; bestMid = mid; break; } final long abs_cmp = Math.abs(cmp); if (abs_cmp < bestDistance) { bestDistance = abs_cmp; bestMid = mid; } } final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(bestMid); final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond(); final double yValue = timeSeriesDataItem.getValue().doubleValue(); final double xJava2D = domainAxis.valueToJava2D(xValue, _plotArea, domainAxisEdge); final double yJava2D = rangeAxis.valueToJava2D(yValue, _plotArea, rangeAxisEdge); final int tmpIndex = bestMid; // Do not perform translation as this will cause precision losing. // We might experience unstable point. For example, // // this.investPoint is 700.9, there are 2 data points which are 700 and // 701. // During first updateInvestPoint(this.investPoint) call, data point 701 // will be chosen, and this.investPoint has been truncated to 700. // During second updateInvestPoint(this.investPoint) call, data point 700 // will be chosen. We may observe an unstable point swings between 700 // and 701. // // translateJava2DToScreen will internally convert Point2D.Double to Point. //final Point2D tmpPoint = chartPanel.translateJava2DToScreen(new Point2D.Double(xJava2D, yJava2D)); final Point2D tmpPoint = new Point2D.Double(xJava2D, yJava2D); this.drawArea.setRect(_plotArea); if (this.drawArea.contains(tmpPoint)) { this.investPointIndex = tmpIndex; this.investPoint = tmpPoint; return true; } return false; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private boolean updateROIPoint(Point2D _ROIPoint) { if (_ROIPoint == null) { return false; }//from w ww .ja va 2 s . c om final ChartPanel chartPanel = this.investmentFlowChartJDialog.getChartPanel(); final JFreeChart chart = chartPanel.getChart(); final XYPlot plot = (XYPlot) chart.getPlot(); // Dataset 0 are the invest information. 1 is the ROI information. final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(1); final TimeSeries timeSeries = timeSeriesCollection.getSeries(0); // I also not sure why. This is what are being done in Mouse Listener Demo 4. // // Don't use it. It will cause us to lose precision. //final Point2D p2 = chartPanel.translateScreenToJava2D((Point)_ROIPoint); /* Try to get correct main chart area. */ final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); /* Believe it? When there is another thread keep updateing time series data, * and keep calling setDirty, _plotArea can be 0 size sometimes. Ignore it. * Just assume we had processed it. */ if (_plotArea.getWidth() == 0.0 && _plotArea.getHeight() == 0.0) { /* Cheat the caller. */ return true; } final ValueAxis domainAxis = plot.getDomainAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); final double coordinateX = domainAxis.java2DToValue(_ROIPoint.getX(), _plotArea, domainAxisEdge); int low = 0; int high = timeSeries.getItemCount() - 1; Date date = new Date((long) coordinateX); final long time = date.getTime(); long bestDistance = Long.MAX_VALUE; int bestMid = 0; while (low <= high) { int mid = (low + high) >>> 1; final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(mid); final Day day = (Day) timeSeriesDataItem.getPeriod(); final long search = day.getFirstMillisecond(); final long cmp = search - time; if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { bestDistance = 0; bestMid = mid; break; } final long abs_cmp = Math.abs(cmp); if (abs_cmp < bestDistance) { bestDistance = abs_cmp; bestMid = mid; } } final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(bestMid); final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond(); final double yValue = timeSeriesDataItem.getValue().doubleValue(); final double xJava2D = domainAxis.valueToJava2D(xValue, _plotArea, domainAxisEdge); final double yJava2D = rangeAxis.valueToJava2D(yValue, _plotArea, rangeAxisEdge); final int tmpIndex = bestMid; // Do not perform translation as this will cause precision losing. // We might experience unstable point. For example, // // this.ROIPoint is 700.9, there are 2 data points which are 700 and // 701. // During first updateROIPoint(this.ROIPoint) call, data point 701 // will be chosen, and this.ROIPoint has been truncated to 700. // During second updateROIPoint(this.ROIPoint) call, data point 700 // will be chosen. We may observe an unstable point swings between 700 // and 701. // // translateJava2DToScreen will internally convert Point2D.Double to Point. //final Point2D tmpPoint = chartPanel.translateJava2DToScreen(new Point2D.Double(xJava2D, yJava2D)); final Point2D tmpPoint = new Point2D.Double(xJava2D, yJava2D); this.drawArea.setRect(_plotArea); if (this.drawArea.contains(tmpPoint)) { this.ROIPointIndex = tmpIndex; this.ROIPoint = tmpPoint; return true; } return false; }
From source file:org.squidy.designer.zoom.impl.PortShape.java
public PortShape() { setBounds(Constants.DEFAULT_PORT_BOUNDS); addInputEventListener(new PBasicInputEventHandler() { /*//from w w w. j a va 2 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:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Translates a Java2D point on the chart to a screen location. * //from w w w. j a v a 2 s . 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.att.aro.diagnostics.GraphPanel.java
/** * This method is invoked when a mouse click event occurs in the GraphPanel. *///ww w. j a v a 2 s . co m @Override public void chartMouseClicked(ChartMouseEvent chartmouseevent) { Point2D point = chartmouseevent.getTrigger().getPoint(); Rectangle2D plotArea = advancedGraphPanel.getScreenDataArea(); XYPlot plot = (XYPlot) advancedGraph.getPlot(); final double lastChartX = new Double( plot.getDomainAxis().java2DToValue(point.getX(), plotArea, plot.getDomainAxisEdge())); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { setCrossHair(lastChartX); } }); for (GraphPanelListener l : listeners) { l.graphPanelClicked(lastChartX); } }
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;//from w w w. j ava 2 s .c o m } ipo.put("x", ip.getX()); ipo.put("y", ip.getY()); jsonNodes.add(ipo); } return hasPageId; }
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 ww w .j av a2 s . c o m @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(); } }); } }; }