Example usage for javax.swing UIManager getDefaults

List of usage examples for javax.swing UIManager getDefaults

Introduction

In this page you can find the example usage for javax.swing UIManager getDefaults.

Prototype

public static UIDefaults getDefaults() 

Source Link

Document

Returns the defaults.

Usage

From source file:pl.edu.icm.visnow.system.main.VisNow.java

public static void main(final String[] args) {
    /*//w w w .  j av a  2s  . com
     * try { for (javax.swing.UIManager.LookAndFeelInfo info :
     * javax.swing.UIManager.getInstalledLookAndFeels()) { if
     * ("Nimbus".equals(info.getName())) {
     * javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } }
     * } catch (ClassNotFoundException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (InstantiationException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (IllegalAccessException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); }
     */
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {

            for (int i = 0; i < args.length; i++) {
                if (args[i].equals("-debug")) {
                    debug = true;
                }

                if (args[i].equals("-substancedebug")) {
                    substancedebug = true;
                }

                if (args[i].equals("-easy")) {
                    libraryLevel = SIMPLE_LIBRARY;
                    VERSION = VERSION_BASE + "-Simple";
                    allowGUISwitch = false;
                }

                if (args[i].equals("-full")) {
                    guiLevel = EXPERT_GUI;
                    libraryLevel = FULL_LIBRARY;
                    VERSION = VERSION_BASE + "-Pro";
                }
            }
            Locale.setDefault(Locale.US);

            renderSplashFrame(0.1f, "Initializing logging...");
            //TODO: test it see #initConfigDir
            //                initConfigDir();
            initLogging();
            startupInfo();
            renderSplashFrame(0.2f, "Initializing Java3D...");
            initJava3D();

            if (substancedebug) {
                try {

                    Class substance = Class.forName("org.jvnet.substance.SubstanceLookAndFeel");
                    Class selectedSkinClass;
                    if (guiLevel == SIMPLE_GUI) {
                        selectedSkinClass = Class.forName("org.jvnet.substance.skin.BusinessBlackSteelSkin");
                    } else {
                        @SuppressWarnings("unchecked")
                        Map<String, Object> skinInfoMap = (Map<String, Object>) substance
                                .getMethod("getAllSkins").invoke(null);
                        List<String> skinClassNameArray = new ArrayList<String>();
                        for (Object object : skinInfoMap.values()) {
                            String cn = (String) object.getClass().getMethod("getClassName").invoke(object);
                            LOGGER.info("Adding substance skin class: " + cn);
                            skinClassNameArray.add(cn);
                        }
                        int skinClassIdx = 0;
                        if (guiLevel == SIMPLE_GUI) {
                            skinClassIdx = 2;
                        } else {
                            skinClassIdx = new Random().nextInt(skinClassNameArray.size());
                        }
                        LOGGER.info("Selected skin: " + skinClassNameArray.get(skinClassIdx));
                        selectedSkinClass = Class.forName(skinClassNameArray.get(skinClassIdx));
                    }

                    //                        selectedSkinClass =Class.forName("org.jvnet.substance.skin.BusinessBlackSteelSkin");
                    javax.swing.UIManager
                            .setLookAndFeel("org.jvnet.substance.skin.SubstanceBusinessLookAndFeel");
                    Class skinClass = Class.forName("org.jvnet.substance.api.SubstanceSkin");
                    @SuppressWarnings("unchecked")
                    Method m = substance.getMethod("setSkin", skinClass);
                    m.invoke(null, selectedSkinClass.newInstance());
                    JFrame.setDefaultLookAndFeelDecorated(true);
                    JDialog.setDefaultLookAndFeelDecorated(true);
                } catch (Exception ex) {
                    LOGGER.error("Failed to set lf: " + ex.getMessage());
                }
            }

            //resize borders from tabbedPane
            //TODO: needs refactoring - initPresentation, initL&F or sth like that
            try {
                UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(4, 0, 0, 0));
            } catch (Exception ex) {
                //this causes exception on MacOS X
            }

            try {
                visnow = new VisNow();

                int argsCount = 0;
                for (int i = 0; i < args.length; i++) {
                    if (!args[i].startsWith("-")) {
                        argsCount++;
                    }
                }
                String[] args2 = new String[argsCount];
                int c = 0;
                for (int i = 0; i < args.length; i++) {
                    if (!args[i].startsWith("-")) {
                        args2[c++] = args[i];
                    }
                }
                visnow.init(args2);
            } catch (VNSystemException ex) {
                Displayer.display(1010101010, ex, null, "Initialization failed.");
                return;
            }

            visnow.initUserMessages();
        }
    });

}

From source file:plugin.notes.gui.JIcon.java

private void buttonFocusLost(FocusEvent evt) {

    setBackground((Color) UIManager.getDefaults().get("Panel.background"));
    button.setBackground((Color) UIManager.getDefaults().get("Button.background"));
}

From source file:plugin.notes.gui.JIcon.java

/**
 *  This method is called from within the constructor to initialize the form.
 *  WARNING: Do NOT modify this code. The content of this method is always
 *  regenerated by the Form Editor./*  w  w w  .  j a v a2 s  . com*/
 */
private void initComponents() {

    contextMenu = new JPopupMenu();
    JMenuItem launchMI = new JMenuItem();
    JMenuItem deleteMI = new JMenuItem();
    button = new JButton();
    label = new JLabel();

    launchMI.setText("Launch File (enter)");
    launchMI.addActionListener(this::launchMIActionPerformed);

    contextMenu.add(launchMI);
    deleteMI.setText("Delete File (del)");
    deleteMI.addActionListener(this::deleteMIActionPerformed);

    contextMenu.add(deleteMI);

    setLayout(new BorderLayout());

    setBackground((Color) UIManager.getDefaults().get("Panel.background"));
    setBorder(new LineBorder(new Color(0, 0, 0)));
    button.setBackground((Color) UIManager.getDefaults().get("Button.background"));
    button.setBorder(null);
    button.addActionListener(this::buttonActionPerformed);

    button.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent evt) {
            buttonFocusGained(evt);
        }

        @Override
        public void focusLost(FocusEvent evt) {
            buttonFocusLost(evt);
        }
    });

    button.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent evt) {
            buttonKeyReleased(evt);
        }
    });

    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent evt) {
            buttonMouseClicked(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            buttonMouseReleased(evt);
        }
    });

    add(button, BorderLayout.NORTH);

    label.setBackground(new Color(204, 204, 204));
    add(label, BorderLayout.CENTER);
}

From source file:ro.nextreports.designer.template.report.TemplateManager.java

public static ReportTemplate createDefaultReportTemplate() {
    ReportTemplate template = new ReportTemplate();
    template.setVersion(ReleaseInfoAdapter.getVersionNumber());
    BandElement title = new BandElement("Title");
    title.setBackground(Color.WHITE);
    title.setForeground(Color.BLACK);
    Font font = (Font) UIManager.getDefaults().get("Panel.font");
    title.setFont(font);/* w  w  w . j a  v a  2s.  c o  m*/
    title.setPadding(new Padding(0, 0, 0, 0));
    Border border = new Border();
    border.setLeftColor(Color.BLACK);
    border.setRightColor(Color.BLACK);
    border.setTopColor(Color.BLACK);
    border.setBottomColor(Color.BLACK);
    title.setBorder(border);
    template.setTitleBand(title);

    BandElement header = new BandElement("Header");
    TemplateManager.restoreBandElement(header, title);
    template.setHeaderBand(header);

    BandElement detail = new BandElement("Detail");
    TemplateManager.restoreBandElement(detail, title);
    template.setDetailBand(detail);

    BandElement footer = new BandElement("Footer");
    TemplateManager.restoreBandElement(footer, title);
    template.setFooterBand(footer);

    return template;
}

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

/**
 * Customize the UI. This includes doing any platform-specific
 * customization.// w w w . ja  va2s. 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:shuffle.fwk.ShuffleController.java

/**
 * Creates a ShuffleController with the given configuration paths for the primary configuration
 * (which tells other managers where to get their configurations). If there are none passed, then
 * "config/main.txt" is assumed.//  w  w w .j a v  a 2  s .c o  m
 * 
 * @param configPaths
 *           The paths as Strings
 */
public ShuffleController(String... configPaths) {
    if (configPaths.length > 0 && configPaths[0] != null) {
        factory = new ConfigFactory(configPaths[0]);
    } else {
        factory = new ConfigFactory();
    }
    Integer menuFontOverride = getPreferencesManager().getIntegerValue(KEY_FONT_SIZE_SCALING);
    if (menuFontOverride != null && menuFontOverride != 100 && menuFontOverride >= 1
            && menuFontOverride <= 10000) {
        float scale = menuFontOverride.floatValue() / 100.0f;
        try {
            // This is the cleanest and most bug-free way to do this hack.
            Set<Object> allKeys = new HashSet<Object>();
            allKeys.add("JMenu.font");
            // Yes we're not supposed to use this, but it is the only one that works with Nimbus LAF
            allKeys.addAll(UIManager.getLookAndFeelDefaults().keySet());
            Object value = UIManager.get("defaultFont");
            if (value != null && value instanceof FontUIResource) {
                FontUIResource fromFont = (javax.swing.plaf.FontUIResource) value;
                FontUIResource toFont = new FontUIResource(fromFont.deriveFont(fromFont.getSize() * scale));
                // This one is necessary
                UIManager.getLookAndFeel().getDefaults().put("defaultFont", toFont);
                // And this one allows other LAF to be used in the future
                UIManager.getDefaults().put("defaultFont", toFont);
            }

            // Needed for Nimbus's JTable row height adjustment
            Object tableFontValue = UIManager.getLookAndFeel().getDefaults().get("Table.font");
            Number bestRowHeight = null;
            if (tableFontValue != null && tableFontValue instanceof FontUIResource) {
                FontUIResource fromFont = (FontUIResource) tableFontValue;
                bestRowHeight = fromFont.getSize();
            }
            Object rowHeightValue = UIManager.getLookAndFeel().getDefaults().get("Table.rowHeight");
            if (rowHeightValue != null && rowHeightValue instanceof Number) {
                Number rowHeight = (Number) rowHeightValue;
                rowHeight = rowHeight.doubleValue() * scale;
                if (bestRowHeight == null || bestRowHeight.intValue() < rowHeight.intValue()) {
                    bestRowHeight = rowHeight;
                }
            }
            if (bestRowHeight != null) {
                bestRowHeight = bestRowHeight.doubleValue() * (4.0 / 3.0);
            }
            if (bestRowHeight != null && bestRowHeight.intValue() > 0) {
                UIManager.getLookAndFeel().getDefaults().put("Table.rowHeight", bestRowHeight.intValue());
            }
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            LOG.log(Level.SEVERE, "Cannot override menu font sizes!", e);
        }
    }
    try {
        setModel(new ShuffleModel(this));
        setView(new ShuffleView(this));
        getModel().checkLocaleConfig();
        loadFrame();
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        LOG.log(Level.SEVERE, "Failure on start:", e);
    }
}

From source file:storybook.toolkit.swing.SwingUtil.java

public static void setUIFont(javax.swing.plaf.FontUIResource f) {
    Enumeration<Object> 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, f);
    }/*from   w ww  . j  av  a2 s. co  m*/
}