Search in sources :

Example 1 with LookAndFeel

use of javax.swing.LookAndFeel in project qi4j-sdk by Qi4j.

the class Envisage method initLookAndFeel.

private void initLookAndFeel() {
    String osName = System.getProperty("os.name").toUpperCase();
    // set to use swing anti alias text only for JVM <= 1.5
    System.setProperty("swing.aatext", "true");
    // set default swing bold to false, only for JVM 1.5 or above
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    // set LaF
    LookAndFeel lnf = UIManager.getLookAndFeel();
    if (lnf != null && lnf.getID().equalsIgnoreCase("Metal")) {
        final String lnfClassName;
        if (osName.startsWith("MAC")) {
            //TODO i18n
            System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Envisage");
            System.setProperty("apple.laf.useScreenMenuBar", "true");
            lnfClassName = UIManager.getSystemLookAndFeelClassName();
        } else if (osName.startsWith("WINDOWS")) {
            UIManager.put("ClassLoader", LookUtils.class.getClassLoader());
            lnfClassName = Options.getSystemLookAndFeelClassName();
            Options.setUseNarrowButtons(false);
        } else {
            UIManager.put("ClassLoader", LookUtils.class.getClassLoader());
            lnfClassName = Options.getCrossPlatformLookAndFeelClassName();
            PlasticLookAndFeel.setTabStyle(PlasticLookAndFeel.TAB_STYLE_METAL_VALUE);
            PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());
            Options.setUseNarrowButtons(false);
        //PlasticLookAndFeel.setMyCurrentTheme(new ExperienceBlueDefaultFont());  // for CJK Font
        }
        if (lnfClassName != null) {
            try {
                UIManager.setLookAndFeel(lnfClassName);
            } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException ex) {
                System.err.println("Unable to set LookAndFeel, use default LookAndFeel.\n" + ex.getMessage());
            }
        }
    }
}
Also used : UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) ExperienceBlue(com.jgoodies.looks.plastic.theme.ExperienceBlue) PlasticLookAndFeel(com.jgoodies.looks.plastic.PlasticLookAndFeel) LookAndFeel(javax.swing.LookAndFeel)

Example 2 with LookAndFeel

use of javax.swing.LookAndFeel in project adempiere by adempiere.

the class PreviewPanel method setLFSelection.

/**
	 *  Update the look list and theme list to show the current selection
	 */
private void setLFSelection() {
    m_setting = true;
    //  Search for PLAF
    ValueNamePair plaf = null;
    LookAndFeel lookFeel = UIManager.getLookAndFeel();
    String look = lookFeel.getClass().getName();
    for (int i = 0; i < AdempierePLAF.getPLAFs().length; i++) {
        ValueNamePair vp = AdempierePLAF.getPLAFs()[i];
        if (vp.getValue().equals(look)) {
            plaf = vp;
            break;
        }
    }
    if (plaf != null)
        lookList.setSelectedValue(plaf, true);
    //  Search for Theme
    MetalTheme metalTheme = null;
    ValueNamePair theme = null;
    boolean metal = UIManager.getLookAndFeel() instanceof MetalLookAndFeel;
    themeList.setModel(new DefaultComboBoxModel(AdempierePLAF.getThemes()));
    if (metal) {
        theme = null;
        AppContext context = AppContext.getAppContext();
        metalTheme = (MetalTheme) context.get("currentMetalTheme");
        if (metalTheme != null) {
            String lookTheme = metalTheme.getName();
            for (int i = 0; i < AdempierePLAF.getThemes().length; i++) {
                ValueNamePair vp = AdempierePLAF.getThemes()[i];
                if (vp.getName().equals(lookTheme)) {
                    theme = vp;
                    break;
                }
            }
        }
        if (theme != null)
            themeList.setSelectedValue(theme, true);
    }
    m_setting = false;
    log.info(lookFeel + " - " + metalTheme);
}
Also used : MetalTheme(javax.swing.plaf.metal.MetalTheme) AppContext(sun.awt.AppContext) ValueNamePair(org.compiere.util.ValueNamePair) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) LookAndFeel(javax.swing.LookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel)

Example 3 with LookAndFeel

use of javax.swing.LookAndFeel in project jdk8u_jdk by JetBrains.

the class DefaultTreeCellRenderer method getTreeCellRendererComponent.

/**
      * Configures the renderer based on the passed in components.
      * The value is set from messaging the tree with
      * <code>convertValueToText</code>, which ultimately invokes
      * <code>toString</code> on <code>value</code>.
      * The foreground color is set based on the selection and the icon
      * is set based on the <code>leaf</code> and <code>expanded</code>
      * parameters.
      */
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    String stringValue = tree.convertValueToText(value, sel, expanded, leaf, row, hasFocus);
    this.tree = tree;
    this.hasFocus = hasFocus;
    setText(stringValue);
    Color fg = null;
    isDropCell = false;
    JTree.DropLocation dropLocation = tree.getDropLocation();
    if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) {
        Color col = DefaultLookup.getColor(this, ui, "Tree.dropCellForeground");
        if (col != null) {
            fg = col;
        } else {
            fg = getTextSelectionColor();
        }
        isDropCell = true;
    } else if (sel) {
        fg = getTextSelectionColor();
    } else {
        fg = getTextNonSelectionColor();
    }
    setForeground(fg);
    Icon icon = null;
    if (leaf) {
        icon = getLeafIcon();
    } else if (expanded) {
        icon = getOpenIcon();
    } else {
        icon = getClosedIcon();
    }
    if (!tree.isEnabled()) {
        setEnabled(false);
        LookAndFeel laf = UIManager.getLookAndFeel();
        Icon disabledIcon = laf.getDisabledIcon(tree, icon);
        if (disabledIcon != null)
            icon = disabledIcon;
        setDisabledIcon(icon);
    } else {
        setEnabled(true);
        setIcon(icon);
    }
    setComponentOrientation(tree.getComponentOrientation());
    selected = sel;
    return this;
}
Also used : JTree(javax.swing.JTree) Color(java.awt.Color) Icon(javax.swing.Icon) LookAndFeel(javax.swing.LookAndFeel)

Example 4 with LookAndFeel

use of javax.swing.LookAndFeel in project jgnash by ccavanaugh.

the class ThemeManager method buildLookAndFeelMenu.

/**
     * Loads the menu with the available look and feels for the application
     * 
     * @return l and f menu
     */
JMenu buildLookAndFeelMenu() {
    String activeLookAndFeelName = UIManager.getLookAndFeel().getName();
    // ButtonGroup buttonGroup = new ButtonGroup();
    JMenu lfMenu = new JMenu();
    lfMenu.setText(rb.getString("Menu.LookAndFeel.Name"));
    lfMenu.add(buildSubstanceMenu());
    List<String> lookAndFeels = new ArrayList<>();
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if (isLookAndFeelAvailable(info.getClassName())) {
            lookAndFeels.add(info.getClassName());
        }
    }
    for (String lookAndFeel : KNOWN) {
        if (isLookAndFeelAvailable(lookAndFeel)) {
            lookAndFeels.add(lookAndFeel);
        }
    }
    Collections.sort(lookAndFeels);
    for (String lookAndFeel : lookAndFeels) {
        try {
            Class<?> lnfClass = Class.forName(lookAndFeel);
            LookAndFeel newLAF = (LookAndFeel) lnfClass.newInstance();
            JRadioButtonMenuItem button = new JRadioButtonMenuItem();
            button.setText(newLAF.getName());
            button.setActionCommand(lookAndFeel);
            button.setName(newLAF.getName());
            button.addActionListener(e -> {
                Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
                pref.put(LF, e.getActionCommand());
                restartUI();
            });
            lfButtonGroup.add(button);
            lfMenu.add(button);
            if (newLAF.getName().equals(activeLookAndFeelName)) {
                button.setSelected(true);
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            Logger.getLogger(ThemeManager.class.getName()).log(Level.WARNING, null, e);
        }
    }
    return lfMenu;
}
Also used : LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) ArrayList(java.util.ArrayList) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) LookAndFeel(javax.swing.LookAndFeel) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) SubstanceLookAndFeel(org.pushingpixels.substance.api.SubstanceLookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) Preferences(java.util.prefs.Preferences) JMenu(javax.swing.JMenu)

Example 5 with LookAndFeel

use of javax.swing.LookAndFeel in project jgnash by ccavanaugh.

the class ThemeManager method getNimbusFontSize.

public static int getNimbusFontSize() {
    Preferences p = Preferences.userNodeForPackage(ThemeManager.class);
    int preferredSize = p.getInt(NIMBUS_FONT_SIZE, 0);
    // and save it
    if (preferredSize == 0) {
        LookAndFeel old = UIManager.getLookAndFeel();
        try {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
            preferredSize = NimbusUtils.getBaseFontSize();
            p.putInt(NIMBUS_FONT_SIZE, preferredSize);
            UIManager.setLookAndFeel(old);
        } catch (Exception e) {
            Logger.getLogger(ThemeManager.class.getName()).log(Level.SEVERE, e.toString(), e);
        }
    }
    return preferredSize;
}
Also used : NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) Preferences(java.util.prefs.Preferences) LookAndFeel(javax.swing.LookAndFeel) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) SubstanceLookAndFeel(org.pushingpixels.substance.api.SubstanceLookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException)

Aggregations

LookAndFeel (javax.swing.LookAndFeel)15 MetalLookAndFeel (javax.swing.plaf.metal.MetalLookAndFeel)9 NimbusLookAndFeel (javax.swing.plaf.nimbus.NimbusLookAndFeel)5 SubstanceLookAndFeel (org.pushingpixels.substance.api.SubstanceLookAndFeel)5 Preferences (java.util.prefs.Preferences)4 MetalTheme (javax.swing.plaf.metal.MetalTheme)4 ValueNamePair (org.compiere.util.ValueNamePair)4 UnsupportedLookAndFeelException (javax.swing.UnsupportedLookAndFeelException)3 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2 JMenu (javax.swing.JMenu)2 JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)2 AppContext (sun.awt.AppContext)2 PlasticLookAndFeel (com.jgoodies.looks.plastic.PlasticLookAndFeel)1 ExperienceBlue (com.jgoodies.looks.plastic.theme.ExperienceBlue)1 SkinLookAndFeel (com.l2fprod.gui.plaf.skin.SkinLookAndFeel)1 Color (java.awt.Color)1 InvalidDnDOperationException (java.awt.dnd.InvalidDnDOperationException)1 ArrayList (java.util.ArrayList)1 Icon (javax.swing.Icon)1 JTree (javax.swing.JTree)1