Example usage for java.awt Font createFont

List of usage examples for java.awt Font createFont

Introduction

In this page you can find the example usage for java.awt Font createFont.

Prototype

public static Font createFont(int fontFormat, File fontFile)
        throws java.awt.FontFormatException, java.io.IOException 

Source Link

Document

Returns a new Font using the specified font type and the specified font file.

Usage

From source file:core.PlanC.java

/**
 * inicio de aplicacion/*from   ww  w.j a v  a 2 s.co  m*/
 * 
 * @param arg - argumentos de entrada
 */
public static void main(String[] args) {

    // user.name

    /*
     * Properties prp = System.getProperties(); System.out.println(getWmicValue("bios", "SerialNumber"));
     * System.out.println(getWmicValue("cpu", "SystemName"));
     */

    try {
        // log
        // -Djava.util.logging.SimpleFormatter.format='%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n'
        // System.setProperty("java.util.logging.SimpleFormatter.format",
        // "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n");
        System.setProperty("java.util.logging.SimpleFormatter.format",
                "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %5$s%6$s%n");

        FileHandler fh = new FileHandler(LOG_FILE);
        fh.setFormatter(new SimpleFormatter());
        fh.setLevel(Level.INFO);
        ConsoleHandler ch = new ConsoleHandler();
        ch.setFormatter(new SimpleFormatter());
        ch.setLevel(Level.INFO);
        logger = Logger.getLogger("");
        Handler[] hs = logger.getHandlers();
        for (int x = 0; x < hs.length; x++) {
            logger.removeHandler(hs[x]);
        }
        logger.addHandler(fh);
        logger.addHandler(ch);
        // point apache log to this log
        System.setProperty("org.apache.commons.logging.Log", Jdk14Logger.class.getName());

        TPreferences.init();
        TStringUtils.init();

        Font fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Light.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("Dosis-Medium.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);
        fo = Font.createFont(Font.TRUETYPE_FONT, TResourceUtils.getFile("AERO_ITALIC.ttf"));
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(fo);

        SwingTimerTimingSource ts = new SwingTimerTimingSource();
        AnimatorBuilder.setDefaultTimingSource(ts);
        ts.init();

        // parse app argument parameters and append to tpreferences to futher uses
        for (String arg : args) {
            String[] kv = arg.split("=");
            TPreferences.setProperty(kv[0], kv[1]);
        }
        RUNNING_MODE = TPreferences.getProperty("runningMode", RM_NORMAL);

        newMsg = Applet.newAudioClip(TResourceUtils.getURL("newMsg.wav"));

    } catch (Exception e) {
        SystemLog.logException1(e, true);
    }

    // pass icon from metal to web look and feel
    Icon i1 = UIManager.getIcon("OptionPane.errorIcon");
    Icon i2 = UIManager.getIcon("OptionPane.informationIcon");
    Icon i3 = UIManager.getIcon("OptionPane.questionIcon");
    Icon i4 = UIManager.getIcon("OptionPane.warningIcon");
    // Object fcui = UIManager.get("FileChooserUI");
    // JFileChooser fc = new JFileChooser();

    WebLookAndFeel.install();
    // WebLookAndFeel.setDecorateFrames(true);
    // WebLookAndFeel.setDecorateDialogs(true);

    UIManager.put("OptionPane.errorIcon", i1);
    UIManager.put("OptionPane.informationIcon", i2);
    UIManager.put("OptionPane.questionIcon", i3);
    UIManager.put("OptionPane.warningIcon", i4);
    // UIManager.put("TFileChooserUI", fcui);

    // warm up the IDW.
    // in my computer, some weird error ocurr if i don't execute this preload.
    new RootWindow(null);

    frame = new TWebFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            Exit.shutdown();
        }
    });

    if (RUNNING_MODE.equals(RM_NORMAL)) {
        initEnviorement();
    }
    if (RUNNING_MODE.equals(RM_CONSOLE)) {
        initConsoleEnviorement();
    }

    if (RUNNING_MODE.equals(ONE_TASK)) {
        String cln = TPreferences.getProperty("taskName", "*TaskNotFound");
        PlanC.logger.log(Level.INFO, "OneTask parameter found in .properties. file Task name = " + cln);
        try {
            Class cls = Class.forName(cln);
            Object dobj = cls.newInstance();
            // new class must be extends form AbstractExternalTask
            TTaskManager.executeTask((Runnable) dobj);
            return;
        } catch (Exception e) {
            PlanC.logger.log(Level.SEVERE, e.getMessage(), e);
            Exit.shutdown();
        }
    }
}

From source file:Main.java

public static void importFont(InputStream stream) {
    try {/*ww  w .j a va  2 s.com*/
        Font font1 = Font.createFont(Font.TRUETYPE_FONT, stream);
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font1);
    } catch (FontFormatException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

/**
 * Loads a font using {@link Font#createdFont}
 * @param s - The resource name, ex: /assets/darkmetro/seoeuil.ttf -> darkmetro/segpeuil
 * @return/*from   ww w.jav a 2s  . c  o  m*/
 */
public static Font loadFont(String s) {
    try {
        return Font.createFont(Font.TRUETYPE_FONT, System.class.getResourceAsStream("/assets/" + s + ".ttf"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Font getFont(String name) {
    Font font = null;// w w w. j a v a2 s.c  o m
    if (cache != null) {
        if ((font = cache.get(name)) != null) {
            return font;
        }
    }
    String fName = "/fonts/" + name;
    try {
        InputStream is = Main.class.getResourceAsStream(fName);
        font = Font.createFont(Font.TRUETYPE_FONT, is);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println(fName + " not loaded.  Using serif font.");
        font = new Font("serif", Font.PLAIN, 24);
    }
    return font;
}

From source file:MainClass.java

public void loadFont() throws FontFormatException, IOException {
    String fontFileName = "yourfont.ttf";
    InputStream is = this.getClass().getResourceAsStream(fontFileName);

    Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);

    Font ttfReal = ttfBase.deriveFont(Font.PLAIN, 24);

}

From source file:de.dakror.jagui.skin.GuiSkin.java

public GuiSkin(File file) {
    try {/*from  ww  w  . j  a v  a  2s  .  c om*/
        skinFile = file;
        flatData = new JSONObject(Helper.getFileContent(file)).getJSONObject("MonoBehaviour");
        if (flatData.has("m_Font") && !flatData.isNull("m_Font"))
            globalFont = Font.createFont(Font.TRUETYPE_FONT,
                    new File(skinFile.getParentFile().getPath() + "/" + flatData.getString("m_Font")));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.bitstrings.maven.plugins.splasher.DrawingContext.java

public Font loadFont(File fontFile) throws IOException, FontFormatException {
    return Font.createFont(Font.TRUETYPE_FONT, fontFile);
}

From source file:DemoFonts.java

public static Font getFont(String name) {
    Font font = null;//from  w  w  w .j  av  a  2 s .  c  o  m
    if (cache != null) {
        if ((font = cache.get(name)) != null) {
            return font;
        }
    }
    String fName = "/fonts/" + name;
    try {
        InputStream is = DemoFonts.class.getResourceAsStream(fName);
        font = Font.createFont(Font.TRUETYPE_FONT, is);
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println(fName + " not loaded.  Using serif font.");
        font = new Font("serif", Font.PLAIN, 24);
    }
    return font;
}

From source file:com.uniteddev.Unity.Login.java

public static void setup() throws IOException, InterruptedException, FontFormatException {
    //fonts//ww w.java2  s . c om
    roboto_thin = Font.createFont(Font.TRUETYPE_FONT, Unity.class.getResourceAsStream("/res/Roboto-Thin.ttf"));
    roboto_regular = Font.createFont(Font.TRUETYPE_FONT,
            Unity.class.getResourceAsStream("/res/Roboto-Regular.ttf"));
    // main
    window = new Window(Unity.title, Unity.favicon, Unity.background, 791, 527);
    release = new Label(Unity.release, Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 12));
    server_lbl = new Label("Server:", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 12));
    server_stat_lbl = new Label("Offline", Color.RED, roboto_regular.deriveFont(Font.PLAIN, 12));
    settingsButton = new Button();
    settingsButton.setImage("/res/gear.png");
    settingsButton.removeDecorations();
    settingsButton.addActionListener(new settingsButton_action());
    // splash screen
    update_lbl = new Label("Updating", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 32));
    progress = new ProgressBar(new Color(255, 255, 255, 100), new Color(255, 255, 255, 255));
    progress.removeDecorations();
    progressText = new Label("Ready.", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14));
    // login screen
    username = new TextField(prefs.get("username", ""), Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14));
    password = new PasswordField(Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14));
    username_lbl = new Label("Username:", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14));
    password_lbl = new Label("Password:", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14));
    loginButton = new Button("Login", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 28));
    loginButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
    loginButton.center();
    loginButton.addActionListener(new loginButton_action());
    invalid_login_lbl = new Label("Invalid Login", Color.RED, roboto_regular.deriveFont(Font.PLAIN, 14));
    invalid_login_lbl.setVisible(false);
    // settings screen
    settings_lbl = new Label("Settings", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 32));
    deleteButton = new Button();
    deleteButton.setImage("/res/recycle.png");
    deleteButton.removeDecorations();
    deleteButton.addActionListener(new deleteButton_action());
    ram_size = new TextField(prefs.get("ram_size", default_ram), Color.WHITE,
            roboto_regular.deriveFont(Font.PLAIN, 14));
    ram_lbl = new Label("RAM Usage (MB):", Color.WHITE, roboto_regular.deriveFont(Font.PLAIN, 14));
    invalid_ram_lbl = new Label(Color.RED, roboto_regular.deriveFont(Font.PLAIN, 14));
    invalid_ram_lbl.setVisible(false);
    saveButton = new Button("Save", Color.WHITE, roboto_thin.deriveFont(Font.PLAIN, 28));
    saveButton.setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
    saveButton.center();
    saveButton.addActionListener(new saveButton_action());
    // sizing and layout
    release.setBounds(5, window.getHeight() - 50, 140, 20);
    server_lbl.setBounds(5, window.getHeight() - 50, 140, 20);
    server_stat_lbl.setBounds(45, window.getHeight() - 50, 200, 20);
    update_lbl.setBounds(115, 20, 320, 50);
    progress.setBounds(20, 75, 320, 10);
    progressText.setBounds(20, 90, 320, 20);
    username.setBounds(155, 30, 115, 20);
    password.setBounds(155, 60, 115, 20);
    username_lbl.setBounds(80, 30, 115, 20);
    password_lbl.setBounds(79, 60, 115, 20);
    loginButton.setBounds(110, 110, 140, 40);
    invalid_login_lbl.setBounds(135, 165, 140, 20);
    settingsButton.setBounds(window.getWidth() - 45, window.getHeight() - 65, 32, 32);
    settings_lbl.setBounds(115, 5, 320, 50);
    deleteButton.setBounds(155, 50, 32, 32);
    ram_size.setBounds(175, 90, 115, 20);
    ram_lbl.setBounds(60, 90, 115, 20);
    saveButton.setBounds(110, 125, 140, 40);
    // setup screens
    login_window = new Label();
    login_window.setBounds(216, 180, 360, 200);
    login_window.add(update_lbl);
    login_window.add(progress);
    login_window.add(progressText);
    login_window.add(username);
    login_window.add(password);
    login_window.add(username_lbl);
    login_window.add(password_lbl);
    login_window.add(loginButton);
    login_window.add(invalid_login_lbl);
    login_window.add(settings_lbl);
    login_window.add(deleteButton);
    login_window.add(ram_size);
    login_window.add(invalid_ram_lbl);
    login_window.add(ram_lbl);
    login_window.add(saveButton);
    // setup and show window
    window.addComponent(release);
    window.addComponent(server_lbl);
    window.addComponent(server_stat_lbl);
    window.addComponent(login_window);
    window.addComponent(settingsButton);
    window.getRootPane().setDefaultButton(loginButton);
    window.setLocationRelativeTo(null);
    release.setVisible(false);
    window.setVisible(true);
    start();
}

From source file:net.team2xh.crt.gui.util.GUIToolkit.java

/**
 * Register a local font to the graphical environment.
 *
 * After registering a font, its font family can be used normally as if
 * the font was installed on the OS.//  w  w  w  .  j a v  a2  s.  c  o  m
 *
 * @param caller Caller instance for resource aquisition
 * @param path Font file path
 */
public static void registerFont(Object caller, String path) {
    try {
        URI uri = caller.getClass().getResource(path).toURI();
        File fontFile = new File(uri);
        Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        ge.registerFont(font);
    } catch (FontFormatException | IOException | URISyntaxException e) {
        System.out.println(e.getMessage());
    }
}