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(Font font) 

Source Link

Document

Constructs a FontUIResource .

Usage

From source file:Main.java

public static void setUIFont(Font f) {
    ////  w  w w  .  j av a2 s .co m
    // sets the default font for all Swing components.
    // ex. 
    //  setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
    //
    FontUIResource fur = new FontUIResource(f);
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof javax.swing.plaf.FontUIResource)
            UIManager.put(key, fur);
    }
}

From source file:jshm.gui.GuiUtil.java

/**
 * This sets the default L&F as well as sets some icons
 */// w  w w  . j  av a 2  s. c  om
public static void init() {
    try {
        // Set the Look & Feel to match the current system
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
    }

    // http://www.java2s.com/Tutorial/Java/0240__Swing/CustomizingaJOptionPaneLookandFeel.htm
    UIManager.put("OptionPane.errorIcon",
            new ImageIcon(GuiUtil.class.getResource("/jshm/resources/images/toolbar/delete.png")));
    UIManager.put("OptionPane.informationIcon",
            new ImageIcon(GuiUtil.class.getResource("/jshm/resources/images/toolbar/infoabout.png")));
    UIManager.put("OptionPane.questionIcon",
            new ImageIcon(GuiUtil.class.getResource("/jshm/resources/images/toolbar/help.png")));
    UIManager.put("OptionPane.warningIcon",
            new ImageIcon(GuiUtil.class.getResource("/jshm/resources/images/toolbar/pause.png")));
    UIManager.put("OptionPane.yesIcon",
            new ImageIcon(GuiUtil.class.getResource("/jshm/resources/images/toolbar/accept32.png")));
    UIManager.put("OptionPane.noIcon",
            new ImageIcon(GuiUtil.class.getResource("/jshm/resources/images/toolbar/delete32.png")));

    float scale = Config.getFloat("font.scale");

    if (1f != scale) {
        LOG.finest("setting ui font scale to + " + scale);

        Enumeration<Object> keys = UIManager.getDefaults().keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);

            if (value instanceof FontUIResource) {
                FontUIResource f = (FontUIResource) value;
                f = new FontUIResource(f.deriveFont(scale * f.getSize2D()));
                UIManager.put(key, f);
            }
        }
    }

    // hook into the wizard displayer
    System.setProperty("WizardDisplayer.default", "jshm.gui.wizards.displayer.WizardDisplayerImpl");
}

From source file:NwFontChooserS.java

static public void setDefaultFont(Font f) {
    FontUIResource fui = new FontUIResource(f);
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource)
            UIManager.put(key, fui);
    }/*from w  w w.  j av  a2  s  .  com*/

}

From source file:edu.ku.brc.ui.skin.SkinItem.java

/**
 * //from w w  w  . ja  va  2  s  .  com
 */
public void register() {
    if (getFont() != null) {
        UIManager.put(name + '.' + "font", new FontUIResource(font));
    }
    if (bgColor != null) {
        UIManager.put(name + '.' + "bgcolor", new ColorUIResource(bgColor));
    }
    if (fgColor != null) {
        UIManager.put(name + '.' + "fgcolor", new ColorUIResource(fgColor));
    }
    if (getBGImage() != null) {
        UIManager.put(name + '.' + "bgimage", bgImage);
    }
}

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  w ww  . j  ava2s .  c  o m*/
    }
}

From source file:au.org.ala.delta.editor.DeltaEditor.java

private void updateFont(Font newFont) {
    FontUIResource fontResource = new FontUIResource(newFont);
    Enumeration<Object> keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object value = UIManager.get(key);
        if (value instanceof FontUIResource) {
            UIManager.put(key, fontResource);
        }//from ww  w  .  ja v  a 2  s. c  om
    }
}

From source file:com.t3.client.TabletopTool.java

public static void main(String[] args) {
    if (MAC_OS_X) {
        // On OSX the menu bar at the top of the screen can be enabled at any time, but the
        // title (ie. name of the application) has to be set before the GUI is initialized (by
        // creating a frame, loading a splash screen, etc).  So we do it here.
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "About TabletopTool...");
        System.setProperty("apple.awt.brushMetalLook", "true");
    }/* w ww . j  a v a  2 s. c o m*/
    // Before anything else, create a place to store all the data
    try {
        AppUtil.getAppHome();
    } catch (Throwable t) {
        t.printStackTrace();

        // Create an empty frame so there's something to click on if the dialog goes in the background
        JFrame frame = new JFrame();
        SwingUtil.centerOnScreen(frame);
        frame.setVisible(true);

        String errorCreatingDir = "Error creating data directory";
        log.error(errorCreatingDir, t);
        JOptionPane.showMessageDialog(frame, t.getMessage(), errorCreatingDir, JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
    verifyJavaVersion();

    configureLogging();

    // System properties
    System.setProperty("swing.aatext", "true");
    // System.setProperty("sun.java2d.opengl", "true");

    final SplashScreen splash = new SplashScreen(SPLASH_IMAGE, getVersion());
    splash.showSplashScreen();

    // Protocol handlers
    // cp:// is registered by the RPTURLStreamHandlerFactory constructor (why?)
    RPTURLStreamHandlerFactory factory = new RPTURLStreamHandlerFactory();
    factory.registerProtocol("asset", new AssetURLStreamHandler());
    URL.setURLStreamHandlerFactory(factory);

    MacroEngine.initialize();
    configureJide(); //TODO find out how to not call this twice without destroying error windows

    final Toolkit tk = Toolkit.getDefaultToolkit();
    tk.getSystemEventQueue().push(new T3EventQueue());

    // LAF
    try {

        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        configureJide();
        if (WINDOWS)
            LookAndFeelFactory.installJideExtension(LookAndFeelFactory.XERTO_STYLE);
        else
            LookAndFeelFactory.installJideExtension();
        if (MAC_OS_X) {
            macOSXicon();
        }
        menuBar = new AppMenuBar();
    } catch (Exception e) {
        TabletopTool.showError("msg.error.lafSetup", e);
        System.exit(1);
    }

    /**
     * This is a tweak that makes the Chinese version work better.
     * <p>
     * Consider reviewing <a
     * href="http://en.wikipedia.org/wiki/CJK_characters"
     * >http://en.wikipedia.org/wiki/CJK_characters</a> before making
     * changes. And http://www.scarfboy.com/coding/unicode-tool is also a
     * really cool site.
     */
    if (Locale.CHINA.equals(Locale.getDefault())) {
        // The following font name appears to be "Sim Sun".  It can be downloaded
        // from here:  http://fr.cooltext.com/Fonts-Unicode-Chinese
        Font f = new Font("\u65B0\u5B8B\u4F53", Font.PLAIN, 12);
        FontUIResource fontRes = new FontUIResource(f);
        for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource)
                UIManager.put(key, fontRes);
        }
    }

    // Draw frame contents on resize
    tk.setDynamicLayout(true);

    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            initialize();
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    clientFrame.setVisible(true);
                    splash.hideSplashScreen();
                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            postInitialize();
                        }
                    });
                }
            });
        }
    });
    // new Thread(new HeapSpy()).start();
}

From source file:net.rptools.maptool.client.MapTool.java

public static void main(String[] args) {
    if (MAC_OS_X) {
        // On OSX the menu bar at the top of the screen can be enabled at any time, but the
        // title (ie. name of the application) has to be set before the GUI is initialized (by
        // creating a frame, loading a splash screen, etc).  So we do it here.
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "About MapTool...");
        System.setProperty("apple.awt.brushMetalLook", "true");
    }/*from  w  w w  . j a  va 2  s .  co  m*/
    // Before anything else, create a place to store all the data
    try {
        AppUtil.getAppHome();
    } catch (Throwable t) {
        t.printStackTrace();

        // Create an empty frame so there's something to click on if the dialog goes in the background
        JFrame frame = new JFrame();
        SwingUtil.centerOnScreen(frame);
        frame.setVisible(true);

        String errorCreatingDir = "Error creating data directory";
        log.error(errorCreatingDir, t);
        JOptionPane.showMessageDialog(frame, t.getMessage(), errorCreatingDir, JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
    verifyJavaVersion();

    configureLogging();

    // System properties
    System.setProperty("swing.aatext", "true");
    // System.setProperty("sun.java2d.opengl", "true");

    final SplashScreen splash = new SplashScreen(SPLASH_IMAGE, getVersion());
    splash.showSplashScreen();

    // Protocol handlers
    // cp:// is registered by the RPTURLStreamHandlerFactory constructor (why?)
    RPTURLStreamHandlerFactory factory = new RPTURLStreamHandlerFactory();
    factory.registerProtocol("asset", new AssetURLStreamHandler());
    URL.setURLStreamHandlerFactory(factory);

    final Toolkit tk = Toolkit.getDefaultToolkit();
    tk.getSystemEventQueue().push(new MapToolEventQueue());

    // LAF
    try {
        // If we are running under Mac OS X then save native menu bar look & feel components
        // Note the order of creation for the AppMenuBar, this specific chronology
        // allows the system to set up system defaults before we go and modify things.
        // That is, please don't move these lines around unless you test the result on windows and mac
        String lafname;
        if (MAC_OS_X) {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            menuBar = new AppMenuBar();
            lafname = "net.rptools.maptool.client.TinyLookAndFeelMac";
            UIManager.setLookAndFeel(lafname);
            macOSXicon();
        }
        // If running on Windows based OS, CJK font is broken when using TinyLAF.
        //         else if (WINDOWS) {
        //            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        //            menuBar = new AppMenuBar();
        //         }
        else {
            lafname = "de.muntjak.tinylookandfeel.TinyLookAndFeel";
            UIManager.setLookAndFeel(lafname);
            menuBar = new AppMenuBar();
        }
        // After the TinyLAF library is initialized, look to see if there is a Default.theme
        // in our AppHome directory and load it if there is.  Unfortunately, changing the
        // search path for the default theme requires subclassing TinyLAF and because
        // we have both the original and a Mac version that gets cumbersome.  (Really
        // the Mac version should use the default and then install the keystroke differences
        // but what we have works and I'm loathe to go playing with it at 1.3b87 -- yes, 87!)
        File f = AppUtil.getAppHome("config");
        if (f.exists()) {
            File f2 = new File(f, "Default.theme");
            if (f2.exists()) {
                if (Theme.loadTheme(f2)) {
                    // re-install the Tiny Look and Feel
                    UIManager.setLookAndFeel(lafname);

                    // Update the ComponentUIs for all Components. This
                    // needs to be invoked for all windows.
                    //SwingUtilities.updateComponentTreeUI(rootComponent);
                }
            }
        }

        com.jidesoft.utils.Lm.verifyLicense("Trevor Croft", "rptools", "5MfIVe:WXJBDrToeLWPhMv3kI2s3VFo");
        LookAndFeelFactory.addUIDefaultsCustomizer(new LookAndFeelFactory.UIDefaultsCustomizer() {
            public void customize(UIDefaults defaults) {
                // Remove red border around menus
                defaults.put("PopupMenu.foreground", Color.lightGray);
            }
        });
        LookAndFeelFactory.installJideExtension(LookAndFeelFactory.XERTO_STYLE);

        /****************************************************************************
         * For TinyLAF 1.3.04 this is how the color was changed for a
         * button.
         */
        // Theme.buttonPressedColor[Theme.style] = new ColorReference(Color.gray);

        /****************************************************************************
         * And this is how it's done in TinyLAF 1.4.0 (no idea about the
         * intervening versions).
         */
        Theme.buttonPressedColor = new SBReference(Color.GRAY, 0, -6, SBReference.SUB3_COLOR);

        configureJide();
    } catch (Exception e) {
        MapTool.showError("msg.error.lafSetup", e);
        System.exit(1);
    }

    /**
     * This is a tweak that makes the Chinese version work better.
     * <p>
     * Consider reviewing <a
     * href="http://en.wikipedia.org/wiki/CJK_characters"
     * >http://en.wikipedia.org/wiki/CJK_characters</a> before making
     * changes. And http://www.scarfboy.com/coding/unicode-tool is also a
     * really cool site.
     */
    if (Locale.CHINA.equals(Locale.getDefault())) {
        // The following font name appears to be "Sim Sun".  It can be downloaded
        // from here:  http://fr.cooltext.com/Fonts-Unicode-Chinese
        Font f = new Font("\u65B0\u5B8B\u4F53", Font.PLAIN, 12);
        FontUIResource fontRes = new FontUIResource(f);
        for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource)
                UIManager.put(key, fontRes);
        }
    }

    // Draw frame contents on resize
    tk.setDynamicLayout(true);

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            initialize();
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    clientFrame.setVisible(true);
                    splash.hideSplashScreen();
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            postInitialize();
                        }
                    });
                }
            });
        }
    });
    // new Thread(new HeapSpy()).start();
}

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
 *//*w  w  w . ja v  a  2  s.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))));
                }
            }
        }
    }
}

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

/**
     * @param args the command line arguments
     * @throws Exception//from   ww  w.  j  a v a2s  . c o  m
     */
    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();
            }
        });
    }