1 19 20 21 package org.netbeans.modules.properties.syntax; 22 23 24 import java.awt.Color ; 25 import java.awt.Font ; 26 import java.awt.SystemColor ; 27 import java.beans.PropertyChangeEvent ; 28 import java.beans.PropertyChangeListener ; 29 import java.beans.PropertyChangeSupport ; 30 import java.util.HashSet ; 31 import java.util.List ; 32 import java.util.Map ; 33 import javax.swing.KeyStroke ; 34 import javax.swing.text.JTextComponent ; 35 36 import org.netbeans.editor.BaseKit; 37 import org.netbeans.editor.Coloring; 38 import org.netbeans.editor.MultiKeyBinding; 39 import org.netbeans.editor.Settings; 40 import org.netbeans.editor.SettingsChangeEvent; 41 import org.netbeans.editor.SettingsChangeListener; 42 import org.netbeans.editor.SettingsNames; 43 import org.netbeans.editor.SettingsUtil; 44 import org.netbeans.modules.properties.TableViewSettings; 45 46 import org.openide.util.SharedClassObject; 47 48 54 public class EditorSettingsCopy extends TableViewSettings implements SettingsChangeListener { 55 56 57 private static EditorSettingsCopy editorSettingsCopy; 58 59 60 private Color keyColor; 61 62 private Color keyBackground; 63 64 private Color valueColor; 65 66 private Color valueBackground; 67 68 private Color highlightColor; 69 70 private Color highlightBackground; 71 72 private Color shadowColor; 73 74 75 private KeyStroke [] keyStrokesFindNext; 76 77 private KeyStroke [] keyStrokesFindPrevious; 78 79 private KeyStroke [] keyStrokesToggleHighlight; 80 81 82 private final PropertyChangeSupport support = new PropertyChangeSupport (this); 83 84 85 private boolean prepared = false; 86 87 88 89 private EditorSettingsCopy() { 90 } 91 92 93 94 public Color getKeyColor() { 95 prepareSettings(); 96 if(keyColor == null) { 97 keyColor = TableViewSettings.KEY_DEFAULT_COLOR; 98 } 99 100 return keyColor; 101 } 102 103 104 public Color getKeyBackground() { 105 prepareSettings(); 106 if(keyBackground == null) { 107 keyBackground = TableViewSettings.KEY_DEFAULT_BACKGROUND; 108 } 109 110 return keyBackground; 111 } 112 113 114 public Color getValueColor() { 115 prepareSettings(); 116 if(valueColor == null) { 117 valueColor = TableViewSettings.VALUE_DEFAULT_COLOR; 118 } 119 120 return valueColor; 121 } 122 123 124 public Color getValueBackground() { 125 prepareSettings(); 126 if(valueBackground == null) { 127 valueBackground = TableViewSettings.VALUE_DEFAULT_BACKGROUND; 128 } 129 130 return valueBackground; 131 } 132 133 134 public Color getHighlightColor() { 135 prepareSettings(); 136 if(highlightColor == null) { 137 highlightColor = TableViewSettings.HIGHLIGHT_DEFAULT_COLOR; 138 } 139 140 return highlightColor; 141 } 142 143 144 public Color getHighlightBackground() { 145 prepareSettings(); 146 if(highlightBackground == null) { 147 highlightBackground = TableViewSettings.HIGHLIGHT_DEFAULT_BACKGROUND; 148 } 149 150 return highlightBackground; 151 } 152 153 154 public Color getShadowColor() { 155 prepareSettings(); 156 if(shadowColor == null) { 157 shadowColor = TableViewSettings.SHADOW_DEFAULT_COLOR; 158 } 159 160 return shadowColor; 161 } 162 163 public Font getFont() { 164 prepareSettings(); 165 Font font = SettingsUtil.getColoring(PropertiesKit.class, 166 SettingsNames.DEFAULT_COLORING, 167 false).getFont(); 168 return font; 169 } 170 171 172 173 public KeyStroke [] getKeyStrokesFindNext() { 174 prepareSettings(); 175 if(keyStrokesFindNext == null || keyStrokesFindNext.length == 0) { 176 keyStrokesFindNext = TableViewSettings.FIND_NEXT_DEFAULT_KEYSTROKES; 177 } 178 179 return keyStrokesFindNext; 180 } 181 182 183 public KeyStroke [] getKeyStrokesFindPrevious() { 184 prepareSettings(); 185 if(keyStrokesFindPrevious == null || keyStrokesFindPrevious.length == 0) { 186 keyStrokesFindPrevious = TableViewSettings.FIND_PREVIOUS_DEFAULT_KEYSTROKES; 187 } 188 189 return keyStrokesFindPrevious; 190 } 191 192 193 public KeyStroke [] getKeyStrokesToggleHighlight() { 194 prepareSettings(); 195 if(keyStrokesToggleHighlight == null || keyStrokesToggleHighlight.length == 0) { 196 keyStrokesToggleHighlight = TableViewSettings.TOGGLE_HIGHLIGHT_DEFAULT_KEYSTROKES; 197 } 198 199 return keyStrokesToggleHighlight; 200 } 201 202 203 public void settingsUpdated() { 204 if (prepared) { 205 support.firePropertyChange(new PropertyChangeEvent (this, null, null, null)); 206 } 207 } 208 209 210 public void addPropertyChangeListener(PropertyChangeListener listener) { 211 support.addPropertyChangeListener(listener); 212 } 213 214 215 public void removePropertyChangeListener(PropertyChangeListener listener) { 216 support.removePropertyChangeListener(listener); 217 } 218 219 223 public synchronized static EditorSettingsCopy getLayerInstance() { 224 if(editorSettingsCopy == null) { 225 editorSettingsCopy = new EditorSettingsCopy(); 226 } 227 228 return editorSettingsCopy; 229 } 230 231 232 private void prepareSettings() { 233 if (prepared) return; 234 235 Settings.addSettingsChangeListener(this); 237 238 updateSettings(); 240 prepared = true; 241 } 242 243 244 247 public void settingsChange(SettingsChangeEvent evt) { 248 updateSettings(); 250 } 251 252 253 private void updateSettings() { 254 if(updateColors()) 255 updateKeyStrokes(); 256 } 257 258 260 private boolean updateColors() { 261 PropertiesOptions propertiesOptions = (PropertiesOptions)SharedClassObject.findObject(PropertiesOptions.class, false); 262 if(propertiesOptions == null) { 263 return false; 264 } 265 266 Map map = propertiesOptions.getColoringMap(); 268 Coloring keyColoring = (Coloring)map.get(PropertiesTokenContext.contextPath.getFullTokenName( 269 PropertiesTokenContext.KEY)); 270 keyColor = keyColoring.getForeColor(); 271 keyBackground = keyColoring.getBackColor(); 272 273 Coloring valueColoring = (Coloring)map.get(PropertiesTokenContext.contextPath.getFullTokenName( 274 PropertiesTokenContext.VALUE)); 275 valueColor = valueColoring.getForeColor(); 276 valueBackground = valueColoring.getBackColor(); 277 278 Coloring highlightColoring = (Coloring)map.get(SettingsNames.HIGHLIGHT_SEARCH_COLORING); 279 highlightColor = highlightColoring.getForeColor(); 280 highlightBackground = highlightColoring.getBackColor(); 281 282 shadowColor = propertiesOptions.getShadowTableCell(); 283 284 Color defaultForeground = ((Coloring)map.get("default")).getForeColor(); Color defaultBackground = ((Coloring)map.get("default")).getBackColor(); 288 if(keyColor == null) keyColor = defaultForeground; 289 if(keyBackground == null) keyBackground = defaultBackground; 290 if(valueColor == null) valueColor = defaultForeground; 291 if(valueBackground == null) valueBackground = defaultBackground; 292 if(highlightColor == null) highlightColor = new Color (SystemColor.textHighlightText.getRGB()); 293 if(highlightBackground == null) highlightBackground = new Color (SystemColor.textHighlight.getRGB()); 294 if(shadowColor == null) shadowColor = new Color (SystemColor.controlHighlight.getRGB()); 295 296 return true; 297 } 298 299 300 private void updateKeyStrokes() { 301 Settings.KitAndValue kv[] = Settings.getValueHierarchy( 304 PropertiesKit.class, SettingsNames.KEY_BINDING_LIST); 305 306 HashSet nextKS = new HashSet (); 308 HashSet prevKS = new HashSet (); 309 HashSet toggleKS = new HashSet (); 310 for (int i = kv.length - 1; i >= 0; i--) { 312 List keyList = (List )kv[i].value; 313 314 JTextComponent.KeyBinding [] bindings = new JTextComponent.KeyBinding [keyList.size()]; 315 316 keyList.toArray(bindings); 317 318 for(int j=0; j<bindings.length; j++) { 320 JTextComponent.KeyBinding binding = bindings[j]; 321 if(binding == null) 322 continue; 323 324 if(binding.actionName.equals(BaseKit.findNextAction)) { 326 if(binding instanceof MultiKeyBinding && ((MultiKeyBinding)binding).keys != null) 327 for (int k=0; k<((MultiKeyBinding)binding).keys.length; k++) 328 nextKS.add(((MultiKeyBinding)binding).keys[k]); 329 else 330 nextKS.add(binding.key); 331 } 332 if(binding.actionName.equals(BaseKit.findPreviousAction)) { 334 if(binding instanceof MultiKeyBinding && ((MultiKeyBinding)binding).keys != null) 335 for (int k=0; k<((MultiKeyBinding)binding).keys.length; k++) 336 prevKS.add(((MultiKeyBinding)binding).keys[k]); 337 else 338 prevKS.add(binding.key); 339 } 340 if(binding.actionName.equals(BaseKit.toggleHighlightSearchAction)) { 342 if(binding instanceof MultiKeyBinding && ((MultiKeyBinding)binding).keys != null) 343 for (int k=0; k<((MultiKeyBinding)binding).keys.length; k++) 344 toggleKS.add(((MultiKeyBinding)binding).keys[k]); 345 else 346 toggleKS.add(binding.key); 347 } 348 349 } } 352 nextKS.toArray(keyStrokesFindNext = new KeyStroke [nextKS.size()]); 354 prevKS.toArray(keyStrokesFindPrevious = new KeyStroke [prevKS.size()]); 355 toggleKS.toArray(keyStrokesToggleHighlight = new KeyStroke [toggleKS.size()]); 356 357 settingsUpdated(); 359 } 360 361 } 362 | Popular Tags |