Example usage for javax.swing.plaf FontUIResource FontUIResource

List of usage examples for javax.swing.plaf FontUIResource FontUIResource

Introduction

In this page you can find the example usage for javax.swing.plaf FontUIResource FontUIResource.

Prototype

public FontUIResource(String name, int style, int size) 

Source Link

Document

Constructs a FontUIResource .

Usage

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Changes the font size to what the user selects (between 8-30)
 *///  w  ww .  j a  v a2s.  co m
private void changeFontSize() {
    Integer[] nums = new Integer[23];
    for (int i = 8; i <= 30; i++) {
        nums[i - 8] = i;
    }
    try {
        int size = (int) JOptionPane.showInputDialog(this, "Choose a font size:", "Font Size",
                JOptionPane.PLAIN_MESSAGE, null, nums, Main.getState().getSettings().getFontSize());
        FontUIResource font = new FontUIResource("Dialog", Font.BOLD, size);

        Main.setUIFont(font);
        Main.getState().getSettings().setFontSize(size);
        SwingUtilities.updateComponentTreeUI(gr);

        for (JInternalFrame i : desktop.getAllFrames())
            i.pack();

    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:net.sf.jabref.JabRef.java

private void setLookAndFeel() {
    try {//from www  . j  av a 2s  .c om
        String lookFeel;
        String systemLnF = UIManager.getSystemLookAndFeelClassName();

        if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
            // Use system Look & Feel by default
            lookFeel = systemLnF;
        } else {
            lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
        }

        // At all cost, avoid ending up with the Metal look and feel:
        if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(lookFeel)) {
            Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel();
            Plastic3DLookAndFeel.setCurrentTheme(new SkyBluer());
            com.jgoodies.looks.Options.setPopupDropShadowEnabled(true);
            UIManager.setLookAndFeel(lnf);
        } else {
            try {
                UIManager.setLookAndFeel(lookFeel);
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                    | UnsupportedLookAndFeelException e) {
                // specified look and feel does not exist on the classpath, so use system l&f
                UIManager.setLookAndFeel(systemLnF);
                // also set system l&f as default
                Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLnF);
                // notify the user
                JOptionPane.showMessageDialog(JabRef.jrf,
                        Localization.lang(
                                "Unable to find the requested Look & Feel and thus the default one is used."),
                        Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Look and feel could not be set", e);
    }

    // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
    boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS);
    if (overrideDefaultFonts) {
        int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
        UIDefaults defaults = UIManager.getDefaults();
        Enumeration<Object> keys = defaults.keys();
        Double zoomLevel = null;
        for (Object key : Collections.list(keys)) {
            if ((key instanceof String) && ((String) key).endsWith(".font")) {
                FontUIResource font = (FontUIResource) UIManager.get(key);
                if (zoomLevel == null) {
                    // zoomLevel not yet set, calculate it based on the first found font
                    zoomLevel = (double) fontSize / (double) font.getSize();
                }
                font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
                defaults.put(key, font);
            }
        }
        if (zoomLevel != null) {
            GUIGlobals.zoomLevel = zoomLevel;
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * tries the native look and feel on mac and windows and metal on unix (gtk still
 * isn't looking that nice, even in 1.6)
 *///w w w.  j  a v  a  2 s .  com
private void setupLookAndFeel() {
    try {
        String plaf = "Mac,Windows,Metal";
        if (System.getProperty("os.name").startsWith("Linux")) {
            plaf = "GTK,Mac,Windows,Metal";
        }

        // this line needs to be implemented in order to make L&F work properly
        UIManager.getLookAndFeelDefaults().put("ClassLoader", getClass().getClassLoader());

        // query list of L&Fs
        UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();

        if (!Strings.isNullOrEmpty(plaf)) {

            String[] instPlafs = plaf.split(",");
            UIManager.LookAndFeelInfo currentLAFI = null;
            search: for (final String instPlaf : instPlafs) {
                for (final UIManager.LookAndFeelInfo plaf1 : plafs) {
                    currentLAFI = plaf1;
                    if (currentLAFI.getName().startsWith(instPlaf)) {
                        UIManager.setLookAndFeel(currentLAFI.getClassName());
                        // setup SANS_SERIF
                        setUIFont(new FontUIResource("SansSerif", Font.PLAIN, Const.FONT_SIZE));
                        break search;
                    }
                }
            }
        }

        if (plaf.startsWith("GTK")) {
            setFontSizeModifier(2);
        }
    } catch (Exception except) {
        setUIFont(new FontUIResource("SansSerif", Font.PLAIN, 12));
    }
}

From source file:org.roche.antibody.services.graphsynchronizer.GraphSynchronizer.java

/**
 * Validates in order to decide, if we can sync our model back or not!
 * //from w  w  w  .  ja  va2s.co m
 * @param code
 * @return JOptionPane.YES_NO_CANCEL_OPTION
 */
private int validate(HELMCode code) {
    int blockersInCode = 0;
    boolean activeDomainDetected = false;
    boolean activeDomainChanged = false;

    String domainChangesMsg = "";

    for (HELMElement elem : code.getAllElements()) {
        if (blocksToRemove.contains(elem.getSequenceRepresentation())) {
            blockersInCode++;
        }
        if (elem instanceof HELMPeptide) {
            HELMPeptide pep = (HELMPeptide) elem;
            if (pep.getSimpleSequence().startsWith(activeDomain.getSequence())
                    || pep.getSimpleSequence().endsWith(activeDomain.getSequence())) {
                activeDomainDetected = true;
            } else {
                domainChangesMsg = checkForSequenceChanges(activeDomain.getSequence(), pep.getSimpleSequence());
                activeDomainChanged = true;
            }
        }
    }
    if (blockersInCode != blockerCount) {
        JOptionPane.showMessageDialog(me.getFrame(), "Blockers were mainpulated! Model cannot be sync back!",
                "Sync Error", JOptionPane.ERROR_MESSAGE);
        return JOptionPane.CANCEL_OPTION;

    } else if (!activeDomainDetected && activeDomainChanged) {
        FontUIResource defaultFont = (FontUIResource) UIManager.get("OptionPane.messageFont");
        UIManager.put("OptionPane.messageFont", new FontUIResource("Courier New", FontUIResource.PLAIN, 13));
        int isConfirmed = JOptionPane.showConfirmDialog(me.getFrame(), domainChangesMsg, "Sequence has changed",
                JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        UIManager.put("OptionPane.messageFont", defaultFont);

        return isConfirmed;

    }
    return JOptionPane.YES_OPTION;
}

From source file:storybook.SbApp.java

public void resetUiFont() {
    if (defaultFont == null) {
        return;//from  w w w . j a  va 2s .  c  o  m
    }
    SwingUtil.setUIFont(
            new FontUIResource(defaultFont.getName(), defaultFont.getStyle(), defaultFont.getSize()));
}