Example usage for java.awt Font TRUETYPE_FONT

List of usage examples for java.awt Font TRUETYPE_FONT

Introduction

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

Prototype

int TRUETYPE_FONT

To view the source code for java.awt Font TRUETYPE_FONT.

Click Source Link

Document

Identify a font resource of type TRUETYPE.

Usage

From source file:pl.mcpg.brainfuckjava.Start.java

public static void main(String[] args) {
    System.out.println("Detected language is " + userLocale.toString() + ".");
    switch (userLocale.toString()) {
    case "pl_PL":
        loadLanguage("pl");
        break;//w  w  w .  j  a v  a2s  .  c  o m
    default:
        loadLanguage("en");
        break;
    }
    Config.load();
    try {
        spacemonoFont = Font.createFont(Font.TRUETYPE_FONT,
                Start.class.getResourceAsStream("/fonts/spacemono.ttf"));
    } catch (FontFormatException | IOException e) {
        e.printStackTrace();
        System.exit(1);
    }
    if (args.length == 0) // if there are no args, just run GUI.
    {
        runGUI();
        return;
    }

    Options options = new Options();
    Option forceLangOption = new Option("l", "forcelang", true, getText("forcelangCli"));
    forceLangOption.setArgName("language");
    Option interactiveOption = new Option("i", "intercml", false, getText("interactiveCli"));
    Option runOption = new Option("r", "run", true, getText("runCli"));
    runOption.setArgs(1);
    Option displayNumbersOption = new Option("n", "displayint", false, getText("dnmCli"));
    Option helpOption = new Option("h", "help", false, getText("helpCli"));
    options.addOption(forceLangOption);
    options.addOption(interactiveOption);
    options.addOption(runOption);
    options.addOption(displayNumbersOption);
    options.addOption(helpOption);

    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('l')) {
            boolean found = true;
            switch (commandLine.getOptionValue('l')) {
            case "pl":
                loadLanguage("pl");
                break;
            case "en":
                loadLanguage("en");
                break;
            default:
                System.err.println(getText("forcedLangNotFound", commandLine.getOptionValue('l')));
                found = false;
                break;
            }
            if (found) {
                System.out.println(getText("forcedLang", commandLine.getOptionValue('l')));
            }
        }
        if (commandLine.hasOption('h')) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar brainfuck.java.jar [-h] [-n] [-i] [-r {file}]",
                    "Brainfuck.java command line options", options,
                    "Issues? Report them on https://github.com/MCPlayG/Brainfuck.java/issues!");
            System.exit(0);
        }
        if (commandLine.hasOption('n')) {
            numberDisplayMode = true;
        }
        if (commandLine.hasOption('i')) {
            new InteractiveCommandLine().run();
            System.exit(0);
        }
        if (commandLine.hasOption('r')) {
            run(new File(commandLine.getOptionValue('r')));
            System.exit(0);
        }
    } catch (ParseException e) {
        System.err.println(getText("parseCliError"));
        e.printStackTrace();
        runGUI();
    }
    runGUI();
}

From source file:core.PlanC.java

/**
 * inicio de aplicacion/*from  w w  w .  java 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 {/*  w w w.java2  s. c o m*/
        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/*ww w  .  java 2 s .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;//from  ww w . j a v  a 2s  .  com
    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 {//  w ww  .j  av a 2  s  . c o m
        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.  ja v a  2s. 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//from  w ww.  jav a2 s .  co m
    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();
}