use of org.jfree.chart.ChartMouseEvent in project SIMVA-SoS by SESoS.
the class ChartComposite method mouseDown.
/**
* Handles a mouse down event.
*
* @param event the event.
*/
public void mouseDown(MouseEvent event) {
Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);
if (scaledDataArea == null)
return;
this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
int x = (int) ((event.x - getClientArea().x) / this.scaleX);
int y = (int) ((event.y - getClientArea().y) / this.scaleY);
this.anchor = new Point2D.Double(x, y);
// force a redraw
this.chart.setNotify(true);
this.canvas.redraw();
// new entity code
ChartEntity entity = null;
if (this.info != null) {
EntityCollection entities = this.info.getEntityCollection();
if (entities != null) {
entity = entities.getEntity(x, y);
}
}
Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
if (listeners.length == 0) {
return;
}
// pass mouse down event if some ChartMouseListener are listening
java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity);
for (int i = listeners.length - 1; i >= 0; i -= 1) {
((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
}
}
use of org.jfree.chart.ChartMouseEvent in project SIMVA-SoS by SESoS.
the class ChartComposite method mouseMove.
/**
* Handles a mouse move event.
*
* @param event the mouse event.
*/
public void mouseMove(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) {
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) {
Rectangle scaledDataArea = getScreenDataArea(this.zoomPoint.x, this.zoomPoint.y);
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) {
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;
int x = (int) ((event.x - getClientArea().x) / this.scaleX);
int y = (int) ((event.y - getClientArea().y) / this.scaleY);
if (this.info != null) {
EntityCollection entities = this.info.getEntityCollection();
if (entities != null) {
entity = entities.getEntity(x, y);
}
}
Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
if (listeners.length == 0) {
return;
}
// pass mouse move event if some ChartMouseListener are listening
java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity);
for (int i = listeners.length - 1; i >= 0; i -= 1) {
((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent);
}
}
Aggregations