Java Code Examples for javafx.scene.control.TextArea#setWrapText()

The following examples show how to use javafx.scene.control.TextArea#setWrapText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GUIUtil.java    From bisq with GNU Affero General Public License v3.0 7 votes vote down vote up
public static void showSelectableTextModal(String title, String text) {
    TextArea textArea = new BisqTextArea();
    textArea.setText(text);
    textArea.setEditable(false);
    textArea.setWrapText(true);
    textArea.setPrefSize(800, 600);

    Scene scene = new Scene(textArea);
    Stage stage = new Stage();
    if (null != title) {
        stage.setTitle(title);
    }
    stage.setScene(scene);
    stage.initModality(Modality.NONE);
    stage.initStyle(StageStyle.UTILITY);
    stage.show();
}
 
Example 2
Source File: AlertMaker.java    From Library-Assistant with Apache License 2.0 7 votes vote down vote up
public static void showErrorMessage(Exception ex, String title, String content) {
    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle("Error occured");
    alert.setHeaderText(title);
    alert.setContentText(content);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);
    String exceptionText = sw.toString();

    Label label = new Label("The exception stacktrace was:");

    TextArea textArea = new TextArea(exceptionText);
    textArea.setEditable(false);
    textArea.setWrapText(true);

    textArea.setMaxWidth(Double.MAX_VALUE);
    textArea.setMaxHeight(Double.MAX_VALUE);
    GridPane.setVgrow(textArea, Priority.ALWAYS);
    GridPane.setHgrow(textArea, Priority.ALWAYS);

    GridPane expContent = new GridPane();
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.add(label, 0, 0);
    expContent.add(textArea, 0, 1);

    alert.getDialogPane().setExpandableContent(expContent);
    alert.showAndWait();
}
 
Example 3
Source File: InterruptibleProcessController.java    From chvote-1-0 with GNU Affero General Public License v3.0 6 votes vote down vote up
private void showAlert(ProcessInterruptedException e) {
    Alert alert = new Alert(Alert.AlertType.ERROR);
    ResourceBundle resources = getResourceBundle();
    alert.setTitle(resources.getString("exception_alert.title"));
    alert.setHeaderText(resources.getString("exception_alert.header"));
    alert.setContentText(e.getMessage());

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    String exceptionText = sw.toString();

    Label stackTraceLabel = new Label(resources.getString("exception_alert.label"));
    TextArea stackTraceTextArea = new TextArea(exceptionText);
    stackTraceTextArea.setEditable(false);
    stackTraceTextArea.setWrapText(true);
    GridPane.setVgrow(stackTraceTextArea, Priority.ALWAYS);
    GridPane.setHgrow(stackTraceTextArea, Priority.ALWAYS);

    GridPane expandableContent = new GridPane();
    expandableContent.setPrefSize(400, 400);
    expandableContent.setMaxWidth(Double.MAX_VALUE);
    expandableContent.add(stackTraceLabel, 0, 0);
    expandableContent.add(stackTraceTextArea, 0, 1);

    alert.getDialogPane().setExpandableContent(expandableContent);
    // Dirty Linux only fix...
    // Expandable zones cause the dialog not to resize correctly
    if (System.getProperty("os.name").matches(".*[Ll]inux.*")) {
        alert.getDialogPane().setPrefSize(600, 400);
        alert.setResizable(true);
        alert.getDialogPane().setExpanded(true);
    }

    alert.showAndWait();
}
 
Example 4
Source File: DetailedSongPanel.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a new detailed song panel.
 */
public DetailedSongPanel() {
    GridPane formPanel = new GridPane();
    formPanel.setHgap(10);
    ccli = new IntegerTextField();
    publisher = new TextField();
    year = new IntegerTextField();
    copyright = new TextField();
    key = new TextField();
    capo = new IntegerTextField();
    info = new TextArea();
    info.setWrapText(true);

    addBlock(formPanel, LabelGrabber.INSTANCE.getLabel("ccli.number.label"), ccli, 1);
    addBlock(formPanel, LabelGrabber.INSTANCE.getLabel("copyright.label"), copyright, 2);
    addBlock(formPanel, LabelGrabber.INSTANCE.getLabel("year.label"), year, 3);
    addBlock(formPanel, LabelGrabber.INSTANCE.getLabel("publisher.label"), publisher, 4);
    addBlock(formPanel, LabelGrabber.INSTANCE.getLabel("key.label"), key, 5);
    addBlock(formPanel, LabelGrabber.INSTANCE.getLabel("capo.label"), capo, 6);
    addBlock(formPanel, LabelGrabber.INSTANCE.getLabel("notes.label"), info, 7);

    setTop(formPanel);

}
 
Example 5
Source File: PainteraAlerts.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a {@link LabelBlockLookup} that returns all contained blocks ("OK") or no blocks ("CANCEL")
 * @param source used to determine block sizes for marching cubes
 * @return {@link LabelBlockLookup} that returns all contained blocks ("OK") or no blocks ("CANCEL")
 */
public static LabelBlockLookup getLabelBlockLookupFromDataSource(final DataSource<?, ?> source) {
	final Alert alert = PainteraAlerts.alert(Alert.AlertType.CONFIRMATION);
	alert.setHeaderText("Define label-to-block-lookup for on-the-fly mesh generation");
	final TextArea ta = new TextArea("Could not deserialize label-to-block-lookup that is required for on the fly mesh generation. " +
			"If you are not interested in 3D meshes, press cancel. Otherwise, press OK. Generating meshes on the fly will be slow " +
			"as the sparsity of objects can not be utilized.");
	ta.setEditable(false);
	ta.setWrapText(true);
	alert.getDialogPane().setContent(ta);
	final Optional<ButtonType> bt = alert.showAndWait();
	if (bt.isPresent() && ButtonType.OK.equals(bt.get())) {
		final CellGrid[] grids = source.getGrids();
		long[][] dims = new long[grids.length][];
		int[][] blockSizes = new int[grids.length][];
		for (int i = 0; i < grids.length; ++i) {
			dims[i] = grids[i].getImgDimensions();
			blockSizes[i] = new int[grids[i].numDimensions()];
			grids[i].cellDimensions(blockSizes[i]);
		}
		LOG.debug("Returning block lookup returning all blocks.");
		return new LabelBlockLookupAllBlocks(dims, blockSizes);
	} else {
		return new LabelBlockLookupNoBlocks();
	}
}
 
Example 6
Source File: FoxEatsDemoView.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
public LabelledRadiusPane getDisplayPane() {
    LabelledRadiusPane left = new LabelledRadiusPane("Input Phrases");
    lArea = new TextArea();
    lArea.setWrapText(true);
    lArea.setFont(Font.font("Helvetica", FontWeight.MEDIUM, 16));
    lArea.layoutYProperty().bind(left.labelHeightProperty().add(10));
    left.layoutBoundsProperty().addListener((v, o, n) -> {
        lArea.setLayoutX(10);
        lArea.setPrefWidth(n.getWidth() - 20);
        lArea.setPrefHeight(n.getHeight() - left.labelHeightProperty().get() - 20);
    });
    lArea.textProperty().addListener((v, o, n) -> {
        lArea.setScrollTop(Double.MAX_VALUE);
        lArea.setScrollLeft(Double.MAX_VALUE);
    });
    left.getChildren().add(lArea);
    
    String smallTabs = "\t\t\t\t\t\t\t";
    String bigTabs = "\t\t\t\t\t\t\t\t";
    demo.getPhraseEntryProperty().addListener((v, o, n) -> {
        Platform.runLater(() -> {
            lArea.appendText("\n" + n[0] + (n[0].length() > 4 ? smallTabs : bigTabs) + n[1] + "\t\t\t\t\t\t\t\t" + n[2]);
        });
    });
    
    demo.getPhraseEndedProperty().addListener((v, o, n) -> {
        Platform.runLater(() -> {
            lArea.appendText("\n\nWhat does a fox eat?");
        });
    });
    
    return left;
}
 
Example 7
Source File: AlertMaker.java    From Library-Assistant with Apache License 2.0 5 votes vote down vote up
public static void showErrorMessage(Exception ex) {
    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle("Error occured");
    alert.setHeaderText("Error Occured");
    alert.setContentText(ex.getLocalizedMessage());

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    ex.printStackTrace(pw);
    String exceptionText = sw.toString();

    Label label = new Label("The exception stacktrace was:");

    TextArea textArea = new TextArea(exceptionText);
    textArea.setEditable(false);
    textArea.setWrapText(true);

    textArea.setMaxWidth(Double.MAX_VALUE);
    textArea.setMaxHeight(Double.MAX_VALUE);
    GridPane.setVgrow(textArea, Priority.ALWAYS);
    GridPane.setHgrow(textArea, Priority.ALWAYS);

    GridPane expContent = new GridPane();
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.add(label, 0, 0);
    expContent.add(textArea, 0, 1);

    alert.getDialogPane().setExpandableContent(expContent);

    styleAlert(alert);
    alert.showAndWait();
}
 
Example 8
Source File: App.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
static void showThrowable(String sender, String className, String message, List<StackTraceElement> stacktrace) {
	if (!Main.getProperties().getBoolean("error-alerting", true)) return;

	Alert alert = new Alert(Alert.AlertType.ERROR);
	((Stage) alert.getDialogPane().getScene().getWindow()).getIcons().add(new Image(App.ICON_URL.toString()));

	alert.setTitle(Main.getString("error"));
	alert.initModality(Modality.WINDOW_MODAL);
	alert.setHeaderText(className + " " + Main.getString("caused-by") + " " + sender);
	alert.setContentText(message);
	StringBuilder exceptionText = new StringBuilder ();
	for (Object item : stacktrace)
		exceptionText.append((item != null ? item.toString() : "null") + "\n");

	TextArea textArea = new TextArea(exceptionText.toString());
	textArea.setEditable(false);
	textArea.setWrapText(true);
	textArea.setMaxWidth(Double.MAX_VALUE);
	textArea.setMaxHeight(Double.MAX_VALUE);

	CheckBox checkBox = new CheckBox(Main.getString("enable-error-alert"));
	checkBox.setSelected(Main.getProperties().getBoolean("error-alerting", true));
	checkBox.selectedProperty().addListener((obs, oldValue, newValue) -> {
		Main.getProperties().put("error-alerting", newValue);
	});

	BorderPane pane = new BorderPane();
	pane.setTop(checkBox);
	pane.setCenter(textArea);

	alert.getDialogPane().setExpandableContent(pane);
	alert.show();
}
 
Example 9
Source File: PresetHandler.java    From game-of-life-java with MIT License 5 votes vote down vote up
private VBox createPresetPage(int pageIndex, FlowPane base) {
    VBox box = new VBox(5);
    for (int i = pageIndex; i < pageIndex + 1; i++) {
        TextArea text = new TextArea(presets[i]);
        text.setWrapText(true);
        currentPreset = Character.toUpperCase(presets[i].charAt(0)) + presets[i].substring(1);
        Label l = new Label(currentPreset);

        HBox nameAndOpen = new HBox(5);
        nameAndOpen.getChildren().addAll(l);
        File f1 = new File("Presets/"+presets[i]+".png");
        if(f1.exists() && !f1.isDirectory()) { 
            Image myPreset = new Image("file:Presets/"+presets[i]+".png");
            ImageView myPresetView = new ImageView();
            myPresetView.setImage(myPreset);
            box.getChildren().add(myPresetView);
        } else {
            File f = new File("Presets/nopreview.png");
            if(f.exists() && !f.isDirectory()) { 
                Image noprevImg = new Image("file:Presets/nopreview.png"); //new Image("Presets/nopreview.png");
                ImageView noprev = new ImageView();
                noprev.setImage(noprevImg);
                box.getChildren().add(noprev);
            } else {
                System.out.println("nopreview.png not found");
            }
        }

        box.getChildren().add(nameAndOpen);
    }
    return box;
}
 
Example 10
Source File: AlertFactory.java    From Motion_Profile_Generator with MIT License 5 votes vote down vote up
public static Alert createExceptionAlert( Exception e, String msg )
{
    Alert alert = new Alert(Alert.AlertType.ERROR);
    alert.setTitle("Exception Dialog");
    alert.setHeaderText("Whoops!");
    alert.setContentText(msg);

    // Create expandable Exception.
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    String exceptionText = sw.toString();

    Label label = new Label("The exception stacktrace was:");

    TextArea textArea = new TextArea(exceptionText);
    textArea.setEditable(false);
    textArea.setWrapText(true);

    textArea.setMaxWidth(Double.MAX_VALUE);
    textArea.setMaxHeight(Double.MAX_VALUE);
    GridPane.setVgrow(textArea, Priority.ALWAYS);
    GridPane.setHgrow(textArea, Priority.ALWAYS);

    GridPane expContent = new GridPane();
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.add(label, 0, 0);
    expContent.add(textArea, 0, 1);

    // Set expandable Exception into the dialog pane.
    alert.getDialogPane().setExpandableContent(expContent);

    return alert;
}
 
Example 11
Source File: JFxBuilder.java    From Weather-Forecast with Apache License 2.0 5 votes vote down vote up
private void createAlertDialog(DialogObject dialog) {
    Alert alert = new Alert(dialog.getType());
    alert.setTitle(dialog.getTitle());
    alert.setHeaderText(dialog.getHeader());
    alert.setContentText(dialog.getContent());

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK) {
        System.exit(0);
    } else {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        dialog.getexception().printStackTrace(pw);
        String exceptionText = sw.toString();

        Label label = new Label("The exception stacktrace was:");

        TextArea textArea = new TextArea(exceptionText);
        textArea.setEditable(false);
        textArea.setWrapText(true);

        textArea.setMaxWidth(Double.MAX_VALUE);
        textArea.setMaxHeight(Double.MAX_VALUE);
        GridPane.setVgrow(textArea, Priority.ALWAYS);
        GridPane.setHgrow(textArea, Priority.ALWAYS);

        GridPane expContent = new GridPane();
        expContent.setMaxWidth(Double.MAX_VALUE);
        expContent.add(label, 0, 0);
        expContent.add(textArea, 0, 1);

        alert.getDialogPane().setExpandableContent(expContent);

        alert.showAndWait();
    }
}
 
Example 12
Source File: Exercise_16_12.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create a text area
	TextArea textArea = new TextArea();
	textArea.setEditable(false);
	textArea.setWrapText(false);

	// Create a scrollPane
	ScrollPane scrollPane = new ScrollPane(textArea);

	// Create two check boxes
	CheckBox chkEditable = new CheckBox("Editable");
	CheckBox chkWrap = new CheckBox("Wrap");

	// Create a hbox
	HBox paneForButtons = new HBox(5);
	paneForButtons.setAlignment(Pos.CENTER);
	paneForButtons.getChildren().addAll(chkEditable, chkWrap);

	// Create a pane 
	BorderPane pane = new BorderPane();
	pane.setCenter(scrollPane);
	pane.setBottom(paneForButtons);

	// Create and register handlers
	chkEditable.setOnAction(e -> {
		textArea.setEditable(chkEditable.isSelected());
	});

	chkWrap.setOnAction(e -> {
		textArea.setWrapText(chkWrap.isSelected());
	});

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane);
	primaryStage.setTitle("Exercise_16_12"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 13
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Tuple2<Label, TextArea> addTopLabelTextArea(GridPane gridPane, int rowIndex, int colIndex,
                                                          String title, String prompt, double top) {

    TextArea textArea = new BisqTextArea();
    textArea.setPromptText(prompt);
    textArea.setWrapText(true);

    final Tuple2<Label, VBox> topLabelWithVBox = addTopLabelWithVBox(gridPane, rowIndex, title, textArea, top);
    GridPane.setColumnIndex(topLabelWithVBox.second, colIndex);

    return new Tuple2<>(topLabelWithVBox.first, textArea);
}
 
Example 14
Source File: GitFxDialog.java    From GitFx with Apache License 2.0 5 votes vote down vote up
@Override
public void gitExceptionDialog(String title, String header, String content, Exception e) {

    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle(title);
    alert.setHeaderText(header);
    alert.setContentText(content);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    String exceptionText = sw.toString();
    Label label = new Label("Exception stack trace:");

    TextArea textArea = new TextArea(exceptionText);
    textArea.setEditable(false);
    textArea.setWrapText(true);

    textArea.setMaxWidth(Double.MAX_VALUE);
    textArea.setMaxHeight(Double.MAX_VALUE);
    GridPane.setVgrow(textArea, Priority.ALWAYS);
    GridPane.setHgrow(textArea, Priority.ALWAYS);

    GridPane expContent = new GridPane();
    expContent.setMaxWidth(Double.MAX_VALUE);
    expContent.add(label, 0, 0);
    expContent.add(textArea, 0, 1);
    alert.getDialogPane().setExpandableContent(expContent);
    alert.showAndWait();
}
 
Example 15
Source File: ExceptionAlerter.java    From Lipi with MIT License 5 votes vote down vote up
public static void showException(Exception e) {

        if (e != null) {
            Alert alert = new Alert(Alert.AlertType.ERROR);
            alert.setTitle("Exception Alert!");
            alert.setHeaderText("An Exception was thrown.");
            alert.setContentText(e.getMessage());

// Create expandable Exception.
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            String exceptionText = sw.toString();

            Label stackTraceHeaderLabel = new Label("The exception stacktrace was:");

            TextArea stackTraceTextArea = new TextArea(exceptionText);
            stackTraceTextArea.setEditable(false);
            stackTraceTextArea.setWrapText(true);

            stackTraceTextArea.setMaxWidth(Double.MAX_VALUE);
            stackTraceTextArea.setMaxHeight(Double.MAX_VALUE);
            GridPane.setVgrow(stackTraceTextArea, Priority.ALWAYS);
            GridPane.setHgrow(stackTraceTextArea, Priority.ALWAYS);

            GridPane expContent = new GridPane();
            expContent.setMaxWidth(Double.MAX_VALUE);
            expContent.add(stackTraceHeaderLabel, 0, 0);
            expContent.add(stackTraceTextArea, 0, 1);

// Set expandable Exception into the dialog pane.
            alert.getDialogPane().setExpandableContent(expContent);
            alert.getDialogPane().setExpanded(true);

            alert.showAndWait();
        }
    }
 
Example 16
Source File: ImagePanel.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private static TextArea createTextArea(TableCell<Annotation, String> cell) {
    TextArea textArea = new TextArea(cell.getItem() == null ? "" : cell.getItem());
    textArea.setPrefRowCount(1);
    textArea.setWrapText(true);
    textArea.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2) {
            if (!textArea.isFocused() && cell.getItem() != null && cell.isEditing()) {
                cell.commitEdit(textArea.getText());
            }
            cell.getTableView().getItems().get(cell.getIndex()).setText(textArea.getText());
        }
    });
    textArea.addEventFilter(MouseEvent.MOUSE_CLICKED, (event) -> {
        if (event.getClickCount() > 1) {
            cell.getTableView().edit(cell.getTableRow().getIndex(), cell.getTableColumn());
        } else {
            TableViewSelectionModel<Annotation> selectionModel = cell.getTableView().getSelectionModel();
            if (event.isControlDown()) {
                if (selectionModel.isSelected(cell.getIndex())) {
                    selectionModel.clearSelection(cell.getIndex());
                } else {
                    selectionModel.select(cell.getIndex());
                }
            } else {
                selectionModel.clearAndSelect(cell.getIndex());
            }
        }
    });
    textArea.addEventFilter(KeyEvent.KEY_PRESSED, (event) -> {
        if (event.getCode() == KeyCode.ENTER && event.isShiftDown() && cell.isEditing()) {
            cell.commitEdit(textArea.getText());
            cell.getTableView().getItems().get(cell.getIndex()).setText(textArea.getText());
            event.consume();
        }
        if (event.getCode() == KeyCode.F2) {
            cell.getTableView().edit(cell.getTableRow().getIndex(), cell.getTableColumn());
        }
    });
    return textArea;
}
 
Example 17
Source File: ShortcutEditingPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Updates the shortcutProperties of the shortcut in the given {@link GridPane propertiesGrid}
 *
 * @param propertiesGrid The shortcutProperties grid
 */
private void updateProperties(final GridPane propertiesGrid) {
    propertiesGrid.getChildren().clear();

    // add miniature
    final Label miniatureLabel = new Label(tr("Miniature:"));
    miniatureLabel.getStyleClass().add("captionTitle");

    GridPane.setValignment(miniatureLabel, VPos.TOP);

    final TextField miniaturePathField = new TextField(Optional.ofNullable(getControl().getShortcut())
            .map(ShortcutDTO::getMiniature).map(URI::getPath).orElse(""));

    HBox.setHgrow(miniaturePathField, Priority.ALWAYS);

    final Button openBrowser = new Button(tr("Browse..."));
    openBrowser.setOnAction(event -> {
        final URI miniatureURI = Optional.ofNullable(getControl().getShortcut()).map(ShortcutDTO::getMiniature)
                .orElseThrow(() -> new IllegalStateException("The shortcut is null"));

        final FileChooser chooser = new FileChooser();
        chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(tr("Images"), "*.miniature, *.png"));

        final File defaultFile = new File(miniatureURI);
        chooser.setInitialDirectory(defaultFile.getParentFile());

        Optional.ofNullable(chooser.showOpenDialog(getControl().getScene().getWindow())).ifPresent(newMiniature -> {
            miniaturePathField.setText(newMiniature.toString());

            getControl().setShortcut(new ShortcutDTO.Builder(getControl().getShortcut())
                    .withMiniature(newMiniature.toURI()).build());
        });
    });

    final HBox miniatureContainer = new HBox(miniaturePathField, openBrowser);

    propertiesGrid.addRow(0, miniatureLabel, miniatureContainer);

    for (Map.Entry<String, Object> entry : shortcutProperties.entrySet()) {
        final int row = propertiesGrid.getRowCount();

        if (!"environment".equals(entry.getKey())) {
            final Label keyLabel = new Label(tr(decamelize(entry.getKey())) + ":");
            keyLabel.getStyleClass().add("captionTitle");
            GridPane.setValignment(keyLabel, VPos.TOP);

            final TextArea valueLabel = new TextArea(entry.getValue().toString());
            valueLabel.setWrapText(true);
            valueLabel.setPrefRowCount(entry.getValue().toString().length() / 25);

            valueLabel.focusedProperty().addListener((observable, oldValue, newValue) -> {
                // update shortcut if TextArea looses focus (doesn't save yet)
                if (!newValue) {
                    shortcutProperties.replace(entry.getKey(), valueLabel.getText());

                    try {
                        final ShortcutDTO shortcut = getControl().getShortcut();
                        final String json = new ObjectMapper().writeValueAsString(shortcutProperties);

                        getControl().setShortcut(new ShortcutDTO.Builder(shortcut)
                                .withScript(json).build());
                    } catch (JsonProcessingException e) {
                        LOGGER.error("Creating new shortcut String failed.", e);
                    }
                }
            });

            propertiesGrid.addRow(row, keyLabel, valueLabel);
        }
    }

    // set the environment
    this.environmentAttributes.clear();

    if (shortcutProperties.containsKey("environment")) {
        final Map<String, String> environment = (Map<String, String>) shortcutProperties.get("environment");

        this.environmentAttributes.putAll(environment);
    }
}
 
Example 18
Source File: DiffDisplayDialog.java    From zest-writer with GNU General Public License v3.0 4 votes vote down vote up
public DiffDisplayDialog(File file, String newContent, String titleContent, String titleExtract) {
	super(Configuration.getBundle().getString("ui.dialog.download.compare.window.title"), Configuration.getBundle().getString("ui.dialog.download.compare.window.header"));
	this.file = file;
	this.newContent = newContent;
	this.titleContent = titleContent;
       this.titleExtract = titleExtract;
       try {
           if(this.file.exists()) {
               this.oldContent = IOUtils.toString(new FileInputStream(this.file), "UTF-8");
           }
       } catch (IOException e) {
           log.error(e.getMessage(), e);
       }
       ;

    // Set the button types.
    ButtonType validButtonType = new ButtonType(Configuration.getBundle().getString("ui.dialog.download.compare.button.confirm"), ButtonData.OK_DONE);
    this.getDialogPane().getButtonTypes().addAll(validButtonType, ButtonType.CANCEL);

	// Create the username and password labels and fields.
	GridPane grid = new GridPane();
	grid.setHgap(10);
	grid.setVgap(10);
	grid.setPadding(new Insets(20, 20, 10, 10));
       Label l01 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.content_name") + " : "+titleContent);
       Label l02 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.extract_name") + " : "+titleExtract);
	Label l1 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.old_content"));
       Label l2 = new Label(Configuration.getBundle().getString("ui.dialog.download.compare.new_content"));
	TextArea textArea1 = new TextArea();
	textArea1.setEditable(false);
       textArea1.setWrapText(true);
       textArea1.setPrefHeight(500);
       textArea1.setText(oldContent);
       ScrollPane scrollPane1 = new ScrollPane();
       scrollPane1.setContent(textArea1);
       scrollPane1.setFitToWidth(true);
	TextArea textArea2 = new TextArea();
       textArea2.setEditable(false);
       textArea2.setWrapText(true);
       textArea2.setPrefHeight(500);
       textArea2.setText(newContent);
       ScrollPane scrollPane2 = new ScrollPane();
       scrollPane2.setContent(textArea2);
       scrollPane2.setFitToWidth(true);


       grid.add(l01, 0, 0,2, 1);
       grid.add(l02, 0, 1, 2, 1);
	grid.add(l1, 0, 2);
    grid.add(l2, 1, 2);
       grid.add(scrollPane1, 0, 3);
       grid.add(scrollPane2, 1, 3);

    // Enable/Disable login button depending on whether a username was entered.
	this.getDialogPane().lookupButton(validButtonType);

	this.getDialogPane().setContent(grid);

	Platform.runLater(textArea1::requestFocus);

	this.setResultConverter(dialogButton -> {
		if(dialogButton == validButtonType) {
               return true;
		}
		return false;
	});
}
 
Example 19
Source File: StringEditorFactory.java    From constellation with Apache License 2.0 4 votes vote down vote up
@Override
protected Node createEditorControls() {
    final GridPane controls = new GridPane();
    controls.setAlignment(Pos.CENTER);
    controls.setVgap(CONTROLS_SPACING);

    final ColumnConstraints cc = new ColumnConstraints();
    cc.setHgrow(Priority.ALWAYS);
    controls.getColumnConstraints().add(cc);
    final RowConstraints rc = new RowConstraints();
    rc.setVgrow(Priority.ALWAYS);
    controls.getRowConstraints().add(rc);

    textArea = new TextArea();
    textArea.setWrapText(true);
    textArea.textProperty().addListener((o, n, v) -> {
        update();
    });
    textArea.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
        if (e.getCode() == KeyCode.DELETE) {
            IndexRange selection = textArea.getSelection();
            if (selection.getLength() == 0) {
                textArea.deleteNextChar();
            } else {
                textArea.deleteText(selection);
            }
            e.consume();
        } else if (e.isShortcutDown() && e.isShiftDown() && (e.getCode() == KeyCode.RIGHT)) {
            textArea.selectNextWord();
            e.consume();
        } else if (e.isShortcutDown() && e.isShiftDown() && (e.getCode() == KeyCode.LEFT)) {
            textArea.selectPreviousWord();
            e.consume();
        } else if (e.isShortcutDown() && (e.getCode() == KeyCode.RIGHT)) {
            textArea.nextWord();
            e.consume();
        } else if (e.isShortcutDown() && (e.getCode() == KeyCode.LEFT)) {
            textArea.previousWord();
            e.consume();
        } else if (e.isShiftDown() && (e.getCode() == KeyCode.RIGHT)) {
            textArea.selectForward();
            e.consume();
        } else if (e.isShiftDown() && (e.getCode() == KeyCode.LEFT)) {
            textArea.selectBackward();
            e.consume();
        } else if (e.isShortcutDown() && (e.getCode() == KeyCode.A)) {
            textArea.selectAll();
            e.consume();
        } else if (e.getCode() == KeyCode.ESCAPE) {
            e.consume();
        }
    });

    noValueCheckBox = new CheckBox(NO_VALUE_LABEL);
    noValueCheckBox.setAlignment(Pos.CENTER);
    noValueCheckBox.selectedProperty().addListener((v, o, n) -> {
        textArea.setDisable(noValueCheckBox.isSelected());
        update();
    });

    controls.addRow(0, textArea);
    controls.addRow(1, noValueCheckBox);
    return controls;
}
 
Example 20
Source File: UnitDescriptionStage.java    From mars-sim with GNU General Public License v3.0 3 votes vote down vote up
public BorderPane init(String unitName, String unitType, String unitDescription) {

    	//this.setSize(350, 400); // undecorated 301, 348 ; decorated : 303, 373

        mainPane = new BorderPane();

        name = new Label(unitName);
        name.setPadding(new Insets(5,5,5,5));
        name.setTextAlignment(TextAlignment.CENTER);
        name.setContentDisplay(ContentDisplay.TOP);

        box0 = new VBox();
        box0.setAlignment(Pos.CENTER);
        box0.setPadding(new Insets(5,5,5,5));
	    box0.getChildren().addAll(name);

        mainPane.setTop(box0);

        String type = "TYPE :";
        String description = "DESCRIPTION :";

        box1 = new VBox();
        ta = new TextArea();

        ta.setEditable(false);
        ta.setWrapText(true);
        box1.getChildren().add(ta);

        ta.setText(System.lineSeparator() + type + System.lineSeparator() + unitType + System.lineSeparator() + System.lineSeparator());
        ta.appendText(description + System.lineSeparator() + unitDescription + System.lineSeparator() + System.lineSeparator());
        ta.setScrollTop(300);

        applyTheme();

        mainPane.setCenter(ta);

        return mainPane;

    }