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

The following examples show how to use javafx.scene.text.Text#setText() . 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: 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 2
Source File: GenericAxes.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Updates the labels path by drawing the labels of the X-axis.
 */
default void updatePathLabelsX(final @NotNull PlottingStyle ticksDisplay, final @NotNull TicksStyle ticksStyle, final @NotNull Text fontText) {
	final Axes model = getModel();
	// Painting the labels on the X-axis.
	final int origx = (int) model.getOriginX();
	final double gap = (ticksDisplay.isX() && ticksStyle.isBottom() ? model.getTicksSize() : 0d) + model.getThickness() / 2d + GAP_LABEL;
	final double sep = model.getGridMaxY() <= -model.getOriginY() ? -gap - GAP_LABEL : gap + fontText.getBaselineOffset();
	final boolean noArrowLeftX = isNoArrowLeftX();
	final boolean noArrowRightX = isNoArrowRightX();
	final boolean showOrig = model.isShowOrigin();
	final double distX = model.getDistLabelsX();
	final boolean yGE0 = model.getGridMinY() >= 0;
	final double gapx = getGapX();

	for(double incrx = model.getIncrementX(), maxx = model.getGridMaxX() / distX, minx = model.getGridMinX() / distX, i = minx * incrx; i <= maxx * incrx;
		i += incrx * distX) {
		final int inti = (int) i;
		if((inti != 0 || (showOrig && yGE0)) && isElementPaintable(noArrowLeftX, noArrowRightX, minx, maxx, inti)) {
			final String str = String.valueOf(inti + origx);
			fontText.setText(str);
			createTextLabel(str, inti * gapx - fontText.getBoundsInLocal().getWidth() / 2d, sep, fontText.getFont());
		}
	}
}
 
Example 3
Source File: SVGGrid.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
private final void produceSVGGridYWestLabelsTexts(final SVGDocument document, final SVGElement texts, final double xorigin, final double tly,
								final double gridWidth, final Text fooText, final double minY, final double maxY, final double labelHeight, final double absStep) {
	final double width = gridWidth / 2d;
	final int gridLabelsSize = shape.getLabelsSize();

	for(double i = tly + (shape.isXLabelSouth() ? -width - gridLabelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
		final String label = String.valueOf((int) j);
		final SVGElement text = new SVGTextElement(document);
		fooText.setText(label);
		text.setAttribute(SVGAttributes.SVG_X, String.valueOf((int) (xorigin - fooText.getLayoutBounds().getWidth() - gridLabelsSize / 4d - width)));
		text.setAttribute(SVGAttributes.SVG_Y, String.valueOf((int) i));
		text.setTextContent(label);
		texts.appendChild(text);
	}
}
 
Example 4
Source File: ViewGrid.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
private final void updatePathLabels(final double minX, final double maxX, final double minY, final double maxY, final double posX,
							final double posY, final double xStep, final double yStep, final double tlx, final double tly, final double absStep) {
	final int labelsSize = model.getLabelsSize();
	if(labelsSize < 0) {
		return;
	}

	final Font font = new Font("cmr10", model.getLabelsSize()); //NON-NLS
	final Text fooText = new Text(String.valueOf((int) maxX));
	fooText.setFont(font);
	// The max height of the font.
	final double labelHeight = fooText.getLayoutBounds().getHeight();
	final double labelWidth = fooText.getBoundsInLocal().getWidth();

	final double origX = model.getOriginX();
	final double origY = model.getOriginY();
	final boolean isWest = model.isYLabelWest();
	final boolean isSouth = model.isXLabelSouth();
	final double xorig = posX + (origX - minX) * xStep;
	final double yorig = isSouth ? posY - yStep * (origY - minY) + labelHeight : posY - yStep * (origY - minY) - 2d;
	final double width = model.getGridWidth() / 2d;
	final double tmp = isSouth ? width : -width;
	String label;
	final double yPos = yorig + tmp;

	for(double i = tlx + (isWest ? width + labelsSize / 4d : -width - labelWidth - labelsSize / 4d), j = minX; j <= maxX; i += absStep, j++) {
		createTextLabel(String.valueOf((int) j), i, yPos, font);
	}

	final double xGapNotWest = xorig + labelsSize / 4d + width;

	for(double i = tly + (isSouth ? -width - labelsSize / 4d : width + labelHeight), j = maxY; j >= minY; i += absStep, j--) {
		label = String.valueOf((int) j);
		fooText.setText(label);
		final double x = isWest ? xorig - fooText.getBoundsInLocal().getWidth() - labelsSize / 4d - width : xGapNotWest;
		createTextLabel(label, x, i, font);
	}
}
 
Example 5
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Text createBlackTextHeader(String s) {
	Text t = new Text();
	t.setCache(true);
	t.setX(10.0f);
	t.setY(270.0f);
	t.setFill(Color.BLACK);//.LIGHTBLUE);// .ORANGE);//.DARKSLATEGREY);
	t.setText(s);
	t.setFont(Font.font(null, FontWeight.BOLD, 14));
	return t;
}
 
Example 6
Source File: MainScene.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Text createTextHeader(String s) {
	Text t = new Text();
	t.setCache(true);
	t.setX(10.0f);
	t.setY(270.0f);
	t.setFill(Color.WHITE);//.LIGHTBLUE);// .ORANGE);//.DARKSLATEGREY);
	t.setText(s);
	t.setFont(Font.font(null, FontWeight.BOLD, 14));
	return t;
}
 
Example 7
Source File: ChatController.java    From ChatRoom-JavaFX with Apache License 2.0 5 votes vote down vote up
@Override
protected void updateItem(UserInfo item, boolean empty) {
	// TODO Auto-generated method stub
	super.updateItem(item, empty);
	setGraphic(null);
          setText(null);
          if (item != null) {

              HBox hBox = new HBox();
              hBox.setSpacing(5); //节点之间的间距

           Text name = new Text(item.getUsername());
           name.setFont(new Font("Arial", 20));//字体样式和大小
           ImageView statusImageView = new ImageView();
           Image statusImage = new Image("images/online.png", 16, 16,true,true);
           statusImageView.setImage(statusImage);

           if(item.getUsername().equals(Utils.ALL)){

           	name.setText("group chat >");
           	statusImageView.setImage(null);
           	//hBox.setStyle("-fx-background-color: #336699;"); //背景色

           }
           ImageView pictureImageView = new ImageView();
           Image image = new Image("images/" + item.getUserpic(),50,50,true,true);
           pictureImageView.setImage(image);

           hBox.getChildren().addAll(statusImageView, pictureImageView, name);
           //hBox.getChildren().addAll(pictureImageView, name);
           hBox.setAlignment(Pos.CENTER_LEFT);
           setGraphic(hBox);
          }
}
 
Example 8
Source File: FridayFunSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private void updateTickLabels() {
  int labelCount = tickLabels.size();
  double step = (getSkinnable().getMaxValue() - getSkinnable().getMinValue()) / labelCount;

  for (int i = 0; i < labelCount; i++) {
    Text tickLabel = tickLabels.get(i);
    tickLabel.setText(String.format("%.1f", getSkinnable().getMinValue() + (i * step)));
  }
}
 
Example 9
Source File: GenericAxes.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
default void updatePathLabelsY(final PlottingStyle ticksDisplay, final TicksStyle ticksStyle, final Text fontText) {
	final Axes model = getModel();
	final int origy = (int) model.getOriginY();
	final double gap;
	final double height = fontText.getBaselineOffset();
	final boolean noArrowTopY = model.getArrowStyle(2) == ArrowStyle.NONE || model.getGridMaxY() == model.getOriginY();
	final boolean noArrowBotY = model.getArrowStyle(0) == ArrowStyle.NONE || model.getGridMinY() == model.getOriginY();
	final boolean showOrig = model.isShowOrigin();
	final double distY = model.getDistLabelsY();
	final boolean xGE0 = model.getGridMinX() >= 0;
	final double gapy = getGapY();

	if(ticksStyle.isBottom() && ticksDisplay.isY()) {
		gap = -(model.getTicksSize() + model.getThickness() / 2d + GAP_LABEL);
	}else {
		gap = -(model.getThickness() / 2d + GAP_LABEL);
	}

	for(double incry = model.getIncrementY(), maxy = model.getGridMaxY() / distY, miny = model.getGridMinY() / distY, i = miny * incry; i <= maxy * incry;
		i += incry * distY) {
		final int inti = (int) i;
		if((inti != 0 || (showOrig && xGE0)) && isElementPaintable(noArrowBotY, noArrowTopY, miny, maxy, inti)) {
			final String str = String.valueOf(inti + origy);
			fontText.setText(str);
			createTextLabel(str, gap - fontText.getBoundsInLocal().getWidth(), height / 2d - inti * gapy, fontText.getFont());
		}
	}
}
 
Example 10
Source File: TimelineEventsSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public TimelineEventsSample() {
    super(70,70);
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200-100);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    getChildren().add(stack);
}
 
Example 11
Source File: Level.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
Example 12
Source File: Level.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
Example 13
Source File: TimelineEventsSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public TimelineEventsSample() {
    super(70,70);
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200-100);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    getChildren().add(stack);
}
 
Example 14
Source File: CountdownTimerTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    duration  = tile.getTimePeriod();
    minValue  = 0;
    maxValue  = duration.getSeconds();
    range     = duration.getSeconds();
    angleStep = ANGLE_RANGE / range;
    locale    = tile.getLocale();

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

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

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.468, PREFERRED_HEIGHT * 0.468, 90, 360);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(tile.getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.1);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.468, PREFERRED_HEIGHT * 0.468, 90, 0);
    bar.setType(ArcType.OPEN);
    bar.setStroke(tile.getBarColor());
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.1);
    bar.setStrokeLineCap(StrokeLineCap.BUTT);
    bar.setFill(null);

    separator = new Line(PREFERRED_WIDTH * 0.5, 1, PREFERRED_WIDTH * 0.5, 0.16667 * PREFERRED_HEIGHT);
    separator.setStroke(tile.getBackgroundColor());
    separator.setFill(Color.TRANSPARENT);

    durationText = new Text();
    durationText.setFont(Fonts.latoRegular(PREFERRED_WIDTH * 0.27333));
    durationText.setFill(tile.getValueColor());
    durationText.setTextOrigin(VPos.CENTER);

    durationFlow = new TextFlow(durationText);
    durationFlow.setTextAlignment(TextAlignment.CENTER);

    timeText = new Text(DTF.format(LocalTime.now().plus(tile.getTimePeriod().getSeconds(), ChronoUnit.SECONDS)));
    timeText.setFont(Fonts.latoRegular(PREFERRED_WIDTH * 0.27333));
    timeText.setFill(tile.getValueColor());
    timeText.setTextOrigin(VPos.CENTER);
    enableNode(timeText, tile.isValueVisible());

    timeFlow = new TextFlow(timeText);
    timeFlow.setTextAlignment(TextAlignment.CENTER);

    runningListener = (o, ov, nv) -> {
        if (nv) {
            timeText.setText(DTF.format(LocalTime.now().plus(duration.getSeconds(), ChronoUnit.SECONDS)));
        }
    };
    timeListener = e -> {
        if (TimeEventType.SECOND == e.TYPE) {
            updateBar();
        }
    };

    getPane().getChildren().addAll(barBackground, bar, separator, titleText, text, durationFlow, timeFlow);
}
 
Example 15
Source File: UserView.java    From NLIDB with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	
	stage = primaryStage;
	stage.setTitle("Window for NLIDB");
	
	Label label1 = new Label("Welcome to Natural Language Interface to DataBase!");
	
	Label lblInput = new Label("Natural Language Input:");
	TextArea fieldIn = new TextArea();
	fieldIn.setPrefHeight(100);
	fieldIn.setPrefWidth(100);
	fieldIn.setWrapText(true);
	fieldIn.setText(TEST_TEXT);
	
	btnTranslate = new Button("translate");
	
	// Define action of the translate button.
	btnTranslate.setOnAction(e -> {
		ctrl.processNaturalLanguage(fieldIn.getText());
	});
	
	display = new Text();
	display.setWrappingWidth(500);
	display.prefHeight(300);
	display.setText("Default display text");

	// choices and button for nodes mapping
	choiceBox = new ComboBox<NodeInfo>();
	choiceBox.setVisibleRowCount(6);
	btnConfirmChoice = new Button("confirm choice");
	btnConfirmChoice.setOnAction(e -> {
		ctrl.chooseNode(getChoice());
	});
	
	// choices and button for tree selection
	treeChoice = new ComboBox<Integer>(); // ! only show 3 choices now
	treeChoice.setItems(FXCollections.observableArrayList(0,1,2));
	treeChoice.getSelectionModel().selectedIndexProperty().addListener((ov, oldV, newV) -> {
		ctrl.showTree(treeChoice.getItems().get((Integer) newV));
	});
	btnTreeConfirm = new Button("confirm tree choice");
	btnTreeConfirm.setOnAction(e -> {
		ctrl.chooseTree(treeChoice.getValue());
	});
	
	vb1 = new VBox();
	vb1.setSpacing(10);
	vb1.getChildren().addAll(
			label1,
			lblInput,fieldIn,
			btnTranslate
			);
	
	vb2 = new VBox();
	vb2.setSpacing(20);
	vb2.getChildren().addAll(display);
	
	hb = new HBox();
	hb.setPadding(new Insets(15, 12, 15, 12));
	hb.setSpacing(10);
	hb.getChildren().addAll(vb1, vb2);
	
	scene = new Scene(hb, 800, 450);
	
	stage.setScene(scene);
	ctrl = new Controller(this);
	stage.show();
	
}
 
Example 16
Source File: FX.java    From FxDock with Apache License 2.0 4 votes vote down vote up
/** creates a text segment */
public static Text text(Object ... attrs)
{
	Text n = new Text();
	
	for(Object a: attrs)
	{
		if(a == null)
		{
			// ignore
		}
		else if(a instanceof CssStyle)
		{
			n.getStyleClass().add(((CssStyle)a).getName());
		}
		else if(a instanceof CssID)
		{
			n.setId(((CssID)a).getID());
		}
		else if(a instanceof FxCtl)
		{
			switch((FxCtl)a)
			{
			case BOLD:
				n.getStyleClass().add(CssTools.BOLD.getName());
				break;
			case FOCUSABLE:
				n.setFocusTraversable(true);
				break;
			case NON_FOCUSABLE:
				n.setFocusTraversable(false);
				break;
			default:
				throw new Error("?" + a);
			}
		}
		else if(a instanceof String)
		{
			n.setText((String)a);
		}
		else if(a instanceof TextAlignment)
		{
			n.setTextAlignment((TextAlignment)a);
		}
		else
		{
			throw new Error("?" + a);
		}			
	}
	
	return n;
}
 
Example 17
Source File: Level.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
Example 18
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image indicateSplitFx(Image image,
            List<Integer> rows, List<Integer> cols,
            Color lineColor, int lineWidth, boolean showSize) {
        try {
            if (rows == null || cols == null) {
                return image;
            }
            Group group = new Group();
            int width = (int) image.getWidth();
            int height = (int) image.getHeight();
            int row;
            for (int i = 0; i < rows.size(); ++i) {
                row = rows.get(i);
                if (row <= 0 || row >= height - 1) {
                    continue;
                }
                Line rowLine = new Line(0, row, width, row);
                rowLine.setStroke(lineColor);
                rowLine.setStrokeWidth(lineWidth);
                group.getChildren().add(rowLine);
            }
            int col;
            for (int i = 0; i < cols.size(); ++i) {
                col = cols.get(i);
                if (col <= 0 || col >= width - 1) {
                    continue;
                }
                Line colLine = new Line(col, 0, col, height);
                colLine.setStroke(lineColor);
                colLine.setStrokeWidth(lineWidth);
                group.getChildren().add(colLine);
            }

            if (showSize) {
                for (int i = 0; i < rows.size() - 1; ++i) {
                    int h = rows.get(i + 1) - rows.get(i) + 1;
                    for (int j = 0; j < cols.size() - 1; ++j) {
                        int w = cols.get(j + 1) - cols.get(j) + 1;
                        Text text = new Text();
                        text.setX(cols.get(j) + w / 3);
                        text.setY(rows.get(i) + h / 3);
                        text.setFill(lineColor);
                        text.setText(w + "x" + h);
                        text.setFont(new javafx.scene.text.Font(lineWidth * 3.0));
                        group.getChildren().add(text);
                    }
                }
            }

            Blend blend = new Blend(BlendMode.SRC_OVER);
            blend.setBottomInput(new ImageInput(image));
            group.setEffect(blend);

            SnapshotParameters parameters = new SnapshotParameters();
            parameters.setFill(Color.TRANSPARENT);
            WritableImage newImage = group.snapshot(parameters, null);

            return newImage;
        } catch (Exception e) {
//            logger.error(e.toString());
            return null;
        }
    }
 
Example 19
Source File: AthenaRestWizard.java    From athena-rest with Apache License 2.0 4 votes vote down vote up
private void doWizard(String name, String desc, Text actiontarget)
		throws IOException {
	// validate
	if (StringUtils.isBlank(name) || StringUtils.isBlank(desc)) {
		JOptionPane.showMessageDialog(null,
				"The name or description is empty. Please check",
				"Warning...", JOptionPane.ERROR_MESSAGE);
		return;
	}

	// unzip file
	File root = new File("tmp");
	deleteDir(root);

	File fileZip = new File(root, "athena-example.zip");

	extractClasspathResource("/athena-example.zip",
			fileZip.getAbsolutePath());

	unZipIt(fileZip.getAbsolutePath(), root.getAbsolutePath());

	// replace names in poms
	File rootPro = new File(root, "athena-example");

	replace(new File(rootPro, "pom.xml"), "athena-example", name);
	replace(new File(rootPro, "pom.xml"), "Athena Example", desc);

	replace(new File(rootPro, "athena-example-data/pom.xml"),
			"athena-example", name);
	replace(new File(rootPro, "athena-example-data/pom.xml"),
			"Athena Example", desc);

	replace(new File(rootPro, "athena-example-rest/pom.xml"),
			"athena-example", name);
	replace(new File(rootPro, "athena-example-rest/pom.xml"),
			"Athena Example", desc);

	replace(new File(rootPro, "athena-example-service/pom.xml"),
			"athena-example", name);
	replace(new File(rootPro, "athena-example-service/pom.xml"),
			"Athena Example", desc);

	// rename folders
	new File(rootPro, "athena-example-data").renameTo(new File(rootPro,
			name + "-data"));
	new File(rootPro, "athena-example-rest").renameTo(new File(rootPro,
			name + "-rest"));
	new File(rootPro, "athena-example-service").renameTo(new File(rootPro,
			name + "-service"));

	// copy to desktop
	javax.swing.filechooser.FileSystemView fsv = javax.swing.filechooser.FileSystemView
			.getFileSystemView();
	copyDirectiory(rootPro.getAbsolutePath(), new File(fsv
			.getHomeDirectory().getAbsoluteFile(), name).getAbsolutePath());

	// rename project root folder
	rootPro.renameTo(new File(rootPro.getParentFile(), name));

	// show result
	actiontarget.setFill(Color.FIREBRICK);
	actiontarget.setText("Please find your project {" + name
			+ "} on your desktop.");
}
 
Example 20
Source File: ImagesBrowserController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
private void makeImagePopup(VBox imageBox, ImageInformation imageInfo,
        ImageView iView) {
    try {
        File file = imageInfo.getImageFileInformation().getFile();
        final Image iImage = imageInfo.getImage();
        imagePop = new Popup();
        imagePop.setWidth(popSize + 40);
        imagePop.setHeight(popSize + 40);
        imagePop.setAutoHide(true);

        VBox vbox = new VBox();
        VBox.setVgrow(vbox, Priority.ALWAYS);
        HBox.setHgrow(vbox, Priority.ALWAYS);
        vbox.setMaxWidth(Double.MAX_VALUE);
        vbox.setMaxHeight(Double.MAX_VALUE);
        vbox.setStyle("-fx-background-color: white;");
        imagePop.getContent().add(vbox);

        popView = new ImageView();
        popView.setImage(iImage);
        if (iImage.getWidth() > iImage.getHeight()) {
            popView.setFitWidth(popSize);
        } else {
            popView.setFitHeight(popSize);
        }
        popView.setPreserveRatio(true);
        vbox.getChildren().add(popView);

        popText = new Text();
        popText.setStyle("-fx-font-size: 1.0em;");

        vbox.getChildren().add(popText);
        vbox.setPadding(new Insets(15, 15, 15, 15));

        String info = imageInfo.getFileName() + "\n"
                + AppVariables.message("Format") + ":" + imageInfo.getImageFormat() + "  "
                + AppVariables.message("ModifyTime") + ":" + DateTools.datetimeToString(file.lastModified()) + "\n"
                + AppVariables.message("Size") + ":" + FileTools.showFileSize(file.length()) + "  "
                + AppVariables.message("Pixels") + ":" + imageInfo.getWidth() + "x" + imageInfo.getHeight() + "\n"
                + AppVariables.message("LoadedSize") + ":"
                + (int) iView.getImage().getWidth() + "x" + (int) iView.getImage().getHeight() + "  "
                + AppVariables.message("DisplayedSize") + ":"
                + (int) iView.getFitWidth() + "x" + (int) iView.getFitHeight();
        popText.setText(info);
        popText.setWrappingWidth(popSize);
        Bounds bounds = imageBox.localToScreen(imageBox.getBoundsInLocal());
        imagePop.show(imageBox, bounds.getMinX() + bounds.getWidth() / 2, bounds.getMinY());

    } catch (Exception e) {
        logger.debug(e.toString());
    }
}