Search in sources :

Example 26 with FontUIResource

use of javax.swing.plaf.FontUIResource in project tigervnc by TigerVNC.

the class VncViewer method setLookAndFeel.

public static void setLookAndFeel() {
    try {
        if (os.startsWith("mac os x")) {
            Class appClass = Class.forName("com.apple.eawt.Application");
            Method getApplication = appClass.getMethod("getApplication", (Class[]) null);
            Object app = getApplication.invoke(appClass);
            Class[] paramTypes = new Class[1];
            paramTypes[0] = Image.class;
            Method setDockIconImage = appClass.getMethod("setDockIconImage", paramTypes);
            setDockIconImage.invoke(app, VncViewer.logoImage);
        }
        // Use Nimbus LookAndFeel if it's available, otherwise fallback
        // to the native laf, or Metal if no native laf is available.
        String laf = System.getProperty("swing.defaultlaf");
        if (laf == null) {
            LookAndFeelInfo[] installedLafs = UIManager.getInstalledLookAndFeels();
            for (int i = 0; i < installedLafs.length; i++) {
                if (installedLafs[i].getName().equals("Nimbus"))
                    laf = installedLafs[i].getClassName();
            }
            if (laf == null)
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        UIManager.setLookAndFeel(laf);
        if (UIManager.getLookAndFeel().getName().equals("Metal")) {
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            Enumeration<Object> keys = UIManager.getDefaults().keys();
            while (keys.hasMoreElements()) {
                Object key = keys.nextElement();
                Object value = UIManager.get(key);
                if (value instanceof FontUIResource) {
                    String name = ((FontUIResource) value).getName();
                    int style = ((FontUIResource) value).getStyle();
                    int size = ((FontUIResource) value).getSize() - 1;
                    FontUIResource f = new FontUIResource(name, style, size);
                    UIManager.put(key, f);
                }
            }
        } else if (UIManager.getLookAndFeel().getName().equals("Nimbus")) {
            Font f = UIManager.getFont("TitledBorder.font");
            String name = f.getName();
            int style = f.getStyle();
            int size = f.getSize() - 2;
            FontUIResource r = new FontUIResource(name, style, size);
            UIManager.put("TitledBorder.font", r);
        }
    } catch (java.lang.Exception e) {
        vlog.info(e.toString());
    }
}
Also used : FontUIResource(javax.swing.plaf.FontUIResource)

Aggregations

FontUIResource (javax.swing.plaf.FontUIResource)26 Font (java.awt.Font)5 UIDefaults (javax.swing.UIDefaults)5 ColorUIResource (javax.swing.plaf.ColorUIResource)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 JFrame (javax.swing.JFrame)2 UISettings (com.intellij.ide.ui.UISettings)1 FontDescriptor (com.intellij.uiDesigner.lw.FontDescriptor)1 Plastic3DLookAndFeel (com.jgoodies.looks.plastic.Plastic3DLookAndFeel)1 SkyBluer (com.jgoodies.looks.plastic.theme.SkyBluer)1 Dimension (java.awt.Dimension)1 Image (java.awt.Image)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1