List of usage examples for javafx.stage Stage getScene
public final Scene getScene()
From source file:net.sf.anathema.framework.presenter.action.about.AnathemaAboutAction.java
private void initCloseOnEscape(final Stage aboutStage) { aboutStage.getScene().getAccelerators().put(new KeyCodeCombination(KeyCode.ESCAPE), new Runnable() { @Override/* w w w . j a v a 2 s .c om*/ public void run() { closeDialog(aboutStage); } }); }
From source file:jlotoprint.MainViewController.java
@FXML public void handleOpenTemplateAction(ActionEvent event) { final Stage templateChooser = MainViewController.loadTemplateChooser(); if (templateChooser != null) { templateChooser.getScene().getRoot().addEventHandler(TemplateDialogEvent.SELECTED, (actionEvent) -> { templateChooser.close();/*from w ww . j ava 2 s. c om*/ Template.load(true); }); } }
From source file:jp.toastkid.script.Controller.java
/** * Set stage to this controller and apply style. * @param stage/*w ww. j a v a 2s . c o m*/ */ public void setStage(final Stage stage) { this.stage = stage; final ObservableList<String> stylesheets = this.stage.getScene().getStylesheets(); if (stylesheets != null) { stylesheets.clear(); } stylesheets.addAll(stage.getScene().getStylesheets()); stylesheets.add(getClass().getClassLoader().getResource("keywords.css").toExternalForm()); }
From source file:gov.va.isaac.sync.view.SyncView.java
/** * @see gov.va.isaac.interfaces.gui.views.PopupViewI#showView(javafx.stage.Window) */// ww w . j a v a2 s.c o m @Override public void showView(Window parent) { initGui(); Stage stage = new Stage(StageStyle.DECORATED); stage.initModality(Modality.NONE); stage.initOwner(parent); Scene scene = new Scene(root_); stage.setScene(scene); stage.setTitle("Datastore Synchronization"); stage.getScene().getStylesheets().add(SyncView.class.getResource("/isaac-shared-styles.css").toString()); stage.sizeToScene(); stage.show(); stage.setOnCloseRequest(windowEvent -> { if (running_.get()) { windowEvent.consume(); } }); }
From source file:jp.co.heppokoact.autocapture.FXMLDocumentController.java
@FXML private void pointButtonClicked(ActionEvent event) throws IOException { System.out.println("pointButtonClicked"); // ??/* w w w .j a v a 2 s .co m*/ Stage transparentStage = createTransparentStage(); // ???? Scene scene = transparentStage.getScene(); // EventHandler<? super MouseEvent> setPrevPoint = e -> { // ???? prevPointX.set((int) e.getScreenX()); prevPointY.set((int) e.getScreenY()); transparentStage.close(); }; // ? EventHandler<MouseEvent> setNextPoint = e -> { // ???? nextPointX.set((int) e.getScreenX()); nextPointY.set((int) e.getScreenY()); scene.setOnMouseClicked(setPrevPoint); }; scene.setOnMouseClicked(setNextPoint); transparentStage.show(); }
From source file:jp.co.heppokoact.autocapture.FXMLDocumentController.java
@FXML private void areaButtonClicked(ActionEvent event) throws IOException { System.out.println("areaButtonClicked"); // ??//from ww w .jav a2 s . co m Stage transparentStage = createTransparentStage(); // ????? Scene scene = transparentStage.getScene(); scene.setOnMousePressed(e -> { // dragStartX = (int) e.getScreenX(); dragStartY = (int) e.getScreenY(); // ?? areaRect = new Rectangle(e.getX(), e.getY(), 0, 0); areaRect.setStroke(Color.RED); areaRect.setStrokeWidth(1.0); areaRect.setFill(Color.TRANSPARENT); ((Pane) scene.getRoot()).getChildren().add(areaRect); }); // ????? scene.setOnMouseDragged(e -> { // ?????? areaRect.setWidth(e.getScreenX() - dragStartX); areaRect.setHeight(e.getScreenY() - dragStartY); }); // ????? scene.setOnMouseReleased(e -> { // ? areaStartX.set(dragStartX); areaStartY.set(dragStartY); areaEndX.set((int) e.getScreenX()); areaEndY.set((int) e.getScreenY()); // ?? transparentStage.close(); }); // ?????? transparentStage.setOnCloseRequest(e -> { // ????? dragStartX = 0; dragStartY = 0; areaRect = null; }); transparentStage.show(); }
From source file:org.noroomattheinn.visibletesla.MainController.java
private void addSystemSpecificHandlers(final Stage theStage) { if (SystemUtils.IS_OS_MAC) { // Add a handler for Command-H theStage.getScene().getAccelerators() .put(new KeyCodeCombination(KeyCode.H, KeyCombination.SHORTCUT_DOWN), new Runnable() { @Override//w w w.ja v a2s . c om public void run() { theStage.setIconified(true); } }); } }
From source file:tachyon.view.ProjectProperties.java
public ProjectProperties(JavaProject project, Window w) { this.project = project; stage = new Stage(); stage.initOwner(w);//from w w w. j a va 2s .co m stage.initModality(Modality.APPLICATION_MODAL); stage.setWidth(600); stage.setTitle("Project Properties - " + project.getProjectName()); stage.getIcons().add(tachyon.Tachyon.icon); stage.setResizable(false); HBox mai, libs, one, two, thr, fou; ListView<String> compileList, runtimeList; Button compileAdd, compileRemove, preview, selectIm, runtimeAdd, runtimeRemove; TextField iconField; stage.setScene(new Scene(new VBox(5, pane = new TabPane( new Tab("Library Settings", box1 = new VBox(15, libs = new HBox(10, new Label("External Libraries"), libsView = new ListView<>(), new VBox(5, addJar = new Button("Add Jar"), removeJar = new Button("Remove Jar"))))), new Tab("Program Settings", new ScrollPane(box2 = new VBox(15, one = new HBox(10, new Label("Main-Class"), mainClass = new TextField(project.getMainClassName()), select = new Button("Select")), two = new HBox(10, new Label("Compile-Time Arguments"), compileList = new ListView<>(), new VBox(5, compileAdd = new Button("Add Argument"), compileRemove = new Button("Remove Argument")))))), new Tab("Deployment Settings", box3 = new VBox(15, thr = new HBox(10, new Label("Icon File"), iconField = new TextField(project.getFileIconPath()), preview = new Button("Preview Image"), selectIm = new Button("Select Icon")), fou = new HBox(10, new Label("Runtime Arguments"), runtimeList = new ListView<>(), new VBox(5, runtimeAdd = new Button("Add Argument"), runtimeRemove = new Button("Remove Argument")))))), new VBox(15, mai = new HBox(10, cancel = new Button("Cancel"), confirm = new Button("Confirm")))))); if (applyCss.get()) { stage.getScene().getStylesheets().add(css); } for (Tab b : pane.getTabs()) { b.setClosable(false); } mainClass.setPromptText("Main-Class"); box1.setPadding(new Insets(5, 10, 5, 10)); mai.setAlignment(Pos.CENTER_RIGHT); mai.setPadding(box1.getPadding()); libs.setAlignment(Pos.CENTER); one.setAlignment(Pos.CENTER); two.setAlignment(Pos.CENTER); thr.setAlignment(Pos.CENTER); fou.setAlignment(Pos.CENTER); box1.setAlignment(Pos.CENTER); box2.setPadding(box1.getPadding()); box2.setAlignment(Pos.CENTER); box3.setPadding(box1.getPadding()); box3.setAlignment(Pos.CENTER); mainClass.setEditable(false); mainClass.setPrefWidth(200); for (JavaLibrary lib : project.getAllLibs()) { libsView.getItems().add(lib.getBinaryAbsolutePath()); } for (String sa : project.getCompileTimeArguments().keySet()) { compileList.getItems().add(sa + ":" + project.getCompileTimeArguments().get(sa)); } for (String sa : project.getRuntimeArguments()) { runtimeList.getItems().add(sa); } compileAdd.setOnAction((e) -> { Dialog<Pair<String, String>> dialog = new Dialog<>(); dialog.setTitle("Compiler Argument"); dialog.initOwner(stage); dialog.setHeaderText("Entry the argument"); ButtonType loginButtonType = new ButtonType("Done", ButtonData.OK_DONE); dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(20, 150, 10, 10)); TextField username = new TextField(); username.setPromptText("Key"); TextField password = new TextField(); password.setPromptText("Value"); grid.add(new Label("Key:"), 0, 0); grid.add(username, 1, 0); grid.add(new Label("Value:"), 0, 1); grid.add(password, 1, 1); Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType); loginButton.setDisable(true); username.textProperty().addListener((observable, oldValue, newValue) -> { loginButton.setDisable(newValue.trim().isEmpty()); }); dialog.getDialogPane().setContent(grid); Platform.runLater(() -> username.requestFocus()); dialog.setResultConverter(dialogButton -> { if (dialogButton == loginButtonType) { return new Pair<>(username.getText(), password.getText()); } return null; }); Optional<Pair<String, String>> result = dialog.showAndWait(); if (result.isPresent()) { compileList.getItems().add(result.get().getKey() + ":" + result.get().getValue()); } }); compileRemove.setOnAction((e) -> { if (compileList.getSelectionModel().getSelectedItem() != null) { compileList.getItems().remove(compileList.getSelectionModel().getSelectedItem()); } }); runtimeAdd.setOnAction((e) -> { TextInputDialog dia = new TextInputDialog(); dia.setTitle("Add Runtime Argument"); dia.setHeaderText("Enter an argument"); dia.initOwner(stage); Optional<String> res = dia.showAndWait(); if (res.isPresent()) { runtimeList.getItems().add(res.get()); } }); runtimeRemove.setOnAction((e) -> { if (runtimeList.getSelectionModel().getSelectedItem() != null) { runtimeList.getItems().remove(runtimeList.getSelectionModel().getSelectedItem()); } }); preview.setOnAction((e) -> { if (!iconField.getText().isEmpty()) { if (iconField.getText().endsWith(".ico")) { List<BufferedImage> read = new ArrayList<>(); try { read.addAll(ICODecoder.read(new File(iconField.getText()))); } catch (IOException ex) { } if (read.size() >= 1) { Image im = SwingFXUtils.toFXImage(read.get(0), null); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } else if (iconField.getText().endsWith(".icns")) { try { BufferedImage ima = Imaging.getBufferedImage(new File(iconField.getText())); if (ima != null) { Image im = SwingFXUtils.toFXImage(ima, null); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } catch (ImageReadException | IOException ex) { } } else { Image im = new Image(new File(iconField.getText()).toURI().toString()); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } }); selectIm.setOnAction((e) -> { FileChooser fc = new FileChooser(); fc.setTitle("Icon File"); String OS = System.getProperty("os.name").toLowerCase(); fc.getExtensionFilters().add(new ExtensionFilter("Icon File", OS.contains("win") ? getWindowsImageExtensions() : getMacImageExtensions())); fc.setSelectedExtensionFilter(fc.getExtensionFilters().get(0)); File lf = fc.showOpenDialog(stage); if (lf != null) { iconField.setText(lf.getAbsolutePath()); } }); addJar.setOnAction((e) -> { FileChooser f = new FileChooser(); f.setTitle("External Libraries"); f.setSelectedExtensionFilter(new ExtensionFilter("Jar Files", "*.jar")); List<File> showOpenMultipleDialog = f.showOpenMultipleDialog(stage); if (showOpenMultipleDialog != null) { for (File fi : showOpenMultipleDialog) { if (!libsView.getItems().contains(fi.getAbsolutePath())) { libsView.getItems().add(fi.getAbsolutePath()); } } } }); removeJar.setOnAction((e) -> { String selected = libsView.getSelectionModel().getSelectedItem(); if (selected != null) { libsView.getItems().remove(selected); } }); select.setOnAction((e) -> { List<String> all = getAll(); ChoiceDialog<String> di = new ChoiceDialog<>(project.getMainClassName(), all); di.setTitle("Select Main Class"); di.initOwner(stage); di.setHeaderText("Select A Main Class"); Optional<String> show = di.showAndWait(); if (show.isPresent()) { mainClass.setText(show.get()); } }); cancel.setOnAction((e) -> { stage.close(); }); confirm.setOnAction((e) -> { project.setMainClassName(mainClass.getText()); project.setFileIconPath(iconField.getText()); project.setRuntimeArguments(runtimeList.getItems()); HashMap<String, String> al = new HashMap<>(); for (String s : compileList.getItems()) { String[] spl = s.split(":"); al.put(spl[0], spl[1]); } project.setCompileTimeArguments(al); project.setAllLibs(libsView.getItems()); stage.close(); }); }
From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java
/** * Implementation of the mouse move. The mouse is moved into the graphics * component.//from w w w .j a v a2 s.com * * @param graphicsComponent * The component to move to * @param constraints * The more specific constraints. Use this, for example when you * want the click point to be relative to a part of the component * (e.g. tree node, table cell, etc) rather than the overall * component itself. May be <code>null</code>. * @param xPos * xPos in component * @param yPos * yPos in component * @param xAbsolute * true if x-position should be absolute * @param yAbsolute * true if y-position should be absolute * @param clickOptions * The click options * @throws StepExecutionException * If the click delay is interrupted or the event confirmation * receives a timeout. */ private void moveImpl(final Object graphicsComponent, final Rectangle constraints, final int xPos, final boolean xAbsolute, final int yPos, final boolean yAbsolute, final ClickOptions clickOptions) throws StepExecutionException { Rectangle bounds = getComponentBounds(graphicsComponent, clickOptions); if (constraints != null) { bounds.x += constraints.x; bounds.y += constraints.y; bounds.height = constraints.height; bounds.width = constraints.width; } Point p = PointUtil.calculateAwtPointToGo(xPos, xAbsolute, yPos, yAbsolute, bounds); // Move if necessary if (isMouseMoveRequired(p)) { if (log.isDebugEnabled()) { log.debug("Moving mouse to: " + p); //$NON-NLS-1$ } Point startpoint = m_mouseMotionTracker.getLastMousePointOnScreen(); if (startpoint == null) { // If there is no starting point the center of the root // component is used if (graphicsComponent instanceof Stage) { Stage s = (Stage) graphicsComponent; Node root = s.getScene().getRoot(); startpoint = (root != null) ? getLocation(root, null) : new Point(Rounding.round(s.getWidth() / 2), Rounding.round(s.getHeight() / 2)); } else { Node node = (Node) graphicsComponent; Node root = node.getScene().getRoot(); Node c = (root != null) ? root : node; startpoint = getLocation(c, null); } } IRobotEventConfirmer confirmer = null; InterceptorOptions options = new InterceptorOptions(new long[] { AWTEvent.MOUSE_MOTION_EVENT_MASK }); //For drag Events we have to register the confirmer earlier //because the drag event is thrown when the movement starts if (DragAndDropHelper.getInstance().isDragMode()) { confirmer = m_interceptor.intercept(options); } final Point[] mouseMove = MouseMovementStrategy.getMovementPath(startpoint, p, clickOptions.getStepMovement(), clickOptions.getFirstHorizontal()); for (int i = 0; i < mouseMove.length - 1; i++) { m_robot.mouseMove(mouseMove[i].x, mouseMove[i].y); m_robot.waitForIdle(); } if (!DragAndDropHelper.getInstance().isDragMode()) { confirmer = m_interceptor.intercept(options); } Point endPoint = mouseMove[mouseMove.length - 1]; m_robot.mouseMove(endPoint.x, endPoint.y); m_robot.waitForIdle(); if (confirmer != null) { confirmMove(confirmer, graphicsComponent); } } }
From source file:com.machinepublishers.jbrowserdriver.ElementServer.java
/** * {@inheritDoc}/*from ww w .j a v a 2 s . co m*/ */ @Override public void click() { AppThread.exec(contextItem.statusCode, new Sync<Object>() { @Override public Object perform() { validate(false); node.eval(SCROLL_INTO_VIEW); if (contextItem.context.get().keyboard.get().isShiftPressed()) { node.eval(new StringBuilder().append("this.origOnclick = this.onclick;") .append("this.onclick=function(event){").append(" this.target='_blank';") .append(" if(event){").append(" if(event.stopPropagation){") .append(" event.stopPropagation();").append(" }").append(" }") .append(" if(this.origOnclick){").append(" this.origOnclick(event? event: null);") .append(" }").append(" this.onclick = this.origOnclick;").append("};").toString()); } return null; } }); if (node instanceof HTMLOptionElement) { AppThread.exec(contextItem.statusCode, new Sync<Object>() { @Override public Object perform() { validate(false); try { new ElementServer((JSObject) ((HTMLOptionElement) node).getParentNode(), contextItem) .click(); } catch (RemoteException e) { Util.handleException(e); } int index = ((HTMLOptionElement) node).getIndex(); for (int i = 0; i <= index; i++) { contextItem.context.get().robot.get().keysType(Keys.DOWN); } contextItem.context.get().robot.get().keysType(Keys.SPACE); return null; } }); } else { AppThread.exec(contextItem.statusCode, new Sync<Object>() { @Override public Object perform() { validate(true); final JSObject obj = (JSObject) node.call("getBoundingClientRect"); final double top = Double.parseDouble(obj.getMember("top").toString()); final double left = Double.parseDouble(obj.getMember("left").toString()); final double bottom = Double.parseDouble(obj.getMember("bottom").toString()); final double right = Double.parseDouble(obj.getMember("right").toString()); double clickX = (left + right) / 2d; double clickY = (top + bottom) / 2d; ElementServer doc = ElementServer.create(contextItem); if (!node.equals(doc.node.eval( "(function(){return document.elementFromPoint(" + clickX + "," + clickY + ");})();"))) { final Stage stage = contextItem.stage.get(); final int minX = Math.max(0, (int) Math.floor(left)); final int maxX = Math.min((int) Math.ceil(stage.getScene().getWidth()), (int) Math.ceil(right)); final int minY = Math.max(0, (int) Math.floor(top)); final int maxY = Math.min((int) Math.ceil(stage.getScene().getHeight()), (int) Math.ceil(bottom)); final int incX = (int) Math.max(1, .05d * (double) (maxX - minX)); final int incY = (int) Math.max(1, .05d * (double) (maxY - minY)); for (int x = minX; x <= maxX; x += incX) { boolean found = false; for (int y = minY; y <= maxY; y += incY) { if (node.equals(doc.node.eval("(function(){return document.elementFromPoint(" + x + "," + y + ");})();"))) { clickX = x; clickY = y; found = true; break; } } if (found) { break; } } } final org.openqa.selenium.Point frameLocation = contextItem.selectedFrameLocation(); contextItem.context.get().robot.get().mouseMove(clickX + frameLocation.getX(), clickY + frameLocation.getY()); contextItem.context.get().robot.get().mouseClick(MouseButton.LEFT); return null; } }); } }