Example usage for javax.swing.plaf FontUIResource getStyle

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

Introduction

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

Prototype

public int getStyle() 

Source Link

Document

Returns the style of this Font .

Usage

From source file:ru.apertum.qsystem.client.forms.FAdmin.java

/**
     * @param args the command line arguments
     * @throws Exception/* w  ww.j  a v a2  s . c om*/
     */
    public static void main(String args[]) throws Exception {
        QLog.initial(args, 3);
        Locale.setDefault(Locales.getInstance().getLangCurrent());

        //?  ? , ? 
        final Thread tPager = new Thread(() -> {
            FAbout.loadVersionSt();
            String result = "";
            try {
                final URL url = new URL(PAGER_URL + "/qskyapi/getpagerdata?qsysver=" + FAbout.VERSION_);
                final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestProperty("User-Agent", "Java bot");
                conn.connect();
                final int code = conn.getResponseCode();
                if (code == 200) {
                    try (BufferedReader in = new BufferedReader(
                            new InputStreamReader(conn.getInputStream(), "utf8"))) {
                        String inputLine;
                        while ((inputLine = in.readLine()) != null) {
                            result += inputLine;
                        }
                    }
                }
                conn.disconnect();
            } catch (Exception e) {
                System.err.println("Pager not enabled. " + e);
                return;
            }
            final Gson gson = GsonPool.getInstance().borrowGson();
            try {
                final Answer answer = gson.fromJson(result, Answer.class);
                forPager = answer;
                if (answer.getData().size() > 0) {
                    forPager.start();
                }
            } catch (Exception e) {
                System.err.println("Pager not enabled but working. " + e);
            } finally {
                GsonPool.getInstance().returnGson(gson);
            }
        });
        tPager.setDaemon(true);
        tPager.start();

        Uses.startSplash();
        //     plugins
        Uses.loadPlugins("./plugins/");
        //      ?.
        FLogin.logining(QUserList.getInstance(), null, true, 3, FLogin.LEVEL_ADMIN);
        Uses.showSplash();
        java.awt.EventQueue.invokeLater(() -> {
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
                        .getInstalledLookAndFeels()) {
                    System.out.println(info.getName());
                    /*Metal Nimbus CDE/Motif Windows   Windows Classic  //GTK+*/
                    if ("Windows".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
                if ("/".equals(File.separator)) {
                    final FontUIResource f = new FontUIResource(new Font("Serif", Font.PLAIN, 10));
                    final Enumeration<Object> keys = UIManager.getDefaults().keys();
                    while (keys.hasMoreElements()) {
                        final Object key = keys.nextElement();
                        final Object value = UIManager.get(key);
                        if (value instanceof FontUIResource) {
                            final FontUIResource orig = (FontUIResource) value;
                            final Font font1 = new Font(f.getFontName(), orig.getStyle(), f.getSize());
                            UIManager.put(key, new FontUIResource(font1));
                        }
                    }
                }
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                    | UnsupportedLookAndFeelException ex) {
            }
            try {
                form = new FAdmin();
                if (forPager != null) {
                    forPager.showData(false);
                } else {
                    form.panelPager.setVisible(false);
                }
                form.setVisible(true);
            } catch (Exception ex) {
                QLog.l().logger().error(" ? ??  . ", ex);
            } finally {
                Uses.closeSplash();
            }
        });
    }

From source file:Main.java

public static void setLookAndFeel(int fontSize) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration<Object> keys = defaults.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();

        if ((key instanceof String) && (((String) key).endsWith(".font"))) {
            FontUIResource font = (FontUIResource) UIManager.get(key);
            defaults.put(key, new FontUIResource(font.getFontName(), font.getStyle(), fontSize));
        }//from w w  w .  ja v  a  2 s. c  om
    }
}

From source file:Main.java

/**
 * Code from http://stackoverflow.com/questions/1236231/managing-swing-ui-default-font-sizes-without-quaqua
 * @param fontSize/*from  www . j a  v a 2  s.  c o  m*/
 */
public static void changeDefaultFontSize(int fontSize) {
    UIDefaults defaults = UIManager.getDefaults();
    // UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    Enumeration<Object> keys = defaults.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if ((key instanceof String) && (((String) key).endsWith(".font"))) {
            FontUIResource font = (FontUIResource) UIManager.get(key);
            defaults.put(key, new FontUIResource(font.getFontName(), font.getStyle(), fontSize));
        }
    }
}

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

private void setLookAndFeel() {
    try {/*from  w  w w . ja  va2 s . c om*/
        String lookFeel;
        String systemLookFeel = UIManager.getSystemLookAndFeelClassName();

        if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
            // FIXME: Problems with OpenJDK and GTK L&F
            // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
            if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
                // Metal L&F
                lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
                LOGGER.warn(
                        "There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
            } else {
                lookFeel = systemLookFeel;
            }
        } else {
            lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
        }

        // FIXME: Open JDK problem
        if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
                && !System.getProperty("java.runtime.name").contains("OpenJDK")) {
            // try to avoid ending up with the ugly Metal L&F
            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(systemLookFeel);
                // also set system l&f as default
                Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
                // notify the user
                JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(),
                        Localization.lang(
                                "Unable to find the requested look and feel and thus the default one is used."),
                        Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
                LOGGER.warn("Unable to find requested look and feel", e);
            }
        }
    } 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();
        for (Object key : Collections.list(keys)) {
            if ((key instanceof String) && ((String) key).endsWith(".font")) {
                FontUIResource font = (FontUIResource) UIManager.get(key);
                font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
                defaults.put(key, font);
            }
        }
    }
}

From source file:com.floreantpos.main.SetUpWindow.java

private void initializeFont() {
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);

        if (value != null && value instanceof FontUIResource) {
            FontUIResource f = (FontUIResource) value;
            String fontName = f.getFontName();

            Font font = new Font(fontName, f.getStyle(), PosUIManager.getDefaultFontSize());
            UIManager.put(key, new FontUIResource(font));
        }/*from  ww  w  .  j  a  va 2s . c o m*/
    }
}

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

private void setLookAndFeel() {
    try {/*from  www.j  a v a2 s . c  o m*/
        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:edu.ku.brc.ui.UIRegistry.java

/**
 * Creates the initial font mapping from the base font size to the other sizes.
 * @param clazz the class of the component
 * @param baseFontArg the base font size
 *//*from  w w w  .  j av  a2s .  c  o  m*/
protected static void adjustAllFonts(final Font oldBaseFont, final Font baseFontArg) {
    if (oldBaseFont != null && baseFontArg != null) {
        int fontSize = baseFontArg.getSize();
        int oldFontSize = oldBaseFont.getSize();
        String family = baseFontArg.getFamily();

        UIDefaults uiDefaults = UIManager.getDefaults();
        Enumeration<Object> e = uiDefaults.keys();
        while (e.hasMoreElements()) {
            Object key = e.nextElement();
            if (key.toString().endsWith(".font")) {
                FontUIResource fontUIRes = (FontUIResource) uiDefaults.get(key);
                if (fontSize != fontUIRes.getSize() || !family.equals(fontUIRes.getFamily())) {
                    UIManager.put(key, new FontUIResource(new Font(family, fontUIRes.getStyle(),
                            fontSize + (fontUIRes.getSize() - oldFontSize))));
                }
            }
        }
    }
}