jdk/src/share/classes/javax/swing/plaf/nimbus/NimbusStyle.java
changeset 5453 3d39f942ca6e
parent 3741 4021567cd4ca
child 5506 202f599c92aa
equal deleted inserted replaced
5452:6645e1f6569d 5453:3d39f942ca6e
    36 import javax.swing.plaf.synth.SynthPainter;
    36 import javax.swing.plaf.synth.SynthPainter;
    37 import javax.swing.plaf.synth.SynthStyle;
    37 import javax.swing.plaf.synth.SynthStyle;
    38 import java.awt.Color;
    38 import java.awt.Color;
    39 import java.awt.Font;
    39 import java.awt.Font;
    40 import java.awt.Insets;
    40 import java.awt.Insets;
       
    41 import java.lang.ref.WeakReference;
    41 import java.util.ArrayList;
    42 import java.util.ArrayList;
    42 import java.util.Collections;
    43 import java.util.Collections;
    43 import java.util.Comparator;
    44 import java.util.Comparator;
    44 import java.util.HashMap;
    45 import java.util.HashMap;
    45 import java.util.List;
    46 import java.util.List;
   191      * Some NimbusStyles are created for a specific component only. In Nimbus,
   192      * Some NimbusStyles are created for a specific component only. In Nimbus,
   192      * this happens whenever the component has as a client property a
   193      * this happens whenever the component has as a client property a
   193      * UIDefaults which overrides (or supplements) those defaults found in
   194      * UIDefaults which overrides (or supplements) those defaults found in
   194      * UIManager.
   195      * UIManager.
   195      */
   196      */
   196     private JComponent component;
   197     private WeakReference<JComponent> component;
   197 
   198 
   198     /**
   199     /**
   199      * Create a new NimbusStyle. Only the prefix must be supplied. At the
   200      * Create a new NimbusStyle. Only the prefix must be supplied. At the
   200      * appropriate time, installDefaults will be called. At that point, all of
   201      * appropriate time, installDefaults will be called. At that point, all of
   201      * the state information will be pulled from UIManager and stored locally
   202      * the state information will be pulled from UIManager and stored locally
   207      *        should be associated with. This is only used when the component
   208      *        should be associated with. This is only used when the component
   208      *        has Nimbus overrides registered in its client properties and
   209      *        has Nimbus overrides registered in its client properties and
   209      *        should be null otherwise.
   210      *        should be null otherwise.
   210      */
   211      */
   211     NimbusStyle(String prefix, JComponent c) {
   212     NimbusStyle(String prefix, JComponent c) {
   212         this.component = c;
   213         if (c != null) {
       
   214             this.component = new WeakReference<JComponent>(c);
       
   215         }
   213         this.prefix = prefix;
   216         this.prefix = prefix;
   214         this.painter = new SynthPainterImpl(this);
   217         this.painter = new SynthPainterImpl(this);
   215     }
   218     }
   216 
   219 
   217     /**
   220     /**
   249 
   252 
   250         // inspect the client properties for the key "Nimbus.Overrides". If the
   253         // inspect the client properties for the key "Nimbus.Overrides". If the
   251         // value is an instance of UIDefaults, then these defaults are used
   254         // value is an instance of UIDefaults, then these defaults are used
   252         // in place of, or in addition to, the defaults in UIManager.
   255         // in place of, or in addition to, the defaults in UIManager.
   253         if (component != null) {
   256         if (component != null) {
   254             Object o = component.getClientProperty("Nimbus.Overrides");
   257             // We know component.get() is non-null here, as if the component
       
   258             // were GC'ed, we wouldn't be processing its style.
       
   259             Object o = component.get().getClientProperty("Nimbus.Overrides");
   255             if (o instanceof UIDefaults) {
   260             if (o instanceof UIDefaults) {
   256                 Object i = component.getClientProperty(
   261                 Object i = component.get().getClientProperty(
   257                         "Nimbus.Overrides.InheritDefaults");
   262                         "Nimbus.Overrides.InheritDefaults");
   258                 boolean inherit = i instanceof Boolean ? (Boolean)i : true;
   263                 boolean inherit = i instanceof Boolean ? (Boolean)i : true;
   259                 UIDefaults d = (UIDefaults)o;
   264                 UIDefaults d = (UIDefaults)o;
   260                 TreeMap<String, Object> map = new TreeMap<String, Object>();
   265                 TreeMap<String, Object> map = new TreeMap<String, Object>();
   261                 for (Object obj : d.keySet()) {
   266                 for (Object obj : d.keySet()) {