import java.util.List; 
import javafx.application.Application; 
import javafx.scene.layout.VBox; 
import javafx.scene.text.Font; 
import javafx.scene.text.Text; 
import javafx.scene.text.TextFlow; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 


public class MainApp extends Application { 

    private TextFlow info() { 
        String osInfo = System.getProperty("os.name") + " version: " + System.getProperty("os.version"); 
        String javaVersion = "Java version: " + System.getProperty("java.version"); 
        Text textInfo = new Text(osInfo + " " + javaVersion); 
        textInfo.setStyle("-fx-font-size: 24px;-fx-fill: #0072c6;"); 
        TextFlow textFlow = new TextFlow(textInfo); 
        textFlow.setPrefHeight(48); 
        textFlow.setStyle("-fx-margin: 10px 0 0 0;"); 
        return textFlow; 
    } 

    private TextFlow title(String title) { 
        Text ttfFonts = new Text(title); 
        ttfFonts.setStyle("-fx-font-size: 24px;-fx-underline: true;"); 
        TextFlow textFlow = new TextFlow(ttfFonts); 
        textFlow.setPrefHeight(48); 
        return textFlow; 
    } 

    private TextFlow addFontFamily(String fontFamily) { 
        List<String> fonts = Font.getFontNames(fontFamily); 
        if (fonts.isEmpty()) { // Font is missing 
            Text fontMissing = new Text("Font: \"" + fontFamily + "\" is missing"); 
            fontMissing.setStyle("-fx-font-size: 20px;-fx-fill: red;"); 
            TextFlow textFlow = new TextFlow(fontMissing); 
            textFlow.setPrefHeight(40); 
            return textFlow; 
        } 
        else { 
            String fontStyle = "-fx-font-family: " + fontFamily + ";-fx-font-size: 20px;"; 
            Text textNormal = new Text(fontFamily + ": normal"); 
            textNormal.setStyle(fontStyle + "-fx-font-weight: normal;"); 
            Text textBold = new Text(" bold"); 
            textBold.setStyle(fontStyle + "-fx-font-weight: bold;"); 
            Text textItalic = new Text(" italic"); 
            textItalic.setStyle(fontStyle + "-fx-font-style: italic;"); 
            TextFlow textFlow = new TextFlow(textNormal, textBold, textItalic); 
            textFlow.setPrefHeight(40); 
            return textFlow; 
        } 
    } 

    @Override 
    public void start(Stage stage) { 
        VBox view = new VBox(); 
        view.setStyle("-fx-padding: 0 0 0 10px;"); 
        Scene scene = new Scene(view); 
        stage.setMinWidth(800); 
        stage.setMinHeight(800); 
        stage.setTitle("JavaFX 1.8 .ttc fonts work"); 
        stage.setScene(scene); 
// 
        view.getChildren().add(info()); 
// 
        view.getChildren().add(title("Test missing font check works")); 
        view.getChildren().add(addFontFamily("Uknown")); 
// 
        view.getChildren().add(title("Test JavaFX 1.8 .ttf fonts: shows bold and italic")); 
        view.getChildren().add(addFontFamily("Arial")); 
        view.getChildren().add(addFontFamily("Courier new")); 
        view.getChildren().add(addFontFamily("Georgia")); 
        view.getChildren().add(addFontFamily("Tahoma")); 
        view.getChildren().add(addFontFamily("Verdana")); 
// 
        view.getChildren().add(title("Test JavaFX 1.8 .ttc fonts bug: shows bold and italic")); 
        view.getChildren().add(addFontFamily("Helvetica")); 
        view.getChildren().add(addFontFamily("Helvetica Neue")); 
        view.getChildren().add(addFontFamily("Lucida Grande")); 
        view.getChildren().add(addFontFamily("Menlo")); 
        view.getChildren().add(addFontFamily("Times New Roman")); 
// 
        stage.show(); 
    } 

    public static void main(String[] args) { 
        launch(MainApp.class); 
    } 

} 
