1 19 24 25 package org.netbeans.swing.plaf.util; 26 27 import javax.swing.*; 28 29 54 public class UIBootstrapValue implements UIDefaults.LazyValue { 55 private boolean installed = false; 56 private final String uiClassName; 57 protected Object [] defaults; 58 59 public UIBootstrapValue(String uiClassName, Object [] defaults) { 60 this.defaults = defaults; 61 this.uiClassName = uiClassName; 62 } 63 64 68 public Object createValue(UIDefaults uidefaults) { 69 if (!installed) { 70 installKeysAndValues(uidefaults); 71 } 72 return uiClassName; 73 } 74 75 76 private void installKeysAndValues(UIDefaults ui) { 77 ui.putDefaults (getKeysAndValues()); 78 installed = true; 79 } 80 81 public Object [] getKeysAndValues() { 82 return defaults; 83 } 84 85 public void uninstall() { 86 if (defaults == null) { 87 return; 88 } 89 for (int i=0; i < defaults.length; i+=2) { 90 UIManager.put (defaults[i], null); 91 } 92 defaults = null; 94 } 95 96 public String toString() { 97 return getClass() + " for " + uiClassName; } 99 100 103 public UIDefaults.LazyValue createShared (String uiClassName) { 104 return new Meta (uiClassName); 105 } 106 107 private class Meta implements UIDefaults.LazyValue { 108 private String name; 109 public Meta (String uiClassName) { 110 this.name = uiClassName; 111 } 112 113 public Object createValue(javax.swing.UIDefaults uidefaults) { 114 if (!installed) { 115 installKeysAndValues(uidefaults); 116 } 117 return name; 118 } 119 120 public String toString() { 121 return "Meta-" + super.toString() + " for " + uiClassName; } 123 } 124 125 public abstract static class Lazy extends UIBootstrapValue implements UIDefaults.LazyValue { 126 public Lazy (String uiClassName) { 127 super (uiClassName, null); 128 } 129 130 public Object [] getKeysAndValues() { 131 if (defaults == null) { 132 defaults = createKeysAndValues(); 133 } 134 return defaults; 135 } 136 137 public abstract Object [] createKeysAndValues(); 138 139 } 140 } 141 | Popular Tags |