コード例 #1
0
  public AbstractDialog() {
    dialogStage = new Stage();

    dialogStage.initStyle(StageStyle.UTILITY);
    dialogStage.initModality(Modality.APPLICATION_MODAL);

    dialogStage.setOnShown(this::onShownHandler);
    dialogStage.iconifiedProperty().addListener(this::onIconifiedChanged);
  }
コード例 #2
0
 public void setStage(Stage stage) {
   this.stage = stage;
   stage.setOnShown(
       new EventHandler<WindowEvent>() {
         @Override
         public void handle(WindowEvent event) {
           refresh();
         }
       });
 }
コード例 #3
0
ファイル: MenuBarController.java プロジェクト: laeubi/jgnash
  @FXML
  private void handleIncomeExpensePieChart() {
    final Stage stage =
        FXMLUtils.loadFXML(
            IncomeExpenseDialogController.class.getResource("IncomeExpenseDialog.fxml"), resources);

    stage.setTitle(resources.getString("Title.IncomeExpenseChart"));

    stage.setOnShown(
        event ->
            Platform.runLater(
                () -> {
                  stage.setMinHeight(stage.getHeight());
                  stage.setMinWidth(stage.getWidth());
                }));

    stage.show();
  }
コード例 #4
0
ファイル: Dialogs.java プロジェクト: wenesga/NetBeansProjects
  /*
   * Show a dialog window with the given node as the root node, and perform
   * the given action when the dialog is shown.
   */
  private static void showDialog(Parent root, final OnShownAction onShown) {

    // Create an undecorated modal stage, with the main window as its owner,
    // and the given root as its content

    final Stage dialog = new Stage(StageStyle.UNDECORATED);
    dialog.initModality(Modality.WINDOW_MODAL);

    final Window owner = Model.getInstance().getMainWindow();
    dialog.initOwner(owner);

    dialog.setScene(new Scene(root));

    dialog.setOnShown(
        new EventHandler<WindowEvent>() {
          @Override
          public void handle(WindowEvent t) {

            // Center the dialog within the main window.
            dialog.setX(owner.getX() + owner.getWidth() / 2 - dialog.getWidth() / 2);
            dialog.setY(owner.getY() + owner.getHeight() / 2 - dialog.getHeight() / 2);

            // Perform the optional callback.
            if (onShown != null) {
              onShown.perform();
            }
          }
        });

    // Fade out the main window, show the dialog, wait for it the closed,
    // then fade the main window back in.

    FadeTransitionBuilder.create().node(owner.getScene().getRoot()).toValue(0.25).build().play();

    dialog.showAndWait();

    FadeTransitionBuilder.create().node(owner.getScene().getRoot()).toValue(1).build().play();
  }
コード例 #5
0
ファイル: PlayingVideo.java プロジェクト: weijiancai/reserve
  @Override
  public void start(final Stage primaryStage) {
    primaryStage.setTitle("Chapter 3-2 Playing Video");
    primaryStage.centerOnScreen();
    primaryStage.initStyle(StageStyle.TRANSPARENT);

    final Group root = new Group();
    final Scene scene = new Scene(root, 540, 300, Color.rgb(0, 0, 0, 0));

    // rounded rectangle with slightly transparent
    Node applicationArea = createBackground(scene);
    root.getChildren().add(applicationArea);

    // allow the user to drag window on the desktop
    attachMouseEvents(scene, primaryStage);

    // allows the user to see the progress of the video playing
    progressSlider = createSlider(scene);
    root.getChildren().add(progressSlider);

    // Dragging over surface
    scene.setOnDragOver(
        new EventHandler<DragEvent>() {
          @Override
          public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            if (db.hasFiles() || db.hasUrl() || db.hasString()) {
              event.acceptTransferModes(TransferMode.COPY);
              if (mediaPlayer != null) {
                mediaPlayer.stop();
              }
            } else {
              event.consume();
            }
          }
        });

    // update slider as video is progressing (later removal)
    progressListener =
        new ChangeListener<Duration>() {
          public void changed(
              ObservableValue<? extends Duration> observable,
              Duration oldValue,
              Duration newValue) {
            progressSlider.setValue(newValue.toSeconds());
          }
        };

    // Dropping over surface
    scene.setOnDragDropped(
        new EventHandler<DragEvent>() {

          @Override
          public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            URI resourceUrlOrFile = null;

            // dragged from web browser address line?
            if (db.hasContent(DataFormat.URL)) {
              try {
                resourceUrlOrFile = new URI(db.getUrl().toString());
              } catch (URISyntaxException ex) {
                ex.printStackTrace();
              }
            } else if (db.hasFiles()) {
              // dragged from the file system
              String filePath = null;
              for (File file : db.getFiles()) {
                filePath = file.getAbsolutePath();
              }
              resourceUrlOrFile = new File(filePath).toURI();
              success = true;
            }
            // load media
            Media media = new Media(resourceUrlOrFile.toString());

            // stop previous media player and clean up
            if (mediaPlayer != null) {
              mediaPlayer.stop();
              mediaPlayer.currentTimeProperty().removeListener(progressListener);
              mediaPlayer.setOnPaused(null);
              mediaPlayer.setOnPlaying(null);
              mediaPlayer.setOnReady(null);
            }

            // create a new media player
            mediaPlayer = MediaPlayerBuilder.create().media(media).build();

            // as the media is playing move the slider for progress
            mediaPlayer.currentTimeProperty().addListener(progressListener);

            // play video when ready status
            mediaPlayer.setOnReady(
                new Runnable() {
                  @Override
                  public void run() {
                    progressSlider.setValue(1);
                    progressSlider.setMax(mediaPlayer.getMedia().getDuration().toMillis() / 1000);
                    mediaPlayer.play();
                  }
                });

            // Lazy init media viewer
            if (mediaView == null) {
              mediaView =
                  MediaViewBuilder.create()
                      .mediaPlayer(mediaPlayer)
                      .x(4)
                      .y(4)
                      .preserveRatio(true)
                      .opacity(.85)
                      .smooth(true)
                      .build();

              mediaView.fitWidthProperty().bind(scene.widthProperty().subtract(220));
              mediaView.fitHeightProperty().bind(scene.heightProperty().subtract(30));

              // make media view as the second node on the scene.
              root.getChildren().add(1, mediaView);
            }

            // sometimes loading errors occur
            mediaView.setOnError(
                new EventHandler<MediaErrorEvent>() {
                  public void handle(MediaErrorEvent event) {
                    event.getMediaError().printStackTrace();
                  }
                });

            mediaView.setMediaPlayer(mediaPlayer);

            event.setDropCompleted(success);
            event.consume();
          }
        });

    // rectangular area holding buttons
    final Group buttonArea = createButtonArea(scene);

    // stop button will stop and rewind the media
    Node stopButton = createStopControl();

    // play button can resume or start a media
    final Node playButton = createPlayControl();

    // pauses media play
    final Node pauseButton = createPauseControl();

    stopButton.setOnMousePressed(
        new EventHandler<MouseEvent>() {
          public void handle(MouseEvent me) {
            if (mediaPlayer != null) {
              buttonArea.getChildren().removeAll(pauseButton, playButton);
              buttonArea.getChildren().add(playButton);
              mediaPlayer.stop();
            }
          }
        });
    // pause media and swap button with play button
    pauseButton.setOnMousePressed(
        new EventHandler<MouseEvent>() {
          public void handle(MouseEvent me) {
            if (mediaPlayer != null) {
              buttonArea.getChildren().removeAll(pauseButton, playButton);
              buttonArea.getChildren().add(playButton);
              mediaPlayer.pause();
              paused = true;
            }
          }
        });

    // play media and swap button with pause button
    playButton.setOnMousePressed(
        new EventHandler<MouseEvent>() {
          public void handle(MouseEvent me) {
            if (mediaPlayer != null) {
              buttonArea.getChildren().removeAll(pauseButton, playButton);
              buttonArea.getChildren().add(pauseButton);
              paused = false;
              mediaPlayer.play();
            }
          }
        });

    // add stop button to button area
    buttonArea.getChildren().add(stopButton);

    // set pause button as default
    buttonArea.getChildren().add(pauseButton);

    // add buttons
    root.getChildren().add(buttonArea);

    // create a close button
    Node closeButton = createCloseButton(scene);
    root.getChildren().add(closeButton);

    primaryStage.setOnShown(
        new EventHandler<WindowEvent>() {
          public void handle(WindowEvent we) {
            previousLocation = new Point2D(primaryStage.getX(), primaryStage.getY());
          }
        });

    primaryStage.setScene(scene);
    primaryStage.show();
  }
コード例 #6
0
    @Override
    public void start(final Stage stage) throws Exception {
      File workingDir = new File(System.getProperty("loadui.working", ".")).getAbsoluteFile();
      Scene splashScene;
      try {
        splashScene =
            FXMLLoader.load(new File(workingDir, "res/loadui-splash.fxml").toURI().toURL());
      } catch (IOException e) {
        splashScene =
            SceneBuilder.create()
                .width(600)
                .height(320)
                .fill(Color.DARKGRAY)
                .root(LabelBuilder.create().text(System.getProperty(LOADUI_NAME, "loadUI")).build())
                .build();
      }

      Image[] icons = new Image[0];
      try {
        icons =
            new Image[] {
              new Image(new File(workingDir, "res/icon_64x64.png").toURI().toURL().toString()),
              new Image(new File(workingDir, "res/icon_32x32.png").toURI().toURL().toString())
            };
      } catch (Exception e) {
        // e.printStackTrace();
      }

      final String noFx = getParameters().getNamed().get(NOFX_OPTION);
      final String agent = getParameters().getNamed().get("agent");

      if ("true".equals(agent)) setDefaultSystemProperty("loadui.instance", "agent");

      if ("false".equals(noFx)) {
        setDefaultSystemProperty("loadui.headless", "false");
        final Stage splash =
            StageBuilder.create()
                .style(StageStyle.TRANSPARENT)
                .scene(splashScene)
                .icons(icons)
                .build();
        splash.initModality(Modality.APPLICATION_MODAL);
        splash.centerOnScreen();
        splash.show();
        splash.toFront();

        stage.getIcons().addAll(icons);
        stage.setOnShown(
            new EventHandler<WindowEvent>() {
              @Override
              public void handle(WindowEvent event) {
                System.out.println("closing splash!");
                splash.close();
              }
            });
      }

      System.out.println("start called!");

      Task<Void> task =
          new Task<Void>() {
            @Override
            protected Void call() throws Exception {
              System.setSecurityManager(null);

              System.out.println("LoadUIFXLauncher: Creating launcher");
              launcher = createLauncher(getParameters().getRaw().toArray(new String[0]));
              System.out.println("LoadUIFXLauncher: Initializing launcher");
              launcher.init();
              System.out.println("LoadUIFXLauncher: Starting launcher");
              launcher.start();

              if ("false".equals(noFx)) {
                launcher
                    .framework
                    .getBundleContext()
                    .registerService(Stage.class, stage, new Hashtable<String, Object>());
              }
              return null;
            }
          };

      new Thread(task).start();
    }