use of net.sf.mzmine.chartbasics.gui.wrapper.MouseEventWrapper in project mzmine2 by mzmine.
the class ChartGestureHandler method createHandler.
/**
* Create preset handlers
*
* @param handler
* @param g
* @param param Parameters for specific handlers <br>
* @return
*/
public static ChartGestureHandler createHandler(Handler handler, final ChartGesture g, Object[] param) {
Consumer<ChartGestureEvent> newHandler = null;
switch(handler) {
case DEBUG:
newHandler = e -> System.out.println(e.toString());
break;
case PREVIOUS_ZOOM_HISTORY:
newHandler = e -> {
ZoomHistory h = e.getChartWrapper().getZoomHistory();
if (h != null) {
Range[] range = h.setPreviousPoint();
if (range != null && range.length > 0 && range[0] != null) {
ValueAxis dom = e.getChart().getXYPlot().getDomainAxis();
ValueAxis ran = e.getChart().getXYPlot().getRangeAxis();
ChartLogics.setZoomAxis(dom, range[0]);
ChartLogics.setZoomAxis(ran, range[1]);
}
}
};
break;
case NEXT_ZOOM_HISTORY:
newHandler = e -> {
ZoomHistory h = e.getChartWrapper().getZoomHistory();
if (h != null) {
Range[] range = h.setNextPoint();
if (range != null && range.length > 0 && range[0] != null) {
ValueAxis dom = e.getChart().getXYPlot().getDomainAxis();
ValueAxis ran = e.getChart().getXYPlot().getRangeAxis();
ChartLogics.setZoomAxis(dom, range[0]);
ChartLogics.setZoomAxis(ran, range[1]);
}
}
};
break;
case TITLE_REMOVER:
newHandler = e -> {
if (e.getEntity() instanceof TitleEntity) {
TitleEntity te = (TitleEntity) e.getEntity();
te.getTitle().setVisible(false);
}
};
break;
case AUTO_ZOOM_AXIS:
newHandler = e -> {
ValueAxis a = e.getAxis();
if (a != null)
ChartLogics.autoAxis(a);
};
break;
case AUTO_ZOOM_OPPOSITE_AXIS:
newHandler = e -> {
if (e.getGesture().getEntity().equals(Entity.AXIS)) {
e.getChartWrapper().autoRangeAxis();
e.getChartWrapper().autoDomainAxis();
} else if (e.getGesture().getEntity().equals(Entity.DOMAIN_AXIS))
e.getChartWrapper().autoRangeAxis();
else
e.getChartWrapper().autoDomainAxis();
};
break;
case SCROLL_AXIS:
newHandler = e -> {
ValueAxis axis = e.getAxis();
if (axis != null) {
double diff = 0.03;
if (e.getMouseEvent().isMouseWheelEvent()) {
diff = -0.10 * e.getMouseEvent().getWheelRotation();
}
ChartLogics.offsetAxis(axis, diff);
}
};
break;
case SCROLL_AXIS_AND_AUTO_ZOOM:
newHandler = e -> {
ValueAxis axis = e.getAxis();
if (axis != null) {
double diff = 0.03;
if (e.getMouseEvent().isMouseWheelEvent()) {
diff = -0.10 * e.getMouseEvent().getWheelRotation();
}
ChartLogics.offsetAxis(axis, diff);
if (e.getGesture().getEntity().equals(Entity.DOMAIN_AXIS))
e.getChartWrapper().autoRangeAxis();
else
e.getChartWrapper().autoDomainAxis();
}
};
break;
case ZOOM_AXIS_INCLUDE_ZERO:
newHandler = e -> {
ValueAxis axis = e.getAxis();
if (axis != null) {
double diff = 0.05;
if (e.getMouseEvent().isMouseWheelEvent()) {
diff = -0.10 * e.getMouseEvent().getWheelRotation();
}
ChartLogics.zoomAxis(axis, diff, true);
}
};
break;
case ZOOM_AXIS_CENTER:
newHandler = e -> {
ValueAxis axis = e.getAxis();
if (axis != null) {
MouseEventWrapper p = e.getMouseEvent();
double diff = 0.05;
if (e.getMouseEvent().isMouseWheelEvent()) {
diff = -0.10 * p.getWheelRotation();
}
// get data space coordinates
Point2D point = e.getCoordinates(p.getX(), p.getY());
if (point != null) {
// vertical ?
Boolean orient = e.isVerticalAxis(axis);
if (orient == null)
return;
else if (orient)
ChartLogics.zoomAxis(axis, diff, point.getY());
else
ChartLogics.zoomAxis(axis, diff, point.getX());
}
}
};
break;
default:
break;
}
if (newHandler == null)
return null;
else
return new ChartGestureHandler(g, newHandler);
}
use of net.sf.mzmine.chartbasics.gui.wrapper.MouseEventWrapper in project mzmine2 by mzmine.
the class ChartGestureDragDiffHandler method createConsumer.
/**
* Handle PRESSED, DRAGGED, RELEASED events to generate drag diff events
*
* @return
*/
private Consumer<ChartGestureEvent> createConsumer() {
return new Consumer<ChartGestureEvent>() {
// variables
boolean wasMouseZoomable = false;
Point2D last = null, first = null;
ChartGestureEvent startEvent = null, lastEvent = null;
@Override
public void accept(ChartGestureEvent event) {
ChartViewWrapper chartPanel = event.getChartWrapper();
JFreeChart chart = chartPanel.getChart();
MouseEventWrapper e = event.getMouseEvent();
// released?
if (event.checkEvent(Event.RELEASED)) {
chartPanel.setMouseZoomable(wasMouseZoomable);
last = null;
} else if (event.checkEvent(Event.PRESSED)) {
// get data space coordinates
last = chartPanel.mouseXYToPlotXY(e.getX(), e.getY());
first = last;
startEvent = event;
lastEvent = event;
if (last != null) {
wasMouseZoomable = chartPanel.isMouseZoomable();
chartPanel.setMouseZoomable(false);
}
} else if (event.checkEvent(Event.DRAGGED)) {
if (last != null) {
// get data space coordinates
Point2D released = chartPanel.mouseXYToPlotXY(e.getX(), e.getY());
if (released != null) {
double offset = 0;
double start = 0;
// scroll x
if (getOrientation(event).equals(Orientation.HORIZONTAL)) {
offset = -(released.getX() - last.getX());
start = first.getX();
} else // scroll y
{
offset = -(released.getY() - last.getY());
start = first.getY();
}
// new dragdiff event
ChartGestureDragDiffEvent dragEvent = new ChartGestureDragDiffEvent(startEvent, lastEvent, event, start, offset, orient);
// choose handler by key filter
for (int i = 0; i < dragDiffHandler.length; i++) if (key[i].filter(event.getMouseEvent()))
dragDiffHandler[i].accept(dragEvent);
// set last event
lastEvent = event;
// save updated last
last = chartPanel.mouseXYToPlotXY(e.getX(), e.getY());
}
}
}
}
};
}
use of net.sf.mzmine.chartbasics.gui.wrapper.MouseEventWrapper in project mzmine2 by mzmine.
the class ChartGestureMouseAdapterFX method handleMousePressed.
/**
* Handles a mouse pressed event. This implementation does nothing, override the method if
* required.
*
* @param canvas the canvas ({@code null} not permitted).
* @param e the event ({@code null} not permitted).
*/
@Override
public void handleMousePressed(ChartCanvas chartPanel, MouseEvent eOrig) {
if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.PRESSED))
return;
MouseEventWrapper e = new MouseEventWrapper(eOrig);
ChartEntity entity = findChartEntity(e);
ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity);
Button button = Button.getButton(e.getButton());
// handle event
lastDragEvent = new ChartGestureEvent(cw, e, entity, new ChartGesture(gestureEntity, Event.PRESSED, button));
handleEvent(lastDragEvent);
}
Aggregations