예제 #1
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());
      }
    }
  }
 private Stage getStage() {
   return (Stage) menuBar.getScene().getWindow();
 }
예제 #3
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());
    }
  }