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:com.diversityarrays.kdxplore.KDXplore.java

private static void applyUIdefaultPreferences(KdxplorePreferences prefs) {
    UIDefaults uiDefaults = UIManager.getDefaults();
    for (KdxPreference<?> pref : KdxPreference.getUiDefaultPreferences()) {
        Object value = prefs.getPreferenceValue(pref);
        if (value != null) {
            uiDefaults.put(pref.uiDefaultName, value);
        }/*  w  w w  . java 2s.c o m*/
    }
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * // w w  w .ja  v a2s  .  c  o m
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}

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

private void setLookAndFeel() {
    try {/*from w  w w  .ja  v a 2  s.  c o m*/
        String lookFeel;
        String systemLookFeel = UIManager.getSystemLookAndFeelClassName();

        if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
            // FIXME: Problems with OpenJDK and GTK L&F
            // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
            if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
                // Metal L&F
                lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
                LOGGER.warn(
                        "There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
            } else {
                lookFeel = systemLookFeel;
            }
        } else {
            lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
        }

        // FIXME: Open JDK problem
        if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
                && !System.getProperty("java.runtime.name").contains("OpenJDK")) {
            // try to avoid ending up with the ugly Metal L&F
            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(systemLookFeel);
                // also set system l&f as default
                Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
                // notify the user
                JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(),
                        Localization.lang(
                                "Unable to find the requested look and feel and thus the default one is used."),
                        Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
                LOGGER.warn("Unable to find requested look and feel", e);
            }
        }
    } 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();
        for (Object key : Collections.list(keys)) {
            if ((key instanceof String) && ((String) key).endsWith(".font")) {
                FontUIResource font = (FontUIResource) UIManager.get(key);
                font = new FontUIResource(font.getName(), font.getStyle(), fontSize);
                defaults.put(key, font);
            }
        }
    }
}

From source file:net.sf.nmedit.nomad.core.NomadLoader.java

private void initLookAndFeel(String lafClassName, String themeClassName, String defaultLafOnPlatform) {
    EnumSet<Platform.OS> defaultLafPlatforms = EnumSet.noneOf(Platform.OS.class);
    {// w w  w .  jav  a  2 s .c o m
        // remove whitespace + lowercase
        defaultLafOnPlatform = defaultLafOnPlatform.replaceAll("\\s", "").toLowerCase();
        // split comma separated list
        String[] dlop = defaultLafOnPlatform.split(",");
        // check items
        for (String s : dlop) {
            if (s.equals("all")) {
                // on all platforms
                defaultLafPlatforms.addAll(EnumSet.allOf(Platform.OS.class));
                break;
            } else if (s.equals("mac")) {
                defaultLafPlatforms.add(Platform.OS.MacOSFlavor);
            } else if (s.equals("unix")) {
                defaultLafPlatforms.add(Platform.OS.UnixFlavor);
            } else if (s.equals("windows")) {
                defaultLafPlatforms.add(Platform.OS.WindowsFlavor);
            }
        }
    }

    // jgoodies specific properties

    PlasticLookAndFeel.setTabStyle(PlasticLookAndFeel.TAB_STYLE_METAL_VALUE);
    //UIManager.put(Options.POPUP_DROP_SHADOW_ENABLED_KEY, Boolean.FALSE);
    Options.setPopupDropShadowEnabled(false);
    Options.setUseNarrowButtons(true);

    //UIManager.put(Options.PLASTIC_MENU_FONT_KEY, new FontUIResource("Verdana", Font.PLAIN, 9));
    //PlasticLookAndFeel.setFontPolicy(FontPolicies.getDefaultWindowsPolicy());
    /*
            UIManager.put("MenuItem.margin", new InsetsUIResource(2,2,1,2));
            UIManager.put("Menu.margin", new InsetsUIResource(1,2,1,2));
            */
    // set the metal theme

    if (defaultLafPlatforms.contains(Platform.flavor())) {
        // use default LAF on current platform

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Throwable e) {
            Log log = LogFactory.getLog(getClass());
            log.warn("could not set look and feel theme", e);

        }

        if (Platform.isFlavor(Platform.OS.MacOSFlavor)) {
            System.setProperty("apple.laf.useScreenMenuBar", "true");
        }

    } else {
        // use LAF setting

        MetalTheme theme = null;
        if (themeClassName != null) {
            try {
                theme = (MetalTheme) Class.forName(themeClassName).newInstance();
                UIManager.put("Plastic.theme", themeClassName);

                if (theme instanceof PlasticTheme) {
                    PlasticLookAndFeel.setPlasticTheme((PlasticTheme) theme);
                    // PlasticLookAndFeel.setTabStyle(settings.getPlasticTabStyle());
                } else if (theme instanceof MetalTheme) {
                    MetalLookAndFeel.setCurrentTheme(theme);
                }

            } catch (Throwable e) {
                Log log = LogFactory.getLog(getClass());
                log.warn("could not set look and feel theme", e);
            }
        }
        // set the look and feel
        if (lafClassName != null) {
            try {
                LookAndFeel LAF = (LookAndFeel) Class.forName(lafClassName).newInstance();
                // it is very important to set the classloader  
                UIManager.getDefaults().put("ClassLoader", getClass().getClassLoader());
                UIManager.setLookAndFeel(LAF);
            } catch (Throwable e) {
                Log log = LogFactory.getLog(getClass());
                log.warn("could not set custom look and feel", e);
            }
        }
    }

}

From source file:com.att.aro.ui.view.MainFrame.java

private JTabbedPane getJTabbedPane() {
    if (jMainTabbedPane == null) {
        UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
        UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true);

        jMainTabbedPane = new JTabbedPane();
        route = new ARODiagnosticsOverviewRouteImpl(jMainTabbedPane);

        bestPracticesTab = new BestPracticesTab(this, route);
        jMainTabbedPane.add(BUNDLE.getString("aro.tab.bestpractices"), bestPracticesTab);
        modelObserver.registerObserver(bestPracticesTab);

        overviewTab = new OverviewTab(route);
        jMainTabbedPane.add(BUNDLE.getString("aro.tab.overview"), overviewTab.layoutDataPanel());
        modelObserver.registerObserver(overviewTab);

        diagnosticsTab = new DiagnosticsTab(this, route);
        jMainTabbedPane.add(BUNDLE.getString("aro.tab.advanced"), diagnosticsTab);
        modelObserver.registerObserver(diagnosticsTab);

        videoTab = new VideoTab(this, route);
        jMainTabbedPane.add(BUNDLE.getString("aro.tab.video"), videoTab);
        modelObserver.registerObserver(videoTab);

        statisticsTab = new StatisticsTab(this);
        jMainTabbedPane.add(BUNDLE.getString("aro.tab.statistics"), statisticsTab);
        modelObserver.registerObserver(statisticsTab);

        waterfallTab = new WaterfallTab(route);
        jMainTabbedPane.add(BUNDLE.getString("aro.tab.waterfall"), waterfallTab.layoutDataPanel());
        modelObserver.registerObserver(waterfallTab);

        jMainTabbedPane.addChangeListener(new ChangeListener() {
            @Override/* w  w  w  .  j  av a2s. com*/
            public void stateChanged(ChangeEvent event) {
                onTabChanged(event);
            }
        });
    }
    return jMainTabbedPane;
}

From source file:gov.nih.nci.nbia.StandaloneDMV3.java

public static 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 = font.deriveFont((float) size);
                UIManager.put(key, font);
            }/*from w  ww  .  jav a2  s  .  c o  m*/
        }
    }
}

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  ww w.j  a v  a2  s.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 . java  2  s  .  co  m
    }
}

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

private void setLookAndFeel() {
    try {/*from   ww w .ja v  a2s. co 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:hermes.browser.HermesBrowser.java

private void initJIDE() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException,
        IllegalAccessException {//from  w w  w.  j  a  v  a 2  s  .  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());

}