Пример #1
0
  private void showSplash(
      final Stage initStage, Task<?> task, InitCompletionHandler initCompletionHandler) {
    progressText.textProperty().bind(task.messageProperty());
    loadProgress.progressProperty().bind(task.progressProperty());
    task.stateProperty()
        .addListener(
            (observableValue, oldState, newState) -> {
              if (newState == Worker.State.SUCCEEDED) {
                loadProgress.progressProperty().unbind();
                loadProgress.setProgress(1);
                initStage.toFront();
                FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.2), splashLayout);
                fadeSplash.setFromValue(1.0);
                fadeSplash.setToValue(0.0);
                fadeSplash.setOnFinished(actionEvent -> initStage.hide());
                fadeSplash.play();

                initCompletionHandler.complete();
              } // todo add code to gracefully handle other task states.
            });

    Scene splashScene = new Scene(splashLayout);
    initStage.initStyle(StageStyle.UNDECORATED);
    final Rectangle2D bounds = Screen.getPrimary().getBounds();
    initStage.setScene(splashScene);
    initStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SPLASH_WIDTH / 2);
    initStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SPLASH_HEIGHT / 2);
    initStage.show();
  }
  private void setupStageLocation(Stage stage) {
    ObservableList<Screen> screens = Screen.getScreens();
    Screen screen =
        screens.size() <= screenNumber ? Screen.getPrimary() : screens.get(screenNumber);

    Rectangle2D bounds = screen.getBounds();
    boolean primary =
        screen.equals(
            Screen.getPrimary()); // WORKAROUND: this doesn't work nice in combination with full
    // screen, so this hack is used to prevent going fullscreen when
    // screen is not primary

    if (primary) {
      stage.setX(bounds.getMinX());
      stage.setY(bounds.getMinY());
      stage.setWidth(bounds.getWidth());
      stage.setHeight(bounds.getHeight());
      stage.setFullScreen(true);
    } else {
      stage.setX(bounds.getMinX());
      stage.setY(bounds.getMinY());
      stage.setWidth(bounds.getWidth());
      stage.setHeight(bounds.getHeight());
      stage.toFront();
    }
  }
  private void displayOnStage(Stage newStage, Stage oldStage) {
    oldStage.setScene(null);

    newStage.setScene(scene);
    newStage.show();

    setupStageLocation(newStage);

    newStage.toFront();
    oldStage.hide();
  }
Пример #4
0
  @FXML
  private void handleAction(ActionEvent event) {
    TextArea textarea = (TextArea) menuBar.getScene().lookup("#textarea");

    if (event.getSource() == chmiWordWrap) {
      wordWrapOn = chmiWordWrap.isSelected();
      textarea.setWrapText(wordWrapOn);

    } else if (event.getSource() == miChangeCase) {
      try {
        if (changeCaseDialog == null) {
          FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ChangeCaseDialog.fxml"));
          Parent root = fxmlLoader.load();
          controller = fxmlLoader.getController();
          controller.setSelectedCase(prefs.get(strSelectedCase, "UPPERCASE"));
          changeCaseDialog = new Stage();
          changeCaseDialog.setResizable(false);
          changeCaseDialog.initStyle(StageStyle.UTILITY);
          changeCaseDialog.setAlwaysOnTop(true);
          changeCaseDialog.setX(prefs.getDouble(strChangeCaseX, changeCaseDialog.getX()));
          changeCaseDialog.setY(prefs.getDouble(strChangeCaseY, changeCaseDialog.getY()));
          Scene scene = new Scene(root);
          changeCaseDialog.setScene(scene);
          changeCaseDialog.setTitle("Change Case");
        }

        changeCaseDialog.toFront();
        changeCaseDialog.show();
      } catch (Exception e) {

      }
    } else if (event.getSource() == miRemoveLineBreaks) {
      if (textarea.getSelectedText().length() == 0) {
        textarea.selectAll();

        if (textarea.getSelectedText().length() == 0) {
          return;
        }
      }

      String result = TextUtilities.removeLineBreaks(textarea.getSelectedText());

      int start = textarea.getSelection().getStart();
      textarea.replaceSelection(result);
      textarea.selectRange(start, start + result.length());
    } else if (event.getSource() == miFont) {
      Font font = textarea.getFont();
      FontSelectorDialog dialog = new FontSelectorDialog(font);
      Optional<Font> op = dialog.showAndWait();
      if (op.isPresent()) {
        textarea.setFont(op.get());
      }
    }
  }
Пример #5
0
  @Override
  public void start(Stage primaryStage) throws RemoteException {

    controller = new BannerController(this);
    Font font = new Font("Arial", HEIGHT);
    text = new Text();
    text.setFont(font);
    text.setFill(Color.BLACK);

    Pane root = new Pane();
    root.getChildren().add(text);
    Scene scene = new Scene(root, WIDTH, HEIGHT);

    primaryStage.setTitle("AEX banner");
    primaryStage.setScene(scene);
    primaryStage.show();
    primaryStage.toFront();

    // Start animation: text moves from right to left
    animationTimer =
        new AnimationTimer() {
          private long prevUpdate;

          @Override
          public void handle(long now) {
            long lag = now - prevUpdate;
            if (lag >= NANO_TICKS) {
              // calculate new location of text
              // TODO

              textPosition = textPosition - 8;
              if (textPosition < -textLength) {
                textPosition = WIDTH;
              }

              text.relocate(textPosition, 0);
              prevUpdate = now;
            }
          }

          @Override
          public void start() {
            prevUpdate = System.nanoTime();
            textPosition = WIDTH;
            text.relocate(textPosition, 0);
            super.start();
          }
        };
    animationTimer.start();
  }
Пример #6
0
  private void showMemoryWarning() {
    Logger.warning("Memory " + (MEMORY_FULL_WARNING_THRESHOLD * 100.0) + "% full.");

    ThreadHelper.runOnFxThread(
        () -> {
          Alert alert = new Alert(AlertType.WARNING);
          alert.setTitle(FxComponent.DEFAULT_RESOURCES.getString("MemoryWarningPane.title"));
          alert.setHeaderText(FxComponent.DEFAULT_RESOURCES.getString("MemoryWarningPane.header"));
          alert.setContentText(
              FxComponent.DEFAULT_RESOURCES.getString("MemoryWarningPane.message"));
          alert.show();
          Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
          stage.toFront();
          stage.setAlwaysOnTop(true);
        });
  }
 public void onWindowShown(Window window) {
   if (window != stage) stage.toFront();
 }
Пример #8
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();
    }
Пример #9
0
  @FXML
  private void handleAction(ActionEvent event) {
    List<IIOImage> iioImageList = GuiController.getInstance().iioImageList;
    List<BufferedImage> imageList = GuiController.getInstance().imageList;
    int imageIndex = GuiController.getInstance().imageIndex;
    if (iioImageList == null
        && (event.getSource() != chmiScreenshotMode)
        && event.getSource() != chmiSegmentedRegions) {
      Alert alert =
          new Alert(Alert.AlertType.INFORMATION, bundle.getString("Please_load_an_image."));
      alert.show();
      return;
    }

    if (event.getSource() == miMetadata) {
      try {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ImageInfoDialog.fxml"));
        Parent root = fxmlLoader.load();
        ImageInfoDialogController controller = fxmlLoader.getController();
        controller.setImage(iioImageList.get(imageIndex));
        Stage imageInfoDialog = new Stage();
        imageInfoDialog.setResizable(false);
        imageInfoDialog.initStyle(StageStyle.UTILITY);
        imageInfoDialog.setAlwaysOnTop(true);
        //            imageInfoDialog.setX(prefs.getDouble(strChangeCaseX, imageInfoDialog.getX()));
        //            imageInfoDialog.setY(prefs.getDouble(strChangeCaseY, imageInfoDialog.getY()));
        Scene scene1 = new Scene(root);
        imageInfoDialog.setScene(scene1);
        imageInfoDialog.setTitle("Image Properties");
        imageInfoDialog.toFront();
        imageInfoDialog.show();
      } catch (Exception e) {

      }
    } else if (event.getSource() == miAutocrop) {
      menuBar.getScene().setCursor(Cursor.WAIT);

      originalImage = (BufferedImage) iioImageList.get(imageIndex).getRenderedImage();
      BufferedImage croppedImage =
          net.sourceforge.vietocr.util.ImageHelper.autoCrop(originalImage, 0.1);
      // if same image, skip
      if (originalImage != croppedImage) {
        stack.push(originalImage);
        imageList.set(imageIndex, croppedImage);
        iioImageList.get(imageIndex).setRenderedImage((BufferedImage) croppedImage);
        GuiController.getInstance().loadImage();
      }

      menuBar.getScene().setCursor(Cursor.DEFAULT);
    } else if (event.getSource() == miBrightness) {

    } else if (event.getSource() == miContrast) {

    } else if (event.getSource() == miDeskew) {
      menuBar.getScene().setCursor(Cursor.WAIT);

      Platform.runLater(
          new Runnable() {
            @Override
            public void run() {
              ImageDeskew deskew =
                  new ImageDeskew((BufferedImage) iioImageList.get(imageIndex).getRenderedImage());
              double imageSkewAngle = deskew.getSkewAngle();

              if ((imageSkewAngle > MINIMUM_DESKEW_THRESHOLD
                  || imageSkewAngle < -(MINIMUM_DESKEW_THRESHOLD))) {
                originalImage = (BufferedImage) iioImageList.get(imageIndex).getRenderedImage();
                stack.push(originalImage);
                BufferedImage rotatedImage =
                    rotateImage(originalImage, Math.toRadians(-imageSkewAngle));
                imageList.set(imageIndex, rotatedImage); // persist the rotated image
                iioImageList.get(imageIndex).setRenderedImage(rotatedImage);
                GuiController.getInstance().loadImage();
              }
              menuBar.getScene().setCursor(Cursor.DEFAULT);
            }
          });
    } else if (event.getSource() == miGrayscale) {

    } else if (event.getSource() == miInvert) {

    } else if (event.getSource() == miMonochrome) {

    } else if (event.getSource() == miSharpen) {

    } else if (event.getSource() == miSmooth) {

    } else if (event.getSource() == miUndo) {
      if (stack.isEmpty()) {
        return;
      }
      BufferedImage image = stack.pop();
      imageList.set(imageIndex, image);
      iioImageList.get(imageIndex).setRenderedImage(image);
      GuiController.getInstance().loadImage();
    } else if (event.getSource() == chmiScreenshotMode) {
      Label labelScreenShotMode = (Label) menuBar.getScene().lookup("#labelScreenShotMode");
      labelScreenShotMode.setText(this.chmiScreenshotMode.isSelected() ? "On" : "Off");
    } else if (event.getSource() == chmiSegmentedRegions) {
      Node segmentedRegionsBox = menuBar.getScene().lookup("#segmentedRegionsBox");
      segmentedRegionsBox.setVisible(chmiSegmentedRegions.isSelected());
    }
  }
 public void showPanel() {
   checkoutStage.show();
   checkoutStage.toFront();
 }