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:literarytermsquestionbank.ShortStories.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    // Set window icon
    this.setIconImage(
            Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/Images/book-icon_ss.png")));

    // Set custom fonts
    try {//from   w  w  w .java2  s  . c  om
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        // Load Great Vibes from resources
        Font bradleyFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/BRADHITC.TTF"));
        ge.registerFont(bradleyFontFace);
        questionLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        checkButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 36f));
        stuckLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f));
        rescueButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        answerLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        youAreViewingLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        quoteIndexTextField.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        totalNumberLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 36f));
        goButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        randomButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        previousButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        nextButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        backButton.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f));
        clueTitleLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 24f));
        clueLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        passageLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        examplesLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        commentsLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 30f));
        storyLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 20f));
        tabbedPane.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));
        menuTitleLabel.setFont(bradleyFontFace.deriveFont(Font.PLAIN, 18f));

        // Load and set Imprint font face
        Font imprintFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/IMPRISHA.TTF"));
        ge.registerFont(imprintFontFace);
        quoteTopLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
        quoteBottomLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
    } catch (FontFormatException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONParser parser = new JSONParser();
    try {
        // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package.
        Object quoteObj = parser
                .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json")));

        // This casts the object to a JSONObject for future manipulation
        JSONObject jsonObject = (JSONObject) quoteObj;

        // This array holds all the quotes
        JSONArray quotesArray = (JSONArray) jsonObject.get("Short Stories");
        Iterator<JSONObject> iterator = quotesArray.iterator();

        // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList
        while (iterator.hasNext()) {
            Collections.addAll(quotesList, iterator.next());
            totalNumberOfQuotes++;
        }

        // Init randomizer
        Random rand = new Random();

        // Generate a random integer between 1 and size of the ArrayList
        quoteIndex = rand.nextInt(quotesList.size()) + 1;

        generateQuote(quoteIndex); // This calls a method to generate a quote and display it
    } catch (Exception e) { // This means something went very wrong when starting the program
        System.out.println("Uh oh, something bad happened. Possible database corruption.");
        JOptionPane.showMessageDialog(null,
                "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}

From source file:literarytermsquestionbank.AChristmasCarol.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    // Set window icon
    this.setIconImage(Toolkit.getDefaultToolkit()
            .getImage(getClass().getResource("/Resources/Images/book-icon_acc.png")));

    // Set custom fonts
    try {/*from w  ww. j  av a  2 s .co  m*/
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        // Load Gill Sans from resources
        Font gillSansFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/GILLSANS.TTF"));
        ge.registerFont(gillSansFontFace);

        tabbedPane.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        questionLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        checkButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        youAreViewingLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        quoteIndexTextField.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 24f));
        totalNumberLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 36f));
        goButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f));
        randomButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f));
        backButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        clueLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        passageLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        exampleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        commentsLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        realAnswerLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        realAnswerTitleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));

        // Load the FreeStyle Script font from resources
        Font freeStyleFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/FREESCPT.TTF"));
        ge.registerFont(freeStyleFontFace);
        salutationLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f));
        signatureLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f));

    } catch (FontFormatException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONParser parser = new JSONParser();

    try {
        // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package.
        Object quoteObj = parser
                .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json")));

        // This casts the object to a JSONObject for future manipulation
        JSONObject jsonObject = (JSONObject) quoteObj;

        // This array holds all the quotes
        JSONArray quotesArray = (JSONArray) jsonObject.get("A Christmas Carol");
        Iterator<JSONObject> iterator = quotesArray.iterator();

        // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList
        while (iterator.hasNext()) {
            Collections.addAll(quotesList, iterator.next());
            totalNumberOfQuotes++;
        }

        // Init randomizer
        Random rand = new Random();

        // Generate a random integer between 1 and size of the ArrayList
        quoteIndex = rand.nextInt(quotesList.size()) + 1;

        generateQuote(quoteIndex); // This calls a method to generate a quote and display it
    } catch (Exception e) { // This means something went very wrong when starting the program
        System.out.println("Uh oh, something bad happened. Possible database corruption.");
        JOptionPane.showMessageDialog(null,
                "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}

From source file:view.AppearanceSettingsDialog.java

private void changeLabel() {
    String fontLocation = getFontCbBox();

    try {/*w w w . j a  v  a2 s  . com*/
        Font newFont = Font.createFont(Font.TRUETYPE_FONT, new File(getFontLocationByName(fontLocation)));
        Font font = null;

        if (cbBold.isSelected() && cbItalic.isSelected()) {
            font = newFont.deriveFont(Font.ITALIC + Font.BOLD, 36);
        } else if (cbBold.isSelected() && !cbItalic.isSelected()) {
            font = newFont.deriveFont(Font.BOLD, 36);
        } else if (!cbBold.isSelected() && cbItalic.isSelected()) {
            font = newFont.deriveFont(Font.ITALIC, 36);
        } else {
            font = newFont.deriveFont(Font.PLAIN, 36);
        }
        lblSampleText.setFont(font);
        return;
    } catch (FontFormatException ex) {
        Logger.getLogger(AppearanceSettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(AppearanceSettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (cbBold.isSelected() && cbItalic.isSelected()) {
        lblSampleText.setFont(new Font(fontLocation, Font.BOLD + Font.ITALIC, 36));
    } else if (cbBold.isSelected() && !cbItalic.isSelected()) {
        lblSampleText.setFont(new Font(fontLocation, Font.BOLD, 36));
    } else if (!cbBold.isSelected() && cbItalic.isSelected()) {
        lblSampleText.setFont(new Font(fontLocation, Font.ITALIC, (Integer) 36));
    } else {
        lblSampleText.setFont(new Font(cbFontType.getSelectedItem().toString(), Font.PLAIN, (Integer) 36));
    }
}

From source file:org.lnicholls.galleon.server.Server.java

private void preLoadFonts() {
    if (log.isDebugEnabled())
        log.debug("preLoadFonts()");
    try {// w  w  w  .  j ava  2 s .c  o m
        Font.createFont(Font.TRUETYPE_FONT, Server.class.getClassLoader().getResourceAsStream(
                ScrollText.class.getPackage().getName().replace('.', '/') + "/" + "default.ttf"));
    } catch (Throwable e) {
    }
}

From source file:abfab3d.shapejs.ShapeJSGlobal.java

/**
 * js function to load a font/*from   ww  w. ja  va  2 s. c om*/
 * returns BufferedImage
 */
public static Object loadFont(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
    if (args.length < 1) {
        throw Context.reportRuntimeError("loadFont() requires one filename.");
    }

    String filename = Context.toString(args[0]);

    if (filename == null || filename.length() == 0) {
        throw Context.reportRuntimeError("No file provided for loadFont() command");
    }

    printf("loading font file: %s\n", filename);

    String reason = null;

    File f = new File(filename);
    Font font = null;
    if (!f.exists()) {
        throw Context.reportRuntimeError(fmt("Cannot find font file: %s\n", f.getAbsoluteFile()));
    }

    if (f.length() > 800000) {
        // Bit of security thought here, font's should not be too large unless they contain some malware payload
        throw Context.reportRuntimeError(fmt("Font file too large"));
    }
    try {
        int type = Font.TRUETYPE_FONT;
        if (filename.indexOf(".ttf") == -1)
            type = Font.TYPE1_FONT;
        font = Font.createFont(type, f);
    } catch (Exception e) {
        reason = e.getMessage();
        e.printStackTrace();
    }
    if (font == null) {
        throw Context.reportRuntimeError(fmt("failed to load font file: %s.  Reason: %s\n", filename, reason));
    }

    return font;
}

From source file:org.jtrfp.trcl.core.ResourceManager.java

public Font getFont(String zipName, String fontFileName) {
    try {/* w w w .j  av a2 s  .  c  o  m*/
        zipName = "/fonts/" + zipName;
        if (zipName.toUpperCase().endsWith(".ZIP")) {// Search the zip
            ZipInputStream zip = new ZipInputStream(ResourceManager.class.getResourceAsStream(zipName));
            ZipEntry entry;

            while ((entry = zip.getNextEntry()) != null) {
                System.out.println("ZIP ENTRY: " + entry.getName());
                if (entry.getName().toUpperCase().endsWith(fontFileName.toUpperCase())) {
                    Font font = Font.createFont(Font.TRUETYPE_FONT, zip);
                    zip.closeEntry();
                    zip.close();
                    return font;
                }
            } // end while(elements)
        } // end if(zip)
        else {
        } // TODO: Handle non-zipped fonts?
    } catch (Exception e) {
        tr.showStopper(e);
    }
    return null;
}

From source file:co.id.app.sys.util.StringUtils.java

public static String getMakeLiner(String temp, int widLimitMetric) {
    if (temp == null) {
        return null;
    }/*from ww  w  .j a  v a  2s.  co m*/
    String strLiner = "";
    Font ft = new Font("Arial, Helvetica, sans-serif", Font.TRUETYPE_FONT, 9);
    JComponent jx = new JComponent() {
        private static final long serialVersionUID = 2792190024722186161L;
    };
    jx.setFont(ft);
    FontMetrics fm = jx.getFontMetrics(ft);
    int strWidMetric = fm.stringWidth(temp);
    while (strWidMetric > 0) {
        char[] ch = temp.toCharArray();
        if (strWidMetric > widLimitMetric) {
            int wChTot = 0;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; wChTot < widLimitMetric; i++) {
                wChTot += fm.charWidth(ch[i]);
                sb.append(ch[i]);
            }

            String strWid = sb.toString();
            int lastChar13 = strWid.lastIndexOf(" ");
            if (lastChar13 != -1) {
                strWid = temp.substring(0, lastChar13);
                strLiner = strLiner + strWid + "<br/>";
                temp = temp.substring(lastChar13 + 1, temp.length());
                strWidMetric = fm.stringWidth(temp);
            } else {
                strWid = temp.substring(0, strWid.length());
                strLiner = strLiner + strWid + "<br/>";
                temp = temp.substring(strWid.length(), temp.length());
                strWidMetric = fm.stringWidth(temp);
            }
        } else {
            strLiner = strLiner + temp;
            temp = "";
            strWidMetric = fm.stringWidth(temp);
        }

    }
    return strLiner;
}

From source file:org.yccheok.jstock.gui.Utils.java

private static Font _getRobotoLightFont() {
    InputStream inputStream = Utils.class.getResourceAsStream("/assets/fonts/Roboto-Light.ttf");
    try {/*from  w  w  w  .j  av  a2  s .c  o m*/
        Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
        if (font != null) {
            return font;
        }
    } catch (FontFormatException ex) {
        log.error(null, ex);
    } catch (IOException ex) {
        log.error(null, ex);
    } finally {
        org.yccheok.jstock.file.Utils.close(inputStream);
    }
    Font oldLabelFont = UIManager.getFont("Label.font");
    return oldLabelFont;
}