Example usage for javax.swing UIDefaults put

List of usage examples for javax.swing UIDefaults put

Introduction

In this page you can find the example usage for javax.swing UIDefaults put.

Prototype

public Object put(Object key, Object value) 

Source Link

Document

Sets the value of key to value for all locales.

Usage

From source file:hermes.browser.HermesBrowser.java

private void initJIDE() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException,
        IllegalAccessException {//from  w ww  .ja  v a2 s .c  om
    try {
        LookAndFeelFactory.installJideExtension();
    } catch (IllegalArgumentException e) {
        log.error("l&f incompatible with JIDE, trying metal: " + e.getMessage(), e);

        UIManager.setLookAndFeel(new MetalLookAndFeel());
        LookAndFeelFactory.installJideExtension();
    }

    ObjectConverterManager.initDefaultConverter();
    CellEditorManager.initDefaultEditor();
    CellRendererManager.initDefaultRenderer();
    ObjectComparatorManager.initDefaultComparator();

    LookAndFeelFactory.UIDefaultsCustomizer uiDefaultsCustomizer = new LookAndFeelFactory.UIDefaultsCustomizer() {
        public void customize(UIDefaults defaults) {
            Map painter = (Map) defaults.get("Theme.painter");
            // ThemePainter painter = (ThemePainter)
            // defaults.get("Theme.painter");

            defaults.put("OptionPaneUI", "com.jidesoft.plaf.basic.BasicJideOptionPaneUI");
            defaults.put("OptionPane.showBanner", Boolean.FALSE); // show
            // banner
            // or
            // not.
            // default
            // is
            // true

            defaults.put("OptionPane.bannerBackgroundDk", painter.get("OptionPane.bannerBackgroundDk"));
            defaults.put("OptionPane.bannerBackgroundLt", painter.get("OptionPane.bannerBackgroundLt"));

            defaults.put("OptionPane.bannerBackgroundDirection", Boolean.TRUE); // default
            // is
            // true

            // optionally, you can set a Paint object for BannerPanel. If
            // so, the three UIDefaults related to banner background above
            // will be ignored.
            defaults.put("OptionPane.bannerBackgroundPaint", null);

            defaults.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder(6, 6, 6, 6));
            defaults.put("OptionPane.buttonOrientation", new Integer(SwingConstants.RIGHT));
        }
    };
    uiDefaultsCustomizer.customize(UIManager.getDefaults());

}

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

private void setLookAndFeel() {
    try {// w  ww . j  av  a  2  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:org.pgptool.gui.ui.tools.UiUtils.java

public static void setLookAndFeel() {
    // NOTE: We doing it this way to prevent dead=locks that is sometimes
    // happens if do it in main thread
    Edt.invokeOnEdtAndWait(new Runnable() {
        @Override/*from   w ww  . j a  v  a2  s.  c  o  m*/
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                fixCheckBoxMenuItemForeground();
                fixFontSize();
            } catch (Throwable t) {
                log.error("Failed to set L&F", t);
            }
        }

        /**
         * In some cases (depends on OS theme) check menu item foreground is same as
         * bacground - thus it;'s invisible when cheked
         */
        private void fixCheckBoxMenuItemForeground() {
            UIDefaults defaults = UIManager.getDefaults();
            Color selectionForeground = defaults.getColor("CheckBoxMenuItem.selectionForeground");
            Color foreground = defaults.getColor("CheckBoxMenuItem.foreground");
            Color background = defaults.getColor("CheckBoxMenuItem.background");
            if (colorsDiffPercentage(selectionForeground, background) < 10) {
                // TODO: That doesn't actually affect defaults. Need to find out how to fix it
                defaults.put("CheckBoxMenuItem.selectionForeground", foreground);
            }
        }

        private int colorsDiffPercentage(Color c1, Color c2) {
            int diffRed = Math.abs(c1.getRed() - c2.getRed());
            int diffGreen = Math.abs(c1.getGreen() - c2.getGreen());
            int diffBlue = Math.abs(c1.getBlue() - c2.getBlue());

            float pctDiffRed = (float) diffRed / 255;
            float pctDiffGreen = (float) diffGreen / 255;
            float pctDiffBlue = (float) diffBlue / 255;

            return (int) ((pctDiffRed + pctDiffGreen + pctDiffBlue) / 3 * 100);
        }

        private void fixFontSize() {
            if (isJreHandlesScaling()) {
                log.info("JRE handles font scaling, won't change it");
                return;
            }
            log.info("JRE doesnt't seem to support font scaling");

            Toolkit toolkit = Toolkit.getDefaultToolkit();
            int dpi = toolkit.getScreenResolution();
            if (dpi == 96) {
                if (log.isDebugEnabled()) {
                    Font font = UIManager.getDefaults().getFont("TextField.font");
                    String current = font != null ? Integer.toString(font.getSize()) : "unknown";
                    log.debug(
                            "Screen dpi seem to be 96. Not going to change font size. Btw current size seem to be "
                                    + current);
                }
                return;
            }
            int targetFontSize = 12 * dpi / 96;
            log.debug("Screen dpi = " + dpi + ", decided to change font size to " + targetFontSize);
            setDefaultSize(targetFontSize);
        }

        private boolean isJreHandlesScaling() {
            try {
                JreVersion noNeedToScaleForVer = JreVersion.parseString("9");
                String jreVersionStr = System.getProperty("java.version");
                if (jreVersionStr != null) {
                    JreVersion curVersion = JreVersion.parseString(jreVersionStr);
                    if (noNeedToScaleForVer.compareTo(curVersion) <= 0) {
                        return true;
                    }
                }

                return false;
            } catch (Throwable t) {
                log.warn("Failed to see oif JRE can handle font scaling. Will assume it does. JRE version: "
                        + System.getProperty("java.version"), t);
                return true;
            }
        }

        public void setDefaultSize(int size) {
            Set<Object> keySet = UIManager.getLookAndFeelDefaults().keySet();
            Object[] keys = keySet.toArray(new Object[keySet.size()]);
            for (Object key : keys) {
                if (key != null && key.toString().toLowerCase().contains("font")) {
                    Font font = UIManager.getDefaults().getFont(key);
                    if (font != null) {
                        Font changedFont = font.deriveFont((float) size);
                        UIManager.put(key, changedFont);
                        Font doubleCheck = UIManager.getDefaults().getFont(key);
                        log.debug("Font size changed for " + key + ". From " + font.getSize() + " to "
                                + doubleCheck.getSize());
                    }
                }
            }
        }
    });
    log.info("L&F set");
}

From source file:org.tellervo.desktop.prefs.Prefs.java

private void installUIDefault(Class<? extends Object> type, String prefskey, String uikey) {
    Object decoded = null;/*from w  w w  .  ja  v  a  2  s .c  om*/
    String pref = prefs.getProperty(prefskey);
    if (pref == null) {
        log.warn("Preference '" + prefskey + "' held null value.");
        return;
    }
    if (Color.class.isAssignableFrom(type)) {
        decoded = Color.decode(pref);
    } else if (Font.class.isAssignableFrom(type)) {
        decoded = Font.decode(pref);
    } else {
        log.warn("Unsupported UIDefault preference type: " + type);
        return;
    }

    if (decoded == null) {
        log.warn("UIDefaults color preference '" + prefskey + "' was not decodable.");
        return;
    }

    UIDefaults uidefaults = UIManager.getDefaults();
    // if (uidefaults.contains(property)) {
    // NOTE: ok, UIDefaults object is strange. Not only does
    // it not implement the Map interface correctly, but entries
    // will not "stick". The entries must be first explicitly
    // removed, and then re-added - aaron
    log.debug("Removing UIDefaults key before overwriting: " + uikey);
    uidefaults.remove(uikey);
    // }

    if (Color.class.isAssignableFrom(type)) {
        uidefaults.put(uikey, new ColorUIResource((Color) decoded));
    } else {
        uidefaults.put(uikey, new FontUIResource((Font) decoded));
    }
}

From source file:org.trianacode.gui.hci.ApplicationFrame.java

/**
 * Initialise the application/*from ww  w . j  a  va 2s .  c o m*/
 */
public static ApplicationFrame initTriana(String args[]) {
    // todo: this is crap, use andrew's UI stuff
    // Andrew Sept 2010: Done - 6 years on... :-)
    UIDefaults uiDefaults = UIManager.getDefaults();
    Object font = ((FontUIResource) uiDefaults.get("TextArea.font")).deriveFont((float) 11);

    Enumeration enumeration = uiDefaults.keys();
    while (enumeration.hasMoreElements()) {
        Object key = enumeration.nextElement();

        if (key.toString().endsWith("font")) {
            uiDefaults.put(key, font);
        }
    }

    String myOSName = Locations.os();
    if (myOSName.equals("windows")) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
    } else {
        if (!myOSName.equals("osx")) {
            try {
                MetalLookAndFeel.setCurrentTheme(new OceanTheme());
                UIManager.setLookAndFeel(new MetalLookAndFeel());
            } catch (Exception e) {
            }
        }

    }

    ApplicationFrame app = new ApplicationFrame("Triana");
    app.init(args);

    return app;
}

From source file:org.ut.biolab.medsavant.MedSavantClient.java

private static void setLAF() {
    try {//from  w w  w . j av  a  2s  .  c  o m

        if (ClientMiscUtils.MAC) {
            customizeForMac();
        }

        // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); //Metal works with sliders.
        //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); //GTK doesn't work with sliders.
        //UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); //Nimbus doesn't work with sliders.
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            LOG.debug("Installed LAF: " + info.getName() + " class: " + info.getClassName());
        }
        LOG.debug("System LAF is: " + UIManager.getSystemLookAndFeelClassName());
        LOG.debug("Cross platform LAF is: " + UIManager.getCrossPlatformLookAndFeelClassName());

        LookAndFeelFactory.addUIDefaultsInitializer(new LookAndFeelFactory.UIDefaultsInitializer() {
            public void initialize(UIDefaults defaults) {
                Map<String, Object> defaultValues = new HashMap<String, Object>();
                defaultValues.put("Slider.trackWidth", new Integer(7));
                defaultValues.put("Slider.majorTickLength", new Integer(6));
                defaultValues.put("Slider.highlight", new ColorUIResource(255, 255, 255));
                defaultValues.put("Slider.horizontalThumbIcon",
                        javax.swing.plaf.metal.MetalIconFactory.getHorizontalSliderThumbIcon());
                defaultValues.put("Slider.verticalThumbIcon",
                        javax.swing.plaf.metal.MetalIconFactory.getVerticalSliderThumbIcon());
                defaultValues.put("Slider.focusInsets", new InsetsUIResource(0, 0, 0, 0));

                for (Map.Entry<String, Object> e : defaultValues.entrySet()) {
                    if (defaults.get(e.getKey()) == null) {
                        LOG.debug("Missing key " + e.getKey() + ", using default value " + e.getValue());
                        defaults.put(e.getKey(), e.getValue());
                    } else {
                        LOG.debug("Found key " + e.getKey() + " with value " + defaults.get(e.getKey()));
                    }
                }
            }
        });

        if (MiscUtils.WINDOWS) {
            UIManager.put("CheckBox.background", new javax.swing.plaf.ColorUIResource(Color.WHITE));
            UIManager.put("Panel.background", new javax.swing.plaf.ColorUIResource(Color.WHITE));
            LookAndFeelFactory.installJideExtension(LookAndFeelFactory.XERTO_STYLE_WITHOUT_MENU);
            /*UIManager.put("JideTabbedPane.tabAreaBackground", new javax.swing.plaf.ColorUIResource(Color.WHITE));
            UIManager.put("JideTabbedPane.background", new javax.swing.plaf.ColorUIResource(Color.WHITE));
            UIManager.put("SidePane.background", new javax.swing.plaf.ColorUIResource(Color.WHITE));*/
        } else {
            LookAndFeelFactory.installJideExtension();
        }

        LookAndFeelFactory.installDefaultLookAndFeelAndExtension();

        System.setProperty("awt.useSystemAAFontSettings", "on");
        System.setProperty("swing.aatext", "true");

        UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));

        //tooltips
        UIManager.put("ToolTip.background", new ColorUIResource(255, 255, 255));
        ToolTipManager.sharedInstance().setDismissDelay(8000);
        ToolTipManager.sharedInstance().setInitialDelay(500);
    } catch (Exception x) {
        LOG.error("Unable to install look & feel.", x);
    }

}

From source file:savant.view.swing.Savant.java

/**
 * Customize the UI. This includes doing any platform-specific
 * customization.// w w  w  . j  a v a2  s.c  om
 */
private void customizeUI() {
    if (MiscUtils.MAC) {
        try {
            macOSXApplication = Application.getApplication();
            macOSXApplication.setAboutHandler(new AboutHandler() {
                @Override
                public void handleAbout(AppEvent.AboutEvent evt) {
                    final Splash dlg = new Splash(instance, true);
                    dlg.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent e) {
                            dlg.setVisible(false);
                        }
                    });
                    dlg.setVisible(true);
                }
            });
            macOSXApplication.setPreferencesHandler(new PreferencesHandler() {
                @Override
                public void handlePreferences(AppEvent.PreferencesEvent evt) {
                    preferencesItemActionPerformed(null);
                }
            });
            macOSXApplication.setQuitHandler(new QuitHandler() {
                @Override
                public void handleQuitRequestWith(AppEvent.QuitEvent evt, QuitResponse resp) {
                    exitItemActionPerformed(null);
                    // If the user agreed to quit, System.exit would have been
                    // called.  Since we got here, the user has said "No" to quitting.
                    resp.cancelQuit();
                }
            });
            fileMenu.remove(jSeparator4);
            fileMenu.remove(exitItem);
            editMenu.remove(jSeparator7);
            editMenu.remove(preferencesItem);
        } catch (Throwable x) {
            LOG.error("Unable to load Apple eAWT classes.", x);
            DialogUtils.displayError("Warning",
                    "Savant requires Java for Mac OS X 10.6 Update 3 (or later).\nPlease check Software Update for the latest version.");
        }
    }
    LookAndFeelFactory.UIDefaultsCustomizer uiDefaultsCustomizer = new LookAndFeelFactory.UIDefaultsCustomizer() {
        @Override
        public void customize(UIDefaults defaults) {
            ThemePainter painter = (ThemePainter) UIDefaultsLookup.get("Theme.painter");
            defaults.put("OptionPaneUI", "com.jidesoft.plaf.basic.BasicJideOptionPaneUI");

            defaults.put("OptionPane.showBanner", Boolean.TRUE); // show banner or not. default is true
            //defaults.put("OptionPane.bannerIcon", JideIconsFactory.getImageIcon(JideIconsFactory.JIDE50));
            defaults.put("OptionPane.bannerFontSize", 13);
            defaults.put("OptionPane.bannerFontStyle", Font.BOLD);
            defaults.put("OptionPane.bannerMaxCharsPerLine", 60);
            defaults.put("OptionPane.bannerForeground", Color.BLACK); //painter != null ? painter.getOptionPaneBannerForeground() : null);  // you should adjust this if banner background is not the default gradient paint
            defaults.put("OptionPane.bannerBorder", null); // use default border

            // set both bannerBackgroundDk and // set both bannerBackgroundLt to null if you don't want gradient
            //defaults.put("OptionPane.bannerBackgroundDk", painter != null ? painter.getOptionPaneBannerDk() : null);
            //defaults.put("OptionPane.bannerBackgroundLt", painter != null ? painter.getOptionPaneBannerLt() : null);
            //defaults.put("OptionPane.bannerBackgroundDirection", Boolean.TRUE); // default is true

            // optionally, you can set a Paint object for BannerPanel. If so, the three UIDefaults related to banner background above will be ignored.
            defaults.put("OptionPane.bannerBackgroundPaint", null);

            defaults.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder(6, 6, 6, 6));
            defaults.put("OptionPane.buttonOrientation", SwingConstants.RIGHT);

        }
    };
    uiDefaultsCustomizer.customize(UIManager.getDefaults());
}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void loadClientOption(ClientOptionsEvent clientOptionEvent) {
    switch (clientOptionEvent) {
    case LOOK_AND_FEEL:
        if (mOptions.isForceLookAndFeel()) {
            SwingUtilities.invokeLater(() -> {
                try {
                    UIManager.setLookAndFeel(SwingHelper.getLookAndFeelClassName(mOptions.getLookAndFeel()));
                    SwingUtilities.updateComponentTreeUI(MainFrame.this);
                    SwingUtilities.updateComponentTreeUI(sPopupMenu);

                    if (mOptions.getLookAndFeel().equalsIgnoreCase("Darcula")) {
                        int iconSize = 32;
                        UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();
                        uiDefaults.put("OptionPane.informationIcon",
                                MaterialIcon.Action.INFO_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.errorIcon",
                                MaterialIcon.Alert.ERROR_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.questionIcon",
                                MaterialIcon.Action.HELP_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.warningIcon",
                                MaterialIcon.Alert.WARNING.get(iconSize, IconColor.WHITE));
                    }//from ww w.  j a v  a  2  s  . c o  m
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                        | UnsupportedLookAndFeelException ex) {
                    //Xlog.timedErr(ex.getMessage());
                }
            });
        }
        break;

    case MENU_ICONS:
        ActionMap actionMap = getRootPane().getActionMap();
        for (Object allKey : actionMap.allKeys()) {
            Action action = actionMap.get(allKey);
            Icon icon = null;
            if (mOptions.isDisplayMenuIcons()) {
                icon = (Icon) action.getValue(ActionManager.JOTA_SMALL_ICON_KEY);
            }
            action.putValue(Action.SMALL_ICON, icon);
        }
        break;

    default:
        throw new AssertionError();
    }

}

From source file:uk.sipperfly.ui.Exactly.java

private void unBagActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unBagActionPerformed
    UIDefaults defaults = new UIDefaults();

    defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    this.unBaggingProgress.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    this.unBaggingProgress.putClientProperty("Nimbus.Overrides", defaults);

    String location = destDirLocation.getText();
    List<String> validDirs = new ArrayList<String>();
    String sourcelocation = this.inputLocationDir.getText();
    if (sourcelocation.isEmpty() || sourcelocation == null) {
        UpdateResult("Must choose a source folder.", 1);
        return;//from  w  ww. j  av  a2 s.co  m
    }
    if (!location.isEmpty() && location != null) {
        validDirs.add(location);
        File f = new File(destDirLocation.getText());
        if (!f.exists()) {
            UpdateResult("Must choose a valid destination folder.", 1);
            return;
        }
        try {
            bgw = new BackgroundWorker(validDirs, this, 4);
            bgw.execute();
        } catch (IOException ex) {
            Logger.getLogger(GACOM).log(Level.SEVERE, null, ex);
        }
    } else {
        UpdateResult("Must choose destination folder.", 1);
        return;
    }
}

From source file:uk.sipperfly.ui.Exactly.java

private void unBaggingProgressPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_unBaggingProgressPropertyChange
    UIDefaults defaults = new UIDefaults();

    defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
}