1 11 package org.eclipse.ui.internal.preferences; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.jface.resource.FontRegistry; 17 import org.eclipse.jface.util.IPropertyChangeListener; 18 import org.eclipse.jface.util.PropertyChangeEvent; 19 import org.eclipse.swt.graphics.Color; 20 import org.eclipse.swt.graphics.Font; 21 import org.eclipse.ui.themes.ITheme; 22 23 26 public class ThemeAdapter extends PropertyMapAdapter { 27 28 private ITheme targetTheme; 29 30 private IPropertyChangeListener listener = new IPropertyChangeListener() { 31 public void propertyChange(PropertyChangeEvent event) { 32 firePropertyChange(event.getProperty()); 33 } 34 }; 35 36 public ThemeAdapter(ITheme targetTheme) { 37 this.targetTheme = targetTheme; 38 } 39 40 43 protected void attachListener() { 44 targetTheme.addPropertyChangeListener(listener); 45 } 46 47 50 protected void detachListener() { 51 targetTheme.removePropertyChangeListener(listener); 52 } 53 54 57 public Set keySet() { 58 return getKeySet(targetTheme); 59 } 60 61 64 public Object getValue(String propertyId, Class propertyType) { 65 return getValue(targetTheme, propertyId, propertyType); 66 } 67 68 public static Set getKeySet(ITheme targetTheme) { 69 Set result = new HashSet (); 70 71 result.addAll(targetTheme.keySet()); 72 result.addAll(targetTheme.getColorRegistry().getKeySet()); 73 result.addAll(targetTheme.getFontRegistry().getKeySet()); 74 75 return result; 76 } 77 78 public static Object getValue(ITheme targetTheme, String propertyId, Class propertyType) { 79 80 if (propertyType.isAssignableFrom(String .class)) { 81 return targetTheme.getString(propertyId); 82 } 83 84 if (propertyType.isAssignableFrom(Color.class)) { 85 Color result = targetTheme.getColorRegistry().get(propertyId); 86 if (result != null) { 87 return result; 88 } 89 } 90 91 if (propertyType.isAssignableFrom(Font.class)) { 92 FontRegistry fonts = targetTheme.getFontRegistry(); 93 94 if (fonts.hasValueFor(propertyId)) { 95 return fonts.get(propertyId); 96 } 97 } 98 99 if (propertyType == Integer .class) { 100 return new Integer (targetTheme.getInt(propertyId)); 101 } 102 103 if (propertyType == Boolean .class) { 104 return targetTheme.getBoolean(propertyId) ? Boolean.TRUE : Boolean.FALSE; 105 } 106 107 return null; 108 } 109 110 113 public boolean propertyExists(String propertyId) { 114 return keySet().contains(propertyId); 115 } 116 117 120 public void setValue(String propertyId, Object newValue) { 121 throw new UnsupportedOperationException (); 122 } 123 124 } 125 | Popular Tags |