本文整理汇总了Java中javafx.scene.input.ScrollEvent.getX方法的典型用法代码示例。如果您正苦于以下问题:Java ScrollEvent.getX方法的具体用法?Java ScrollEvent.getX怎么用?Java ScrollEvent.getX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.input.ScrollEvent
的用法示例。
在下文中一共展示了ScrollEvent.getX方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleZoomable
import javafx.scene.input.ScrollEvent; //导入方法依赖的package包/类
/**
* Handle the case where a plot implements the {@link Zoomable} interface.
*
* @param zoomable the zoomable plot.
* @param e the mouse wheel event.
*/
private void handleZoomable(ChartCanvas canvas, Zoomable zoomable,
ScrollEvent e) {
// don't zoom unless the mouse pointer is in the plot's data area
ChartRenderingInfo info = canvas.getRenderingInfo();
PlotRenderingInfo pinfo = info.getPlotInfo();
Point2D p = new Point2D.Double(e.getX(), e.getY());
if (pinfo.getDataArea().contains(p)) {
Plot plot = (Plot) zoomable;
// do not notify while zooming each axis
boolean notifyState = plot.isNotify();
plot.setNotify(false);
int clicks = (int) e.getDeltaY();
double zf = 1.0 + this.zoomFactor;
if (clicks < 0) {
zf = 1.0 / zf;
}
if (canvas.isDomainZoomable()) {
zoomable.zoomDomainAxes(zf, pinfo, p, true);
}
if (canvas.isRangeZoomable()) {
zoomable.zoomRangeAxes(zf, pinfo, p, true);
}
plot.setNotify(notifyState); // this generates the change event too
}
}
示例2: handleZoomable
import javafx.scene.input.ScrollEvent; //导入方法依赖的package包/类
/**
* Handle the case where a plot implements the {@link Zoomable} interface.
*
* @param zoomable the zoomable plot.
* @param e the mouse wheel event.
*/
private void handleZoomable(ChartCanvas canvas, Zoomable zoomable,
ScrollEvent e) {
// don't zoom unless the mouse pointer is in the plot's data area
ChartRenderingInfo info = canvas.getRenderingInfo();
PlotRenderingInfo pinfo = info.getPlotInfo();
Point2D p = new Point2D.Double(e.getX(), e.getY());
if (pinfo.getDataArea().contains(p)) {
Plot plot = (Plot) zoomable;
// do not notify while zooming each axis
boolean notifyState = plot.isNotify();
plot.setNotify(false);
int clicks = (int) e.getDeltaY();
double zf = 1.0 + this.zoomFactor;
if (clicks < 0) {
zf = 1.0 / zf;
}
if (true) { //this.chartPanel.isDomainZoomable()) {
zoomable.zoomDomainAxes(zf, pinfo, p, true);
}
if (true) { //this.chartPanel.isRangeZoomable()) {
zoomable.zoomRangeAxes(zf, pinfo, p, true);
}
plot.setNotify(notifyState); // this generates the change event too
}
}
示例3: mouseWheelMoved
import javafx.scene.input.ScrollEvent; //导入方法依赖的package包/类
public void mouseWheelMoved(ScrollEvent e) {
double scaledDeltaY = e.getDeltaY() > 0 ? -1 : 1;
double formerZoom = zoom;
zoom -= scaledDeltaY;
zoom = zoom <= 1 ? 1 : zoom;
double deltaX = deltaStart.getX() - delta.getX();
double deltaY = deltaStart.getY() - delta.getY();
double projX = (e.getX() + deltaX) / (formerZoom * zoomFactor);
double projY = (e.getY() + deltaY) / (formerZoom * zoomFactor);
double newPointX = (projX * zoom * zoomFactor) - deltaX;
double newPointY = (projY * zoom * zoomFactor) - deltaY;
setDeltaStart(new Point((int) newPointX, (int) newPointY));
delta = new Point((int) e.getX(), (int) e.getY());
}
示例4: handle
import javafx.scene.input.ScrollEvent; //导入方法依赖的package包/类
@Override
public void handle( ScrollEvent event ) {
EventType<? extends Event> eventType = event.getEventType();
if ( eventType == ScrollEvent.SCROLL_STARTED ) {
//mouse wheel events never send SCROLL_STARTED
ignoring = true;
} else if ( eventType == ScrollEvent.SCROLL_FINISHED ) {
//end non-mouse wheel event
ignoring = false;
} else if ( eventType == ScrollEvent.SCROLL &&
//If we are allowing mouse wheel zooming
mouseWheelZoomAllowed.get() &&
//If we aren't between SCROLL_STARTED and SCROLL_FINISHED
!ignoring &&
//inertia from non-wheel gestures might have touch count of 0
!event.isInertia() &&
//Only care about vertical wheel events
event.getDeltaY() != 0 &&
//mouse wheel always has touch count of 0
event.getTouchCount() == 0 ) {
//Find out which axes to zoom based on the strategy
double eventX = event.getX();
double eventY = event.getY();
DefaultChartInputContext context = new DefaultChartInputContext( chartInfo, eventX, eventY );
AxisConstraint zoomMode = mouseWheelAxisConstraintStrategy.getConstraint( context );
if ( zoomMode == AxisConstraint.None )
return;
//If we are are doing a zoom animation, stop it. Also of note is that we don't zoom the
//mouse wheel zooming. Because the mouse wheel can "fly" and generate a lot of events,
//animation doesn't work well. Plus, as the mouse wheel changes the view a small amount in
//a predictable way, it "looks like" an animation when you roll it.
//We might experiment with mouse wheel zoom animation in the future, though.
zoomAnimation.stop();
//At this point we are a mouse wheel event, based on everything I've read
Point2D dataCoords = chartInfo.getDataCoordinates( eventX, eventY );
//Determine the proportion of change to the lower and upper bounds based on how far the
//cursor is along the axis.
double xZoomBalance = getBalance( dataCoords.getX(),
xAxis.getLowerBound(), xAxis.getUpperBound() );
double yZoomBalance = getBalance( dataCoords.getY(),
yAxis.getLowerBound(), yAxis.getUpperBound() );
//Are we zooming in or out, based on the direction of the roll
double direction = -Math.signum( event.getDeltaY() );
//TODO: Do we need to handle "continuous" scroll wheels that don't work based on ticks?
//If so, the 0.2 needs to be modified
double zoomAmount = 0.2 * direction;
if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Horizontal ) {
double xZoomDelta = ( xAxis.getUpperBound() - xAxis.getLowerBound() ) * zoomAmount;
xAxis.setAutoRanging( false );
xAxis.setLowerBound( xAxis.getLowerBound() - xZoomDelta * xZoomBalance );
xAxis.setUpperBound( xAxis.getUpperBound() + xZoomDelta * ( 1 - xZoomBalance ) );
}
if ( zoomMode == AxisConstraint.Both || zoomMode == AxisConstraint.Vertical ) {
double yZoomDelta = ( yAxis.getUpperBound() - yAxis.getLowerBound() ) * zoomAmount;
yAxis.setAutoRanging( false );
yAxis.setLowerBound( yAxis.getLowerBound() - yZoomDelta * yZoomBalance );
yAxis.setUpperBound( yAxis.getUpperBound() + yZoomDelta * ( 1 - yZoomBalance ) );
}
}
}