1 11 12 package org.eclipse.jface.text.formatter; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.jface.preference.IPreferenceStore; 18 19 24 public class FormattingContext implements IFormattingContext { 25 26 27 private final Map fMap= new HashMap (); 28 29 32 public void dispose() { 33 fMap.clear(); 34 } 35 36 39 public String [] getPreferenceKeys() { 40 return new String [] { 41 }; 42 } 43 44 47 public Object getProperty(Object key) { 48 return fMap.get(key); 49 } 50 51 54 public boolean isBooleanPreference(String key) { 55 return false; 56 } 57 58 61 public boolean isDoublePreference(String key) { 62 return false; 63 } 64 65 68 public boolean isFloatPreference(String key) { 69 return false; 70 } 71 72 75 public boolean isIntegerPreference(String key) { 76 return false; 77 } 78 79 82 public boolean isLongPreference(String key) { 83 return false; 84 } 85 86 89 public boolean isStringPreference(String key) { 90 return false; 91 } 92 93 96 public void mapToStore(Map map, IPreferenceStore store) { 97 98 final String [] preferences= getPreferenceKeys(); 99 100 String result= null; 101 String preference= null; 102 103 for (int index= 0; index < preferences.length; index++) { 104 105 preference= preferences[index]; 106 result= (String )map.get(preference); 107 108 if (result != null) { 109 110 try { 111 if (isBooleanPreference(preference)) { 112 store.setValue(preference, result.equals(IPreferenceStore.TRUE)); 113 } else if (isIntegerPreference(preference)) { 114 store.setValue(preference, Integer.parseInt(result)); 115 } else if (isStringPreference(preference)) { 116 store.setValue(preference, result); 117 } else if (isDoublePreference(preference)) { 118 store.setValue(preference, Double.parseDouble(result)); 119 } else if (isFloatPreference(preference)) { 120 store.setValue(preference, Float.parseFloat(result)); 121 } else if (isLongPreference(preference)) { 122 store.setValue(preference, Long.parseLong(result)); 123 } 124 } catch (NumberFormatException exception) { 125 } 127 } 128 } 129 } 130 131 134 public void setProperty(Object key, Object property) { 135 fMap.put(key, property); 136 } 137 138 141 public void storeToMap(IPreferenceStore store, Map map, boolean useDefault) { 142 143 final String [] preferences= getPreferenceKeys(); 144 145 String preference= null; 146 for (int index= 0; index < preferences.length; index++) { 147 148 preference= preferences[index]; 149 150 if (isBooleanPreference(preference)) { 151 map.put(preference, (useDefault ? store.getDefaultBoolean(preference) : store.getBoolean(preference)) ? IPreferenceStore.TRUE : IPreferenceStore.FALSE); 152 } else if (isIntegerPreference(preference)) { 153 map.put(preference, String.valueOf(useDefault ? store.getDefaultInt(preference) : store.getInt(preference))); 154 } else if (isStringPreference(preference)) { 155 map.put(preference, useDefault ? store.getDefaultString(preference) : store.getString(preference)); 156 } else if (isDoublePreference(preference)) { 157 map.put(preference, String.valueOf(useDefault ? store.getDefaultDouble(preference) : store.getDouble(preference))); 158 } else if (isFloatPreference(preference)) { 159 map.put(preference, String.valueOf(useDefault ? store.getDefaultFloat(preference) : store.getFloat(preference))); 160 } else if (isLongPreference(preference)) { 161 map.put(preference, String.valueOf(useDefault ? store.getDefaultLong(preference) : store.getLong(preference))); 162 } 163 } 164 } 165 } 166 | Popular Tags |