129
|
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
|
131
|
14
|
|
15 import dwtx.jface.text.formatter.MultiPassContentFormatter; // packageimport
|
|
16 import dwtx.jface.text.formatter.ContextBasedFormattingStrategy; // packageimport
|
|
17 import dwtx.jface.text.formatter.IFormattingStrategy; // packageimport
|
|
18 import dwtx.jface.text.formatter.IContentFormatterExtension; // packageimport
|
|
19 import dwtx.jface.text.formatter.IFormattingStrategyExtension; // packageimport
|
|
20 import dwtx.jface.text.formatter.IContentFormatter; // packageimport
|
|
21 import dwtx.jface.text.formatter.FormattingContextProperties; // packageimport
|
|
22 import dwtx.jface.text.formatter.ContentFormatter; // packageimport
|
|
23 import dwtx.jface.text.formatter.IFormattingContext; // packageimport
|
|
24
|
129
|
25 module dwtx.jface.text.formatter.FormattingContext;
|
|
26
|
|
27 import dwt.dwthelper.utils;
|
|
28
|
|
29 import java.util.HashMap;
|
|
30 import java.util.Map;
|
|
31
|
|
32 import dwtx.jface.preference.IPreferenceStore;
|
|
33
|
|
34 /**
|
|
35 * Default implementation of <code>IFormattingContext</code>.
|
|
36 *
|
|
37 * @since 3.0
|
|
38 */
|
|
39 public class FormattingContext : IFormattingContext {
|
|
40
|
|
41 /** Map to store the properties */
|
|
42 private final Map fMap= new HashMap();
|
|
43
|
|
44 /*
|
|
45 * @see dwtx.jface.text.formatter.IFormattingContext#dispose()
|
|
46 */
|
|
47 public void dispose() {
|
|
48 fMap.clear();
|
|
49 }
|
|
50
|
|
51 /*
|
|
52 * @see dwtx.jface.text.formatter.IFormattingContext#getPreferenceKeys()
|
|
53 */
|
|
54 public String[] getPreferenceKeys() {
|
|
55 return new String[] {
|
|
56 };
|
|
57 }
|
|
58
|
|
59 /*
|
|
60 * @see dwtx.jface.text.formatter.IFormattingContext#getProperty(java.lang.Object)
|
|
61 */
|
|
62 public Object getProperty(Object key) {
|
|
63 return fMap.get(key);
|
|
64 }
|
|
65
|
|
66 /*
|
|
67 * @see dwtx.jface.text.formatter.IFormattingContext#isBooleanPreference(java.lang.String)
|
|
68 */
|
|
69 public bool isBooleanPreference(String key) {
|
|
70 return false;
|
|
71 }
|
|
72
|
|
73 /*
|
|
74 * @see dwtx.jface.text.formatter.IFormattingContext#isDoublePreference(java.lang.String)
|
|
75 */
|
|
76 public bool isDoublePreference(String key) {
|
|
77 return false;
|
|
78 }
|
|
79
|
|
80 /*
|
|
81 * @see dwtx.jface.text.formatter.IFormattingContext#isFloatPreference(java.lang.String)
|
|
82 */
|
|
83 public bool isFloatPreference(String key) {
|
|
84 return false;
|
|
85 }
|
|
86
|
|
87 /*
|
|
88 * @see dwtx.jface.text.formatter.IFormattingContext#isIntegerPreference(java.lang.String)
|
|
89 */
|
|
90 public bool isIntegerPreference(String key) {
|
|
91 return false;
|
|
92 }
|
|
93
|
|
94 /*
|
|
95 * @see dwtx.jface.text.formatter.IFormattingContext#isLongPreference(java.lang.String)
|
|
96 */
|
|
97 public bool isLongPreference(String key) {
|
|
98 return false;
|
|
99 }
|
|
100
|
|
101 /*
|
|
102 * @see dwtx.jface.text.formatter.IFormattingContext#isStringPreference(java.lang.String)
|
|
103 */
|
|
104 public bool isStringPreference(String key) {
|
|
105 return false;
|
|
106 }
|
|
107
|
|
108 /*
|
|
109 * @see dwtx.jface.text.formatter.IFormattingContext#mapToStore(java.util.Map, dwtx.jface.preference.IPreferenceStore)
|
|
110 */
|
|
111 public void mapToStore(Map map, IPreferenceStore store) {
|
|
112
|
|
113 final String[] preferences= getPreferenceKeys();
|
|
114
|
|
115 String result= null;
|
|
116 String preference= null;
|
|
117
|
|
118 for (int index= 0; index < preferences.length; index++) {
|
|
119
|
|
120 preference= preferences[index];
|
134
|
121 result= cast(String)map.get(preference);
|
129
|
122
|
|
123 if (result !is null) {
|
|
124
|
|
125 try {
|
|
126 if (isBooleanPreference(preference)) {
|
|
127 store.setValue(preference, result.equals(IPreferenceStore.TRUE));
|
|
128 } else if (isIntegerPreference(preference)) {
|
|
129 store.setValue(preference, Integer.parseInt(result));
|
|
130 } else if (isStringPreference(preference)) {
|
|
131 store.setValue(preference, result);
|
|
132 } else if (isDoublePreference(preference)) {
|
|
133 store.setValue(preference, Double.parseDouble(result));
|
|
134 } else if (isFloatPreference(preference)) {
|
|
135 store.setValue(preference, Float.parseFloat(result));
|
|
136 } else if (isLongPreference(preference)) {
|
|
137 store.setValue(preference, Long.parseLong(result));
|
|
138 }
|
|
139 } catch (NumberFormatException exception) {
|
|
140 // Do nothing
|
|
141 }
|
|
142 }
|
|
143 }
|
|
144 }
|
|
145
|
|
146 /*
|
|
147 * @see dwtx.jface.text.formatter.IFormattingContext#setProperty(java.lang.Object, java.lang.Object)
|
|
148 */
|
|
149 public void setProperty(Object key, Object property) {
|
|
150 fMap.put(key, property);
|
|
151 }
|
|
152
|
|
153 /*
|
|
154 * @see dwtx.jface.text.formatter.IFormattingContext#storeToMap(dwtx.jface.preference.IPreferenceStore, java.util.Map, bool)
|
|
155 */
|
|
156 public void storeToMap(IPreferenceStore store, Map map, bool useDefault) {
|
|
157
|
|
158 final String[] preferences= getPreferenceKeys();
|
|
159
|
|
160 String preference= null;
|
|
161 for (int index= 0; index < preferences.length; index++) {
|
|
162
|
|
163 preference= preferences[index];
|
|
164
|
|
165 if (isBooleanPreference(preference)) {
|
|
166 map.put(preference, (useDefault ? store.getDefaultBoolean(preference) : store.getBoolean(preference)) ? IPreferenceStore.TRUE : IPreferenceStore.FALSE);
|
|
167 } else if (isIntegerPreference(preference)) {
|
|
168 map.put(preference, String.valueOf(useDefault ? store.getDefaultInt(preference) : store.getInt(preference)));
|
|
169 } else if (isStringPreference(preference)) {
|
|
170 map.put(preference, useDefault ? store.getDefaultString(preference) : store.getString(preference));
|
|
171 } else if (isDoublePreference(preference)) {
|
|
172 map.put(preference, String.valueOf(useDefault ? store.getDefaultDouble(preference) : store.getDouble(preference)));
|
|
173 } else if (isFloatPreference(preference)) {
|
|
174 map.put(preference, String.valueOf(useDefault ? store.getDefaultFloat(preference) : store.getFloat(preference)));
|
|
175 } else if (isLongPreference(preference)) {
|
|
176 map.put(preference, String.valueOf(useDefault ? store.getDefaultLong(preference) : store.getLong(preference)));
|
|
177 }
|
|
178 }
|
|
179 }
|
|
180 }
|