< prev index next >

src/java.desktop/share/classes/javax/swing/UIManager.java

Print this page




 562      *        the look and feel
 563      * @exception ClassNotFoundException if the <code>LookAndFeel</code>
 564      *           class could not be found
 565      * @exception InstantiationException if a new instance of the class
 566      *          couldn't be created
 567      * @exception IllegalAccessException if the class or initializer isn't accessible
 568      * @exception UnsupportedLookAndFeelException if
 569      *          <code>lnf.isSupportedLookAndFeel()</code> is false
 570      * @throws ClassCastException if {@code className} does not identify
 571      *         a class that extends {@code LookAndFeel}
 572      */
 573     public static void setLookAndFeel(String className)
 574         throws ClassNotFoundException,
 575                InstantiationException,
 576                IllegalAccessException,
 577                UnsupportedLookAndFeelException
 578     {
 579         if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(className)) {
 580             // Avoid reflection for the common case of metal.
 581             setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
 582         }
 583         else {
 584             Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
 585             setLookAndFeel((LookAndFeel)(lnfClass.newInstance()));


 586         }
 587     }
 588 
 589     /**
 590      * Returns the name of the <code>LookAndFeel</code> class that implements
 591      * the native system look and feel if there is one, otherwise
 592      * the name of the default cross platform <code>LookAndFeel</code>
 593      * class. This value can be overriden by setting the
 594      * <code>swing.systemlaf</code> system property.
 595      *
 596      * @return the <code>String</code> of the <code>LookAndFeel</code>
 597      *          class
 598      *
 599      * @see #setLookAndFeel
 600      * @see #getCrossPlatformLookAndFeelClassName
 601      */
 602     public static String getSystemLookAndFeelClassName() {
 603         String systemLAF = AccessController.doPrivileged(
 604                              new GetPropertyAction("swing.systemlaf"));
 605         if (systemLAF != null) {


1032      *
1033      * @return <code>UIDefaults</code> from the current look and feel
1034      * @see #getDefaults
1035      * @see #setLookAndFeel(LookAndFeel)
1036      * @see LookAndFeel#getDefaults
1037      */
1038     public static UIDefaults getLookAndFeelDefaults() {
1039         maybeInitialize();
1040         return getLAFState().getLookAndFeelDefaults();
1041     }
1042 
1043     /**
1044      * Finds the Multiplexing <code>LookAndFeel</code>.
1045      */
1046     private static LookAndFeel getMultiLookAndFeel() {
1047         LookAndFeel multiLookAndFeel = getLAFState().multiLookAndFeel;
1048         if (multiLookAndFeel == null) {
1049             String defaultName = "javax.swing.plaf.multi.MultiLookAndFeel";
1050             String className = getLAFState().swingProps.getProperty(multiplexingLAFKey, defaultName);
1051             try {
1052                 Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
1053                 multiLookAndFeel = (LookAndFeel)lnfClass.newInstance();

1054             } catch (Exception exc) {
1055                 System.err.println("UIManager: failed loading " + className);
1056             }
1057         }
1058         return multiLookAndFeel;
1059     }
1060 
1061     /**
1062      * Adds a <code>LookAndFeel</code> to the list of auxiliary look and feels.
1063      * The auxiliary look and feels tell the multiplexing look and feel what
1064      * other <code>LookAndFeel</code> classes for a component instance are to be used
1065      * in addition to the default <code>LookAndFeel</code> class when creating a
1066      * multiplexing UI.  The change will only take effect when a new
1067      * UI class is created or when the default look and feel is changed
1068      * on a component instance.
1069      * <p>Note these are not the same as the installed look and feels.
1070      *
1071      * @param laf the <code>LookAndFeel</code> object
1072      * @see #removeAuxiliaryLookAndFeel
1073      * @see #setLookAndFeel


1367 
1368     private static void initializeAuxiliaryLAFs(Properties swingProps)
1369     {
1370         String auxLookAndFeelNames = swingProps.getProperty(auxiliaryLAFsKey);
1371         if (auxLookAndFeelNames == null) {
1372             return;
1373         }
1374 
1375         Vector<LookAndFeel> auxLookAndFeels = new Vector<LookAndFeel>();
1376 
1377         StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,",");
1378         String factoryName;
1379 
1380         /* Try to load each LookAndFeel subclass in the list.
1381          */
1382 
1383         while (p.hasMoreTokens()) {
1384             String className = p.nextToken();
1385             try {
1386                 Class<?> lnfClass = SwingUtilities.loadSystemClass(className);

1387                 LookAndFeel newLAF = (LookAndFeel)lnfClass.newInstance();
1388                 newLAF.initialize();
1389                 auxLookAndFeels.addElement(newLAF);
1390             }
1391             catch (Exception e) {
1392                 System.err.println("UIManager: failed loading auxiliary look and feel " + className);
1393             }
1394         }
1395 
1396         /* If there were problems and no auxiliary look and feels were
1397          * loaded, make sure we reset auxLookAndFeels to null.
1398          * Otherwise, we are going to use the MultiLookAndFeel to get
1399          * all component UI's, so we need to load it now.
1400          */
1401         if (auxLookAndFeels.size() == 0) {
1402             auxLookAndFeels = null;
1403         }
1404         else {
1405             getLAFState().multiLookAndFeel = getMultiLookAndFeel();
1406             if (getLAFState().multiLookAndFeel == null) {




 562      *        the look and feel
 563      * @exception ClassNotFoundException if the <code>LookAndFeel</code>
 564      *           class could not be found
 565      * @exception InstantiationException if a new instance of the class
 566      *          couldn't be created
 567      * @exception IllegalAccessException if the class or initializer isn't accessible
 568      * @exception UnsupportedLookAndFeelException if
 569      *          <code>lnf.isSupportedLookAndFeel()</code> is false
 570      * @throws ClassCastException if {@code className} does not identify
 571      *         a class that extends {@code LookAndFeel}
 572      */
 573     public static void setLookAndFeel(String className)
 574         throws ClassNotFoundException,
 575                InstantiationException,
 576                IllegalAccessException,
 577                UnsupportedLookAndFeelException
 578     {
 579         if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(className)) {
 580             // Avoid reflection for the common case of metal.
 581             setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
 582         } else {

 583             Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
 584             @SuppressWarnings("deprecation")
 585             LookAndFeel laf = (LookAndFeel)(lnfClass.newInstance());
 586             setLookAndFeel(laf);
 587         }
 588     }
 589 
 590     /**
 591      * Returns the name of the <code>LookAndFeel</code> class that implements
 592      * the native system look and feel if there is one, otherwise
 593      * the name of the default cross platform <code>LookAndFeel</code>
 594      * class. This value can be overriden by setting the
 595      * <code>swing.systemlaf</code> system property.
 596      *
 597      * @return the <code>String</code> of the <code>LookAndFeel</code>
 598      *          class
 599      *
 600      * @see #setLookAndFeel
 601      * @see #getCrossPlatformLookAndFeelClassName
 602      */
 603     public static String getSystemLookAndFeelClassName() {
 604         String systemLAF = AccessController.doPrivileged(
 605                              new GetPropertyAction("swing.systemlaf"));
 606         if (systemLAF != null) {


1033      *
1034      * @return <code>UIDefaults</code> from the current look and feel
1035      * @see #getDefaults
1036      * @see #setLookAndFeel(LookAndFeel)
1037      * @see LookAndFeel#getDefaults
1038      */
1039     public static UIDefaults getLookAndFeelDefaults() {
1040         maybeInitialize();
1041         return getLAFState().getLookAndFeelDefaults();
1042     }
1043 
1044     /**
1045      * Finds the Multiplexing <code>LookAndFeel</code>.
1046      */
1047     private static LookAndFeel getMultiLookAndFeel() {
1048         LookAndFeel multiLookAndFeel = getLAFState().multiLookAndFeel;
1049         if (multiLookAndFeel == null) {
1050             String defaultName = "javax.swing.plaf.multi.MultiLookAndFeel";
1051             String className = getLAFState().swingProps.getProperty(multiplexingLAFKey, defaultName);
1052             try {
1053                 @SuppressWarnings("deprecation")
1054                 Object o = SwingUtilities.loadSystemClass(className).newInstance();
1055                 multiLookAndFeel = (LookAndFeel)o;
1056             } catch (Exception exc) {
1057                 System.err.println("UIManager: failed loading " + className);
1058             }
1059         }
1060         return multiLookAndFeel;
1061     }
1062 
1063     /**
1064      * Adds a <code>LookAndFeel</code> to the list of auxiliary look and feels.
1065      * The auxiliary look and feels tell the multiplexing look and feel what
1066      * other <code>LookAndFeel</code> classes for a component instance are to be used
1067      * in addition to the default <code>LookAndFeel</code> class when creating a
1068      * multiplexing UI.  The change will only take effect when a new
1069      * UI class is created or when the default look and feel is changed
1070      * on a component instance.
1071      * <p>Note these are not the same as the installed look and feels.
1072      *
1073      * @param laf the <code>LookAndFeel</code> object
1074      * @see #removeAuxiliaryLookAndFeel
1075      * @see #setLookAndFeel


1369 
1370     private static void initializeAuxiliaryLAFs(Properties swingProps)
1371     {
1372         String auxLookAndFeelNames = swingProps.getProperty(auxiliaryLAFsKey);
1373         if (auxLookAndFeelNames == null) {
1374             return;
1375         }
1376 
1377         Vector<LookAndFeel> auxLookAndFeels = new Vector<LookAndFeel>();
1378 
1379         StringTokenizer p = new StringTokenizer(auxLookAndFeelNames,",");
1380         String factoryName;
1381 
1382         /* Try to load each LookAndFeel subclass in the list.
1383          */
1384 
1385         while (p.hasMoreTokens()) {
1386             String className = p.nextToken();
1387             try {
1388                 Class<?> lnfClass = SwingUtilities.loadSystemClass(className);
1389                 @SuppressWarnings("deprecation")
1390                 LookAndFeel newLAF = (LookAndFeel)lnfClass.newInstance();
1391                 newLAF.initialize();
1392                 auxLookAndFeels.addElement(newLAF);
1393             }
1394             catch (Exception e) {
1395                 System.err.println("UIManager: failed loading auxiliary look and feel " + className);
1396             }
1397         }
1398 
1399         /* If there were problems and no auxiliary look and feels were
1400          * loaded, make sure we reset auxLookAndFeels to null.
1401          * Otherwise, we are going to use the MultiLookAndFeel to get
1402          * all component UI's, so we need to load it now.
1403          */
1404         if (auxLookAndFeels.size() == 0) {
1405             auxLookAndFeels = null;
1406         }
1407         else {
1408             getLAFState().multiLookAndFeel = getMultiLookAndFeel();
1409             if (getLAFState().multiLookAndFeel == null) {


< prev index next >