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