List of usage examples for org.jfree.chart.entity EntityCollection getEntity
public ChartEntity getEntity(double x, double y);
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override public void mouseDragged(MouseEvent e) { Insets insets = getInsets();// w w w . j a v a 2s. c o m int x = (int) ((e.getX() - insets.left) / getScaleX()); int y = (int) ((e.getY() - insets.top) / getScaleY()); ChartEntity entity = null; EntityCollection entities = null; if (getChartRenderingInfo() != null) { 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(); // seriesIndex = selectedSeriesIndex; // isDirty = true; // } seriesIndex = followDomainTrace(selectedSeriesIndex, x); } 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()); // horizontalTraceLocation = (int) axisTrace.getX(); // verticalTraceLocation = (int) axisTrace.getY(); // seriesIndex = seriesIndex0; // isDirty = true; // } seriesIndex = followDomainTrace(0, x); } 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()); } // 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); } } } } } // if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) { if (isInternalLegendEnabled && isInternalLegendSelected) { int cursorType = findCursorOnSelectedItem(e.getX(), e.getY()); setCursor(Cursor.getPredefinedCursor(cursorType)); } else if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) == 0) { int cursorType = findCursorOnSelectedItem(e.getX(), e.getY()); setCursor(Cursor.getPredefinedCursor(cursorType)); } else if (getCursor() != defaultCursor) { setCursor(defaultCursor); } if (isInternalLegendEnabled && isInternalLegendSelected && findCursorOnSelectedItem(e.getX(), e.getY()) != Cursor.DEFAULT_CURSOR && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { changeInternalLegend(e); } else if (getMaskDragIndicator() != Cursor.DEFAULT_CURSOR && this.getSelectedMask() != null && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { changeSelectedMask(e); } else if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) { // Do masking service // if no initial masking point was set, ignore dragging... makeNewMask(e); } else { super.mouseDragged(e); } }
From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java
/** * Returns a string for the tooltip./*from ww w. j ava2 s.co m*/ * * @param e * the mouse event. * * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(final org.eclipse.swt.events.MouseEvent e) { String result = null; if (this.info != null) { final EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { final Rectangle insets = getClientArea(); final ChartEntity entity = entities.getEntity((int) ((e.x - insets.x) / this.scaleX), (int) ((e.y - insets.y) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:org.gumtree.vis.awt.JChartPanel.java
protected Point2D translateScreenToChart(Point2D point) { EntityCollection entities = getChartRenderingInfo().getEntityCollection(); ChartEntity entity = entities.getEntity(point.getX(), point.getY()); if (entity instanceof XYItemEntity) { XYDataset dataset = ((XYItemEntity) entity).getDataset(); int item = ((XYItemEntity) entity).getItem(); double chartX = dataset.getXValue(0, item); double chartY = dataset.getYValue(0, item); // double chartZ = ((XYZDataset) dataset).getZValue(0, item); return new Point2D.Double(chartX, chartY); }/*w w w. j a v a 2s .com*/ return null; }
From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java
/** * Handles a mouse move event.// w w w. j ava 2s . c om * * @param event * the mouse event. */ public void mouseMove(final MouseEvent event) { // handle axis trace if (this.horizontalAxisTrace || this.verticalAxisTrace) { this.horizontalTraceLineY = event.y; this.verticalTraceLineX = event.x; this.canvas.redraw(); } // handle tool tips in a simple way if (this.displayToolTips) { final String s = getToolTipText(event); if (s == null && this.canvas.getToolTipText() != null || s != null && !s.equals(this.canvas.getToolTipText())) this.canvas.setToolTipText(s); } // handle zoom box boolean hZoom, vZoom; if (this.zoomPoint != null) { final Rectangle scaledDataArea = getScreenDataArea(this.zoomPoint.x, this.zoomPoint.y); final org.eclipse.swt.graphics.Point movingPoint = getPointInRectangle(event.x, event.y, scaledDataArea); if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... this.zoomRectangle = new Rectangle(this.zoomPoint.x, this.zoomPoint.y, movingPoint.x - this.zoomPoint.x, movingPoint.y - this.zoomPoint.y); } else if (hZoom) { this.zoomRectangle = new Rectangle(this.zoomPoint.x, scaledDataArea.y, movingPoint.x - this.zoomPoint.x, scaledDataArea.height); } else if (vZoom) { final int ymax = Math.max(movingPoint.y, scaledDataArea.y); this.zoomRectangle = new Rectangle(scaledDataArea.x, this.zoomPoint.y, scaledDataArea.width, ymax - this.zoomPoint.y); } this.canvas.redraw(); } // new entity code ChartEntity entity = null; // [MG] the code below is not used now, see [MG] comment below // int x = (int) ((event.x - getClientArea().x) / this.scaleX); // int y = (int) ((event.y - getClientArea().y) / this.scaleY); if (this.info != null) { final EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { // [MG] -- the code below from original // org.jfree.experimental.chart.swt.ChartComposite // doewn't work -- because entities already placed with respect to the // scale factor. // // entity = entities.getEntity(x, y); // entity = entities.getEntity(event.x - getClientArea().x, event.y - getClientArea().y); } } final Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class); if (listeners.length == 0) { return; } // pass mouse move event if some ChartMouseListener are listening final java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event); final ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent); } }
From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java
/** * Returns a string for the tooltip.//ww w .ja v a 2 s. c o m * * @param e * the mouse event. * * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(org.eclipse.swt.events.MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Rectangle insets = getClientArea(); ChartEntity entity = entities.getEntity((int) ((e.x - insets.x) / this.scaleX), (int) ((e.y - insets.y) / this.scaleY)); if (entity != null) { // TODO Figure out a better way to do this. so that you can // remove the dependency from ODIE. if (entity instanceof CategoryItemEntity) { Datapoint dp = (Datapoint) ((CategoryItemEntity) entity).getColumnKey(); result = (dp.getConceptId() == null ? dp.getType() : dp.getConceptId()); } // else{ // logger.debug("Got " + entity.getClass().getName() + // " instead of CategoryItemEntity"); // } // result = entity.getToolTipText(); } } } return result; }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Returns the chart entity at a given point. * <P>/* ww w . j av a2 s . c om*/ * This method will return null if there is (a) no entity at the given point, or (b) no entity * collection has been generated. * * @param viewX * the x-coordinate. * @param viewY * the y-coordinate. * @return The chart entity (possibly <code>null</code>). */ public ChartEntity getEntityForPoint(int viewX, int viewY) { ChartEntity result = null; if (this.info != null) { Insets insets = getInsets(); double x = (viewX - insets.left) / this.scaleX; double y = (viewY - insets.top) / this.scaleY; EntityCollection entities = this.info.getEntityCollection(); result = entities != null ? entities.getEntity(x, y) : null; } return result; }
From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java
/** * Handles a mouse down event.// w w w. j a va2 s . c o m * * @param event * the event. */ public void mouseDown(final MouseEvent event) { final Rectangle scaledDataArea = getScreenDataArea(event.x, event.y); if (scaledDataArea == null) return; this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea); final int x = (int) ((event.x - getClientArea().x) / this.scaleX); final int y = (int) ((event.y - getClientArea().y) / this.scaleY); this.anchor = new Point2D.Double(x, y); this.chart.setNotify(true); // force a redraw this.canvas.redraw(); // new entity code ChartEntity entity = null; if (this.info != null) { final EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { // [MG] -- the code below from original // org.jfree.experimental.chart.swt.ChartComposite // doesn't work -- because entities already placed with respect to the // scale factor. // // [IM] -- reinstated the code below, since other version wasn't // working. This one ( // the one that doesn't shift them) now works. Feb 10. entity = entities.getEntity(x, y); // // entity = entities.getEntity(event.x - getClientArea().x, event.y - // getClientArea().y); } } final Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class); if (listeners.length == 0) { return; } // pass mouse down event if some ChartMouseListener are listening final java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event); final ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); } }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Receives notification of mouse clicks on the panel. These are translated and passed on to any * registered chart mouse click listeners. * // w w w .j av a2 s.co m * @param event * Information about the mouse event. */ public void mouseClicked(MouseEvent event) { Insets insets = getInsets(); int x = (int) ((event.getX() - insets.left) / this.scaleX); int y = (int) ((event.getY() - insets.top) / this.scaleY); this.anchor = new Point2D.Double(x, y); if (this.chart == null) { return; } this.chart.setNotify(true); // force a redraw // new entity code... Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class); if (listeners.length == 0) { return; } ChartEntity entity = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); } }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Implementation of the MouseMotionListener's method. * //ww w. j a v a 2 s . c o m * @param e * the event. */ public void mouseMoved(MouseEvent e) { Graphics2D g2 = (Graphics2D) getGraphics(); if (this.horizontalAxisTrace) { drawHorizontalAxisTrace(g2, e.getX()); } if (this.verticalAxisTrace) { drawVerticalAxisTrace(g2, e.getY()); } g2.dispose(); Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class); if (listeners.length == 0) { return; } Insets insets = getInsets(); int x = (int) ((e.getX() - insets.left) / this.scaleX); int y = (int) ((e.getY() - insets.top) / this.scaleY); ChartEntity entity = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } // we can only generate events if the panel's chart is not null // (see bug report 1556951) if (this.chart != null) { ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseMoved(event); } } }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Returns a string for the tooltip.//from w w w .j a va2 s.c o m * * @param e * the mouse event. * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Insets insets = getInsets(); ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX), (int) ((e.getY() - insets.top) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }