1 19 24 25 package org.netbeans.swing.plaf.util; 26 27 import javax.swing.*; 28 import java.awt.*; 29 30 57 public class GuaranteedValue implements UIDefaults.LazyValue { 58 private Object value; 59 60 public GuaranteedValue(String key, Object fallback) { 61 if (key == null || fallback == null) { 63 throw new NullPointerException ("Null parameters: " + key + ',' + fallback); 64 } 65 66 value = UIManager.get(key); 67 if (value == null) { 68 value = fallback; 69 } 70 } 71 72 public GuaranteedValue(String [] keys, Object fallback) { 73 if (keys == null || fallback == null) { 75 throw new NullPointerException ("Null parameters: " + keys + ',' + fallback); 76 } 77 for (int i=0; i < keys.length; i++) { 78 value = UIManager.get(keys[i]); 79 if (value != null) { 80 break; 81 } 82 } 83 if (value == null) { 84 value = fallback; 85 } 86 } 87 88 public Object createValue(UIDefaults table) { 89 return value; 90 } 91 92 94 public Color getColor() { 95 Object o = createValue(null); 96 if (o instanceof Color) { 97 return (Color) o; 98 } else { 99 return null; 100 } 101 } 102 103 public Font getFont() { 104 Object o = createValue(null); 105 if (o instanceof Font) { 106 return (Font) o; 107 } else { 108 return null; 109 } 110 } 111 } 112 | Popular Tags |