Example usage for java.awt Font getSize

List of usage examples for java.awt Font getSize

Introduction

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

Prototype

public int getSize() 

Source Link

Document

Returns the point size of this Font , rounded to an integer.

Usage

From source file:forge.toolbox.FSkin.java

/**
 * Loads two sprites: the default (which should be a complete
 * collection of all symbols) and the preferred (which may be
 * incomplete).// ww  w  . j a  v  a2s. co  m
 *
 * Font must be present in the skin folder, and will not
 * be replaced by default.  The fonts are pre-derived
 * in this method and saved in a HashMap for future access.
 *
 * Color swatches must be present in the preferred
 * sprite, and will not be replaced by default.
 *
 * Background images must be present in skin folder,
 * and will not be replaced by default.
 *
 * Icons, however, will be pulled from the two sprites. Obviously,
 * preferred takes precedence over default, but if something is
 * missing, the default picture is retrieved.
 */
public static void loadFull(final boolean onInit) {
    if (onInit) {
        // No need for this method to be loaded while on the EDT.
        FThreads.assertExecutedByEdt(false);

        // Preferred skin name must be called via loadLight() method,
        // which does some cleanup and init work.
        if (preferredName.isEmpty()) {
            loadLight("default", true);
        }
    }

    FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Processing image sprites: ", 7);

    // Grab and test various sprite files.
    final String defaultDir = ForgeConstants.DEFAULT_SKINS_DIR;
    final File f1 = new File(defaultDir + ForgeConstants.SPRITE_ICONS_FILE);
    final File f2 = new File(preferredDir + ForgeConstants.SPRITE_ICONS_FILE);
    final File f3 = new File(defaultDir + ForgeConstants.SPRITE_FOILS_FILE);
    final File f4 = new File(defaultDir + ForgeConstants.SPRITE_AVATARS_FILE);
    final File f5 = new File(preferredDir + ForgeConstants.SPRITE_AVATARS_FILE);
    final File f6 = new File(defaultDir + ForgeConstants.SPRITE_OLD_FOILS_FILE);
    final File f7 = new File(defaultDir + ForgeConstants.SPRITE_TROPHIES_FILE);
    final File f8 = new File(defaultDir + ForgeConstants.DRAFT_DECK_IMG_FILE);

    try {
        int p = 0;
        bimDefaultSprite = ImageIO.read(f1);
        FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
        bimPreferredSprite = ImageIO.read(f2);
        FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
        bimFoils = ImageIO.read(f3);
        FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
        bimOldFoils = f6.exists() ? ImageIO.read(f6) : ImageIO.read(f3);
        FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
        bimDefaultAvatars = ImageIO.read(f4);
        FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
        bimTrophies = ImageIO.read(f7);
        FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
        bimQuestDraftDeck = ImageIO.read(f8);

        if (f5.exists()) {
            bimPreferredAvatars = ImageIO.read(f5);
        }

        FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);

        preferredH = bimPreferredSprite.getHeight();
        preferredW = bimPreferredSprite.getWidth();
    } catch (final Exception e) {
        System.err.println("FSkin$loadFull: Missing a sprite (default icons, " + "preferred icons, or foils.");
        e.printStackTrace();
    }

    // Initialize fonts
    if (onInit) { //set default font size only once onInit
        final Font f = UIManager.getDefaults().getFont("Label.font");
        if (f != null) {
            defaultFontSize = f.getSize();
        }
    }
    SkinFont.setBaseFont(GuiUtils.newFont(preferredDir + ForgeConstants.FONT_FILE));

    // Put various images into map (except sprite and splash).
    // Exceptions handled inside method.
    SkinIcon.setIcon(FSkinProp.BG_TEXTURE, preferredDir + ForgeConstants.TEXTURE_BG_FILE);
    SkinIcon.setIcon(FSkinProp.BG_MATCH, preferredDir + ForgeConstants.MATCH_BG_FILE);

    // Run through enums and load their coords.
    Colors.updateAll();
    for (final FSkinProp prop : FSkinProp.values()) {
        switch (prop.getType()) {
        case IMAGE:
            SkinImage.setImage(prop);
            break;
        case ICON:
            SkinIcon.setIcon(prop);
            break;
        case FOIL:
            setImage(prop, bimFoils);
            break;
        case OLD_FOIL:
            setImage(prop, bimOldFoils);
            break;
        case TROPHY:
            setImage(prop, bimTrophies);
            break;
        default:
            break;
        }
    }

    // Assemble avatar images
    assembleAvatars();

    // Images loaded; can start UI init.
    FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Creating display components.");
    loaded = true;

    // Clear references to buffered images
    bimDefaultSprite.flush();
    bimFoils.flush();
    bimOldFoils.flush();
    bimPreferredSprite.flush();
    bimDefaultAvatars.flush();
    bimQuestDraftDeck.flush();
    bimTrophies.flush();

    if (bimPreferredAvatars != null) {
        bimPreferredAvatars.flush();
    }

    bimDefaultSprite = null;
    bimFoils = null;
    bimOldFoils = null;
    bimPreferredSprite = null;
    bimDefaultAvatars = null;
    bimPreferredAvatars = null;
    bimQuestDraftDeck = null;
    bimTrophies = null;

    //establish encoding symbols
    final File dir = new File(ForgeConstants.CACHE_SYMBOLS_DIR);
    if (!dir.mkdir()) { //ensure symbols directory exists and is empty
        File[] files = dir.listFiles();
        assert files != null;
        for (final File file : files) {
            file.delete();
        }
    }

    addEncodingSymbol("W", FSkinProp.IMG_MANA_W);
    addEncodingSymbol("U", FSkinProp.IMG_MANA_U);
    addEncodingSymbol("B", FSkinProp.IMG_MANA_B);
    addEncodingSymbol("R", FSkinProp.IMG_MANA_R);
    addEncodingSymbol("G", FSkinProp.IMG_MANA_G);
    addEncodingSymbol("W/U", FSkinProp.IMG_MANA_HYBRID_WU);
    addEncodingSymbol("U/B", FSkinProp.IMG_MANA_HYBRID_UB);
    addEncodingSymbol("B/R", FSkinProp.IMG_MANA_HYBRID_BR);
    addEncodingSymbol("R/G", FSkinProp.IMG_MANA_HYBRID_RG);
    addEncodingSymbol("G/W", FSkinProp.IMG_MANA_HYBRID_GW);
    addEncodingSymbol("W/B", FSkinProp.IMG_MANA_HYBRID_WB);
    addEncodingSymbol("U/R", FSkinProp.IMG_MANA_HYBRID_UR);
    addEncodingSymbol("B/G", FSkinProp.IMG_MANA_HYBRID_BG);
    addEncodingSymbol("R/W", FSkinProp.IMG_MANA_HYBRID_RW);
    addEncodingSymbol("G/U", FSkinProp.IMG_MANA_HYBRID_GU);
    addEncodingSymbol("2/W", FSkinProp.IMG_MANA_2W);
    addEncodingSymbol("2/U", FSkinProp.IMG_MANA_2U);
    addEncodingSymbol("2/B", FSkinProp.IMG_MANA_2B);
    addEncodingSymbol("2/R", FSkinProp.IMG_MANA_2R);
    addEncodingSymbol("2/G", FSkinProp.IMG_MANA_2G);
    addEncodingSymbol("P/W", FSkinProp.IMG_MANA_PHRYX_W);
    addEncodingSymbol("P/U", FSkinProp.IMG_MANA_PHRYX_U);
    addEncodingSymbol("P/B", FSkinProp.IMG_MANA_PHRYX_B);
    addEncodingSymbol("P/R", FSkinProp.IMG_MANA_PHRYX_R);
    addEncodingSymbol("P/G", FSkinProp.IMG_MANA_PHRYX_G);
    for (int i = 0; i <= 20; i++) {
        addEncodingSymbol(String.valueOf(i), FSkinProp.valueOf("IMG_MANA_" + i));
    }
    addEncodingSymbol("X", FSkinProp.IMG_MANA_X);
    addEncodingSymbol("Y", FSkinProp.IMG_MANA_Y);
    addEncodingSymbol("Z", FSkinProp.IMG_MANA_Z);
    addEncodingSymbol("C", FSkinProp.IMG_CHAOS);
    addEncodingSymbol("Q", FSkinProp.IMG_UNTAP);
    addEncodingSymbol("S", FSkinProp.IMG_MANA_SNOW);
    addEncodingSymbol("T", FSkinProp.IMG_TAP);

    // Set look and feel after skin loaded
    FView.SINGLETON_INSTANCE.setSplashProgessBarMessage("Setting look and feel...");
    final ForgeLookAndFeel laf = new ForgeLookAndFeel();
    laf.setForgeLookAndFeel(Singletons.getView().getFrame());
}

From source file:at.tuwien.ifs.somtoolbox.apps.viewer.GeneralUnitPNode.java

/**
 * Initializes textual details//from w  ww  . jav  a 2  s  . c  o m
 * 
 * @param threshold Displays description of mapped inputs below certain threshold (count), otherwise a count is
 *            displayed.
 * @param fontSize Text size
 * @param yInOffset Positional offset
 */
private PNode[] initData(int threshold, int fontSize, double yInOffset, int detailLevel, int variant) {
    final String commonVectorLabelPrefix = state.growingLayer.getCommonVectorLabelPrefix();
    int nodesToDisplay = u.getNumberOfMappedInputs() * threshold / 100;

    if (variant == DATA_DISPLAY_VARIANT_INPUTOBJECT || variant == DATA_DISPLAY_VARIANT_INPUTOBJECTSHIFTED) { // Display
        // stars
        // or
        // simply
        // count
        if (locations != null) {
            PNode[] dataNodes = new PNode[nodesToDisplay];
            for (int index = 0; index < nodesToDisplay; index++) {
                PNode star = new StarPNode();
                String inputName = u.getMappedInputName(index);
                String inputDistance = StringUtils.format(u.getMappedInputDistance(index), 3);
                String inputText = "";

                try {
                    if (dataInfo != null) {
                        inputText = URLDecoder.decode(dataInfo.getDataDisplayName(inputName), "UTF-8");
                    } else {
                        inputText = URLDecoder.decode(inputName, "UTF-8");
                    }
                } catch (Exception e) {
                    inputText = inputName;
                }
                star.addAttribute("id", inputName.replaceFirst(commonVectorLabelPrefix, ""));
                star.addAttribute("type", "data");
                star.setPickable(true);
                if (dataInfo != null) {
                    try {
                        star.addAttribute("tooltip", inputText + "\ndistance: " + inputDistance + "\n"
                                + URLDecoder.decode(dataInfo.getDataLocation(inputName), "UTF-8"));
                    } catch (Exception e) {
                        Logger.getLogger("at.tuwien.ifs.somtoolbox").warning(
                                "URLDecoder had problems reading the name of the datum '" + inputName + "'.");
                        star.addAttribute("tooltip", inputText + "\ndistance: " + inputDistance);
                    }
                    star.addAttribute("location", dataInfo.getBaseDir() + dataInfo.getDataLocation(inputName));
                } else {
                    star.addAttribute("tooltip", inputText + "\ndistance: " + inputDistance);
                    star.addAttribute("location", inputName);
                }
                star.setOffset(this.X + locations[variant][index].getX(),
                        this.Y + locations[variant][index].getY());
                dataNodes[index] = star;
            }
            return dataNodes;
        } else {
            return new PNode[0];
        }
    } else {
        PNode[] dataNodes = new PNode[nodesToDisplay];
        if (detailLevel == DETAIL_LEVEL_HIGH) {
            Font font = new Font("Sans", Font.PLAIN, fontSize);
            final int numDataCol = 3;
            double xDataOffsets[] = new double[numDataCol];
            for (int i = 0; i < numDataCol; i++) {
                xDataOffsets[i] = i * width / numDataCol + 2;
            }
            double yOffset = yInOffset + dataCountDetail[detailLevel].getBoundsReference().getHeight() + 2;
            int numData = Math.min(dataNodes.length, u.getNumberOfMappedInputs()); // limitation by number of labels
            // in unit description file
            int x = 0;
            for (int index = 0; index < numData; index++) {
                PText pText = null;
                final String inputName = u.getMappedInputNames()[index];
                String inputText = null;
                try {
                    if (dataInfo != null) {
                        inputText = URLDecoder.decode(dataInfo.getDataDisplayName(inputName), "UTF-8");
                    } else {
                        inputText = URLDecoder.decode(inputName, "UTF-8");
                    }
                } catch (Exception e) {
                    Logger.getLogger("at.tuwien.ifs.somtoolbox").warning(
                            "URLDecoder had problems reading the name of the datum '" + inputName + "'.");
                    inputText = inputName;
                }
                pText = new PText(inputText.replaceFirst(commonVectorLabelPrefix, ""));

                pText.addAttribute("id", inputName);
                pText.addAttribute("type", "data");
                pText.setFont(font);
                pText.setTextPaint(Color.BLUE);
                pText.setOffset(this.X + xDataOffsets[x], this.Y + yOffset);
                if (dataInfo != null) {
                    try {
                        pText.addAttribute("tooltip",
                                inputText + "\ndistance: "
                                        + StringUtils.format(u.getMappedInputDistances()[index], 3) + "\n"
                                        + URLDecoder.decode(dataInfo.getDataLocation(inputName), "UTF-8"));
                    } catch (Exception e) {
                        Logger.getLogger("at.tuwien.ifs.somtoolbox").warning(
                                "URLDecoder had problems reading the name of the datum '" + inputName + "'.");
                        pText.addAttribute("tooltip", pText.getText() + "\ndistance: "
                                + StringUtils.format(u.getMappedInputDistances()[index], 3));
                    }
                    pText.addAttribute("location", dataInfo.getBaseDir() + dataInfo.getDataLocation(inputName));
                } else {
                    pText.addAttribute("tooltip", inputText + "\ndistance: "
                            + StringUtils.format(u.getMappedInputDistances()[index], 3));
                    pText.addAttribute("location", inputName);
                }
                dataNodes[index] = pText;
                if (pText.getBoundsReference().getWidth() > width / numDataCol) {
                    pText.setText(pText.getText().substring(0, Math.min(16, pText.getText().length())) + "...");
                }
                x++;
                if ((index + 1) % numDataCol == 0) { // next line
                    yOffset += font.getSize() + 2; // TODO: check qualityHighYOffset!!!!
                    x = 0;
                }
            }
            return dataNodes;
        }
    }
    return new PNode[0];
}

From source file:org.nuclos.client.ui.collect.Chart.java

static String fontToString(Font font) {
    String strStyle;/*from   w  w w  .j  av a 2 s.  co m*/

    if (font.isBold()) {
        strStyle = font.isItalic() ? "bolditalic" : "bold";
    } else {
        strStyle = font.isItalic() ? "italic" : "plain";
    }

    return font.getName() + "-" + strStyle + "-" + font.getSize();
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Get the font information from the configuration properties.
 * //  ww  w  .  ja v  a 2 s.co  m
 * @return A Font instance based on the configuration
 */
private Font getFontFromProperties() {
    Font newFont = null;
    final String fontName = properties.getProperty(ConfigurationProperty.FONT_NAME.key(), "Courier");
    final String fontSize = properties.getProperty(ConfigurationProperty.FONT_SIZE.key(), "12");
    final String fontStyle = properties.getProperty(ConfigurationProperty.FONT_STYLE.key(), "0");

    try {
        newFont = new Font(fontName, Integer.parseInt(fontStyle), Integer.parseInt(fontSize));
        if (newFont.getSize() < MINIMUM_FONT_SIZE) {
            throw new IllegalArgumentException("Font size too small: " + newFont.getSize());
        }
    } catch (Throwable throwable) {
        LOGGER.warn("Cannot setup font from properties (" + fontName + "," + fontSize + "," + fontStyle + ")",
                throwable);
    }

    return newFont;
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Present the user with a font selection dialog and update the widgets if
 * the user chooses a font./*from   w  ww . j  a va 2s  . c o m*/
 */
private void configureFont() {
    FontChooser chooser;
    Font newFont;
    Color newColor;

    chooser = new FontChooser(this);
    chooser.setFont(getFontFromProperties());
    chooser.setColor(getColorFromProperties());

    LOGGER.debug("Font before choices: " + chooser.getNewFont());

    chooser.setVisible(true);

    newFont = chooser.getNewFont();
    newColor = chooser.getNewColor();

    // Values will be null if user canceled request
    if (newFont != null && newColor != null) {
        properties.setProperty(ConfigurationProperty.FONT_NAME.key(), newFont.getName());
        properties.setProperty(ConfigurationProperty.FONT_SIZE.key(), newFont.getSize() + "");
        properties.setProperty(ConfigurationProperty.FONT_STYLE.key(), newFont.getStyle() + "");

        properties.setProperty(ConfigurationProperty.FONT_COLOR.key(), newColor.getRGB() + "");

        LOGGER.debug("Font after choices: " + newFont);
        setFont(newFont, newColor);
    }
}