Java Code Examples for javafx.scene.text.Font#loadFont()

The following examples show how to use javafx.scene.text.Font#loadFont() . 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: Main.java    From Cryogen with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    //iCloudTest.dryRun("email", "password");
    Font.loadFont(Main.class.getResource("binResc/Roboto-Thin.ttf").toExternalForm(), 24);
    StaticStage.mainStage = primaryStage;
    primaryStage.initStyle(StageStyle.TRANSPARENT);
    primaryStage.setTitle("Icew1nd");
    StaticStage.loadScreen(Lite.splash() ? "Splash" : "Title");
    primaryStage.setMinHeight(600);
    primaryStage.setMinWidth(800);
    primaryStage.setHeight(600);
    primaryStage.setWidth(800);
    primaryStage.getIcons().addAll(
            //This isn't working with my ultra-high DPI. :(
            new Image(Main.class.getResourceAsStream("binResc/icon.png"))
    );
}
 
Example 2
Source File: POELevelFx.java    From Path-of-Leveling with MIT License 6 votes vote down vote up
public void setUpFonts() throws Exception{
    Platform.setImplicitExit( false );
    addTrayIcon();
    Font.loadFont(POELevelFx.class.getResource("/fonts/Fontin-Regular.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/Fontin-Italic.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/Fontin-Bold.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/Fontin-SmallCaps.ttf").toExternalForm(), 10);

    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-Thin.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-ThinItalic.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-Regular.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-ThinItalic.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-MediumItalic.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-Medium.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-Light.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-LightItalic.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-Italic.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-Bold.ttf").toExternalForm(), 10);
    Font.loadFont(POELevelFx.class.getResource("/fonts/AlegreyaSansSC-BoldItalic.ttf").toExternalForm(), 10);
}
 
Example 3
Source File: GitFxController.java    From GitFx with Apache License 2.0 6 votes vote down vote up
@Override
    public void initialize(URL url, ResourceBundle rb) {
        Font.loadFont(GitFxController.class.getResource("/fonts/fontawesome-webfont.ttf").toExternalForm(), 12);
        
        //[CHANGE] I think we should use some common resource from where all these values are fetched...
        gitinit.setText('\uf04b' + "");		
        gitopen.setText('\uf07c' + "");
        gitsettings.setText('\uf013' + "");
        gitsync.setText('\uf021' + "");
        gitclone.setText('\uf0c5' + "");
        
        RepositoryTree.getSelectionModel().selectedItemProperty().addListener(
                (observable, oldValue, newValue) -> {
                    TreeItem<String> selectedItem = (TreeItem<String>) newValue;
                    if (selectedItem != null) {
//[LOG]					logger.debug("Selected Text" + selectedItem.getValue());
                        addProgressIndicator(historyContainer);
                        if (!selectedItem.getValue().equals("github"))
                            initializeHistoryAccordion(selectedItem.getValue());
                    }
                });
        GitFXGsonUtil.checkRepoInformation();
        initializeTree();
        initializeHistoryAccordion();
    }
 
Example 4
Source File: Desktop.java    From exit_code_java with GNU General Public License v3.0 6 votes vote down vote up
public static Font loadFont(String fontName, double fontSize) {

        try {
            java.net.URL fontUrl = Desktop.class.getResource(fontName);
            if(fontUrl != null){
                return Font.loadFont(fontUrl.toExternalForm(), fontSize);
            }else{
                return Font.loadFont("file:" + fontName, fontSize);
            }

        } catch(IllegalArgumentException | NullPointerException s) {
            Logger.warn("\""+ fontName +"\" was not found. Using default font");
            return Font.loadFont("/resources/fonts/Roboto-Regular.ttf", fontSize);

        }
    }
 
Example 5
Source File: Main.java    From exit_code_java with GNU General Public License v3.0 6 votes vote down vote up
public static Font loadFont(String fontName, double fontSize) {
        if (fontName == null) {
            return Font.loadFont("/resources/fonts/Roboto-Regular.ttf", fontSize);
        }

    try {
        java.net.URL fontUrl = Main.class.getResource(fontName);
        if(fontUrl != null) {
            return Font.loadFont(fontUrl.toExternalForm(), fontSize);
        } else {
            return Font.loadFont("file:" + fontName, fontSize);
        }

    } catch(IllegalArgumentException | NullPointerException s) {
        Logger.warn("\""+ fontName +"\" was not found. Using default font");
        return Font.loadFont("/resources/fonts/Roboto-Regular.ttf", fontSize);
    }
}
 
Example 6
Source File: RoundLcdClock.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/digital.ttf"), (0.5833333333 * PREFERRED_HEIGHT));         // "Digital-7"
    //Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/digitalreadout.ttf"), (0.5833333333 * PREFERRED_HEIGHT));  // "Digital Readout Upright"


    canvasBkg = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxBkg    = canvasBkg.getGraphicsContext2D();

    canvasFg  = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxFg     = canvasFg.getGraphicsContext2D();

    pane      = new Pane();
    pane.getChildren().setAll(canvasBkg, canvasFg);

    getChildren().setAll(pane);
    resize();
}
 
Example 7
Source File: App.java    From DeskChan with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Load all fonts from 'assets/fonts'. **/
private void loadFonts() {
	File[] fonts = Main.getPluginProxy().getAssetsDirPath().resolve("fonts").listFiles();
	if (fonts != null) {
		try {
			for (File fontPath : fonts) {
				if (fontPath.getName().endsWith(".ttf")) {
					Font.loadFont(new FileInputStream(fontPath), 10);
				}
			}
		} catch (IOException e) {
			Main.log(e);
		}
	}
	LocalFont.setDefaultFont(Main.getProperties().getString("interface.font"));
	CharacterBalloon.setDefaultFont(Main.getProperties().getString("balloon.font"));
}
 
Example 8
Source File: SimpleLineChartSkin.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.06 * PREFERRED_HEIGHT)); // "OpenSans"

    canvasBkg = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxBkg    = canvasBkg.getGraphicsContext2D();

    canvasFg  = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    ctxFg     = canvasFg.getGraphicsContext2D();

    pane      = new Pane();
    pane.getChildren().setAll(canvasBkg, canvasFg);

    getChildren().setAll(pane);
    resize();
    drawBackground();
    drawForeground();
}
 
Example 9
Source File: Lipi.java    From Lipi with MIT License 6 votes vote down vote up
private void readyGui() {

        //Must do this for opening browser;
        HostServicesProviderUtil.INSTANCE.init(getHostServices());

        //Load font
        File f = new File("kalpurush.ttf");
        try {
            Font.loadFont(f.getCanonicalPath(), 10);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

        wizPane = new VBox();

        wizPane.getStylesheets().add(Paths.get("res/material.css").toAbsolutePath().toUri().toString());
        wizPane.getStylesheets().add(Paths.get("res/custom.css").toAbsolutePath().toUri().toString());

        primaryStage.getIcons().add(
                new Image(Paths.get("res/lipi-icon.png").toAbsolutePath().toUri().toString())
        );
    }
 
Example 10
Source File: TalkClient.java    From Talk with MIT License 5 votes vote down vote up
@Override
	public void start(Stage primaryStage) throws IOException {
		Font.loadFont(getClass().getResource("/assets/OpenSansEmoji.ttf").toExternalForm(), 16);

//		Font.getFamilies();
//		for(String s: Font.getFamilies()) {
//			System.out.println(s);
//		}
		pStage = primaryStage;
		pStage.setTitle("Talk by netcan v"+ VERSION);
		pStage.setResizable(false);
		loginScene();
	}
 
Example 11
Source File: OnOffSwitchSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.5 * PREFERRED_HEIGHT)); // "OpenSans"
    font = Font.font("Open Sans", 0.5 * PREFERRED_HEIGHT);

    background = new Region();
    background.getStyleClass().setAll("background");
    background.setStyle("-switch-color: " + Util.colorToCss((Color) getSkinnable().getSwitchColor()) + ";");

    selectedText  = new Text("1");
    selectedText.setFont(font);
    selectedText.getStyleClass().setAll("selected-text");
    selectedText.setStyle("-text-color-on: " + Util.colorToCss((Color) getSkinnable().getTextColorOn()) + ";");

    deselectedText = new Text("0");
    deselectedText.setFont(font);
    deselectedText.getStyleClass().setAll("deselected-text");
    deselectedText.setStyle("-text-color-off: " + Util.colorToCss((Color) getSkinnable().getTextColorOff()) + ";");

    thumb = new Region();
    thumb.getStyleClass().setAll("thumb");
    thumb.setMouseTransparent(true);
    thumb.setStyle("-thumb-color: " + Util.colorToCss((Color) getSkinnable().getThumbColor()) + ";");

    pane = new Pane(background, selectedText, deselectedText, thumb);
    pane.getStyleClass().setAll("on-off-switch");

    moveToDeselected = new TranslateTransition(Duration.millis(180), thumb);
    moveToSelected = new TranslateTransition(Duration.millis(180), thumb);

    // Add all nodes
    getChildren().setAll(pane);
}
 
Example 12
Source File: AppStarter.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
private void loadRequiredFonts() {
    Font.loadFont(AppStarter.class.getResourceAsStream("/font/NotoSerif-Regular.ttf"), -1);
    Font.loadFont(AppStarter.class.getResourceAsStream("/font/NotoSerif-Italic.ttf"), -1);
    Font.loadFont(AppStarter.class.getResourceAsStream("/font/NotoSerif-Bold.ttf"), -1);
    Font.loadFont(AppStarter.class.getResourceAsStream("/font/NotoSerif-BoldItalic.ttf"), -1);
    Font.loadFont(AppStarter.class.getResourceAsStream("/font/DejaVuSansMono.ttf"), -1);
    Font.loadFont(AppStarter.class.getResourceAsStream("/font/DejaVuSansMono-Bold.ttf"), -1);
    Font.loadFont(AppStarter.class.getResourceAsStream("/font/DejaVuSansMono-Oblique.ttf"), -1);
}
 
Example 13
Source File: RunTestsJavaFX.java    From Lipi with MIT License 5 votes vote down vote up
private void readyGui(Stage primaryStage) {
        this.primaryStage = primaryStage;
        editorStage = new Stage();

        tabbedHMDPostEditor = new TabbedHMDPostEditor(editorStage);
        editorStage.setScene(new Scene(tabbedHMDPostEditor));

        primaryStage.setTitle("Main Application");
        editorStage.setTitle("Hugo Markdown Editor");
        //Must do this for opening browser;
        HostServicesProviderUtil.INSTANCE.init(getHostServices());

        pane = new VBox();

        File f = new File("kalpurush.ttf");
        try {
            Font.loadFont(f.getCanonicalPath(), 10);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

        pane.getStylesheets().add(Paths.get("res/material.css").toAbsolutePath().toUri().toString());
        pane.getStylesheets().add(Paths.get("res/custom.css").toAbsolutePath().toUri().toString());
//

        primaryStage.setScene(new Scene(pane));
    }
 
Example 14
Source File: Game2048.java    From util4j with Apache License 2.0 4 votes vote down vote up
/**
 * 初始化游戏字体
 */
@Override
public void init() {
    Font.loadFont(Game2048.class.getClassLoader().getResource(TTF).toExternalForm(), 10.0);
}
 
Example 15
Source File: UI.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void loadFonts() {
    Font.loadFont(UI.class.getResource("octicons/octicons-local.ttf").toExternalForm(), 32);
}
 
Example 16
Source File: SimpleGaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.06 * PREFERRED_HEIGHT)); // "OpenSans"

    sectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionsCtx    = sectionsCanvas.getGraphicsContext2D();

    measuredRangeCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    measuredRangeCanvas.setManaged(getSkinnable().isMeasuredRangeVisible());
    measuredRangeCanvas.setVisible(getSkinnable().isMeasuredRangeVisible());
    measuredRangeCtx    = measuredRangeCanvas.getGraphicsContext2D();        
    
    if (getSkinnable().getValue() < getSkinnable().getMinValue()) getSkinnable().setValue(getSkinnable().getMinValue());
    if (getSkinnable().getValue() > getSkinnable().getMaxValue()) getSkinnable().setValue(getSkinnable().getMaxValue());

    needleRotate = new Rotate(180 - getSkinnable().getStartAngle());
    if (getSkinnable().getMinValue() < 0) {
        needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue() - getSkinnable().getMinValue()) * angleStep);
    } else {
        //needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue() + getSkinnable().getMinValue()) * angleStep);
    }

    angleStep = getSkinnable().getAngleRange() / (getSkinnable().getMaxValue() - getSkinnable().getMinValue());
    needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue()) * angleStep);

    needle = new Path();
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getStyleClass().setAll("needle");
    needle.getTransforms().setAll(needleRotate);       

    value = new Text(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMinValue()) + getSkinnable().getUnit());
    value.setMouseTransparent(true);
    value.setTextOrigin(VPos.CENTER);
    value.getStyleClass().setAll("value");

    title = new Text(getSkinnable().getTitle());
    title.setTextOrigin(VPos.CENTER);
    title.getStyleClass().setAll("title");

    // Add all nodes
    pane = new Pane();
    pane.getStyleClass().add("simple-gauge");
    pane.getChildren().setAll(sectionsCanvas,
                              measuredRangeCanvas,
                              needle,
                              value,
                              title);

    getChildren().setAll(pane);
    resize();
}
 
Example 17
Source File: Fonts.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
/** Loads Montserrat font. */
private static void montserrat() {
  Font.loadFont(Fonts.class.getResource("/jupiter/fonts/Montserrat/Montserrat-Medium.ttf").toExternalForm(), 10);
  Font.loadFont(Fonts.class.getResource("/jupiter/fonts/Montserrat/Montserrat-Regular.ttf").toExternalForm(), 10);
  Font.loadFont(Fonts.class.getResource("/jupiter/fonts/Montserrat/Montserrat-SemiBold.ttf").toExternalForm(), 10);
}
 
Example 18
Source File: Fonts.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
/** Loads Anonymous Pro font. */
private static void anonymous() {
  Font.loadFont(Fonts.class.getResource("/jupiter/fonts/Anonymous_Pro/AnonymousPro.ttf").toExternalForm(), 10);
  Font.loadFont(Fonts.class.getResource("/jupiter/fonts/Anonymous_Pro/AnonymousPro-Bold.ttf").toExternalForm(), 10);
}
 
Example 19
Source File: QlockTwoSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    startX     = PREFERRED_WIDTH * 0.114;
    startY     = PREFERRED_WIDTH * 0.112;
    stepX      = PREFERRED_WIDTH * 0.072;
    stepY      = PREFERRED_WIDTH * 0.08;
    font       = Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/din.otf"), PREFERRED_WIDTH * 0.048);
    background = new Region();
    background.getStyleClass().addAll("background", getSkinnable().getColor().STYLE_CLASS);

    stainlessBackground.setImage(texture.getImage(PREFERRED_WIDTH, PREFERRED_HEIGHT));
    stainlessBackground.setOpacity(getSkinnable().getColor() == QlockTwo.QlockColor.STAINLESS_STEEL ? 1 : 0);

    p1 = new Region();
    p1.getStyleClass().add("dot-off");
    p2 = new Region();
    p2.getStyleClass().add("dot-off");
    p3 = new Region();
    p3.getStyleClass().add("dot-off");
    p4 = new Region();
    p4.getStyleClass().add("dot-off");

    highlight = new Region();
    highlight.getStyleClass().add("highlight");

    matrix = new Label[11][10];
    for (int y = 0 ; y < 10 ; y++) {
        for (int x = 0 ; x < 11 ; x++) {
            matrix[x][y] = new Label();
            matrix[x][y].setAlignment(Pos.CENTER);
            matrix[x][y].setPrefWidth(PREFERRED_WIDTH * 0.048);
            matrix[x][y].setPrefHeight(PREFERRED_HEIGHT * 0.048);
            matrix[x][y].setText(getSkinnable().getQlock().getMatrix()[y][x]);
            matrix[x][y].setFont(font);
            matrix[x][y].getStyleClass().add("text-off");
        }
    }

    pane.getChildren().setAll(background,
                              stainlessBackground,
                              p4,
                              p3,
                              p2,
                              p1);
    for (int y = 0 ; y < 10 ; y++) {
        for (int x = 0 ; x < 11 ; x++) {
            pane.getChildren().add(matrix[x][y]);
        }
    }
    pane.getChildren().add(highlight);

    getChildren().setAll(pane);
    resize();
}
 
Example 20
Source File: FontUtils.java    From PDF4Teachers with Apache License 2.0 2 votes vote down vote up
public static Font getFont(String family, boolean italic, boolean bold, double size){

        return Font.loadFont(getFontFile(family, italic, bold), size);
    }