jdk/src/java.desktop/share/classes/javax/swing/UIDefaults.java
changeset 36511 9d0388c6b336
parent 30464 929bafd0db6f
child 37714 7a0b1c7e7054
equal deleted inserted replaced
36510:043f1af70518 36511:9d0388c6b336
    28 
    28 
    29 import javax.swing.plaf.ComponentUI;
    29 import javax.swing.plaf.ComponentUI;
    30 import javax.swing.border.*;
    30 import javax.swing.border.*;
    31 import javax.swing.event.SwingPropertyChangeSupport;
    31 import javax.swing.event.SwingPropertyChangeSupport;
    32 
    32 
       
    33 import java.io.IOException;
       
    34 import java.io.InputStream;
       
    35 import java.io.UncheckedIOException;
    33 import java.lang.reflect.*;
    36 import java.lang.reflect.*;
    34 import java.util.HashMap;
    37 import java.util.HashMap;
    35 import java.util.Map;
    38 import java.util.Map;
    36 import java.util.Enumeration;
    39 import java.util.Enumeration;
    37 import java.util.Hashtable;
    40 import java.util.Hashtable;
    38 import java.util.ResourceBundle;
    41 import java.util.ResourceBundle;
    39 import java.util.ResourceBundle.Control;
       
    40 import java.util.Locale;
    42 import java.util.Locale;
    41 import java.util.Vector;
    43 import java.util.Vector;
    42 import java.util.MissingResourceException;
    44 import java.util.MissingResourceException;
    43 import java.awt.Font;
    45 import java.awt.Font;
    44 import java.awt.Color;
    46 import java.awt.Color;
    50 import java.security.PrivilegedAction;
    52 import java.security.PrivilegedAction;
    51 
    53 
    52 import sun.reflect.misc.MethodUtil;
    54 import sun.reflect.misc.MethodUtil;
    53 import sun.reflect.misc.ReflectUtil;
    55 import sun.reflect.misc.ReflectUtil;
    54 import sun.swing.SwingUtilities2;
    56 import sun.swing.SwingUtilities2;
    55 import sun.util.CoreResourceBundleControl;
       
    56 
    57 
    57 /**
    58 /**
    58  * A table of defaults for Swing components.  Applications can set/get
    59  * A table of defaults for Swing components.  Applications can set/get
    59  * default values via the <code>UIManager</code>.
    60  * default values via the <code>UIManager</code>.
    60  * <p>
    61  * <p>
   300         if (values == null) {
   301         if (values == null) {
   301             values = new TextAndMnemonicHashMap();
   302             values = new TextAndMnemonicHashMap();
   302             for (int i=resourceBundles.size()-1; i >= 0; i--) {
   303             for (int i=resourceBundles.size()-1; i >= 0; i--) {
   303                 String bundleName = resourceBundles.get(i);
   304                 String bundleName = resourceBundles.get(i);
   304                 try {
   305                 try {
   305                     Control c = CoreResourceBundleControl.getRBControlInstance(bundleName);
       
   306                     ResourceBundle b;
   306                     ResourceBundle b;
   307                     if (c != null) {
   307                     if (isDesktopResourceBundle(bundleName)) {
   308                         b = ResourceBundle.getBundle(bundleName, l, c);
   308                         // load resource bundle from java.desktop module
       
   309                         b = ResourceBundle.getBundle(bundleName, l, UIDefaults.class.getModule());
   309                     } else {
   310                     } else {
   310                         b = ResourceBundle.getBundle(bundleName, l);
   311                         b = ResourceBundle.getBundle(bundleName, l, ClassLoader.getSystemClassLoader());
   311                     }
   312                     }
   312                     Enumeration<String> keys = b.getKeys();
   313                     Enumeration<String> keys = b.getKeys();
   313 
   314 
   314                     while (keys.hasMoreElements()) {
   315                     while (keys.hasMoreElements()) {
   315                         String key = keys.nextElement();
   316                         String key = keys.nextElement();
   325                 }
   326                 }
   326             }
   327             }
   327             resourceCache.put(l, values);
   328             resourceCache.put(l, values);
   328         }
   329         }
   329         return values;
   330         return values;
       
   331     }
       
   332 
       
   333     /*
       
   334      * Test if the specified baseName of the ROOT locale is in java.desktop module.
       
   335      * JDK always defines the resource bundle of the ROOT locale.
       
   336      */
       
   337     private static boolean isDesktopResourceBundle(String baseName) {
       
   338         Module thisModule = UIDefaults.class.getModule();
       
   339         return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
       
   340             @Override
       
   341             public Boolean run() {
       
   342                 Class<?> c = Class.forName(thisModule, baseName);
       
   343                 if (c != null) {
       
   344                     return true;
       
   345                 } else {
       
   346                     String resourceName = baseName.replace('.', '/') + ".properties";
       
   347                     try (InputStream in = thisModule.getResourceAsStream(resourceName)) {
       
   348                         return in != null;
       
   349                     } catch (IOException e) {
       
   350                         throw new UncheckedIOException(e);
       
   351                     }
       
   352                 }
       
   353             }
       
   354         });
   330     }
   355     }
   331 
   356 
   332     /**
   357     /**
   333      * Sets the value of <code>key</code> to <code>value</code> for all locales.
   358      * Sets the value of <code>key</code> to <code>value</code> for all locales.
   334      * If <code>key</code> is a string and the new value isn't
   359      * If <code>key</code> is a string and the new value isn't
   765                 Method m = (Method)get(uiClass);
   790                 Method m = (Method)get(uiClass);
   766                 if (m == null) {
   791                 if (m == null) {
   767                     m = uiClass.getMethod("createUI", new Class<?>[]{JComponent.class});
   792                     m = uiClass.getMethod("createUI", new Class<?>[]{JComponent.class});
   768                     put(uiClass, m);
   793                     put(uiClass, m);
   769                 }
   794                 }
   770                 uiObject = MethodUtil.invoke(m, null, new Object[]{target});
   795 
       
   796                 if (uiClass.getModule() == ComponentUI.class.getModule()) {
       
   797                     // uiClass is a system LAF if it's in java.desktop module
       
   798                     uiObject = m.invoke(null, new Object[]{target});
       
   799                 } else {
       
   800                     uiObject = MethodUtil.invoke(m, null, new Object[]{target});
       
   801                 }
   771             }
   802             }
   772             catch (NoSuchMethodException e) {
   803             catch (NoSuchMethodException e) {
   773                 getUIError("static createUI() method not found in " + uiClass);
   804                 getUIError("static createUI() method not found in " + uiClass);
   774             }
   805             }
   775             catch (Exception e) {
   806             catch (Exception e) {