001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: Lookandfeel.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.swing;
009:
010: import com.uwyn.rife.tools.SortListComparables;
011: import java.util.ArrayList;
012: import java.util.HashMap;
013: import java.util.HashSet;
014: import java.util.LinkedHashMap;
015: import java.util.Map;
016: import javax.swing.LookAndFeel;
017: import javax.swing.UIManager;
018:
019: public abstract class Lookandfeel {
020: // possible JDK Look & Feels
021: private static final String LAF_GTK_CLASS = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
022: private static final String LAF_MAC_CLASS = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
023: private static final String LAF_METAL_CLASS = "javax.swing.plaf.metal.MetalLookAndFeel";
024: private static final String LAF_MOTIF_CLASS = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
025: private static final String LAF_WINDOWS_CLASS = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
026:
027: private static final String LAF_KUNSTSTOFF_CLASS = "com.incors.plaf.kunststoff.KunststoffLookAndFeel";
028: private static final String LAF_ALLOY_CLASS = "com.incors.plaf.alloy.AlloyLookAndFeel";
029: private static final String LAF_COMPIERE_CLASS = "org.compiere.plaf.CompiereLookAndFeel";
030:
031: private static final String LAF_JGOODIES_WINDOWS_CLASS = "com.jgoodies.plaf.windows.ExtWindowsLookAndFeel";
032: private static final String LAF_JGOODIES_PLASTIC_CLASS = "com.jgoodies.plaf.plastic.PlasticLookAndFeel";
033: private static final String LAF_JGOODIES_PLASTIC3D_CLASS = "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel";
034: private static final String LAF_JGOODIES_PLASTICXP_CLASS = "com.jgoodies.plaf.plastic.PlasticXPLookAndFeel";
035:
036: private static final String LAF_JGOODIESV2_WINDOWS_CLASS = "com.jgoodies.looks.windows.WindowsLookAndFeel";
037: private static final String LAF_JGOODIESV2_PLASTIC_CLASS = "com.jgoodies.looks.plastic.PlasticLookAndFeel";
038: private static final String LAF_JGOODIESV2_PLASTIC3D_CLASS = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel";
039: private static final String LAF_JGOODIESV2_PLASTICXP_CLASS = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
040:
041: private static final String LAF_METOUIA_CLASS = "net.sourceforge.mlf.metouia.MetouiaLookAndFeel";
042: private static final String LAF_OYOAHA_CLASS = "com.oyoaha.swing.plaf.oyoaha.OyoahaLookAndFeel";
043: private static final String LAF_SLAF_CLASS = "com.memoire.slaf.SlafLookAndFeel";
044:
045: private static final String[] JDK_LAFS = new String[] {
046: LAF_GTK_CLASS, LAF_MAC_CLASS, LAF_METAL_CLASS,
047: LAF_MOTIF_CLASS, LAF_WINDOWS_CLASS, LAF_KUNSTSTOFF_CLASS,
048: LAF_ALLOY_CLASS, LAF_COMPIERE_CLASS,
049: LAF_JGOODIES_WINDOWS_CLASS, LAF_JGOODIES_PLASTIC_CLASS,
050: LAF_JGOODIES_PLASTIC3D_CLASS, LAF_JGOODIES_PLASTICXP_CLASS,
051: LAF_JGOODIESV2_WINDOWS_CLASS, LAF_JGOODIESV2_PLASTIC_CLASS,
052: LAF_JGOODIESV2_PLASTIC3D_CLASS,
053: LAF_JGOODIESV2_PLASTICXP_CLASS, LAF_METOUIA_CLASS,
054: LAF_OYOAHA_CLASS, LAF_SLAF_CLASS };
055:
056: public static Map<String, String> getAvailableLookAndFeels() {
057: // get the possible look & feel classnames
058: HashSet<String> classnames = new HashSet<String>();
059:
060: for (UIManager.LookAndFeelInfo info : UIManager
061: .getInstalledLookAndFeels()) {
062: classnames.add(info.getClassName());
063: }
064:
065: for (String classname : JDK_LAFS) {
066: classnames.add(classname);
067: }
068:
069: // get the list of supported look & feels
070: ArrayList<String> supported_names = new ArrayList<String>();
071: HashMap<String, String> supported_mappings = new HashMap<String, String>();
072: Class<LookAndFeel> laf_class = null;
073: String laf_name = null;
074: LookAndFeel lookandfeel = null;
075: for (String classname : classnames) {
076: try {
077: laf_class = (Class<LookAndFeel>) Class
078: .forName(classname);
079: lookandfeel = laf_class.newInstance();
080: laf_name = lookandfeel.getName();
081:
082: if (lookandfeel.isSupportedLookAndFeel()) {
083: supported_names.add(laf_name);
084: supported_mappings.put(laf_name, classname);
085: }
086: } catch (Throwable exception) {
087: // If anything weird happens, just continue and ignore it
088: }
089: }
090:
091: // sort them
092: SortListComparables sort = new SortListComparables();
093: sort.sort(supported_names);
094:
095: // put them in a linked hashmap
096: LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
097: for (String name : supported_names) {
098: result.put(name, supported_mappings.get(name));
099: }
100:
101: return result;
102: }
103: }
|