Example usage for javafx.geometry Bounds getMinX

List of usage examples for javafx.geometry Bounds getMinX

Introduction

In this page you can find the example usage for javafx.geometry Bounds getMinX.

Prototype

public final double getMinX() 

Source Link

Document

The x coordinate of the upper-left corner of this Bounds .

Usage

From source file:com.eviware.loadui.ui.fx.util.NodeUtils.java

public static Bounds absoluteBoundsOf(Node node) {
    double tX = node.getScene().getWindow().getX() + node.getScene().getX();
    double tY = node.getScene().getWindow().getY() + node.getScene().getY();
    Bounds boundsInScene = node.localToScene(node.getBoundsInLocal());
    return new BoundingBox(boundsInScene.getMinX() + tX, boundsInScene.getMinY() + tY, boundsInScene.getWidth(),
            boundsInScene.getHeight());/*from w ww .  j a va 2  s .  c om*/
}

From source file:com.eviware.loadui.ui.fx.util.NodeUtils.java

public static Rectangle2D localToScreen(Node node, Scene scene) {
    Bounds selectableBounds = node.localToScene(node.getBoundsInLocal());

    return new Rectangle2D(selectableBounds.getMinX() + scene.getX() + scene.getWindow().getX(),
            selectableBounds.getMinY() + scene.getY() + scene.getWindow().getY(),
            node.getBoundsInLocal().getWidth(), node.getBoundsInLocal().getHeight());
}

From source file:net.rptools.image.listeners.DrawHandler.java

/**
 * Convert the shape into an image for storage in the layer model.
 *//*from  w  w  w .j a va2 s. c  o  m*/
@ThreadPolicy(ThreadPolicy.ThreadId.JFX)
private void finalizeDrawing() {
    final SnapshotParameters params = new SnapshotParameters();
    params.setFill(Color.TRANSPARENT);
    final WritableImage snapshot = currentShape.snapshot(params, null);
    final Bounds bounds = currentShape.getBoundsInParent();
    getLayer().addImage(snapshot, bounds.getMinX(), bounds.getMinY());
    getLayer().getDrawable().getChildren().remove(currentShape);
}

From source file:Main.java

public void setCamTranslate(final Cam cam) {
    final Bounds bounds = cam.getBoundsInLocal();
    final double pivotX = bounds.getMinX() + bounds.getWidth() / 2;
    final double pivotY = bounds.getMinY() + bounds.getHeight() / 2;
    cam.t.setX(-pivotX);// w w w  .  j  a  v  a  2 s  . c o  m
    cam.t.setY(-pivotY);
}

From source file:Main.java

public void setCamPivot(final Cam cam) {
    final Bounds bounds = cam.getBoundsInLocal();
    final double pivotX = bounds.getMinX() + bounds.getWidth() / 2;
    final double pivotY = bounds.getMinY() + bounds.getHeight() / 2;
    final double pivotZ = bounds.getMinZ() + bounds.getDepth() / 2;
    cam.p.setX(pivotX);//w w w  . j a va2  s. com
    cam.p.setY(pivotY);
    cam.p.setZ(pivotZ);
    cam.ip.setX(-pivotX);
    cam.ip.setY(-pivotY);
    cam.ip.setZ(-pivotZ);
}

From source file:Main.java

public void setCamScale(final Cam cam, final Scene scene) {
    final Bounds bounds = cam.getBoundsInLocal();
    final double pivotX = bounds.getMinX() + bounds.getWidth() / 2;
    final double pivotY = bounds.getMinY() + bounds.getHeight() / 2;
    final double pivotZ = bounds.getMinZ() + bounds.getDepth() / 2;

    double width = scene.getWidth();
    double height = scene.getHeight();

    double scaleFactor = 1.0;
    double scaleFactorY = 1.0;
    double scaleFactorX = 1.0;
    if (bounds.getWidth() > 0.0001) {
        scaleFactorX = width / bounds.getWidth(); // / 2.0;
    }/* ww w. j  a v a2  s .  c  o  m*/
    if (bounds.getHeight() > 0.0001) {
        scaleFactorY = height / bounds.getHeight(); //  / 1.5;
    }
    if (scaleFactorX > scaleFactorY) {
        scaleFactor = scaleFactorY;
    } else {
        scaleFactor = scaleFactorX;
    }
    cam.s.setX(scaleFactor);
    cam.s.setY(scaleFactor);
    cam.s.setZ(scaleFactor);
}

From source file:Main.java

public void resetCam() {
    cam.t.setX(0.0);/*from  w  ww  .jav  a2  s.  c om*/
    cam.t.setY(0.0);
    cam.t.setZ(0.0);
    cam.rx.setAngle(45.0);
    cam.ry.setAngle(-7.0);
    cam.rz.setAngle(0.0);
    cam.s.setX(1.25);
    cam.s.setY(1.25);
    cam.s.setZ(1.25);

    cam.p.setX(0.0);
    cam.p.setY(0.0);
    cam.p.setZ(0.0);

    cam.ip.setX(0.0);
    cam.ip.setY(0.0);
    cam.ip.setZ(0.0);

    final Bounds bounds = cam.getBoundsInLocal();
    final double pivotX = bounds.getMinX() + bounds.getWidth() / 2;
    final double pivotY = bounds.getMinY() + bounds.getHeight() / 2;
    final double pivotZ = bounds.getMinZ() + bounds.getDepth() / 2;

    cam.p.setX(pivotX);
    cam.p.setY(pivotY);
    cam.p.setZ(pivotZ);

    cam.ip.setX(-pivotX);
    cam.ip.setY(-pivotY);
    cam.ip.setZ(-pivotZ);
}

From source file:com.heliosdecompiler.helios.gui.controller.FileTreeController.java

@FXML
public void initialize() {
    this.rootItem = new TreeItem<>(new TreeNode("[root]"));
    this.root.setRoot(this.rootItem);
    this.root.setCellFactory(new TreeCellFactory<>(node -> {
        if (node.getParent() == null) {
            ContextMenu export = new ContextMenu();

            MenuItem exportItem = new MenuItem("Export");

            export.setOnAction(e -> {
                File file = messageHandler.chooseFile().withInitialDirectory(new File("."))
                        .withTitle(Message.GENERIC_CHOOSE_EXPORT_LOCATION_JAR.format())
                        .withExtensionFilter(new FileFilter(Message.FILETYPE_JAVA_ARCHIVE.format(), "*.jar"),
                                true)/*  w  w w .ja  v a 2 s .  c o m*/
                        .promptSave();

                OpenedFile openedFile = (OpenedFile) node.getMetadata().get(OpenedFile.OPENED_FILE);

                Map<String, byte[]> clone = new HashMap<>(openedFile.getContents());

                backgroundTaskHelper.submit(
                        new BackgroundTask(Message.TASK_SAVING_FILE.format(node.getDisplayName()), true, () -> {
                            try {
                                if (!file.exists()) {
                                    if (!file.createNewFile()) {
                                        throw new IOException("Could not create export file");
                                    }
                                }

                                try (ZipOutputStream zipOutputStream = new ZipOutputStream(
                                        new FileOutputStream(file))) {
                                    for (Map.Entry<String, byte[]> ent : clone.entrySet()) {
                                        ZipEntry zipEntry = new ZipEntry(ent.getKey());
                                        zipOutputStream.putNextEntry(zipEntry);
                                        zipOutputStream.write(ent.getValue());
                                        zipOutputStream.closeEntry();
                                    }
                                }

                                messageHandler.handleMessage(Message.GENERIC_EXPORTED.format());
                            } catch (IOException ex) {
                                messageHandler.handleException(Message.ERROR_IOEXCEPTION_OCCURRED.format(), ex);
                            }
                        }));
            });

            export.getItems().add(exportItem);
            return export;
        }
        return null;
    }));

    root.addEventHandler(KeyEvent.KEY_RELEASED, event -> {
        if (event.getCode() == KeyCode.ENTER) {
            TreeItem<TreeNode> selected = this.root.getSelectionModel().getSelectedItem();
            if (selected != null) {
                if (selected.getChildren().size() != 0) {
                    selected.setExpanded(!selected.isExpanded());
                } else {
                    getParentController().getAllFilesViewerController().handleClick(selected.getValue());
                }
            }
        }
    });

    Tooltip tooltip = new Tooltip();
    StringBuilder search = new StringBuilder();

    List<TreeItem<TreeNode>> searchContext = new ArrayList<>();
    AtomicInteger searchIndex = new AtomicInteger();

    root.focusedProperty().addListener((observable, oldValue, newValue) -> {
        if (!newValue) {
            tooltip.hide();
            search.setLength(0);
        }
    });

    root.boundsInLocalProperty().addListener((observable, oldValue, newValue) -> {
        Bounds bounds = root.localToScreen(newValue);
        tooltip.setAnchorX(bounds.getMinX());
        tooltip.setAnchorY(bounds.getMinY());
    });

    root.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
        if (tooltip.isShowing() && event.getCode() == KeyCode.UP) {
            if (searchIndex.decrementAndGet() < 0) {
                searchIndex.set(searchContext.size() - 1);
            }
        } else if (tooltip.isShowing() && event.getCode() == KeyCode.DOWN) {
            if (searchIndex.incrementAndGet() >= searchContext.size()) {
                searchIndex.set(0);
            }
        } else {
            return;
        }
        event.consume();

        root.scrollTo(root.getRow(searchContext.get(searchIndex.get())));
        root.getSelectionModel().select(searchContext.get(searchIndex.get()));
    });

    root.addEventHandler(KeyEvent.KEY_TYPED, event -> {
        if (event.getCharacter().charAt(0) == '\b') {
            if (search.length() > 0) {
                search.setLength(search.length() - 1);
            }
        } else if (event.getCharacter().charAt(0) == '\u001B') { //esc
            tooltip.hide();
            search.setLength(0);
            return;
        } else if (search.length() > 0
                || (search.length() == 0 && StringUtils.isAlphanumeric(event.getCharacter()))) {
            search.append(event.getCharacter());
            if (!tooltip.isShowing()) {
                tooltip.show(root.getScene().getWindow());
            }
        }

        if (!tooltip.isShowing())
            return;

        String str = search.toString();
        tooltip.setText("Search for: " + str);

        searchContext.clear();

        ArrayDeque<TreeItem<TreeNode>> deque = new ArrayDeque<>();
        deque.addAll(rootItem.getChildren());

        while (!deque.isEmpty()) {
            TreeItem<TreeNode> item = deque.poll();
            if (item.getValue().getDisplayName().contains(str)) {
                searchContext.add(item);
            }
            if (item.isExpanded() && item.getChildren().size() > 0)
                deque.addAll(item.getChildren());
        }

        searchIndex.set(0);
        if (searchContext.size() > 0) {
            root.scrollTo(root.getRow(searchContext.get(0)));
            root.getSelectionModel().select(searchContext.get(0));
        }
    });

    openedFileController.loadedFiles().addListener((MapChangeListener<String, OpenedFile>) change -> {
        if (change.getValueAdded() != null) {
            updateTree(change.getValueAdded());
        }
        if (change.getValueRemoved() != null) {
            this.rootItem.getChildren()
                    .removeIf(ti -> ti.getValue().equals(change.getValueRemoved().getRoot()));
        }
    });
}

From source file:Main.java

private void showBounds() {
    if (layoutCbx.isSelected()) {
        Bounds b = mainRect.getLayoutBounds();
        layoutBoundsRect.setX(b.getMinX());
        layoutBoundsRect.setY(b.getMinY());
        layoutBoundsRect.setWidth(b.getWidth());
        layoutBoundsRect.setHeight(b.getHeight());

        layoutBoundsRect.setVisible(true);
    } else {//from   w  w  w.  ja  v a2 s .  c o m
        layoutBoundsRect.setVisible(false);
    }

    if (localCbx.isSelected()) {
        Bounds b1 = mainRect.getBoundsInLocal();

        Bounds b = b1; // mainRect.localToParent(b1);
        localBoundsRect.setX(b.getMinX());
        localBoundsRect.setY(b.getMinY());
        localBoundsRect.setWidth(b.getWidth());
        localBoundsRect.setHeight(b.getHeight());
        localBoundsRect.setVisible(true);
    } else {
        localBoundsRect.setVisible(false);
    }

    if (parentCbx.isSelected()) {
        Bounds b = mainRect.getBoundsInParent();
        parentBoundsRect.setX(b.getMinX());
        parentBoundsRect.setY(b.getMinY());
        parentBoundsRect.setWidth(b.getWidth());
        parentBoundsRect.setHeight(b.getHeight());
        parentBoundsRect.setVisible(true);
    } else {
        parentBoundsRect.setVisible(false);
    }
}

From source file:Main.java

private void playLayoutBoundsPathTransition() {
    Bounds b = mainRect.getLayoutBounds();
    Path path = new Path();
    path.getElements().add(new MoveTo(b.getMinX(), b.getMinY()));
    path.getElements().add(new LineTo(b.getMaxX(), b.getMinY()));
    path.getElements().add(new LineTo(b.getMaxX(), b.getMaxY()));
    path.getElements().add(new LineTo(b.getMinX(), b.getMaxY()));
    path.getElements().add(new LineTo(b.getMinX(), b.getMinY()));

    LAYOUT_BOUNDS_PATH_TRANSITION.setPath(path);
    LAYOUT_BOUNDS_PATH_TRANSITION.play();
}