Java Code Examples for javafx.scene.text.TextFlow#setPrefWidth()

The following examples show how to use javafx.scene.text.TextFlow#setPrefWidth() . 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: TopicsGallery.java    From helloiot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void updateItem(TopicInfoFactory item, boolean empty) {
    super.updateItem(item, empty);
    if (item == null) {
        setGraphic(null);
        setText(null);
    } else {                 
        Text t = IconBuilder.create(item.getGlyph(), 18.0).build();
        t.setFill(Color.WHITE);
        TextFlow tf = new TextFlow(t);
        tf.setTextAlignment(TextAlignment.CENTER);
        tf.setPadding(new Insets(5, 5, 5, 5));
        tf.setStyle("-fx-background-color: #505050; -fx-background-radius: 5px;");
        tf.setPrefWidth(30.0);    
        
        setGraphic(tf);
        setText(item.getTypeName());
    }
}
 
Example 2
Source File: TopicsTemplate.java    From helloiot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void updateItem(TemplateInfo item, boolean empty) {
    super.updateItem(item, empty);
    if (item == null) {
        setGraphic(null);
        setText(null);
    } else {               
        Text t = IconBuilder.create(IconFontGlyph.valueOf(item.icon), 18.0).build();
        t.setFill(Color.WHITE);
        TextFlow tf = new TextFlow(t);
        tf.setTextAlignment(TextAlignment.CENTER);
        tf.setPadding(new Insets(5, 5, 5, 5));
        tf.setStyle("-fx-background-color: #505050; -fx-background-radius: 5px;");
        tf.setPrefWidth(30.0);      
        
        setGraphic(tf);
        setText(item.name);
    }
}
 
Example 3
Source File: ClientLoginNode.java    From helloiot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void updateItem(TopicInfo item, boolean empty) {
    super.updateItem(item, empty);
    if (item == null) {
        setGraphic(null);
        setText(null);
    } else {
        Text t = IconBuilder.create(item.getFactory().getGlyph(), 18.0).build();
        t.setFill(Color.WHITE);
        TextFlow tf = new TextFlow(t);
        tf.setTextAlignment(TextAlignment.CENTER);
        tf.setPadding(new Insets(5, 5, 5, 5));
        tf.setStyle("-fx-background-color: #505050; -fx-background-radius: 5px;");
        tf.setPrefWidth(30.0);              
        setGraphic(tf);
        
        String label = item.getLabel().getValue();
        setText(item.getFactory().getTypeName() + ((label == null || label.isEmpty()) ? "" : " : " + label));
    }
}
 
Example 4
Source File: TimeTileSkin.java    From OEE-Designer with MIT License 5 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    text = new Text(tile.getText());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());

    LocalTime duration = tile.getDuration();

    leftText = new Text(Integer.toString(duration.getHour() > 0 ? duration.getHour() : duration.getMinute()));
    leftText.setFill(tile.getValueColor());
    leftUnit = new Text(duration.getHour() > 0 ? "h" : "m");
    leftUnit.setFill(tile.getValueColor());

    rightText = new Text(Integer.toString(duration.getHour() > 0 ? duration.getMinute() : duration.getSecond()));
    rightText.setFill(tile.getValueColor());
    rightUnit = new Text(duration.getHour() > 0 ? "m" : "s");
    rightUnit.setFill(tile.getValueColor());

    timeText = new TextFlow(leftText, leftUnit, rightText, rightUnit);
    timeText.setTextAlignment(TextAlignment.RIGHT);
    timeText.setPrefWidth(PREFERRED_WIDTH * 0.9);

    description = new Label(tile.getDescription());
    description.setAlignment(Pos.TOP_RIGHT);
    description.setWrapText(true);
    description.setTextFill(tile.getTextColor());
    Helper.enableNode(description, !tile.getDescription().isEmpty());

    getPane().getChildren().addAll(titleText, text, timeText, description);
}
 
Example 5
Source File: TimeTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    text = new Text(tile.getText());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());

    LocalTime duration = tile.getDuration();

    leftText = new Text(Integer.toString(duration.getHour() > 0 ? duration.getHour() : duration.getMinute()));
    leftText.setFill(tile.getValueColor());
    leftUnit = new Text(duration.getHour() > 0 ? "h" : "m");
    leftUnit.setFill(tile.getValueColor());

    rightText = new Text(Integer.toString(duration.getHour() > 0 ? duration.getMinute() : duration.getSecond()));
    rightText.setFill(tile.getValueColor());
    rightUnit = new Text(duration.getHour() > 0 ? "m" : "s");
    rightUnit.setFill(tile.getValueColor());

    timeText = new TextFlow(leftText, leftUnit, rightText, rightUnit);
    timeText.setTextAlignment(TextAlignment.RIGHT);
    timeText.setPrefWidth(PREFERRED_WIDTH * 0.9);

    description = new Label(tile.getDescription());
    description.setAlignment(Pos.TOP_RIGHT);
    description.setWrapText(true);
    description.setTextFill(tile.getDescriptionColor());
    Helper.enableNode(description, !tile.getDescription().isEmpty());

    getPane().getChildren().addAll(titleText, text, timeText, description);
}
 
Example 6
Source File: SetupDialog.java    From archivo with GNU General Public License v3.0 5 votes vote down vote up
private void initDialog() {
    dialog.setHeaderText("Welcome to Archivo");

    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);

    List<Text> text = buildExplanationText();
    TextFlow explanation = new TextFlow(text.toArray(new Text[text.size()]));
    explanation.setPrefWidth(EXPLANATION_WIDTH);
    explanation.setLineSpacing(3);
    grid.add(explanation, 0, 0, 2, 1);

    grid.add(new Label("Media access key"), 0, 1);
    TextField mak = new TextField();
    grid.add(mak, 1, 1);

    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    // Only enable the OK button after the user has entered the MAK
    Node okButton = dialog.getDialogPane().lookupButton(ButtonType.OK);
    okButton.setDisable(true);
    mak.textProperty().addListener(((observable, oldValue, newValue) -> {
        okButton.setDisable(newValue.trim().isEmpty());
    }));

    dialog.getDialogPane().setContent(grid);

    Platform.runLater(mak::requestFocus);

    dialog.setResultConverter(button -> {
        if (button == ButtonType.OK) {
            return mak.getText().trim();
        }
        return null;
    });
}
 
Example 7
Source File: ChangeMAKDialog.java    From archivo with GNU General Public License v3.0 5 votes vote down vote up
private void initDialog() {
    dialog.setHeaderText("Could not authenticate with TiVo");

    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);

    List<Text> text = buildExplanationText();
    TextFlow explanation = new TextFlow(text.toArray(new Text[text.size()]));
    explanation.setPrefWidth(EXPLANATION_WIDTH);
    explanation.setLineSpacing(3);
    grid.add(explanation, 0, 0, 2, 1);

    grid.add(new Label("Media access key"), 0, 1);
    TextField makField = new TextField();
    if (mak != null) {
        makField.setText(mak);
    }
    grid.add(makField, 1, 1);

    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK);

    // Only enable the OK button after the user has entered the MAK
    Node okButton = dialog.getDialogPane().lookupButton(ButtonType.OK);
    okButton.setDisable(true);
    makField.textProperty().addListener(((observable, oldValue, newValue) -> {
        okButton.setDisable(newValue.trim().isEmpty());
    }));

    dialog.getDialogPane().setContent(grid);

    Platform.runLater(makField::requestFocus);

    dialog.setResultConverter(button -> {
        if (button == ButtonType.OK) {
            return makField.getText().trim();
        }
        return null;
    });
}
 
Example 8
Source File: DeckShipPane.java    From logbook-kai with MIT License 4 votes vote down vote up
/**
 * 艦娘選択
 *
 * @param event
 */
@FXML
void shipChange(ActionEvent event) {
    PopupSelectbox<ShipItem> box = new PopupSelectbox<>();

    ObservableList<ShipItem> ships = FXCollections.observableArrayList();
    ships.add(new ShipItem());
    ships.addAll(ShipCollection.get()
            .getShipMap()
            .values()
            .stream()
            .sorted(Comparator.comparing(Ship::getShipId))
            .sorted(Comparator.comparing(Ship::getLv).reversed())
            .map(ShipItem::toShipItem)
            .collect(Collectors.toList()));

    FilteredList<ShipItem> filtered = new FilteredList<>(ships);
    TextFlow textFlow = new TextFlow();
    textFlow.setPrefWidth(260);
    for (ShipTypeGroup group : ShipTypeGroup.values()) {
        CheckBox checkBox = new CheckBox(group.name());
        checkBox.selectedProperty().addListener((ov, o, n) -> {
            Set<String> types = new HashSet<>();
            textFlow.getChildrenUnmodifiable()
                    .stream()
                    .filter(node -> node instanceof CheckBox)
                    .map(node -> (CheckBox) node)
                    .filter(CheckBox::isSelected)
                    .map(CheckBox::getText)
                    .map(ShipTypeGroup::valueOf)
                    .map(ShipTypeGroup::shipTypes)
                    .forEach(types::addAll);

            filtered.setPredicate(ShipFilter.TypeFilter.builder()
                    .types(types)
                    .build());
        });
        textFlow.getChildren().add(checkBox);
    }
    TitledPane titledPane = new TitledPane("フィルター", new VBox(textFlow));
    titledPane.setAnimated(false);
    Accordion accordion = new Accordion(titledPane);

    box.getHeaderContents().add(accordion);
    box.setItems(filtered);
    box.setCellFactory(new ShipCell());
    box.selectedItemProperty().addListener((ov, o, n) -> {
        this.selectedShip.setValue(n != null && n.idProperty() != null ? n.getId() : 0);
    });
    box.getStylesheets().add("logbook/gui/deck.css");
    box.show(this.shipButton);
}