Change mouse button handling in simulation plot. Left click drag zooms

area, and ctrl left click drag pans.
This commit is contained in:
kruland2607 2013-02-05 10:04:49 -06:00
parent 06e702839f
commit b16917995d
2 changed files with 155 additions and 156 deletions

View File

@ -1099,7 +1099,7 @@ TCMotorSelPan.noDescription = No description available.
! PlotDialog
PlotDialog.CheckBox.Showdatapoints = Show data points
PlotDialog.lbl.Chart = mouse wheel to zoom. alt-mouse wheel to zoom x axis only. drag to pan.
PlotDialog.lbl.Chart = left click drag to zoom area. mouse wheel to zoom. ctrl-mouse wheel to zoom x axis only. ctrl-left click drag to pan. right click drag to zoom dynamically.
! "main" prefix is used for the main application dialog

View File

@ -15,7 +15,6 @@ import javax.swing.BorderFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.Pannable;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
@ -41,8 +40,11 @@ public class SimulationChart extends ChartPanel {
private double panW;
private double panH;
private enum Interaction {ZOOM, PAN};
private Interaction interaction = Interaction.PAN;
private enum Interaction {
ZOOM
};
private Interaction interaction = null;
private MouseWheelHandler mouseWheelHandler = null;
@ -77,8 +79,8 @@ public class SimulationChart extends ChartPanel {
@Override
public void mousePressed(MouseEvent e) {
if ( e.getButton() == MouseEvent.BUTTON1 || e.getButton() == MouseEvent.BUTTON3) {
// if no modifiers, use pan
if (e.getButton() == MouseEvent.BUTTON3) {
Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
if (screenDataArea != null && screenDataArea.contains(e.getPoint())) {
@ -87,21 +89,23 @@ public class SimulationChart extends ChartPanel {
this.panLast = e.getPoint();
this.startPoint = e.getPoint();
}
}
if ( e.getButton() == MouseEvent.BUTTON2 ) {
// middle/scroll button
} else if ( e.getButton() == MouseEvent.BUTTON3 ) { // right button
interaction = Interaction.ZOOM;
setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
} else if ( e.getButton() == MouseEvent.BUTTON1 ) { // left button
interaction = Interaction.PAN;
setCursor( Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR));
}
else {
interaction = null;
super.mousePressed(e);
}
}
@Override
public void mouseDragged(MouseEvent e) {
if (interaction == null) {
super.mouseDragged(e);
return;
}
if (panLast == null) {
return;
}
@ -117,17 +121,6 @@ public class SimulationChart extends ChartPanel {
this.getChart().getPlot().setNotify(false);
switch (interaction) {
case PAN:
Pannable p = (Pannable) this.getChart().getPlot();
if ( p.getOrientation() == PlotOrientation.VERTICAL){
p.panDomainAxes( wPercent, this.getChartRenderingInfo().getPlotInfo(),panLast);
p.panRangeAxes( hPercent, this.getChartRenderingInfo().getPlotInfo(),panLast);
} else {
p.panDomainAxes( hPercent, this.getChartRenderingInfo().getPlotInfo(),panLast);
p.panRangeAxes( wPercent, this.getChartRenderingInfo().getPlotInfo(),panLast);
}
break;
case ZOOM:
Zoomable pz = (Zoomable) this.getChart().getPlot();
@ -154,10 +147,16 @@ public class SimulationChart extends ChartPanel {
@Override
public void mouseReleased(MouseEvent e) {
if (interaction == null) {
super.mouseReleased(e);
return;
}
if (this.panLast != null) {
this.panLast = null;
setCursor(Cursor.getDefaultCursor());
}
interaction = null;
}
@ -257,7 +256,7 @@ public class SimulationChart extends ChartPanel {
if (SimulationChart.this.isDomainZoomable()) {
zoomable.zoomDomainAxes(zf, pinfo, p, true);
}
boolean domainOnly = ( e.getModifiers() & InputEvent.ALT_MASK ) != 0;
boolean domainOnly = (e.getModifiers() & InputEvent.CTRL_MASK) != 0;
if (SimulationChart.this.isRangeZoomable() && !domainOnly) {
zoomable.zoomRangeAxes(zf, pinfo, p, true);
}