下面列出了javafx.scene.control.cell.ComboBoxTableCell#javafx.geometry.Point2D 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void handle(MouseEvent event) {
//use this so that when the mouse moves over the canvas and something in canvas controls has focus, the key presses
//and mouse events are sent to the canvas rather than the focuses control
canvasView.focusToCanvas(event.getTarget() == canvasView.uiCanvasEditor.getCanvas());
double sceneX = event.getSceneX();
double sceneY = event.getSceneY();
for (Node node : canvasView.notificationPane.getContentPane().getChildren()) {
Point2D point2D = node.sceneToLocal(sceneX, sceneY);
if (node.contains(point2D)) {
canvasView.notificationPane.getContentPane().setMouseTransparent(false);
return;
}
}
canvasView.notificationPane.getContentPane().setMouseTransparent(true);
}
public Jewel(Point2D point) {
circle.setCenterX(SIZE / 2);
circle.setCenterY(SIZE / 2);
circle.setFill(colors[new Random().nextInt(colors.length)]);
setTranslateX(point.getX() * SIZE);
setTranslateY(point.getY() * SIZE);
getChildren().add(circle);
setOnMouseClicked(event -> {
if (selected == null) {
selected = this;
}
else {
swap(selected, this);
checkState();
selected = null;
}
});
}
/** Compute 'insets'
*
* <p>Determines where the tabs' content Pane
* is located relative to the bounds of the TabPane
*/
private void computeInsets()
{
// Called with delay by refreshHack, may be invoked when already disposed
if (jfx_node == null)
return;
// There is always at least one tab. All tabs have the same size.
final Pane pane = (Pane)jfx_node.getTabs().get(0).getContent();
final Point2D tabs_bounds = jfx_node.localToScene(0.0, 0.0);
final Point2D pane_bounds = pane.localToScene(0.0, 0.0);
final int[] insets = new int[] { (int)(pane_bounds.getX() - tabs_bounds.getX()),
(int)(pane_bounds.getY() - tabs_bounds.getY()) };
// logger.log(Level.INFO, "Insets: " + Arrays.toString(insets));
if (insets[0] < 0 || insets[1] < 0)
{
logger.log(Level.WARNING, "Inset computation failed: TabPane at " + tabs_bounds + ", content pane at " + pane_bounds);
insets[0] = insets[1] = 0;
}
model_widget.runtimePropInsets().setValue(insets);
}
private void handleStart(final MouseEvent event)
{
if (! event.isPrimaryButtonDown())
return;
active = true;
// Event originates from a node that allows 'clicking' beyond the
// model elements, i.e. the size of the 'parent'.
// The 'parent', however, may be scrolled, and the rubber band needs
// to show up in the 'parent', so convert coordinates
// from event to the parent:
final Point2D in_parent = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
x0 = in_parent.getX();
y0 = in_parent.getY();
rect.setX(x0);
rect.setY(y0);
rect.setWidth(1);
rect.setHeight(1);
parent.getChildren().add(rect);
event.consume();
}
/**
* Creates a new connection segment for the given start and end points.
*
* @param start the point where the segment starts
* @param end the point where the segment ends
* @param intersections the intersection-points of this segment with other connections
*/
public ConnectionSegment(final Point2D start, final Point2D end, final List<Double> intersections) {
this.start = start;
this.end = end;
this.intersections = intersections;
horizontal = start.getY() == end.getY();
if (horizontal) {
sign = start.getX() < end.getX() ? 1 : -1;
} else {
sign = start.getY() < end.getY() ? 1 : -1;
}
filterIntersections();
}
/**
* Fires a newly created {@link MouseEvent} of type
* {@link MouseEvent#MOUSE_PRESSED} to the target {@link Node} of the last mouse
* interaction.
*
* @param mods
* The {@link Modifiers} for the {@link MouseEvent}.
*/
public void mousePress(final Modifiers mods) {
waitForIdle();
run(() -> {
Point2D local = lastMouseInteraction.target.sceneToLocal(lastMouseInteraction.sceneX,
lastMouseInteraction.sceneY);
Point2D screen = lastMouseInteraction.target.localToScreen(local.getX(), local.getY());
fireEvent(lastMouseInteraction.target,
new MouseEvent(lastMouseInteraction.target, lastMouseInteraction.target, MouseEvent.MOUSE_PRESSED,
local.getX(), local.getY(), screen.getX(), screen.getY(), MouseButton.PRIMARY, 1,
mods.shift, mods.control, mods.alt, mods.meta, true, false, false, false, false, false,
new PickResult(lastMouseInteraction.target, lastMouseInteraction.sceneX,
lastMouseInteraction.sceneY)));
});
waitForIdle();
}
@Override
public void init() {
for (int y = 0; y < ENEMY_ROWS; y++) {
for (int x = 0; x < ENEMIES_PER_ROW; x++) {
double px = random(0, getAppWidth() - 100);
double py = random(0, getAppHeight() / 2.0);
Entity enemy = spawnEnemy(px, py);
var a = animationBuilder()
.autoReverse(true)
.interpolator(Interpolators.ELASTIC.EASE_IN_OUT())
.repeatInfinitely()
.duration(Duration.seconds(1.0))
.translate(enemy)
.from(new Point2D(px, py))
.to(new Point2D(random(0, getAppWidth() - 100), random(0, getAppHeight() / 2.0)))
.build();
animations.add(a);
a.start();
}
}
}
/**
* Returns the screen point for the provided LatLong. Note: Unexpected
* results can be obtained if this method is called as a result of a zoom
* change, as the zoom event is fired before the bounds are updated, and
* bounds need to be used to obtain the answer!
* <p>
* One workaround is to only operate off bounds_changed events.
*
* @param loc
* @return
*/
public Point2D fromLatLngToPoint(LatLong loc) {
// System.out.println("GoogleMap.fromLatLngToPoint loc: " + loc);
Projection proj = getProjection();
//System.out.println("map.fromLatLngToPoint Projection: " + proj);
LatLongBounds llb = getBounds();
// System.out.println("GoogleMap.fromLatLngToPoint Bounds: " + llb);
GMapPoint topRight = proj.fromLatLngToPoint(llb.getNorthEast());
// System.out.println("GoogleMap.fromLatLngToPoint topRight: " + topRight);
GMapPoint bottomLeft = proj.fromLatLngToPoint(llb.getSouthWest());
// System.out.println("GoogleMap.fromLatLngToPoint bottomLeft: " + bottomLeft);
double scale = Math.pow(2, getZoom());
GMapPoint worldPoint = proj.fromLatLngToPoint(loc);
// System.out.println("GoogleMap.fromLatLngToPoint worldPoint: " + worldPoint);
double x = (worldPoint.getX() - bottomLeft.getX()) * scale;
double y = (worldPoint.getY() - topRight.getY()) * scale;
// System.out.println("GoogleMap.fromLatLngToPoint x: " + x + " y: " + y);
return new Point2D(x, y);
}
/**
* Fires a newly created {@link MouseEvent} of type
* {@link MouseEvent#MOUSE_MOVED} to the given target {@link Node}.
*
* @param sceneX
* The final x-coordinate (in scene) for the drag.
* @param sceneY
* The final y-coordinate (in scene) for the drag.
* @param mods
* The {@link Modifiers} for the {@link MouseEvent}.
*/
public void mouseMove(final Node target, final double sceneX, final double sceneY, final Modifiers mods) {
waitForIdle();
// save mouse interaction data
lastMouseInteraction = new MouseInteraction();
lastMouseInteraction.target = target;
lastMouseInteraction.sceneX = sceneX;
lastMouseInteraction.sceneY = sceneY;
run(() -> {
Point2D local = target.sceneToLocal(sceneX, sceneY);
Point2D screen = target.localToScreen(local.getX(), local.getY());
fireEvent(target,
new MouseEvent(target, target, MouseEvent.MOUSE_MOVED, local.getX(), local.getY(), screen.getX(),
screen.getY(), MouseButton.NONE, 0, mods.shift, mods.control, mods.alt, mods.meta, false,
false, false, false, false, false, new PickResult(target, sceneX, sceneY)));
});
waitForIdle();
}
private void moveDataWithAnimation(final TableView<Person> sourceTable,
final TableView<Person> destinationTable,
final Pane commonTableAncestor, final TableRow<Person> row) {
// Create imageview to display snapshot of row:
final ImageView imageView = createImageView(row);
// Start animation at current row:
final Point2D animationStartPoint = row.localToScene(new Point2D(0, 0)); // relative to Scene
final Point2D animationEndPoint = computeAnimationEndPoint(destinationTable); // relative to Scene
// Set start location
final Point2D startInRoot = commonTableAncestor.sceneToLocal(animationStartPoint); // relative to commonTableAncestor
imageView.relocate(startInRoot.getX(), startInRoot.getY());
// Create animation
final Animation transition = createAndConfigureAnimation(
sourceTable, destinationTable, commonTableAncestor, row,
imageView, animationStartPoint, animationEndPoint);
// add animated image to display
commonTableAncestor.getChildren().add(imageView);
// start animation
transition.play();
}
/**
* Fires a newly created {@link MouseEvent} of type
* {@link MouseEvent#MOUSE_RELEASED} to the target {@link Node} of the last
* mouse interaction.
*
* @param mods
* The {@link Modifiers} for the {@link MouseEvent}.
*/
public void mouseRelease(final Modifiers mods) {
waitForIdle();
run(() -> {
Point2D local = lastMouseInteraction.target.sceneToLocal(lastMouseInteraction.sceneX,
lastMouseInteraction.sceneY);
Point2D screen = lastMouseInteraction.target.localToScreen(local.getX(), local.getY());
fireEvent(lastMouseInteraction.target,
new MouseEvent(lastMouseInteraction.target, lastMouseInteraction.target, MouseEvent.MOUSE_RELEASED,
local.getX(), local.getY(), screen.getX(), screen.getY(), MouseButton.PRIMARY, 1,
mods.shift, mods.control, mods.alt, mods.meta, false, false, false, false, false, false,
new PickResult(lastMouseInteraction.target, lastMouseInteraction.sceneX,
lastMouseInteraction.sceneY)));
});
waitForIdle();
}
protected int getIndexAt(ListView<?> listView, Point2D point) {
if (point == null) {
return listView.getSelectionModel().getSelectedIndex();
}
point = listView.localToScene(point);
Set<Node> lookupAll = getListCells(listView);
ListCell<?> selected = null;
for (Node cellNode : lookupAll) {
Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
if (boundsInScene.contains(point)) {
selected = (ListCell<?>) cellNode;
break;
}
}
if (selected == null) {
return -1;
}
return selected.getIndex();
}
@Override
protected void onCollisionBegin(Entity bonus, Entity player) {
BonusType type = (BonusType) bonus.getComponent(SubTypeComponent.class).getValue();
fire(new BonusPickupEvent(BonusPickupEvent.ANY, type));
bonus.getComponent(CollidableComponent.class).setValue(false);
bonus.setUpdateEnabled(false);
animationBuilder()
.duration(Duration.seconds(0.66))
.interpolator(Interpolators.ELASTIC.EASE_IN())
.onFinished(bonus::removeFromWorld)
.scale(bonus)
.to(new Point2D(0, 0))
.buildAndPlay();
}
/**
* Sets the error message as tooltip for the matching control.
*
* @param below The control needed for positioning the tooltip.
* @param reference The control which gets the tooltip.
*/
@Override
protected void toggleTooltip(Node reference, Control below) {
String fieldTooltip = field.getTooltip();
if ((reference.isFocused() || reference.isHover())
&& (!fieldTooltip.equals("") || field.getErrorMessages().size() > 0)) {
tooltip.setText((!fieldTooltip.equals("") ? fieldTooltip + "\n" : "")
+ String.join("\n", field.getErrorMessages()));
if (tooltip.isShowing()) {
return;
}
Point2D p = below.localToScene(0.0, 0.0);
tooltip.show(
reference.getScene().getWindow(),
p.getX() + reference.getScene().getX() + reference.getScene().getWindow().getX(),
p.getY() + reference.getScene().getY() + reference.getScene().getWindow().getY()
+ below.getHeight() + 5
);
} else {
tooltip.hide();
}
}
/**
* Gets the new joint positions of the temporary joints.
*
* @return the list of positions of the temporary joints
*/
private List<Point2D> getNewJointPositions() {
final SkinLookup skinLookup = graphEditor.getSkinLookup();
final List<Point2D> allJointPositions = GeometryUtils.getJointPositions(connection, skinLookup);
final Set<Integer> jointsToCleanUp = JointCleaner.findJointsToCleanUp(allJointPositions);
final List<Point2D> newJointPositions = new ArrayList<>();
for (int i = 0; i < allJointPositions.size(); i++) {
if (!jointsToCleanUp.contains(i)) {
newJointPositions.add(allJointPositions.get(i));
}
}
return newJointPositions;
}
/**
* Draws a color wheel into the given {@link WritableImage}, starting at the
* given offsets, in the given size (in pixel).
*
* @param image
* The {@link WritableImage} in which the color wheel is drawn.
* @param offsetX
* The horizontal offset (in pixel).
* @param offsetY
* The vertical offset (in pixel).
* @param size
* The size (in pixel).
*/
private void renderColorWheel(WritableImage image, int offsetX, int offsetY,
int size) {
PixelWriter px = image.getPixelWriter();
double radius = size / 2;
Point2D mid = new Point2D(radius, radius);
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
double d = mid.distance(x, y);
if (d <= radius) {
// compute hue angle
double angleRad = d == 0 ? 0
: Math.atan2(y - mid.getY(), x - mid.getX());
// compute saturation depending on distance to
// middle
// ([0;1])
double sat = d / radius;
Color color = Color.hsb(angleRad * 180 / Math.PI, sat, 1);
px.setColor(offsetX + x, offsetY + y, color);
} else {
px.setColor(offsetX + x, offsetY + y, Color.TRANSPARENT);
}
}
}
}
@Test
public void selectAllRows() {
TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
LoggingRecorder lr = new LoggingRecorder();
Platform.runLater(() -> {
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Point2D point = getPoint(tableView, 1, 1);
RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
rfxTableView.focusGained(null);
tableView.getSelectionModel().selectRange(0, 5);
rfxTableView.focusLost(null);
});
List<Recording> recordings = lr.waitAndGetRecordings(1);
Recording recording = recordings.get(0);
AssertJUnit.assertEquals("recordSelect", recording.getCall());
AssertJUnit.assertEquals("all", recording.getParameters()[0]);
}
@Spawns("Laser")
public Entity newLaser(SpawnData data) {
play("shoot" + FXGLMath.random(1, 4) + ".wav");
return entityBuilder()
.type(SpaceRunnerType.BULLET)
.from(data)
.viewWithBBox(texture("sprite_laser.png"))
.with(new CollidableComponent(true))
.with(new ProjectileComponent(new Point2D(1, 0), 850),
new OffscreenCleanComponent())
.build();
}
private void onMouseClicked(MouseEvent me) {
if (!me.getButton().equals(MouseButton.PRIMARY)) {
me.consume();
return;
}
if (Settings.getEditShape() == POLYGON) {
Point2D pt = imageView.parentToLocal(me.getX(), me.getY());
if (path == null) {
// Start a polygon shape with double-click or SHORTCUT + mouse click
if (!me.isShortcutDown() && me.getClickCount() != 2) {
me.consume();
return;
}
beginShape(pt);
}
else {
// End a polygon shape with double-click (and space key)
if (me.getClickCount() == 2) {
endShape(pt);
return;
}
path.getElements().add(new LineTo(pt.getX(), pt.getY()));
points.add(pt);
updatePath(pt);
}
}
me.consume();
}
@Spawns("ai_point")
public Entity newAIPoint(SpawnData data) {
return entityBuilder()
.from(data)
.type(SpaceRunnerType.AI_POINT)
.bbox(new HitBox("MAIN", new Point2D(-400, 0), BoundingShape.box(400, 30)))
.view(new Text())
.with("collisions", new ArrayList<Entity>())
.with("enemies", 0)
.with(new AIPointComponent())
.with(new CollidableComponent(true), new MoveComponent())
.build();
}
@Test
public void testHVH2()
{
Edge edge = new DependencyEdge();
edge.connect(aNode3, aNode4, aGraph);
aGraph.addEdge(edge);
Point2D[] points = SegmentationStyleFactory.createHVHStrategy().getPath(edge, aGraph);
assertEquals( 2, points.length );
assertEquals( new Point2D(120,50), points[0]);
assertEquals( new Point2D(110,50), points[1]);
}
BaseShape( BasicView view, Supplier<Shape> buildRootShape) {
this.view = view;
rootShape = buildRootShape.get();
view.select(rootShape);
// select shape on click
Disposable disposable = JavaFxObservable.eventsOf(rootShape, MouseEvent.MOUSE_CLICKED)
.subscribe( e -> {
view.select(rootShape);
e.consume();
});
// dispose "listeners" when shape is removed from the scene
JavaFxObservable.changesOf(rootShape.sceneProperty())
.filter( scene -> scene == null )
.subscribe( s -> disposable.dispose());
// calculate delta between shape location and initial mouse position on mouse pressed
JavaFxObservable
.eventsOf( rootShape, MouseEvent.MOUSE_PRESSED )
.map( e -> new Point2D( e.getSceneX(), e.getSceneY()))
.subscribe( p -> {
view.select(rootShape);
Bounds bounds = rootShape.localToScene(rootShape.getLayoutBounds());
delta = p.subtract( new Point2D(bounds.getMinX(), bounds.getMinY()) );
});
// User current mouse position and delta to recalculate and set new shape location on mouse dragged
JavaFxObservable
.eventsOf( rootShape, MouseDragEvent.MOUSE_DRAGGED )
.map( e -> rootShape.sceneToLocal(e.getSceneX() - delta.getX(), e.getSceneY() - delta.getY()))
.map( p -> rootShape.localToParent(p))
.subscribe( p -> rootShape.relocate( p.getX(), p.getY()));
}
protected Point getLocation(MouseEvent e) {
// XXX: Viewer may be null if the host is removed in the same pass in
// which the event is forwarded.
if (getHost().getViewer() == null) {
return new Point(e.getSceneX(), e.getSceneY());
}
// FIXME: Prevent invocation of interaction policies when their host
// does not have a link to the viewer.
Point2D location = ((InfiniteCanvasViewer) getHost().getRoot().getViewer()).getCanvas().getContentGroup()
.sceneToLocal(e.getSceneX(), e.getSceneY());
return new Point(location.getX(), location.getY());
}
private void playSpawnAnimation(Entity player) {
player.setScaleX(0);
player.setScaleY(0);
getGameWorld().addEntity(player);
animationBuilder()
.duration(Duration.seconds(0.86))
.interpolator(Interpolators.BOUNCE.EASE_OUT())
.scale(player)
.from(new Point2D(0, 0))
.to(new Point2D(1, 1))
.buildAndPlay();
}
@Override
public void init() {
double t = 0;
for (int y = 0; y < ENEMY_ROWS; y++) {
for (int x = 0; x < ENEMIES_PER_ROW; x++) {
boolean toRight = FXGLMath.randomBoolean();
Entity enemy = spawnEnemy(toRight ? 50 : Config.WIDTH - 50 - 40, 50 + y*75);
Animation<?> anim = animationBuilder()
.delay(Duration.seconds(t))
.autoReverse(true)
.interpolator(Interpolators.SMOOTH.EASE_OUT())
.duration(Duration.seconds(3))
.repeatInfinitely()
.translate(enemy)
.from(enemy.getPosition())
.to(new Point2D(toRight ? Config.WIDTH - 50 - 40 : 50, 50 + y*75))
.build();
animations.add(anim);
anim.start();
t += 0.3;
}
}
}
private void setArenaScreenOrigin(Screen screen) {
final double dpiScaleFactor = ShootOFFController.getDpiScaleFactorForScreen();
final Rectangle2D arenaScreenBounds = screen.getBounds();
arenaScreenOrigin = new Point2D(arenaScreenBounds.getMinX() * dpiScaleFactor,
arenaScreenBounds.getMinY() * dpiScaleFactor);
logger.debug("Set arenaScreenOrigin to {}", arenaScreenOrigin);
}
/** arc from current position, using the specified center coordinates, radius, and angle */
public void arcRel(double xc, double yc, double radius, double angle)
{
// arcTo seems to fail if sweep angle is greater than 360
if(angle >= FX.TWO_PI)
{
angle = FX.TWO_PI - 0.0000001;
}
else if(angle <= -FX.TWO_PI)
{
angle = - FX.TWO_PI + 0.0000001;
}
Point2D p = currentPos();
double a = Math.atan2(yc + yorigin - p.getY(), p.getX() - xc - xorigin);
double b = a - angle;
double xe = xorigin + xc + radius * Math.cos(b);
double ye = yorigin - yc - radius * Math.sin(b);
// arcTo sweep is explained here:
// https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/ArcTo.html
boolean large = (angle >= Math.PI);
boolean sweep = (angle > 0);
add(new ArcTo(radius, radius, 0, xe, ye, large, sweep));
}
/**
* Connects the start point on the left side of a node to an end point on the bottom side of a node.
*
* @param start the start position
* @param end the end position
* @return a list of points connecting the start and end
*/
private static List<Point2D> connectLeftToBottom(final Point2D start, final Point2D end) {
final List<Point2D> path = new ArrayList<>();
if (start.getX() > end.getX() + MINIMUM_EXTENSION) {
if (start.getY() > end.getY() + MINIMUM_EXTENSION) {
addPoint(path, end.getX(), start.getY());
} else {
final double averageX = (start.getX() + end.getX()) / 2;
addPoint(path, averageX, start.getY());
addPoint(path, averageX, end.getY() + MINIMUM_EXTENSION);
addPoint(path, end.getX(), end.getY() + MINIMUM_EXTENSION);
}
} else {
if (start.getY() > end.getY() + MINIMUM_EXTENSION) {
final double averageY = (start.getY() + end.getY()) / 2;
addPoint(path, start.getX() - MINIMUM_EXTENSION, start.getY());
addPoint(path, start.getX() - MINIMUM_EXTENSION, averageY);
addPoint(path, end.getX(), averageY);
} else {
addPoint(path, start.getX() - MINIMUM_EXTENSION, start.getY());
addPoint(path, start.getX() - MINIMUM_EXTENSION, end.getY() + MINIMUM_EXTENSION);
addPoint(path, end.getX(), end.getY() + MINIMUM_EXTENSION);
}
}
return path;
}
@Test
public void testStraight2()
{
Edge edge = new DependencyEdge();
edge.connect(aNode3, aNode4, aGraph);
aGraph.addEdge(edge);
Point2D[] points = SegmentationStyleFactory.createStraightStrategy().getPath(edge, aGraph);
assertEquals( 2, points.length );
assertEquals( new Point2D(120,50), points[0]);
assertEquals( new Point2D(110,50), points[1]);
}
protected void handleDragMouseEvent(final MouseEvent mouseEvent) {
Point2D c = getChart().getPlotArea().sceneToLocal(mouseEvent.getSceneX(), mouseEvent.getSceneY());
final double yPosData = getNumericAxis().getValueForDisplay(c.getY() - dragDelta.y);
if (getNumericAxis().isValueOnAxis(yPosData)) {
valueProperty().set(yPosData);
}
mouseEvent.consume();
}