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());
}
}
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;
}
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();
}
}
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();
}
}
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());
}
Aggregations