Java Code Examples for javafx.scene.layout.Region#getLayoutX()

The following examples show how to use javafx.scene.layout.Region#getLayoutX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelLayoutUpdater.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if a node's JavaFX region has different layout values than those currently stored in the model.
 *
 * @param node the model instance for the node
 *
 * @return {@code true} if any layout value has changed, {@code false if not}
 */
private boolean checkNodeChanged(final GNode node) {

    final GNodeSkin nodeSkin = skinLookup.lookupNode(node);

    if (nodeSkin == null) {
        return false;
    }

    final Region nodeRegion = nodeSkin.getRoot();

    if (nodeRegion.getLayoutX() != node.getX()) {
        return true;
    } else if (nodeRegion.getLayoutY() != node.getY()) {
        return true;
    } else if (nodeRegion.getWidth() != node.getWidth()) {
        return true;
    } else if (nodeRegion.getHeight() != node.getHeight()) {
        return true;
    }
    return false;
}
 
Example 2
Source File: ModelLayoutUpdater.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if a joint's JavaFX region has different layout values than those currently stored in the model.
 *
 * @param joint the model instance for the joint
 *
 * @return {@code true} if any layout value has changed, {@code false if not}
 */
private boolean checkJointChanged(final GJoint joint) {

    final GJointSkin jointSkin = skinLookup.lookupJoint(joint);

    if (jointSkin == null) {
        return false;
    }

    final Region jointRegion = jointSkin.getRoot();

    final double jointRegionX = jointRegion.getLayoutX() + jointSkin.getWidth() / 2;
    final double jointRegionY = jointRegion.getLayoutY() + jointSkin.getHeight() / 2;

    if (jointRegionX != joint.getX()) {
        return true;
    } else if (jointRegionY != joint.getY()) {
        return true;
    }
    return false;
}
 
Example 3
Source File: CellGestures.java    From fxgraph with Do What The F*ck You Want To Public License 5 votes vote down vote up
private static void dragEast(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) {
	final double deltaX = event.getSceneX() - mouseLocation.value.getX();
	final double newMaxX = region.getLayoutX() + region.getWidth() + deltaX;
	if(newMaxX >= region.getLayoutX() && newMaxX <= region.getParent().getBoundsInLocal().getWidth() - handleRadius) {
		region.setPrefWidth(region.getPrefWidth() + deltaX);
	}
}
 
Example 4
Source File: CellGestures.java    From fxgraph with Do What The F*ck You Want To Public License 5 votes vote down vote up
private static void dragWest(MouseEvent event, Wrapper<Point2D> mouseLocation, Region region, double handleRadius) {
	final double deltaX = event.getSceneX() - mouseLocation.value.getX();
	final double newX = region.getLayoutX() + deltaX;
	if(newX != 0 && newX <= region.getParent().getBoundsInLocal().getWidth() - handleRadius) {
		region.setLayoutX(newX);
		region.setPrefWidth(region.getPrefWidth() - deltaX);
	}
}
 
Example 5
Source File: Commands.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Updates the model's layout values to match those in the skin instances.
 *
 * <p>
 * This method adds set operations to the given compound command but does <b>not</b> execute it.
 * </p>
 *
 * @param command a {@link CompoundCommand} to which the set commands will be added
 * @param model the {@link GModel} whose layout values should be updated
 * @param skinLookup the {@link SkinLookup} in use for this graph editor instance
 */
public static void updateLayoutValues(final CompoundCommand command, final GModel model, final SkinLookup skinLookup) {

    final EditingDomain editingDomain = getEditingDomain(model);

    if (editingDomain != null) {

        for (final GNode node : model.getNodes()) {

            final Region nodeRegion = skinLookup.lookupNode(node).getRoot();

            command.append(SetCommand.create(editingDomain, node, NODE_X, nodeRegion.getLayoutX()));
            command.append(SetCommand.create(editingDomain, node, NODE_Y, nodeRegion.getLayoutY()));
            command.append(SetCommand.create(editingDomain, node, NODE_WIDTH, nodeRegion.getWidth()));
            command.append(SetCommand.create(editingDomain, node, NODE_HEIGHT, nodeRegion.getHeight()));
        }

        for (final GConnection connection : model.getConnections()) {

            for (final GJoint joint : connection.getJoints()) {

                final GJointSkin jointSkin = skinLookup.lookupJoint(joint);
                final Region jointRegion = jointSkin.getRoot();

                final double x = jointRegion.getLayoutX() + jointSkin.getWidth() / 2;
                final double y = jointRegion.getLayoutY() + jointSkin.getHeight() / 2;

                command.append(SetCommand.create(editingDomain, joint, JOINT_X, x));
                command.append(SetCommand.create(editingDomain, joint, JOINT_Y, y));
            }
        }
    }
}
 
Example 6
Source File: GeometryUtils.java    From graph-editor with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets the layout x and y values from all joints in a list of joint skins.
 *
 * @param jointSkins a list of joint skin instances
 *
 * @return a {@link List} of {@link Point2D} objects containing joint x and y values
 */
public static List<Point2D> getJointPositions(final List<GJointSkin> jointSkins) {

    final List<Point2D> jointPositions = new ArrayList<>();

    for (final GJointSkin jointSkin : jointSkins) {

        final Region region = jointSkin.getRoot();

        final double x = region.getLayoutX() + jointSkin.getWidth() / 2;
        final double y = region.getLayoutY() + jointSkin.getHeight() / 2;

        jointPositions.add(new Point2D(x, y));
    }

    return jointPositions;
}