1 29 30 package nextapp.echo2.app; 31 32 import java.util.HashMap ; 33 import java.util.Map ; 34 35 37 40 public class MutableStyleSheet 41 implements StyleSheet { 42 43 private Map namedStyleMap = new HashMap (); 44 private Map defaultStyleMap = new HashMap (); 45 46 54 public void addStyle(Class componentClass, String styleName, Style style) { 55 if (styleName == null) { 56 defaultStyleMap.put(componentClass, style); 57 } else { 58 Map styleMap = (Map ) namedStyleMap.get(styleName); 59 if (styleMap == null) { 60 styleMap = new HashMap (); 61 namedStyleMap.put(styleName, styleMap); 62 } 63 styleMap.put(componentClass, style); 64 } 65 } 66 67 74 public void addStyleSheet(MutableStyleSheet styleSheet) { 75 namedStyleMap.putAll(styleSheet.namedStyleMap); 76 defaultStyleMap.putAll(styleSheet.defaultStyleMap); 77 } 78 79 82 public Style getStyle(Class componentClass, String styleName) { 83 if (styleName == null) { 84 while (componentClass != Object .class) { 86 Style style = (Style) defaultStyleMap.get(componentClass); 87 if (style != null) { 88 return style; 89 } 90 componentClass = componentClass.getSuperclass(); 91 } 92 return null; 93 } else { 94 Map styleMap = (Map ) namedStyleMap.get(styleName); 96 if (styleMap == null) { 97 return null; 98 } 99 while (componentClass != Object .class) { 100 Style style = (Style) styleMap.get(componentClass); 101 if (style != null) { 102 return style; 103 } 104 componentClass = componentClass.getSuperclass(); 105 } 106 return null; 107 } 108 } 109 } 110 | Popular Tags |