Java Code Examples for javafx.scene.text.Text#setBoundsType()

The following examples show how to use javafx.scene.text.Text#setBoundsType() . 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: FXStockToken.java    From Rails with GNU General Public License v2.0 6 votes vote down vote up
private void populate() {
    // fill the background
    Circle circle = new Circle();

    circle.centerXProperty().bind(Bindings.divide(widthProperty(), 2));
    circle.centerYProperty().bind(Bindings.divide(heightProperty(), 2));
    circle.radiusProperty().bind(Bindings.divide(widthProperty(), 2));

    circle.setFill(backgroundColor);

    Text text = new Text(name);

    text.setStroke(foregroundColor);
    text.setBoundsType(TextBoundsType.VISUAL);

    getChildren().addAll(circle, text);
}
 
Example 2
Source File: StringViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Text getLabel(String pString)
{
	Text label = new Text();
	if (aUnderlined)
	{
		label.setUnderline(true);
	}
	label.setFont(getFont());
	label.setBoundsType(TextBoundsType.VISUAL);
	label.setText(pString);
	
	if(aAlignment == Align.LEFT)
	{
		label.setTextAlignment(TextAlignment.LEFT);
	}
	else if(aAlignment == Align.CENTER)
	{
		label.setTextAlignment(TextAlignment.CENTER);
	}
	else if(aAlignment == Align.RIGHT) 
	{
		label.setTextAlignment(TextAlignment.RIGHT);
	}
	return label;
}
 
Example 3
Source File: FridayFunSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private Text createCenteredText(double cx, double cy, String styleClass) {
  Text text = new Text();
  text.getStyleClass().add(styleClass);
  text.setTextOrigin(VPos.CENTER);
  text.setTextAlignment(TextAlignment.CENTER);
  double width = cx > ARTBOARD_SIZE * 0.5 ? ((ARTBOARD_SIZE - cx) * 2.0) : cx * 2.0;
  text.setWrappingWidth(width);
  text.setBoundsType(TextBoundsType.VISUAL);
  text.setY(cy);
  text.setX(cx - (width / 2.0));

  return text;
}
 
Example 4
Source File: LinearSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
@Override
public void initializeParts() {
  value = new Text(0, ARTBOARD_HEIGHT * 0.5, String.format(FORMAT, getSkinnable().getValue()));
  value.getStyleClass().add("value");
  value.setTextOrigin(VPos.CENTER);
  value.setTextAlignment(TextAlignment.CENTER);
  value.setMouseTransparent(true);
  value.setWrappingWidth(ARTBOARD_HEIGHT);
  value.setBoundsType(TextBoundsType.VISUAL);

  thumb = new Circle(ARTBOARD_HEIGHT * 0.5, ARTBOARD_HEIGHT * 0.5, ARTBOARD_HEIGHT * 0.5);
  thumb.getStyleClass().add("thumb");

  thumbGroup = new Group(thumb, value);

  valueBar = new Line();
  valueBar.getStyleClass().add("valueBar");
  valueBar.setStrokeLineCap(StrokeLineCap.ROUND);
  applyCss(valueBar);
  strokeWidthFromCSS = valueBar.getStrokeWidth();

  scale = new Line();
  scale.getStyleClass().add("scale");
  scale.setStrokeLineCap(StrokeLineCap.ROUND);

  // always needed
  drawingPane = new Pane();
}
 
Example 5
Source File: SlimSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private Text createCenteredText(double cx, double cy, String styleClass) {
  Text text = new Text();
  text.getStyleClass().add(styleClass);
  text.setTextOrigin(VPos.CENTER);
  text.setTextAlignment(TextAlignment.CENTER);
  double width = cx > ARTBOARD_WIDTH * 0.5 ? ((ARTBOARD_WIDTH - cx) * 2.0) : cx * 2.0;
  text.setWrappingWidth(width);
  text.setBoundsType(TextBoundsType.VISUAL);
  text.setY(cy);

  return text;
}
 
Example 6
Source File: StockTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    averagingListener = o -> handleEvents("AVERAGING_PERIOD");

    timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());

    state = State.CONSTANT;

    if (tile.isAutoScale()) tile.calcAutoScale();

    low            = tile.getMaxValue();
    high           = tile.getMinValue();
    movingAverage  = tile.getMovingAverage();
    noOfDatapoints = tile.getAveragingPeriod();
    dataList       = new LinkedList<>();

    // To get smooth lines in the chart we need at least 4 values
    if (noOfDatapoints < 4) throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");

    graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);

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

    valueText = new Text(String.format(locale, formatString, tile.getValue()));
    valueText.setBoundsType(TextBoundsType.VISUAL);
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());

    valueUnitFlow = new TextFlow(valueText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);

    highText = new Text();
    highText.setTextOrigin(VPos.BOTTOM);
    highText.setFill(tile.getValueColor());

    lowText = new Text();
    lowText.setTextOrigin(VPos.TOP);
    lowText.setFill(tile.getValueColor());

    text = new Text(tile.getText());
    text.setTextOrigin(VPos.TOP);
    text.setFill(tile.getTextColor());

    timeSpanText = new Text("");
    timeSpanText.setTextOrigin(VPos.TOP);
    timeSpanText.setFill(tile.getTextColor());
    Helper.enableNode(timeSpanText, !tile.isTextVisible());

    referenceLine = new Line();
    referenceLine.getStrokeDashArray().addAll(3d, 3d);
    referenceLine.setVisible(false);

    pathElements = new ArrayList<>(noOfDatapoints);
    pathElements.add(0, new MoveTo());
    for (int i = 1 ; i < noOfDatapoints ; i++) { pathElements.add(i, new LineTo()); }

    sparkLine = new Path();
    sparkLine.getElements().addAll(pathElements);
    sparkLine.setFill(null);
    sparkLine.setStroke(tile.getBarColor());
    sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
    sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
    sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);

    dot = new Circle();
    dot.setFill(tile.getBarColor());
    dot.setVisible(false);

    triangle = new Path();
    triangle.setStroke(null);
    triangle.setFill(state.color);
    indicatorPane = new StackPane(triangle);

    changeText = new Label(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() - tile.getReferenceValue())));
    changeText.setTextFill(state.color);
    changeText.setAlignment(Pos.CENTER_RIGHT);

    changePercentageText = new Text(new StringBuilder().append(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() / tile.getReferenceValue() * 100.0) - 100.0)).append("\u0025").toString());
    changePercentageText.setFill(state.color);

    changePercentageFlow = new TextFlow(indicatorPane, changePercentageText);
    changePercentageFlow.setTextAlignment(TextAlignment.RIGHT);

    getPane().getChildren().addAll(titleText, valueUnitFlow, sparkLine, dot, referenceLine, highText, lowText, timeSpanText, text, changeText, changePercentageFlow);
}
 
Example 7
Source File: StockTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    averagingListener = o -> handleEvents("AVERAGING_PERIOD");

    timeFormatter = DateTimeFormatter.ofPattern("HH:mm", tile.getLocale());

    state = State.CONSTANT;

    if (tile.isAutoScale()) tile.calcAutoScale();

    low            = tile.getMaxValue();
    high           = tile.getMinValue();
    movingAverage  = tile.getMovingAverage();
    noOfDatapoints = tile.getAveragingPeriod();
    dataList       = new LinkedList<>();

    // To get smooth lines in the chart we need at least 4 values
    if (noOfDatapoints < 4) throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");

    graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);

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

    valueText = new Text(String.format(locale, formatString, tile.getValue()));
    valueText.setBoundsType(TextBoundsType.VISUAL);
    valueText.setFill(tile.getValueColor());
    Helper.enableNode(valueText, tile.isValueVisible());

    valueUnitFlow = new TextFlow(valueText);
    valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);

    highText = new Text();
    highText.setTextOrigin(VPos.BOTTOM);
    highText.setFill(tile.getValueColor());

    lowText = new Text();
    lowText.setTextOrigin(VPos.TOP);
    lowText.setFill(tile.getValueColor());

    text = new Text(tile.getText());
    text.setTextOrigin(VPos.TOP);
    text.setFill(tile.getTextColor());

    timeSpanText = new Text("");
    timeSpanText.setTextOrigin(VPos.TOP);
    timeSpanText.setFill(tile.getTextColor());
    Helper.enableNode(timeSpanText, !tile.isTextVisible());

    referenceLine = new Line();
    referenceLine.getStrokeDashArray().addAll(3d, 3d);
    referenceLine.setVisible(false);

    pathElements = new ArrayList<>(noOfDatapoints);
    pathElements.add(0, new MoveTo());
    for (int i = 1 ; i < noOfDatapoints ; i++) { pathElements.add(i, new LineTo()); }

    sparkLine = new Path();
    sparkLine.getElements().addAll(pathElements);
    sparkLine.setFill(null);
    sparkLine.setStroke(tile.getBarColor());
    sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
    sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
    sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);

    dot = new Circle();
    dot.setFill(tile.getBarColor());
    dot.setVisible(false);

    triangle = new Path();
    triangle.setStroke(null);
    triangle.setFill(state.color);
    indicatorPane = new StackPane(triangle);

    changeText = new Label(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() - tile.getReferenceValue())));
    changeText.setTextFill(state.color);
    changeText.setAlignment(Pos.CENTER_RIGHT);

    changePercentageText = new Text(new StringBuilder().append(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", (tile.getCurrentValue() / tile.getReferenceValue() * 100.0) - 100.0)).append(Helper.PERCENTAGE).toString());
    changePercentageText.setFill(state.color);

    changePercentageFlow = new TextFlow(indicatorPane, changePercentageText);
    changePercentageFlow.setTextAlignment(TextAlignment.RIGHT);

    getPane().getChildren().addAll(titleText, valueUnitFlow, sparkLine, dot, referenceLine, highText, lowText, timeSpanText, text, changeText, changePercentageFlow);
}