Mercurial > projects > dwt2
comparison org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContext.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 | |
14 | |
15 module org.eclipse.jface.text.formatter.FormattingContext; | |
16 | |
17 import org.eclipse.jface.text.formatter.MultiPassContentFormatter; // packageimport | |
18 import org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy; // packageimport | |
19 import org.eclipse.jface.text.formatter.IFormattingStrategy; // packageimport | |
20 import org.eclipse.jface.text.formatter.IContentFormatterExtension; // packageimport | |
21 import org.eclipse.jface.text.formatter.IFormattingStrategyExtension; // packageimport | |
22 import org.eclipse.jface.text.formatter.IContentFormatter; // packageimport | |
23 import org.eclipse.jface.text.formatter.FormattingContextProperties; // packageimport | |
24 import org.eclipse.jface.text.formatter.ContentFormatter; // packageimport | |
25 import org.eclipse.jface.text.formatter.IFormattingContext; // packageimport | |
26 | |
27 import java.lang.all; | |
28 import java.util.Map; | |
29 import java.util.HashMap; | |
30 import java.util.Set; | |
31 | |
32 | |
33 | |
34 import org.eclipse.jface.preference.IPreferenceStore; | |
35 | |
36 /** | |
37 * Default implementation of <code>IFormattingContext</code>. | |
38 * | |
39 * @since 3.0 | |
40 */ | |
41 public class FormattingContext : IFormattingContext { | |
42 | |
43 /** Map to store the properties */ | |
44 private const Map fMap; | |
45 | |
46 this(){ | |
47 fMap= new HashMap(); | |
48 } | |
49 | |
50 /* | |
51 * @see org.eclipse.jface.text.formatter.IFormattingContext#dispose() | |
52 */ | |
53 public void dispose() { | |
54 fMap.clear(); | |
55 } | |
56 | |
57 /* | |
58 * @see org.eclipse.jface.text.formatter.IFormattingContext#getPreferenceKeys() | |
59 */ | |
60 public String[] getPreferenceKeys() { | |
61 return null; | |
62 } | |
63 | |
64 /* | |
65 * @see org.eclipse.jface.text.formatter.IFormattingContext#getProperty(java.lang.Object) | |
66 */ | |
67 public Object getProperty(Object key) { | |
68 return fMap.get(key); | |
69 } | |
70 | |
71 /* | |
72 * @see org.eclipse.jface.text.formatter.IFormattingContext#isBooleanPreference(java.lang.String) | |
73 */ | |
74 public bool isBooleanPreference(String key) { | |
75 return false; | |
76 } | |
77 | |
78 /* | |
79 * @see org.eclipse.jface.text.formatter.IFormattingContext#isDoublePreference(java.lang.String) | |
80 */ | |
81 public bool isDoublePreference(String key) { | |
82 return false; | |
83 } | |
84 | |
85 /* | |
86 * @see org.eclipse.jface.text.formatter.IFormattingContext#isFloatPreference(java.lang.String) | |
87 */ | |
88 public bool isFloatPreference(String key) { | |
89 return false; | |
90 } | |
91 | |
92 /* | |
93 * @see org.eclipse.jface.text.formatter.IFormattingContext#isIntegerPreference(java.lang.String) | |
94 */ | |
95 public bool isIntegerPreference(String key) { | |
96 return false; | |
97 } | |
98 | |
99 /* | |
100 * @see org.eclipse.jface.text.formatter.IFormattingContext#isLongPreference(java.lang.String) | |
101 */ | |
102 public bool isLongPreference(String key) { | |
103 return false; | |
104 } | |
105 | |
106 /* | |
107 * @see org.eclipse.jface.text.formatter.IFormattingContext#isStringPreference(java.lang.String) | |
108 */ | |
109 public bool isStringPreference(String key) { | |
110 return false; | |
111 } | |
112 | |
113 /* | |
114 * @see org.eclipse.jface.text.formatter.IFormattingContext#mapToStore(java.util.Map, org.eclipse.jface.preference.IPreferenceStore) | |
115 */ | |
116 public void mapToStore(Map map, IPreferenceStore store) { | |
117 | |
118 final String[] preferences= getPreferenceKeys(); | |
119 | |
120 String result= null; | |
121 String preference= null; | |
122 | |
123 for (int index= 0; index < preferences.length; index++) { | |
124 | |
125 preference= preferences[index]; | |
126 result= stringcast(map.get(preference)); | |
127 | |
128 if (result !is null) { | |
129 | |
130 try { | |
131 if (isBooleanPreference(preference)) { | |
132 store.setValue(preference, result.equals(IPreferenceStore.TRUE)); | |
133 } else if (isIntegerPreference(preference)) { | |
134 store.setValue(preference, Integer.parseInt(result)); | |
135 } else if (isStringPreference(preference)) { | |
136 store.setValue(preference, result); | |
137 } else if (isDoublePreference(preference)) { | |
138 store.setValue(preference, Double.parseDouble(result)); | |
139 } else if (isFloatPreference(preference)) { | |
140 store.setValue(preference, Float.parseFloat(result)); | |
141 } else if (isLongPreference(preference)) { | |
142 store.setValue(preference, Long.parseLong(result)); | |
143 } | |
144 } catch (NumberFormatException exception) { | |
145 // Do nothing | |
146 } | |
147 } | |
148 } | |
149 } | |
150 | |
151 /* | |
152 * @see org.eclipse.jface.text.formatter.IFormattingContext#setProperty(java.lang.Object, java.lang.Object) | |
153 */ | |
154 public void setProperty(Object key, Object property) { | |
155 fMap.put(key, property); | |
156 } | |
157 | |
158 /* | |
159 * @see org.eclipse.jface.text.formatter.IFormattingContext#storeToMap(org.eclipse.jface.preference.IPreferenceStore, java.util.Map, bool) | |
160 */ | |
161 public void storeToMap(IPreferenceStore store, Map map, bool useDefault) { | |
162 | |
163 final String[] preferences= getPreferenceKeys(); | |
164 | |
165 String preference= null; | |
166 for (int index= 0; index < preferences.length; index++) { | |
167 | |
168 preference= preferences[index]; | |
169 | |
170 if (isBooleanPreference(preference)) { | |
171 map.put(preference, (useDefault ? store.getDefaultBoolean(preference) : store.getBoolean(preference)) ? IPreferenceStore.TRUE : IPreferenceStore.FALSE); | |
172 } else if (isIntegerPreference(preference)) { | |
173 map.put(preference, String_valueOf(useDefault ? store.getDefaultInt(preference) : store.getInt(preference))); | |
174 } else if (isStringPreference(preference)) { | |
175 map.put(preference, useDefault ? store.getDefaultString(preference) : store.getString(preference)); | |
176 } else if (isDoublePreference(preference)) { | |
177 map.put(preference, String_valueOf(useDefault ? store.getDefaultDouble(preference) : store.getDouble(preference))); | |
178 } else if (isFloatPreference(preference)) { | |
179 map.put(preference, String_valueOf(useDefault ? store.getDefaultFloat(preference) : store.getFloat(preference))); | |
180 } else if (isLongPreference(preference)) { | |
181 map.put(preference, String_valueOf(useDefault ? store.getDefaultLong(preference) : store.getLong(preference))); | |
182 } | |
183 } | |
184 } | |
185 } |