1 19 20 package org.netbeans.modules.properties; 21 22 import java.awt.Color ; 23 import java.awt.Event ; 24 import java.awt.Font ; 25 import java.awt.SystemColor ; 26 import java.awt.event.KeyEvent ; 27 import java.beans.PropertyChangeListener ; 28 import java.beans.PropertyChangeSupport ; 29 import javax.swing.KeyStroke ; 30 import javax.swing.UIManager ; 31 import org.openide.util.Lookup; 32 import org.openide.util.LookupEvent; 33 import org.openide.util.LookupListener; 34 35 40 public abstract class TableViewSettings { 41 42 43 public static final Color KEY_DEFAULT_COLOR = new Color (0, 0, 153); 44 45 public static final Color KEY_DEFAULT_BACKGROUND = Color.white; 46 47 public static final Color VALUE_DEFAULT_COLOR = new Color (153, 0, 107); 48 49 public static final Color VALUE_DEFAULT_BACKGROUND = Color.white; 50 51 public static final Color HIGHLIGHT_DEFAULT_COLOR = Color.black; 52 53 public static final Color HIGHLIGHT_DEFAULT_BACKGROUND = Color.yellow; 54 55 public static final Color SHADOW_DEFAULT_COLOR = new Color (SystemColor.controlHighlight.getRGB()); 56 57 public static final KeyStroke [] FIND_NEXT_DEFAULT_KEYSTROKES = new KeyStroke [] {KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)}; 58 59 public static final KeyStroke [] FIND_PREVIOUS_DEFAULT_KEYSTROKES = new KeyStroke [] {KeyStroke.getKeyStroke(KeyEvent.VK_F3, Event.SHIFT_MASK)}; 60 61 public static final KeyStroke [] TOGGLE_HIGHLIGHT_DEFAULT_KEYSTROKES = new KeyStroke [] {KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.SHIFT_MASK | Event.ALT_MASK)}; 62 63 private static DelegatingSettings delegatingSettings; 65 66 private static Lookup.Result<TableViewSettings> registrations; 68 69 72 protected TableViewSettings() { 73 } 74 75 80 public synchronized static TableViewSettings getDefault() { 81 82 if (delegatingSettings == null) { 83 Lookup lookup = Lookup.getDefault(); 84 Lookup.Template<TableViewSettings> template = new Lookup.Template<TableViewSettings>(TableViewSettings.class); 85 registrations = lookup.lookup(template); 86 registrations.addLookupListener(new LookupListener() { 87 public void resultChanged(LookupEvent e) { 88 TableViewSettings peer = null; 89 if (registrations.allInstances().isEmpty()) { 90 peer = new HardcodedSettings(); 91 } else { 92 peer = registrations.allInstances().iterator().next(); 93 } 94 delegatingSettings.setPeer(peer); 95 } 96 }); 97 TableViewSettings peer = null; 98 if (registrations.allInstances().isEmpty()) { 99 peer = new HardcodedSettings(); 100 } else { 101 peer = registrations.allInstances().iterator().next(); 102 } 103 delegatingSettings = new DelegatingSettings(peer); 104 } 105 106 return delegatingSettings; 107 } 108 109 111 public abstract Color getKeyColor(); 112 public abstract Color getKeyBackground(); 113 public abstract Color getValueColor(); 114 public abstract Color getValueBackground(); 115 public abstract Color getHighlightColor(); 116 public abstract Color getHighlightBackground(); 117 public abstract Color getShadowColor(); 118 public abstract Font getFont(); 119 120 public abstract KeyStroke [] getKeyStrokesFindNext(); 121 public abstract KeyStroke [] getKeyStrokesFindPrevious(); 122 public abstract KeyStroke [] getKeyStrokesToggleHighlight(); 123 124 public abstract void addPropertyChangeListener(PropertyChangeListener listener); 125 public abstract void removePropertyChangeListener(PropertyChangeListener listener); 126 127 131 private static class DelegatingSettings extends TableViewSettings implements PropertyChangeListener { 132 133 private PropertyChangeSupport events = new PropertyChangeSupport (this); 134 135 private TableViewSettings peer; 136 137 DelegatingSettings(TableViewSettings peer) { 138 this.peer = peer; 139 peer.addPropertyChangeListener(this); 140 } 141 142 void setPeer(TableViewSettings peer) { 143 this.peer.removePropertyChangeListener(this); 144 this.peer = peer; 145 this.peer.addPropertyChangeListener(this); 146 events.firePropertyChange(null, null, null); 148 } 149 150 public void addPropertyChangeListener(PropertyChangeListener listener) { 151 events.addPropertyChangeListener(listener); 152 } 153 154 public Color getHighlightBackground() { 155 return peer.getHighlightBackground(); 156 } 157 158 public Color getHighlightColor() { 159 return peer.getHighlightColor(); 160 } 161 162 public Color getKeyBackground() { 163 return peer.getKeyBackground(); 164 } 165 166 public Color getKeyColor() { 167 return peer.getKeyColor(); 168 } 169 170 public Font getFont() { 171 return peer.getFont(); 172 } 173 174 public KeyStroke [] getKeyStrokesFindNext() { 175 return peer.getKeyStrokesFindNext(); 176 } 177 178 public KeyStroke [] getKeyStrokesFindPrevious() { 179 return peer.getKeyStrokesFindPrevious(); 180 } 181 182 public KeyStroke [] getKeyStrokesToggleHighlight() { 183 return peer.getKeyStrokesToggleHighlight(); 184 } 185 186 public Color getShadowColor() { 187 return peer.getShadowColor(); 188 } 189 190 public Color getValueBackground() { 191 return peer.getValueBackground(); 192 } 193 194 public Color getValueColor() { 195 return peer.getValueColor(); 196 } 197 198 public void removePropertyChangeListener(PropertyChangeListener listener) { 199 events.removePropertyChangeListener(listener); 200 } 201 202 public void propertyChange(java.beans.PropertyChangeEvent evt) { 203 events.firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); 204 } 205 206 } 207 208 211 private static class HardcodedSettings extends TableViewSettings { 212 public Color getKeyColor() {return KEY_DEFAULT_COLOR;} 213 public Color getKeyBackground() {return KEY_DEFAULT_BACKGROUND;} 214 public Color getValueColor() {return VALUE_DEFAULT_COLOR;} 215 public Color getValueBackground() {return VALUE_DEFAULT_BACKGROUND;} 216 public Color getHighlightColor() {return HIGHLIGHT_DEFAULT_COLOR;} 217 public Color getHighlightBackground() {return HIGHLIGHT_DEFAULT_BACKGROUND;} 218 public Color getShadowColor() { return SHADOW_DEFAULT_COLOR;} 219 public Font getFont() { return UIManager.getFont("TextField.font"); } 220 221 public KeyStroke [] getKeyStrokesFindNext() {return FIND_NEXT_DEFAULT_KEYSTROKES;} 222 public KeyStroke [] getKeyStrokesFindPrevious() {return FIND_PREVIOUS_DEFAULT_KEYSTROKES;} 223 public KeyStroke [] getKeyStrokesToggleHighlight() {return TOGGLE_HIGHLIGHT_DEFAULT_KEYSTROKES;} 224 225 public void addPropertyChangeListener(PropertyChangeListener listener) {} 226 public void removePropertyChangeListener(PropertyChangeListener listener) {} 227 } 228 } 229 | Popular Tags |