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() {
|
145
|
55 return null;
|
129
|
56 }
|
|
57
|
|
58 /*
|
|
59 * @see dwtx.jface.text.formatter.IFormattingContext#getProperty(java.lang.Object)
|
|
60 */
|
|
61 public Object getProperty(Object key) {
|
|
62 return fMap.get(key);
|
|
63 }
|
|
64
|
|
65 /*
|
|
66 * @see dwtx.jface.text.formatter.IFormattingContext#isBooleanPreference(java.lang.String)
|
|
67 */
|
|
68 public bool isBooleanPreference(String key) {
|
|
69 return false;
|
|
70 }
|
|
71
|
|
72 /*
|
|
73 * @see dwtx.jface.text.formatter.IFormattingContext#isDoublePreference(java.lang.String)
|
|
74 */
|
|
75 public bool isDoublePreference(String key) {
|
|
76 return false;
|
|
77 }
|
|
78
|
|
79 /*
|
|
80 * @see dwtx.jface.text.formatter.IFormattingContext#isFloatPreference(java.lang.String)
|
|
81 */
|
|
82 public bool isFloatPreference(String key) {
|
|
83 return false;
|
|
84 }
|
|
85
|
|
86 /*
|
|
87 * @see dwtx.jface.text.formatter.IFormattingContext#isIntegerPreference(java.lang.String)
|
|
88 */
|
|
89 public bool isIntegerPreference(String key) {
|
|
90 return false;
|
|
91 }
|
|
92
|
|
93 /*
|
|
94 * @see dwtx.jface.text.formatter.IFormattingContext#isLongPreference(java.lang.String)
|
|
95 */
|
|
96 public bool isLongPreference(String key) {
|
|
97 return false;
|
|
98 }
|
|
99
|
|
100 /*
|
|
101 * @see dwtx.jface.text.formatter.IFormattingContext#isStringPreference(java.lang.String)
|
|
102 */
|
|
103 public bool isStringPreference(String key) {
|
|
104 return false;
|
|
105 }
|
|
106
|
|
107 /*
|
|
108 * @see dwtx.jface.text.formatter.IFormattingContext#mapToStore(java.util.Map, dwtx.jface.preference.IPreferenceStore)
|
|
109 */
|
|
110 public void mapToStore(Map map, IPreferenceStore store) {
|
|
111
|
|
112 final String[] preferences= getPreferenceKeys();
|
|
113
|
|
114 String result= null;
|
|
115 String preference= null;
|
|
116
|
|
117 for (int index= 0; index < preferences.length; index++) {
|
|
118
|
|
119 preference= preferences[index];
|
134
|
120 result= cast(String)map.get(preference);
|
129
|
121
|
|
122 if (result !is null) {
|
|
123
|
|
124 try {
|
|
125 if (isBooleanPreference(preference)) {
|
|
126 store.setValue(preference, result.equals(IPreferenceStore.TRUE));
|
|
127 } else if (isIntegerPreference(preference)) {
|
|
128 store.setValue(preference, Integer.parseInt(result));
|
|
129 } else if (isStringPreference(preference)) {
|
|
130 store.setValue(preference, result);
|
|
131 } else if (isDoublePreference(preference)) {
|
|
132 store.setValue(preference, Double.parseDouble(result));
|
|
133 } else if (isFloatPreference(preference)) {
|
|
134 store.setValue(preference, Float.parseFloat(result));
|
|
135 } else if (isLongPreference(preference)) {
|
|
136 store.setValue(preference, Long.parseLong(result));
|
|
137 }
|
|
138 } catch (NumberFormatException exception) {
|
|
139 // Do nothing
|
|
140 }
|
|
141 }
|
|
142 }
|
|
143 }
|
|
144
|
|
145 /*
|
|
146 * @see dwtx.jface.text.formatter.IFormattingContext#setProperty(java.lang.Object, java.lang.Object)
|
|
147 */
|
|
148 public void setProperty(Object key, Object property) {
|
|
149 fMap.put(key, property);
|
|
150 }
|
|
151
|
|
152 /*
|
|
153 * @see dwtx.jface.text.formatter.IFormattingContext#storeToMap(dwtx.jface.preference.IPreferenceStore, java.util.Map, bool)
|
|
154 */
|
|
155 public void storeToMap(IPreferenceStore store, Map map, bool useDefault) {
|
|
156
|
|
157 final String[] preferences= getPreferenceKeys();
|
|
158
|
|
159 String preference= null;
|
|
160 for (int index= 0; index < preferences.length; index++) {
|
|
161
|
|
162 preference= preferences[index];
|
|
163
|
|
164 if (isBooleanPreference(preference)) {
|
|
165 map.put(preference, (useDefault ? store.getDefaultBoolean(preference) : store.getBoolean(preference)) ? IPreferenceStore.TRUE : IPreferenceStore.FALSE);
|
|
166 } else if (isIntegerPreference(preference)) {
|
|
167 map.put(preference, String.valueOf(useDefault ? store.getDefaultInt(preference) : store.getInt(preference)));
|
|
168 } else if (isStringPreference(preference)) {
|
|
169 map.put(preference, useDefault ? store.getDefaultString(preference) : store.getString(preference));
|
|
170 } else if (isDoublePreference(preference)) {
|
|
171 map.put(preference, String.valueOf(useDefault ? store.getDefaultDouble(preference) : store.getDouble(preference)));
|
|
172 } else if (isFloatPreference(preference)) {
|
|
173 map.put(preference, String.valueOf(useDefault ? store.getDefaultFloat(preference) : store.getFloat(preference)));
|
|
174 } else if (isLongPreference(preference)) {
|
|
175 map.put(preference, String.valueOf(useDefault ? store.getDefaultLong(preference) : store.getLong(preference)));
|
|
176 }
|
|
177 }
|
|
178 }
|
|
179 }
|