Java Code Examples for javafx.scene.text.Font#font()
The following examples show how to use
javafx.scene.text.Font#font() .
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: JFXFontCalibration.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Override public double getCalibrationFactor() throws Exception { final Font font = Font.font(FontCalibration.FONT, FontCalibration.SIZE); if (! font.getName().startsWith(FontCalibration.FONT)) { logger.log(Level.SEVERE, "Cannot obtain font " + FontCalibration.FONT + " for calibration. Got " + font.getName()); logger.log(Level.SEVERE, "Font calibration will default to 1.0. Check installation of calibration font"); return 1.0; } text.setFont(font); final Bounds measure = text.getLayoutBounds(); logger.log(Level.FINE, "Font calibration measure: " + measure.getWidth() + " x " + measure.getHeight()); final double factor = FontCalibration.PIXEL_WIDTH / measure.getWidth(); logger.log(Level.CONFIG, "JFX font calibration factor: {0}", factor); return factor; }
Example 2
Source File: FireSmokeTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 3
Source File: TimeTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); fontSize = size * 0.12; leftUnit.setFont(Fonts.latoRegular(fontSize)); rightUnit.setFont(Fonts.latoRegular(fontSize)); fontSize = size * 0.1; description.setFont(Fonts.latoRegular(fontSize)); }
Example 4
Source File: CountdownTimerTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 5
Source File: RadarChartTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 6
Source File: TurnoverTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 7
Source File: HighLowTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); maxWidth = width - (width - size * 0.275); fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; upperUnitText.setFont(Fonts.latoRegular(fontSize)); if (upperUnitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(upperUnitText, maxWidth, fontSize); } fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; unitText.setFont(Fonts.latoRegular(fontSize)); if (unitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(unitText, maxWidth, fontSize); } fontSize = size * 0.1; description.setFont(Fonts.latoRegular(fontSize)); }
Example 8
Source File: RadarNodeChartTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 9
Source File: FluidTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 10
Source File: DebugInfo.java From CrazyAlpha with GNU General Public License v2.0 | 5 votes |
public DebugInfo() { font = Font.font(20); fillColor = Color.WHITE; strokeColor = Color.TRANSPARENT; x = 10; y = Game.getInstance().getRender().getHeight() - 50; }
Example 11
Source File: BarChartTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 12
Source File: GeneralOptionsPane.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("unchecked") GeneralOptionsPane() { initComponents(); Font titleFont = Font.font(16); editorSettingsLabel.setFont(titleFont); fileSettingsLabel.setFont(titleFont); // font family fontFamilyField.getItems().addAll(getMonospacedFonts()); fontFamilyField.getSelectionModel().select(0); fontFamilyField.setButtonCell(new FontListCell()); fontFamilyField.setCellFactory(p -> new FontListCell()); // font size fontSizeField.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(Options.MIN_FONT_SIZE, Options.MAX_FONT_SIZE)); // line separator String defaultLineSeparator = System.getProperty( "line.separator", "\n" ); String defaultLineSeparatorStr = defaultLineSeparator.replace("\r", "CR").replace("\n", "LF"); lineSeparatorField.getItems().addAll( new Item<>(Messages.get("GeneralOptionsPane.platformDefault", defaultLineSeparatorStr), null), new Item<>(Messages.get("GeneralOptionsPane.sepWindows"), "\r\n"), new Item<>(Messages.get("GeneralOptionsPane.sepUnix"), "\n")); // encoding encodingField.getItems().addAll(getAvailableEncodings()); // file extensions markdownFileExtensionsField.setPromptText(Options.DEF_MARKDOWN_FILE_EXTENSIONS); }
Example 13
Source File: RadialPercentageTileSkin.java From tilesfx with Apache License 2.0 | 5 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); }
Example 14
Source File: QlockTwoSkin.java From Enzo with Apache License 2.0 | 4 votes |
private void resize() { size = getSkinnable().getWidth() < getSkinnable().getHeight() ? getSkinnable().getWidth() : getSkinnable().getHeight(); width = getSkinnable().getWidth(); height = getSkinnable().getHeight(); if (width > height) { width = 1 / (ASPECT_RATIO / height); } else if (1 / (ASPECT_RATIO / height) > width) { height = width; } if (width > 0 && height > 0) { background.setPrefSize(width, height); if (width != 0 && height != 0) { stainlessBackground.setImage(texture.getImage(width, height)); } p4.setPrefSize(0.012 * width, 0.012 * height); p4.setTranslateX(0.044 * width); p4.setTranslateY(0.944 * height); p3.setPrefSize(0.012 * width, 0.012 * height); p3.setTranslateX(0.944 * width); p3.setTranslateY(0.944 * height); p2.setPrefSize(0.012 * width, 0.012 * height); p2.setTranslateX(0.944 * width); p2.setTranslateY(0.044 * height); p1.setPrefSize(0.012 * width, 0.012 * height); p1.setTranslateX(0.044 * width); p1.setTranslateY(0.044 * height); startX = size * 0.114; startY = size * 0.112; stepX = size * 0.072; stepY = size * 0.08; font = Font.font("DINfun Pro", FontWeight.NORMAL, FontPosture.REGULAR, size * 0.048); for (int y = 0 ; y < 10 ; y++) { for (int x = 0 ; x < 11 ; x++) { matrix[x][y].setFont(font); matrix[x][y].setPrefSize(size * 0.048, size * 0.048); matrix[x][y].setTranslateY(startY + y * stepY); matrix[x][y].setTranslateX(startX + x * stepX); matrix[x][y].setTranslateY(startY + y * stepY); } } highlight.setPrefSize(0.8572706909179687 * width, 0.7135147094726563 * height); highlight.setTranslateX(0.14224906921386718 * width); highlight.setTranslateY(0.28614569091796876 * height); } }
Example 15
Source File: ImageCounterTileSkin.java From tilesfx with Apache License 2.0 | 4 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } //maxWidth = size * 0.9; text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); //maxWidth = width - (width - size * 0.275); maxWidth = width - size * 0.05 - contentBounds.getWidth() * 0.5; fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; upperUnitText.setFont(Fonts.latoRegular(fontSize)); if (upperUnitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(upperUnitText, maxWidth, fontSize); } fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; unitText.setFont(Fonts.latoRegular(fontSize)); if (unitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(unitText, maxWidth, fontSize); } fontSize = size * 0.1; description.setFont(Fonts.latoRegular(fontSize)); if (description.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(description, maxWidth, fontSize); } }
Example 16
Source File: SliderTileSkin.java From tilesfx with Apache License 2.0 | 4 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } //maxWidth = size * 0.9; text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); maxWidth = width - (width - size * 0.275); fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; upperUnitText.setFont(Fonts.latoRegular(fontSize)); if (upperUnitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(upperUnitText, maxWidth, fontSize); } fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; unitText.setFont(Fonts.latoRegular(fontSize)); if (unitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(unitText, maxWidth, fontSize); } fontSize = size * 0.1; description.setFont(Fonts.latoRegular(fontSize)); }
Example 17
Source File: PercentageTileSkin.java From tilesfx with Apache License 2.0 | 4 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } maxWidth = width - size * 0.275; fontSize = size * 0.12; unitText.setFont(Fonts.latoRegular(fontSize)); if (unitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(unitText, maxWidth, fontSize); } maxWidth = width - size * 0.55; fontSize = size * 0.18; percentageText.setFont(Fonts.latoRegular(fontSize)); if (percentageText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(percentageText, maxWidth, fontSize); } percentageText.relocate(size * 0.05, height - size * 0.305); maxWidth = width - size * 0.9; fontSize = size * 0.12; percentageUnitText.setFont(Fonts.latoRegular(fontSize)); if (percentageUnitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(percentageUnitText, maxWidth, fontSize); } percentageUnitText.relocate(percentageText.getLayoutBounds().getMaxX() + size * 0.075, height - size * 0.25); maxWidth = width - size * 0.8; fontSize = size * 0.05; maxValueUnitText.setFont(Fonts.latoRegular(fontSize)); if (maxValueUnitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(maxValueUnitText, maxWidth, fontSize); } maxValueUnitText.setX((width - size * 0.075) - maxValueUnitText.getLayoutBounds().getWidth()); maxValueUnitText.setY(height - size * 0.145); maxWidth = width - size * 0.55; fontSize = size * 0.08; maxValueText.setFont(Fonts.latoRegular(fontSize)); if (maxValueText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(maxValueText, maxWidth, fontSize); } if (unitText.isVisible()) { maxValueText.setX((width - size * 0.075) - (size * 0.01 + maxValueText.getLayoutBounds().getWidth() + maxValueUnitText.getLayoutBounds().getWidth())); } else { maxValueText.setX((width - size * 0.075) - maxValueText.getLayoutBounds().getWidth()); } maxValueText.setY(height - size * 0.145); fontSize = size * 0.1; description.setFont(Fonts.latoRegular(fontSize)); }
Example 18
Source File: PlusMinusTileSkin.java From tilesfx with Apache License 2.0 | 4 votes |
@Override protected void resizeStaticText() { double maxWidth = width - size * 0.1; double fontSize = size * textSize.factor; boolean customFontEnabled = tile.isCustomFontEnabled(); Font customFont = tile.getCustomFont(); Font font = (customFontEnabled && customFont != null) ? Font.font(customFont.getFamily(), fontSize) : Fonts.latoRegular(fontSize); titleText.setFont(font); if (titleText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(titleText, maxWidth, fontSize); } switch(tile.getTitleAlignment()) { default : case LEFT : titleText.relocate(size * 0.05, size * 0.05); break; case CENTER: titleText.relocate((width - titleText.getLayoutBounds().getWidth()) * 0.5, size * 0.05); break; case RIGHT : titleText.relocate(width - (size * 0.05) - titleText.getLayoutBounds().getWidth(), size * 0.05); break; } //maxWidth = size * 0.9; text.setText(tile.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(text, maxWidth, fontSize); } switch(tile.getTextAlignment()) { default : case LEFT : text.setX(size * 0.05); break; case CENTER: text.setX((width - text.getLayoutBounds().getWidth()) * 0.5); break; case RIGHT : text.setX(width - (size * 0.05) - text.getLayoutBounds().getWidth()); break; } text.setY(height - size * 0.05); maxWidth = width - (width - size * 0.275); fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; upperUnitText.setFont(Fonts.latoRegular(fontSize)); if (upperUnitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(upperUnitText, maxWidth, fontSize); } fontSize = upperUnitText.getText().isEmpty() ? size * 0.12 : size * 0.10; unitText.setFont(Fonts.latoRegular(fontSize)); if (unitText.getLayoutBounds().getWidth() > maxWidth) { Helper.adjustTextSize(unitText, maxWidth, fontSize); } fontSize = size * 0.1; description.setFont(Fonts.latoRegular(fontSize)); }
Example 19
Source File: TButtonSkin.java From Enzo with Apache License 2.0 | 4 votes |
private void resize() { size = getSkinnable().getWidth() < getSkinnable().getHeight() ? getSkinnable().getWidth() : getSkinnable().getHeight(); width = size; height = size; if (width > 0 && height > 0) { frame.setPrefSize(width, height); off.setPrefSize(0.7916666666666666 * width, 0.7916666666666666 * height); off.setTranslateX(0.10416666666666667 * width); off.setTranslateY(0.10416666666666667 * height); offInnerShadow.setOffsetY(-5.0 / 144.0 * size); offInnerShadow.setRadius(2.0 / 144.0 * size); offInnerShadow1.setRadius(3.0 / 144.0 * size); offDropShadow.setOffsetY(10.0 / 144.0 * size); offDropShadow.setRadius(10.0 / 144.0 * size); ledOff.setPrefSize(0.08333333333333333 * width, 0.08333333333333333 * height); ledOff.setTranslateX(0.4583333333333333 * width); ledOff.setTranslateY(0.7291666666666666 * height); ledOffInnerShadow.setRadius(1.0 / 144.0 * size); ledOffInnerShadow1.setRadius(1.0 / 144.0 * size); on.setPrefSize(0.7916666666666666 * width, 0.7916666666666666 * height); on.setTranslateX(0.10416666666666667 * width); on.setTranslateY(0.10416666666666667 * height); onInnerShadow.setOffsetY(-2.0 / 144.0 * size); onInnerShadow.setRadius(2.0 / 144.0 * size); onInnerShadow1.setOffsetY(4.0 / 144.0 * size); onInnerShadow1.setRadius(2.0 / 144.0 * size); onDropShadow.setRadius(1.0 / 144.0 * size); ledOn.setPrefSize(0.08333333333333333 * width, 0.08333333333333333 * height); ledOn.setTranslateX(0.4583333333333333 * width); ledOn.setTranslateY(0.75 * height); ledOnInnerShadow.setRadius(1.0 / 144.0 * size); ledOnInnerShadow1.setRadius(2.0 / 144.0 * size); ledOnGlow.setRadius(9.0 / 144.0 * size); font = Font.font("Open Sans", FontWeight.BOLD, FontPosture.REGULAR, 28.0 / 144.0 * size); text.setFont(font); if (text.getLayoutBounds().getWidth() > 0.78 * width) { text.setText("..."); } text.setTranslateX((width - text.getLayoutBounds().getWidth()) * 0.5); text.setTranslateY((height - text.getLayoutBounds().getHeight()) * 0.49); textInnerShadow.setOffsetY(-1.0 / 144.0 * size); textInnerShadow.setRadius(1.0 / 144.0 * size); textInnerShadow1.setOffsetY(1.0 / 144.0 * size); textInnerShadow1.setRadius(1.0 / 144.0 * size); } }
Example 20
Source File: Example4M.java From Introduction-to-JavaFX-for-Game-Development with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void start(Stage theStage) { theStage.setTitle( "Click the Target!" ); Group root = new Group(); Scene theScene = new Scene( root ); theStage.setScene( theScene ); Canvas canvas = new Canvas( 500, 500 ); //Image restart = new Image("restart.png"); root.getChildren().add( canvas ); Circle targetData = new Circle(100,100,32); IntValue points = new IntValue(0); theScene.setOnMouseClicked( new EventHandler<MouseEvent>() { public void handle(MouseEvent e) { if ( targetData.containsPoint( e.getX(), e.getY() ) ) { double x = 50 + 400 * Math.random(); double y = 50 + 400 * Math.random(); targetData.setCenter(x,y); points.value++; } else points.value = 0; } }); GraphicsContext gc = canvas.getGraphicsContext2D(); Font theFont = Font.font( "Helvetica", FontWeight.BOLD, 24 ); gc.setFont( theFont ); gc.setStroke( Color.BLACK ); gc.setLineWidth(1); Image bullseye = new Image( "bullseye.png" ); new AnimationTimer() { public void handle(long currentNanoTime) { // Clear the canvas gc.setFill( new Color(0.85, 0.85, 1.0, 1.0) ); gc.fillRect(0,0, 512,512); gc.drawImage( bullseye, targetData.getX() - targetData.getRadius(), targetData.getY() - targetData.getRadius() ); gc.setFill( Color.BLUE ); String pointsText = "Points: " + points.value; gc.fillText( pointsText, 360, 36 ); gc.strokeText( pointsText, 360, 36 ); } }.start(); theStage.show(); }