Example usage for javax.swing UIDefaults get

List of usage examples for javax.swing UIDefaults get

Introduction

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

Prototype

public Object get(Object key) 

Source Link

Document

Returns the value for key.

Usage

From source file:Main.java

/**
 * Convenience method for retrieving a subset of the UIDefaults pertaining to a particular class.
 * /*from www  . ja v a 2s. c o  m*/
 * @param className
 *            fully qualified name of the class of interest
 * @return the UIDefaults of the class named
 */
public static UIDefaults getUIDefaultsOfClass(String className) {
    UIDefaults retVal = new UIDefaults();
    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    List<?> listKeys = Collections.list(defaults.keys());
    for (Object key : listKeys) {
        if (key instanceof String && ((String) key).startsWith(className)) {
            String stringKey = (String) key;
            String property = stringKey;
            if (stringKey.contains(".")) { //$NON-NLS-1$
                property = stringKey.substring(stringKey.indexOf(".") + 1); //$NON-NLS-1$
            }
            retVal.put(property, defaults.get(key));
        }
    }
    return retVal;
}

From source file:LayeredPaneDemo.java

protected Object findDefaultResource(String id) {
    Object obj = null;/* ww  w .  j a  va 2 s. c  om*/
    try {
        UIDefaults uiDef = UIManager.getDefaults();
        obj = uiDef.get(id);
    } catch (Exception ex) {
        System.err.println(ex);
    }
    if (obj == null)
        obj = myDefaults.get(id);
    return obj;
}

From source file:UIDefaultsTreeModel.java

public UIDefaultsTreeModel() {
    innerModel = new DefaultTreeModel(rootNode);
    innerModel.insertNodeInto(colorNode, rootNode, 0);
    innerModel.insertNodeInto(borderNode, rootNode, 1);
    innerModel.insertNodeInto(fontNode, rootNode, 2);
    innerModel.insertNodeInto(iconNode, rootNode, 3);
    innerModel.insertNodeInto(otherNode, rootNode, 4);
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration elems = defaults.keys();
    String keyName;//  w ww.  ja  v a2  s. c  om
    Object valueForKey;
    while (elems.hasMoreElements()) {
        DefaultMutableTreeNode newKeyNode;
        DefaultMutableTreeNode newValueNode;
        try {
            keyName = elems.nextElement().toString();
            valueForKey = defaults.get(keyName);

            newKeyNode = new DefaultMutableTreeNode(keyName);
            newValueNode = new DefaultMutableTreeNode(valueForKey);

            if (valueForKey instanceof java.awt.Color) {
                innerModel.insertNodeInto(newKeyNode, colorNode, 0);
            } else if (valueForKey instanceof javax.swing.border.Border) {
                innerModel.insertNodeInto(newKeyNode, borderNode, 0);
            } else if (valueForKey instanceof java.awt.Font) {
                innerModel.insertNodeInto(newKeyNode, fontNode, 0);
            } else if (valueForKey instanceof javax.swing.Icon) {
                innerModel.insertNodeInto(newKeyNode, iconNode, 0);
            } else {
                innerModel.insertNodeInto(newKeyNode, otherNode, 0);
            }
            innerModel.insertNodeInto(newValueNode, newKeyNode, 0);
        } catch (NullPointerException e) {
        }
    }
}

From source file:com.eviware.soapui.support.components.JPropertiesTable.java

private Font getUIDefaultFont() {
    UIDefaults uidefs = UIManager.getLookAndFeelDefaults();
    for (Object key : uidefs.keySet()) {
        if (uidefs.get(key) instanceof Font) {
            return uidefs.getFont(key);
        }/*from w  ww.ja  va  2  s  .c om*/
    }
    return null;
}

From source file:hermes.browser.HermesBrowser.java

private void initJIDE() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException,
        IllegalAccessException {// w  w  w. ja v a 2s.com
    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: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 a v  a2 s. c om*/
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:org.nuclos.client.main.MainController.java

private Map<String, Map<String, Action>> getCommandMap() {
    HashMap<String, Map<String, Action>> res = new HashMap<String, Map<String, Action>>();
    HashMap<String, Action> mainController = new HashMap<String, Action>();

    /* that's too cumbersome:
    mainController.put(//from  w  ww.java 2  s .c  om
       "cmdChangePassword",
       new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
       cmdChangePassword();
    }
       });
     */

    mainController.put("cmdDirectHelp", cmdDirectHelp);
    mainController.put("cmdShowPersonalTasks", cmdShowPersonalTasks);
    mainController.put("cmdShowTimelimitTasks", cmdShowTimelimitTasks);
    mainController.put("cmdShowPersonalSearchFilters", cmdShowPersonalSearchFilters);
    mainController.put("cmdChangePassword", cmdChangePassword);
    mainController.put("cmdOpenSettings", cmdOpenSettings);
    mainController.put("cmdOpenManagementConsole", cmdOpenManagementConsole);
    //mainController.put("cmdOpenEntityWizard", cmdOpenEntityWizard);
    mainController.put("cmdOpenRelationEditor", cmdOpenRelationEditor);
    mainController.put("cmdOpenCustomComponentWizard", cmdOpenCustomComponentWizard);
    //mainController.put("cmdRefreshClientCaches", cmdRefreshClientCaches);
    mainController.put("cmdSelectAll", cmdSelectAll);
    mainController.put("cmdHelpContents", cmdHelpContents);
    mainController.put("cmdShowAboutDialog", cmdShowAboutDialog);
    mainController.put("cmdShowProjectReleaseNotes", cmdShowProjectReleaseNotes);
    mainController.put("cmdShowNuclosReleaseNotes", cmdShowNuclosReleaseNotes);
    mainController.put("cmdLogoutExit", cmdLogoutExit);
    mainController.put("cmdWindowClosing", cmdWindowClosing);
    mainController.put("cmdExecuteRport", cmdExecuteRport);

    for (Method m : getClass().getDeclaredMethods()) {
        if (m.getName().startsWith("cmd")) {
            Class<?>[] pt = m.getParameterTypes();
            if (pt.length == 0 || (pt.length == 1 && pt[0].isAssignableFrom(ActionEvent.class))) {
                final Method fm = m;
                Action a = new AbstractAction(m.getName()) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        miDelegator(e, fm);
                    }
                };
                mainController.put(m.getName(), a);
            }
        }
    }

    res.put("MainController", mainController);

    HashMap<String, Action> clipboardUtils = new HashMap<String, Action>();
    clipboardUtils.put("cutAction", new ClipboardUtils.CutAction());
    clipboardUtils.put("copyAction", new ClipboardUtils.CopyAction());
    clipboardUtils.put("pasteAction", new ClipboardUtils.PasteAction());

    res.put("ClipboardUtils", clipboardUtils);

    HashMap<String, Action> dev = new HashMap<String, Action>();
    dev.put("jmsNotification", new AbstractAction("Test JMS notification") {

        @Override
        public void actionPerformed(ActionEvent e) {
            String s = JOptionPane.showInputDialog(getMainFrame(), "Topic: Message");
            if (s == null)
                return;
            String[] a = s.split(": *");
            if (a.length == 2) {
                // testFacadeRemote.testClientNotification(a[0], a[1]);
                throw new UnsupportedOperationException("TestFacade removed");
            } else {
                JOptionPane.showMessageDialog(getMainFrame(), "Wrong input format");
            }
        }
    });

    dev.put("webPrefs", new AbstractAction("Test Web Prefs-Access") {

        @Override
        public void actionPerformed(ActionEvent e) {
            String s = JOptionPane.showInputDialog(getMainFrame(), "Access-Path");
            if (s == null)
                return;
            try {
                Map<String, String> m = getWebAccessPrefs().getPrefsMap(s);
                StringBuilder sb = new StringBuilder();
                for (String k : m.keySet())
                    sb.append(k).append(": ").append(m.get(k)).append("\n");
                JOptionPane.showMessageDialog(getMainFrame(), sb.toString());
            } catch (CommonBusinessException e1) {
                Errors.getInstance().showExceptionDialog(getMainFrame(), e1);
            }
        }
    });

    dev.put("uiDefaults", new AbstractAction("UIDefaults") {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFrame out = new JFrame("UIDefaults");
            out.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            out.getContentPane().setLayout(new BorderLayout());
            final UIDefTableModel mdl = new UIDefTableModel();
            final JTable contentTable = new JTable(mdl);
            JScrollPane sp = new JScrollPane(contentTable);
            out.getContentPane().add(sp, BorderLayout.CENTER);

            UIDefaults defs = UIManager.getDefaults();
            for (Object key : CollectionUtils.iterableEnum((defs.keys())))
                mdl.add(key.toString(), defs.get(key));
            mdl.sort();

            contentTable.getColumnModel().getColumn(1).setCellRenderer(new UIDefaultsRenderer());
            contentTable.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    int row = contentTable.rowAtPoint(e.getPoint());
                    mdl.forceValue(contentTable.convertRowIndexToModel(row));
                }
            });
            out.pack();
            out.setVisible(true);
        }
    });

    dev.put("checkJawin", new AbstractAction("Check Jawin") {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                SystemUtils.checkJawin();
                JOptionPane.showMessageDialog(Main.getInstance().getMainFrame(), "Jawin ok");
            } catch (Exception ex) {
                Errors.getInstance().showDetailedExceptionDialog(Main.getInstance().getMainFrame(), ex);
            }
        }
    });

    res.put("Dev", dev);

    return res;
}

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

private void initUIDefaults() {
    // UIDEFAULTS.putAll(UIManager.getDefaults());
    UIDefaults defaults = UIManager.getDefaults();
    // XXX: Even though Hashtable implements Map since
    // Java 1.2, UIDefaults is "special"... the Iterator
    // returned by UIDefaults keySet object does not return any
    // keys, and therefore Enumeration must be used instead - aaron
    Enumeration<?> e = defaults.keys();

    while (e.hasMoreElements()) {
        Object key = e.nextElement();
        Object value = defaults.get(key);

        // for some reason, java 1.6 seems to have some null values.
        if (value == null)
            continue;

        // log.debug("Saving UIDefault: " + key);
        UIDEFAULTS.put(key, value);/*  w  w  w .j a  v  a2s. c  o  m*/
    }
}

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

/**
 * Loads any saved uidefaults preferences and installs them
 *//*from ww w  . jav a2 s  . c o m*/
private synchronized void installUIDefaultsPrefs() {
    Iterator<?> it = prefs.entrySet().iterator();
    UIDefaults uidefaults = UIManager.getDefaults();
    log.debug("iterating prefs");
    while (it.hasNext()) {
        @SuppressWarnings("rawtypes")
        Map.Entry entry = (Map.Entry) it.next();
        String prefskey = entry.getKey().toString();
        if (!prefskey.startsWith("uidefaults.") || prefskey.length() <= "uidefaults.".length())
            continue;
        String uikey = prefskey.substring("uidefaults.".length());
        Object object = uidefaults.get(uikey);
        log.debug("prefs property " + uikey + " " + object);
        installUIDefault(object.getClass(), prefskey, uikey);
    }
}

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

/**
 * Initialise the application//from   w  w w  .  j a  va 2 s  .com
 */
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;
}