Search in sources :

Example 51 with Rectangle2D

use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.

the class Tracker method handleKeyEvent.

/**
 * Allow move/resize with cursor keys, and abort Drag & Drop operations with ESC key.
 *  <p>
 *  Shift: Resize
 *
 *  @param event {@link KeyEvent}
 */
protected void handleKeyEvent(final KeyEvent event) {
    // Consume handled event to keep the key focus,
    // which is otherwise lost to the 'tab-order' traversal
    final KeyCode code = event.getCode();
    boolean notify = false;
    switch(code) {
        case UP:
            if (event.isShiftDown())
                setPosition(tracker.getX(), tracker.getY(), tracker.getWidth(), tracker.getHeight() - 1);
            else
                setPosition(tracker.getX(), tracker.getY() - 1, tracker.getWidth(), tracker.getHeight());
            notify = true;
            break;
        case DOWN:
            if (event.isShiftDown())
                setPosition(tracker.getX(), tracker.getY(), tracker.getWidth(), tracker.getHeight() + 1);
            else
                setPosition(tracker.getX(), tracker.getY() + 1, tracker.getWidth(), tracker.getHeight());
            notify = true;
            break;
        case LEFT:
            if (event.isShiftDown())
                setPosition(tracker.getX(), tracker.getY(), tracker.getWidth() - 1, tracker.getHeight());
            else
                setPosition(tracker.getX() - 1, tracker.getY(), tracker.getWidth(), tracker.getHeight());
            notify = true;
            break;
        case RIGHT:
            if (event.isShiftDown())
                setPosition(tracker.getX(), tracker.getY(), tracker.getWidth() + 1, tracker.getHeight());
            else
                setPosition(tracker.getX() + 1, tracker.getY(), tracker.getWidth(), tracker.getHeight());
            notify = true;
            break;
        case ESCAPE:
            if (start_x >= 0) {
                setPosition(orig);
                endMouseDrag(null);
                notify = true;
            }
            break;
        default:
            return;
    }
    event.consume();
    if (notify)
        notifyListenerOfChange();
    if (code != KeyCode.ESCAPE) {
        // Reset tracker as if we started at this position.
        // That way, a sequence of cursor key moves turns into individual
        // undo-able actions.
        orig = new Rectangle2D(tracker.getX(), tracker.getY(), tracker.getWidth(), tracker.getHeight());
    }
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) KeyCode(javafx.scene.input.KeyCode)

Example 52 with Rectangle2D

use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.

the class PopOver method determineSide.

/**
 * @param owner_bounds Bounds of active owner
 *  @return Suggested Side for the popup
 */
private Side determineSide(final Bounds owner_bounds) {
    // Determine center of active owner
    final double owner_x = owner_bounds.getMinX() + owner_bounds.getWidth() / 2;
    final double owner_y = owner_bounds.getMinY() + owner_bounds.getHeight() / 2;
    // Locate screen
    Rectangle2D screen_bounds = null;
    for (Screen screen : Screen.getScreens()) {
        final Rectangle2D check = screen.getVisualBounds();
        if (check.contains(owner_x, owner_y)) {
            screen_bounds = check;
            break;
        }
    }
    if (screen_bounds == null)
        return Side.BOTTOM;
    // left .. right as -0.5 .. +0.5
    double lr = (owner_x - screen_bounds.getMinX()) / screen_bounds.getWidth() - 0.5;
    // top..buttom as -0.5 .. +0.5
    double tb = (owner_y - screen_bounds.getMinY()) / screen_bounds.getHeight() - 0.5;
    // More left/right from center, or top/bottom from center of screen?
    if (Math.abs(lr) > Math.abs(tb))
        return (lr < 0) ? Side.RIGHT : Side.LEFT;
    else
        return (tb < 0) ? Side.BOTTOM : Side.TOP;
}
Also used : Screen(javafx.stage.Screen) Rectangle2D(javafx.geometry.Rectangle2D)

Example 53 with Rectangle2D

use of javafx.geometry.Rectangle2D in project assembly64fx by freabemania.

the class Main method start.

@Override
public void start(Stage splashStage) {
    GlobalRepoService.getInstance().put("main", this);
    try {
        PlatformInfo platformInfo = platformInfoService.getPlatformInfo(platformInfoService.getPlaformPrefix());
        if (platformInfo.isNewerAvailable(version)) {
            try {
                UpgradeController upgradeDialog = GuiUtils.noShowDialog("upgrade.fxml", true, true, "New version available", splashStage, platformInfo);
                upgradeDialog.getStage().showAndWait();
                UpgradeOptions upgradeChoice = upgradeDialog.getUpgradeChoice();
                if (upgradeChoice == UpgradeOptions.DOWNLOAD) {
                    this.getHostServices().showDocument("http://hackerswithstyle.ddns.net/assembly/download.html");
                    ReturningTask<Void> exitWithDelay = () -> {
                        try {
                            Thread.sleep(500);
                            System.exit(1);
                        } catch (Exception e) {
                        }
                        return null;
                    };
                    ExecutorUtil.executeAsyncWithRetry(exitWithDelay);
                } else if (upgradeChoice == UpgradeOptions.UPGRADE) {
                    Autoupgrade.getInstance().doUpgrade();
                    return;
                }
            } catch (Exception e) {
                LOGGER.info("Unable to startup", e);
            }
        }
    } catch (Exception e) {
        OfflineController offlineController = (OfflineController) GuiUtils.showDialogBare("assemblyOffline.fxml", "Ooops :-/", new Object[] {});
        if (offlineController.openSidify()) {
            GuiUtils.showDialog("sidifyMain.fxml", true, "Sidify Heroium", new Object[] { Boolean.FALSE });
            return;
        } else {
            System.exit(1);
        }
    }
    GuiUtils.showDialog("authLogin.fxml", "Login to Assembly", new Object[] {});
    List<String> inputParams = getParameters().getRaw();
    if (platformInfoService.isWin() && inputParams.size() == 1) {
        File f = new File(inputParams.get(0));
        if (f.exists()) {
            launchViceOrImageView(f);
            System.exit(1);
        }
    }
    final Rectangle2D bounds = Screen.getPrimary().getBounds();
    maxHeight = bounds.getHeight() - 150;
    if (maxHeight > 700) {
        maxHeight = 700;
    }
    try {
        // Utils.getInstance().assertFolders();
        if (isAppActive()) {
            GenericMessageDialogController.withErrorProps("Another instance of", "Assembly64 is already active!").withExitAfterOk().showAndWait();
        }
        if (localDbService.getLocalDB().containsKey("uid")) {
            Analytics.sendEvent("application", "startup_existing_user_" + platformInfoService.getPlaformPrefix());
        } else {
            Analytics.sendEvent("application", "startup_new_user_" + platformInfoService.getPlaformPrefix());
        }
        ImageView splash = new ImageView(new Image(getClass().getResourceAsStream("image-assemblysplash.png")));
        splashLayout = new VBox();
        splashLayout.getChildren().addAll(splash);
        Scene splashScene = new Scene(splashLayout, Color.TRANSPARENT);
        splashStage.setScene(splashScene);
        splashStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SPLASH_WIDTH / 2);
        splashStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SPLASH_HEIGHT / 2);
        splashStage.initStyle(StageStyle.TRANSPARENT);
        splashStage.setAlwaysOnTop(true);
        splashStage.show();
        ExecutorUtil.executeAsyncWithRetry(() -> {
            try {
                artifactsService.updateChecksumInPrivateFolder();
            } catch (Exception e) {
                LOGGER.error("Unable to update checksum", e);
            }
            return null;
        }, 5);
        ExecutorUtil.executeAsyncWithRetry(() -> {
            try {
                artifactsService.getArtifactsDb();
                refreshedArtifacts.set(true);
            } catch (Exception e) {
                LOGGER.error("Unable to get artifacts", e);
                Thread.sleep(1000);
                throw e;
            }
            return null;
        }, 5);
        ReturningTask<Void> continueTask = () -> {
            int retries = 0;
            while (retries < 5) {
                Thread.sleep(2000);
                if (refreshedArtifacts.get() == Boolean.TRUE) {
                    LOGGER.info("Got artifacts from server, ok to start");
                    break;
                }
                retries++;
            }
            if (refreshedArtifacts.get() == Boolean.FALSE) {
                Platform.runLater(() -> {
                    splashStage.close();
                });
                Platform.runLater(() -> {
                    GuiUtils.showDialog("assemblyOffline.fxml", "Ooops :-/", new Object[] {});
                    try {
                        Thread.sleep(10000);
                    } catch (Exception e) {
                    // TODO Auto-generated catch block
                    }
                });
            } else {
                FadeTransition fadeSplash2 = new FadeTransition(Duration.seconds(0.7), splashLayout);
                fadeSplash2.setFromValue(1.0);
                fadeSplash2.setToValue(0.0);
                fadeSplash2.setOnFinished(actionEvent -> {
                    splashStage.hide();
                    viewPrimary();
                });
                fadeSplash2.play();
            // }
            }
            return null;
        };
        ExecutorUtil.executeAsyncWithRetry(continueTask);
    } catch (Exception e) {
        GenericMessageDialogController.withErrorProps("Error", "Error when starting Assembly").withExitAfterOk().showAndWait();
    }
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) RandomAccessFile(java.io.RandomAccessFile) Scheduler(se.light.assembly64.Scheduler) TYPE(se.light.assembly64.model.GuiLocation.TYPE) LoggerFactory(org.slf4j.LoggerFactory) PathService(se.light.assembly64.service.PathService) VBox(javafx.scene.layout.VBox) StringUtils(org.apache.commons.lang3.StringUtils) FileLock(java.nio.channels.FileLock) Application(javafx.application.Application) ArtifactType(se.light.assembly64.model.ArtifactType) LogConfig(se.light.assembly64.LogConfig) ContextMenu(javafx.scene.control.ContextMenu) Type(se.light.assembly64.Support.Type) WindowEvent(javafx.stage.WindowEvent) WorkLocation(se.light.assembly64.model.WorkLocation) Pane(javafx.scene.layout.Pane) Rectangle2D(javafx.geometry.Rectangle2D) MenuItem(javafx.scene.control.MenuItem) ButtonType(se.light.assembly64.fx.GenericMessageDialogController.ButtonType) Set(java.util.Set) Screen(javafx.stage.Screen) Artifact(se.light.assembly64.model.Artifact) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) UserService(se.light.assembly64.service.UserService) Platform(javafx.application.Platform) Duration(javafx.util.Duration) List(java.util.List) PlatformInfoService(se.light.assembly64.service.PlatformInfoService) Optional(java.util.Optional) InstallationService(se.light.assembly64.service.InstallationService) Autoupgrade(se.light.assembly64.Autoupgrade) ReturningTask(se.light.assembly64.model.ReturningTask) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) GuiLocation(se.light.assembly64.model.GuiLocation) MouseEvent(javafx.scene.input.MouseEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) GenericMessageDialogController.heroesOnlyFeatureDialog(se.light.assembly64.fx.GenericMessageDialogController.heroesOnlyFeatureDialog) ArrayList(java.util.ArrayList) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) ViceService(se.light.assembly64.service.ViceService) UpgradeOptions(se.light.assembly64.Support.UpgradeOptions) FadeTransition(javafx.animation.FadeTransition) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Support.resolveInstallationExpandedKey(se.light.assembly64.Support.resolveInstallationExpandedKey) DirectoryChooser(javafx.stage.DirectoryChooser) Color(javafx.scene.paint.Color) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) MenuBar(javafx.scene.control.MenuBar) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) FileUtils(org.apache.commons.io.FileUtils) ArtifactsService(se.light.assembly64.service.ArtifactsService) File(java.io.File) Menu(javafx.scene.control.Menu) Consumer(java.util.function.Consumer) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) PlatformInfo(se.light.assembly64.model.PlatformInfo) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Support.resolveLeafInInstallationExpandedKey(se.light.assembly64.Support.resolveLeafInInstallationExpandedKey) Image(javafx.scene.image.Image) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) FadeTransition(javafx.animation.FadeTransition) Rectangle2D(javafx.geometry.Rectangle2D) Image(javafx.scene.image.Image) Scene(javafx.scene.Scene) PlatformInfo(se.light.assembly64.model.PlatformInfo) UpgradeOptions(se.light.assembly64.Support.UpgradeOptions) ImageView(javafx.scene.image.ImageView) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) VBox(javafx.scene.layout.VBox)

Example 54 with Rectangle2D

use of javafx.geometry.Rectangle2D in project JavaFXLibrary by eficode.

the class TestDragRobotController method openNewWindow.

private void openNewWindow() {
    Parent root;
    try {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/javafxlibrary/ui/TestDragRobotSecondUI.fxml"));
        root = fxmlLoader.load();
        Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
        secondStage = new Stage();
        secondStage.setScene(new Scene(root));
        secondStage.initStyle(StageStyle.UNDECORATED);
        secondStage.setX(screenBounds.getMinX() + screenBounds.getWidth() - 200);
        secondStage.setTitle("Second window");
        secondStage.show();
    } catch (IOException | NullPointerException e) {
        e.printStackTrace();
    }
}
Also used : Parent(javafx.scene.Parent) Rectangle2D(javafx.geometry.Rectangle2D) Stage(javafx.stage.Stage) IOException(java.io.IOException) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader)

Example 55 with Rectangle2D

use of javafx.geometry.Rectangle2D in project DeskChan by DeskChan.

the class MovablePane method setPosition.

void setPosition(Point2D topLeft) {
    if (topLeft == null) {
        setDefaultPosition();
        return;
    }
    Bounds bounds = getLayoutBounds();
    Rectangle2D rect = new Rectangle2D(topLeft.getX(), topLeft.getY(), bounds.getWidth(), bounds.getHeight());
    for (Screen screen : Screen.getScreens()) {
        rect = snapRect(rect, screen.getBounds());
        rect = snapRect(rect, screen.getVisualBounds());
    }
    relocate(rect.getMinX(), rect.getMinY());
}
Also used : Screen(javafx.stage.Screen) Bounds(javafx.geometry.Bounds) Rectangle2D(javafx.geometry.Rectangle2D)

Aggregations

Rectangle2D (javafx.geometry.Rectangle2D)96 Image (javafx.scene.image.Image)14 Point2D (javafx.geometry.Point2D)13 Scene (javafx.scene.Scene)11 Color (javafx.scene.paint.Color)11 Screen (javafx.stage.Screen)11 List (java.util.List)8 IOException (java.io.IOException)7 Rectangle (javafx.scene.shape.Rectangle)7 Stage (javafx.stage.Stage)7 GameApplication (com.almasb.fxgl.app.GameApplication)6 GameSettings (com.almasb.fxgl.app.GameSettings)6 FXGL (com.almasb.fxgl.dsl.FXGL)6 KeyCode (javafx.scene.input.KeyCode)6 Duration (javafx.util.Duration)6 Interpolators (com.almasb.fxgl.animation.Interpolators)4 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)4 Entity (com.almasb.fxgl.entity.Entity)4 BufferedImage (java.awt.image.BufferedImage)4 Collectors (java.util.stream.Collectors)4