Пример #1
0
  /**
   * Switches scenes
   *
   * @param fxml
   * @param obj
   * @throws Exception
   */
  public static void replaceSceneContent(String fxml, Object obj) throws Exception {

    FXMLLoader loader = new FXMLLoader();

    try {

      loader = new FXMLLoader(SpaceTraderMain.class.getResource(fxml));
    } catch (Exception e) {

    }
    try {
      loader.setController(obj);

    } catch (Exception e) {
      System.out.println(e);
    }
    Parent page;
    page = (Parent) loader.load();

    Scene scene;
    scene = mystage.getScene();

    if (scene == null) {
      scene = new Scene(page, 700, 450);
      // scene.getStylesheets().add(SpaceTraderMain.class.getResource("demo.css").toExternalForm());
      mystage.setScene(scene);
    } else {
      mystage.getScene().setRoot(page);
    }
    mystage.sizeToScene();

    // return page;

  }
Пример #2
0
 public void setDialogStage(Stage dialogStage, PromptData param) {
   this.dialogStage = dialogStage;
   switch (Main.programTheme) {
     case Main.THEMELIGHT:
       dialogStage
           .getScene()
           .getStylesheets()
           .add(getClass().getResource("/css/" + Main.FILENAMETHEMELIGHT).toExternalForm());
       break;
     case Main.THEMEDARK:
       dialogStage
           .getScene()
           .getStylesheets()
           .add(getClass().getResource("/css/" + Main.FILENAMETHEMEDARK).toExternalForm());
       break;
     case Main.THEMENANAHIRA:
       dialogStage
           .getScene()
           .getStylesheets()
           .add(getClass().getResource("/css/" + Main.FILENAMETHEMENANAHIRA).toExternalForm());
       break;
     default:
       dialogStage
           .getScene()
           .getStylesheets()
           .add(getClass().getResource("/css/" + Main.FILENAMETHEMELIGHT).toExternalForm());
       break;
   }
   promptLabel.setText(param.getMessage());
   promptTextField.setText(param.getDefaultValue());
   promptTextField.setOnKeyPressed(
       event -> {
         if (event.getCode().equals(KeyCode.ENTER)) handleOk();
       });
 }
Пример #3
0
 public static void addResizeListener(final Stage stage, final BorderPane menu) {
   final ResizeListener resizeListener = new ResizeListener(stage, menu);
   stage.getScene().addEventHandler(MouseEvent.MOUSE_MOVED, resizeListener);
   stage.getScene().addEventHandler(MouseEvent.MOUSE_PRESSED, resizeListener);
   stage.getScene().addEventHandler(MouseEvent.MOUSE_DRAGGED, resizeListener);
   final ObservableList<Node> children = stage.getScene().getRoot().getChildrenUnmodifiable();
   for (final Node child : children) {
     ResizeAndMoveHelper.addListenerDeeply(child, resizeListener);
   }
 }
 @FXML
 public void onBackButtonClicked(MouseEvent event) throws IOException {
   Scene currentScene = ((Node) event.getSource()).getScene();
   Stage currentStage = (Stage) currentScene.getWindow();
   FXMLLoader loader =
       new FXMLLoader(getClass().getResource("OptionsMenu.fxml"), tusca_db.Tusca_db.BUNDLE);
   Parent root = (Parent) loader.load();
   Scene scene =
       new Scene(root, currentStage.getScene().getWidth(), currentStage.getScene().getHeight());
   currentStage.setScene(scene);
 }
  public EasyEditShareView(
      Stage stage, OnToggleListener toggleListener, OnSetPatchListener setPatchListener) {
    this.stage = stage;
    this.toggleListener = toggleListener;
    this.effects = initEffects(stage.getScene().getRoot());

    this.title = (Text) stage.getScene().getRoot().lookup("#bank");

    this.next = (Button) stage.getScene().getRoot().lookup("#next");
    this.before = (Button) stage.getScene().getRoot().lookup("#before");

    next.setOnAction(event -> setPatchListener.next());
    before.setOnAction(event -> setPatchListener.before());
  }
Пример #6
0
  /**
   * Traverse the scene graph for all open stages and pick an event target for a dock event based on
   * the location. Once the event target is chosen run the event task with the target and the
   * previous target of the last dock event if one is cached. If an event target is not found fire
   * the explicit dock event on the stage root if one is provided.
   *
   * @param location The location of the dock event in screen coordinates.
   * @param eventTask The event task to be run when the event target is found.
   * @param explicit The explicit event to be fired on the stage root when no event target is found.
   */
  private void pickEventTarget(Point2D location, EventTask eventTask, Event explicit) {
    // RFE for public scene graph traversal API filed but closed:
    // https://bugs.openjdk.java.net/browse/JDK-8133331

    ObservableList<Stage> stages =
        FXCollections.unmodifiableObservableList(StageHelper.getStages());
    // fire the dock over event for the active stages
    for (Stage targetStage : stages) {
      // obviously this title bar does not need to receive its own events
      // though users of this library may want to know when their
      // dock node is being dragged by subclassing it or attaching
      // an event listener in which case a new event can be defined or
      // this continue behavior can be removed
      if (targetStage == this.dockNode.getStage()) continue;

      eventTask.reset();

      Node dragNode = dragNodes.get(targetStage);

      Parent root = targetStage.getScene().getRoot();
      Stack<Parent> stack = new Stack<Parent>();
      if (root.contains(root.screenToLocal(location.getX(), location.getY()))
          && !root.isMouseTransparent()) {
        stack.push(root);
      }
      // depth first traversal to find the deepest node or parent with no children
      // that intersects the point of interest
      while (!stack.isEmpty()) {
        Parent parent = stack.pop();
        // if this parent contains the mouse click in screen coordinates in its local bounds
        // then traverse its children
        boolean notFired = true;
        for (Node node : parent.getChildrenUnmodifiable()) {
          if (node.contains(node.screenToLocal(location.getX(), location.getY()))
              && !node.isMouseTransparent()) {
            if (node instanceof Parent) {
              stack.push((Parent) node);
            } else {
              eventTask.run(node, dragNode);
            }
            notFired = false;
            break;
          }
        }
        // if none of the children fired the event or there were no children
        // fire it with the parent as the target to receive the event
        if (notFired) {
          eventTask.run(parent, dragNode);
        }
      }

      if (explicit != null && dragNode != null && eventTask.getExecutions() < 1) {
        Event.fireEvent(dragNode, explicit.copyFor(this, dragNode));
        dragNodes.put(targetStage, null);
      }
    }
  }
Пример #7
0
  /** Method which switches the which phase of the game is being displayed on the GUI */
  public void switchScenes() {
    if (currentRoot == draftLayout) {
      primaryStage.getScene().setRoot(votingLayout);
      currentRoot = votingLayout;
      draftingPhase = false;
      // votingLayout.onResize();
      chatNode = votingLayout.getChatNode();
      tickerReel = votingLayout.getTickerReel();

    } else {
      primaryStage.getScene().setRoot(draftLayout);
      currentRoot = draftLayout;
      draftingPhase = true;
      draftLayout.getHand().onResize();
      chatNode = draftLayout.getChatNode();
      tickerReel = draftLayout.getTickerReel();
    }
  }
 @Override
 public void start(Stage primaryStage) {
   primaryStage.setTitle("TreeTable View Sample");
   primaryStage.setScene(new Scene(new ChoiceBoxTreeTableSample()));
   primaryStage.sizeToScene();
   primaryStage.show();
   TreeTableView<?> treeTableView =
       (TreeTableView<?>) primaryStage.getScene().getRoot().lookup(".tree-table-view");
   treeTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
 }
Пример #9
0
  @Override
  public void start(Stage primaryStage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("MainScene.fxml"));

    primaryStage.setTitle("Hello World");
    primaryStage.setScene(new Scene(root, 1024, 768));
    primaryStage.getScene().getStylesheets().add("app/GameTabStyle.css");
    // primaryStage.setResizable(false);
    primaryStage.show();
  }
Пример #10
0
  private Parent replaceSceneContent(String fxml) throws Exception {
    Parent page =
        (Parent) FXMLLoader.load(App.class.getResource(fxml), null, new JavaFXBuilderFactory());

    Scene scene = stage.getScene();
    if (scene == null) {
      //            scene = new Scene(page, 700, 550);
      scene = new Scene(page, 700, 550);
      scene
          .getStylesheets()
          .addAll(App.class.getResource("/styles/simple_calendar.css").toExternalForm());
      scene.getStylesheets().add(App.class.getResource("/styles/style.css").toExternalForm());

      stage.setScene(scene);
    } else {
      stage.getScene().setRoot(page);
    }
    stage.sizeToScene();
    return page;
  }
Пример #11
0
 @Override
 public void start(Stage stage) throws Exception {
   String fxmlFile = "/chat.fxml";
   FXMLLoader loader = new FXMLLoader();
   Parent root = loader.load(getClass().getResourceAsStream(fxmlFile));
   stage.setTitle("Chat");
   stage.setScene(new Scene(root));
   stage.getScene().getStylesheets().add("/css/JMetroLightTheme.css");
   stage.show();
   stage.setOnCloseRequest(event -> Controller.getInst().close());
 }
Пример #12
0
 @Override
 public void postInit(final Stage stage) {
   initStyles();
   stage.setMinHeight(580);
   stage.setMinWidth(800);
   final Scene scene = stage.getScene();
   stage.getIcons().add(new Image("images/icons/JACP_512_512.png"));
   // add style sheet
   scene.getStylesheets().add(STYLES[0]);
   instance[0] = this;
   ApplicationLauncher.latch.countDown();
 }
Пример #13
0
 @FXML
 public void tosignup() {
   try {
     //		awaitpa.await();
     // .println("help please");
     Parent page =
         FXMLLoader.load(getClass().getResource("/up.fxml"), null, new JavaFXBuilderFactory());
     fstage.getScene().setRoot(page);
     kd.fstage = fstage;
     fstage.show();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  @Override
  public void start(Stage primaryStage) throws IOException {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("Coefficient.fxml"));
    Parent root = (Parent) loader.load();
    Scene scene = new Scene(root);
    // scene.getStylesheets().add(getClass().getResource("Styles.css").toExternalForm());
    // primaryStage.getIcons().add(new Image("/path/to/stackoverflow.jpg"));
    primaryStage.setScene(scene);

    CoefficientController c = loader.getController();
    c.initGUI();
    primaryStage
        .getScene()
        .getStylesheets()
        .add(getClass().getResource("Styles.css").toExternalForm());
    primaryStage.show();
  }
Пример #15
0
 @InvokableAction(
     name = "Resize window",
     category = "general",
     description = "Resize the screen to 1x/1.5x/2x/3x video size",
     alternatives =
         "Adjust screen;Adjust window size;Adjust aspect ratio;Fix screen;Fix window size;Fix aspect ratio;Correct aspect ratio;",
     defaultKeyMapping = {"ctrl+shift+a"})
 public static void scaleIntegerRatio() {
   Platform.runLater(
       () -> {
         JaceApplication.getApplication().primaryStage.setFullScreen(false);
         size++;
         if (size > 3) {
           size = 0;
         }
         int width = 0, height = 0;
         switch (size) {
           case 0: // 1x
             width = 560;
             height = 384;
             break;
           case 1: // 1.5x
             width = 840;
             height = 576;
             break;
           case 2: // 2x
             width = 560 * 2;
             height = 384 * 2;
             break;
           case 3: // 3x (retina) 2880x1800
             width = 560 * 3;
             height = 384 * 3;
             break;
           default: // 2x
             width = 560 * 2;
             height = 384 * 2;
         }
         Stage stage = JaceApplication.getApplication().primaryStage;
         double vgap = stage.getScene().getY();
         double hgap = stage.getScene().getX();
         stage.setWidth(hgap * 2 + width);
         stage.setHeight(vgap + height);
       });
 }
Пример #16
0
 /**
  * Gets the scenes relative location. The relative location is based on how the scene's is located
  * relative to the operating system.
  *
  * @param The stage of which scene to get the relative location.
  * @return The relative location of the scene. The relative location is based on how the scene's
  *     is located relative to the operating system.
  */
 private TranslatedPoint getRelativeSceneLocation(Stage stage) {
   return new TranslatedPoint(
       stage.getX() + stage.getScene().getX(), stage.getY() + stage.getScene().getY());
 }
 @Override
 public void start(Stage stage) throws Exception {
   scene = stage.getScene();
 }
Пример #18
0
  private void setStageParams(Stage stage) {
    Controller ctrlr = MainStage.controller;
    ProgramSettings ps = SingleObject.getProgramSettings();
    WindowState ws = ps.getWinState();
    Window w = stage.getScene().getWindow();
    w.setX(ws.getX());
    w.setY(ws.getY());
    w.setWidth(ws.getWidth());
    w.setHeight(ws.getHeight());
    stage.setMaximized(ws.isMaximized());

    double oldDuration = ctrlr.getAlarmSplitPane().getDuration();
    ctrlr.getAlarmSplitPane().setDuration(0);
    ctrlr.getAlarmSplitPane().setExpandedSize(ws.getAlarmDividerPositions());
    if (ws.isAlarmsShowing()) {
      ctrlr.getAlarmSplitPane().showSide();
    } else {
      ctrlr.getAlarmSplitPane().hideSide();
    }
    ctrlr.getAlarmSplitPane().setDuration(oldDuration);

    ctrlr.getTreeSplitPane().setExpandedSize(ws.getTreeDividerPositions());
    oldDuration = ctrlr.getTreeSplitPane().getDuration();
    ctrlr.getTreeSplitPane().setDuration(0);
    if (ws.isTreeShowing()) {
      Platform.runLater(() -> ctrlr.getTreeSplitPane().showSide());
    } else {
      Platform.runLater(() -> ctrlr.getTreeSplitPane().hideSide());
    }
    ctrlr.getTreeSplitPane().setDuration(oldDuration);
    Platform.runLater(() -> ctrlr.getSpTreeController().getTvSchemes().requestFocus());

    ctrlr
        .getMainPane()
        .isShowingProperty()
        .bind(
            SingleObject.mainStage
                .fullScreenProperty()
                .isNotEqualTo(new SimpleBooleanProperty(true)));
    ctrlr.getvToolBarPane().isShowingProperty().bind(ctrlr.getMainPane().isShowingProperty());

    ctrlr
        .getMainPane()
        .getSideBar()
        .visibleProperty()
        .addListener(
            (observ, old, newValue) -> {
              if (newValue) {
                String[] state = ctrlr.getMainPane().getUserData().toString().split(";");
                if (Boolean.valueOf(state[0])) {
                  Platform.runLater(() -> ctrlr.getAlarmSplitPane().showSide());
                } else {
                  if (Boolean.valueOf(state[1]))
                    Platform.runLater(() -> ctrlr.getTreeSplitPane().showSide());
                }
              } else {
                ctrlr
                    .getMainPane()
                    .setUserData(
                        ctrlr.getAlarmSplitPane().isShowingProperty().get()
                            + ";"
                            + ctrlr.getTreeSplitPane().isShowingProperty().get());
                if (ctrlr.getAlarmSplitPane().isShowingProperty().get()) {
                  Platform.runLater(() -> ctrlr.getAlarmSplitPane().hideSide());
                } else {
                  Platform.runLater(() -> ctrlr.getTreeSplitPane().hideSide());
                }
              }
            });

    ctrlr
        .getAlarmSplitPane()
        .getSideBar()
        .visibleProperty()
        .addListener(
            (observ, old, newValue) -> {
              if (!ctrlr.getMainPane().isShowingProperty().get()) {
                Platform.runLater(() -> ctrlr.getTreeSplitPane().hideSide());
              } else {
                if (ctrlr.getMainPane().getUserData() != null) {
                  String[] state = ctrlr.getMainPane().getUserData().toString().split(";");
                  if (Boolean.valueOf(state[1]))
                    Platform.runLater(() -> ctrlr.getTreeSplitPane().showSide());
                  ctrlr.getMainPane().setUserData(null);
                }
              }
            });

    ctrlr
        .getAlarmSplitPane()
        .getSideBar()
        .visibleProperty()
        .addListener(
            (observ, old, newVal) -> {
              if (newVal) {
                ctrlr.getShowAlarm().getStyleClass().add("hide-down");
                ctrlr.getShowAlarm().getStyleClass().remove("show-up");
              } else {
                ctrlr.getShowAlarm().getStyleClass().remove("hide-down");
                ctrlr.getShowAlarm().getStyleClass().add("show-up");
              }
            });

    ctrlr.getToolBarController().getHideLeft().setGraphic(null);
    ctrlr
        .getTreeSplitPane()
        .isShowingProperty()
        .addListener(
            (observ, old, newValue) -> {
              if (newValue) {
                ctrlr.getToolBarController().getHideLeft().getStyleClass().add("hide-left");
                ctrlr.getToolBarController().getHideLeft().getStyleClass().remove("show-right");
              } else {
                ctrlr.getToolBarController().getHideLeft().getStyleClass().remove("hide-left");
                ctrlr.getToolBarController().getHideLeft().getStyleClass().add("show-right");
              }
            });

    ctrlr.getToolBarController().getFit().setGraphic(null);
    SingleObject.mainStage
        .fullScreenProperty()
        .addListener(
            (observ, old, newValue) -> {
              if (newValue) {
                ctrlr.getToolBarController().getFit().getStyleClass().add("full-screen-on");
                ctrlr.getToolBarController().getFit().getStyleClass().remove("full-screen-off");
              } else {
                ctrlr.getToolBarController().getFit().getStyleClass().remove("full-screen-on");
                ctrlr.getToolBarController().getFit().getStyleClass().add("full-screen-off");
              }
            });

    SchemeSettings ss = ps.getSchemeSettings();
    SingleObject.mainScheme.getRoot().setScaleX(ss.getSchemeScale());
    SingleObject.mainScheme.getRoot().setScaleY(ss.getSchemeScale());
    ctrlr.getMenuBarController().setLocaleName(ps.getLocaleName());

    ps.getHotkeys().forEach(e -> SingleObject.hotkeys.put(e.getIdCode(), e));
  }
Пример #19
0
  @Override
  public void start(final Stage primaryStage) {
    // initialize the stage
    primaryStage.setTitle("Modal Confirm Example");
    final WebView webView = new WebView();
    webView.getEngine().load("http://docs.oracle.com/javafx/");
    primaryStage.setScene(new Scene(webView));
    primaryStage.show();

    // initialize the confirmation dialog
    final Stage util = new Stage(StageStyle.TRANSPARENT);
    util.initModality(Modality.APPLICATION_MODAL);
    util.setScene(
        new Scene(
            StackPaneBuilder.create()
                .children(
                    PaneBuilder.create().styleClass("modal-dialog-glass").build(),
                    HBoxBuilder.create()
                        .styleClass("modal-dialog-content")
                        .children(
                            LabelBuilder.create().text("Will you like this page?").build(),
                            ButtonBuilder.create()
                                .text("Yes")
                                .defaultButton(true)
                                .onAction(
                                    new EventHandler<ActionEvent>() {
                                      @Override
                                      public void handle(ActionEvent actionEvent) {
                                        // take action and close the dialog.
                                        System.out.println(
                                            "Liked: " + webView.getEngine().getTitle());
                                        primaryStage.getScene().getRoot().setEffect(null);
                                        util.close();
                                      }
                                    })
                                .build(),
                            ButtonBuilder.create()
                                .text("No")
                                .cancelButton(true)
                                .onAction(
                                    new EventHandler<ActionEvent>() {
                                      @Override
                                      public void handle(ActionEvent actionEvent) {
                                        // abort action and close the dialog.
                                        System.out.println(
                                            "Disliked: " + webView.getEngine().getTitle());
                                        primaryStage.getScene().getRoot().setEffect(null);
                                        util.close();
                                      }
                                    })
                                .build())
                        .build())
                .build(),
            Color.TRANSPARENT));
    util.getScene()
        .getStylesheets()
        .add(getClass().getResource("/assets/fxml/modal-dialog.css").toExternalForm());

    // show the confirmation dialog each time a new page is loaded.
    webView
        .getEngine()
        .getLoadWorker()
        .stateProperty()
        .addListener(
            new ChangeListener<Worker.State>() {
              @Override
              public void changed(
                  ObservableValue<? extends Worker.State> observableValue,
                  Worker.State state,
                  Worker.State newState) {
                if (newState.equals(Worker.State.SUCCEEDED)) {
                  primaryStage.getScene().getRoot().setEffect(new BoxBlur());
                  util.show();
                  util.toFront();
                }
              }
            });
  }