Ejemplo n.º 1
0
  public EditorPane(ISandboxStage stage) {
    this.sandboxStage = stage;

    lblTitle = new Label("New File");

    Button btnOpen = StyleUtil.buildButton("Open");
    btnOpen.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            promptSave();

            chooseFile();
          }
        });

    btnSave = StyleUtil.buildButton("Save");
    btnSave.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            saveFile();
          }
        });

    btnSave.setDisable(!isModified);

    Button btnClear = StyleUtil.buildButton("Clear");
    btnClear.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            lblTitle.setText("New File");
            taSource.setText(S_EMPTY);
          }
        });

    Button btnClose = StyleUtil.buildButton("Close");
    btnClose.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            promptSave();

            sandboxStage.editorClosed(EditorPane.this);
          }
        });

    Button btnRun = StyleUtil.buildButton("Run");
    btnRun.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            if (isModified) {
              promptSave();
            }

            setVMLanguage();

            sandboxStage.runFile(EditorPane.this);
          }
        });

    hBoxTitle = new HBox();
    hBoxTitle.setSpacing(10);
    hBoxTitle.setPadding(new Insets(0, 10, 0, 10));
    hBoxTitle.getChildren().add(lblTitle);
    hBoxTitle.getChildren().add(btnOpen);
    hBoxTitle.getChildren().add(btnSave);
    hBoxTitle.getChildren().add(btnClear);
    hBoxTitle.getChildren().add(btnClose);
    hBoxTitle.getChildren().add(btnRun);

    hBoxTitle.setStyle("-fx-background-color:#dddddd; -fx-padding:4px;");

    taSource = new TextArea();
    String styleSource =
        "-fx-font-family:monospace; -fx-font-size:12px; -fx-background-color:white;";
    taSource.setStyle(styleSource);

    taSource
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  final ObservableValue<? extends String> observable,
                  final String oldValue,
                  final String newValue) {
                setModified(true);
              }
            });

    taSource
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> arg0, Boolean oldValue, Boolean newValue) {
                if (Boolean.TRUE.equals(newValue)) {
                  setVMLanguage();
                }
              }
            });

    setTextAreaSaveCombo(taSource);

    taLineNumbers = new TextArea();
    String styleLineNumber =
        "-fx-padding:0; -fx-font-family:monospace; -fx-font-size:12px; -fx-background-color:#eeeeee;";
    taLineNumbers.setStyle(styleLineNumber);
    taLineNumbers.setEditable(false);
    taLineNumbers.setWrapText(true);

    HBox hBoxTextAreas = new HBox();

    hBoxTextAreas.getChildren().add(taLineNumbers);
    hBoxTextAreas.getChildren().add(taSource);

    taSource.prefWidthProperty().bind(hBoxTextAreas.widthProperty());

    getChildren().add(hBoxTitle);
    getChildren().add(hBoxTextAreas);

    hBoxTitle.prefWidthProperty().bind(widthProperty());
    hBoxTitle.prefHeightProperty().bind(heightProperty().multiply(0.1));

    hBoxTextAreas.prefWidthProperty().bind(widthProperty());
    hBoxTextAreas.prefHeightProperty().bind(heightProperty().multiply(0.9));
  }