Mercurial > projects > dwt-addons
comparison dwtx/jface/text/formatter/MultiPassContentFormatter.d @ 158:25f1f92fa3df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 26 Aug 2008 02:46:34 +0200 |
parents | f70d9508c95c |
children | 1a5b8f8129df |
comparison
equal
deleted
inserted
replaced
157:7f75eaa8103a | 158:25f1f92fa3df |
---|---|
23 import dwtx.jface.text.formatter.FormattingContextProperties; // packageimport | 23 import dwtx.jface.text.formatter.FormattingContextProperties; // packageimport |
24 import dwtx.jface.text.formatter.ContentFormatter; // packageimport | 24 import dwtx.jface.text.formatter.ContentFormatter; // packageimport |
25 import dwtx.jface.text.formatter.IFormattingContext; // packageimport | 25 import dwtx.jface.text.formatter.IFormattingContext; // packageimport |
26 | 26 |
27 import dwt.dwthelper.utils; | 27 import dwt.dwthelper.utils; |
28 | |
29 import dwtx.dwtxhelper.Collection; | 28 import dwtx.dwtxhelper.Collection; |
30 | |
31 | 29 |
32 import dwtx.core.runtime.Assert; | 30 import dwtx.core.runtime.Assert; |
33 import dwtx.jface.text.BadLocationException; | 31 import dwtx.jface.text.BadLocationException; |
34 import dwtx.jface.text.DefaultPositionUpdater; | 32 import dwtx.jface.text.DefaultPositionUpdater; |
35 import dwtx.jface.text.IDocument; | 33 import dwtx.jface.text.IDocument; |
71 /** | 69 /** |
72 * Creates a new non-deleting position updater. | 70 * Creates a new non-deleting position updater. |
73 * | 71 * |
74 * @param category The position category to update its positions | 72 * @param category The position category to update its positions |
75 */ | 73 */ |
76 public this(final String category) { | 74 public this(String category) { |
77 super(category); | 75 super(category); |
78 } | 76 } |
79 | 77 |
80 /* | 78 /* |
81 * @see dwtx.jface.text.DefaultPositionUpdater#notDeleted() | 79 * @see dwtx.jface.text.DefaultPositionUpdater#notDeleted() |
126 * Creates a new content formatter. | 124 * Creates a new content formatter. |
127 * | 125 * |
128 * @param partitioning the document partitioning for this formatter | 126 * @param partitioning the document partitioning for this formatter |
129 * @param type the default content type | 127 * @param type the default content type |
130 */ | 128 */ |
131 public this(final String partitioning, final String type) { | 129 public this(String partitioning, String type) { |
132 fPartitioning= partitioning; | 130 fPartitioning= partitioning; |
133 fType= type; | 131 fType= type; |
134 } | 132 } |
135 | 133 |
136 /* | 134 /* |
137 * @see dwtx.jface.text.formatter.IContentFormatterExtension#format(dwtx.jface.text.IDocument, dwtx.jface.text.formatter.IFormattingContext) | 135 * @see dwtx.jface.text.formatter.IContentFormatterExtension#format(dwtx.jface.text.IDocument, dwtx.jface.text.formatter.IFormattingContext) |
138 */ | 136 */ |
139 public final void format(final IDocument medium, final IFormattingContext context) { | 137 public final void format(IDocument medium, IFormattingContext context) { |
140 | 138 |
141 context.setProperty(FormattingContextProperties.CONTEXT_MEDIUM, medium); | 139 context.setProperty(FormattingContextProperties.CONTEXT_MEDIUM, medium); |
142 | 140 |
143 final Boolean document= cast(Boolean)context.getProperty(FormattingContextProperties.CONTEXT_DOCUMENT); | 141 final Boolean document= cast(Boolean)context.getProperty(FormattingContextProperties.CONTEXT_DOCUMENT); |
144 if (document is null || !document.booleanValue()) { | 142 if (document is null || !document.booleanValue()) { |
161 } | 159 } |
162 | 160 |
163 /* | 161 /* |
164 * @see dwtx.jface.text.formatter.IContentFormatter#format(dwtx.jface.text.IDocument, dwtx.jface.text.IRegion) | 162 * @see dwtx.jface.text.formatter.IContentFormatter#format(dwtx.jface.text.IDocument, dwtx.jface.text.IRegion) |
165 */ | 163 */ |
166 public final void format(final IDocument medium, final IRegion region) { | 164 public final void format(IDocument medium, IRegion region) { |
167 | 165 |
168 final FormattingContext context= new FormattingContext(); | 166 final FormattingContext context= new FormattingContext(); |
169 | 167 |
170 context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE); | 168 context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE); |
171 context.setProperty(FormattingContextProperties.CONTEXT_REGION, region); | 169 context.setProperty(FormattingContextProperties.CONTEXT_REGION, region); |
185 * @param context The formatting context to use | 183 * @param context The formatting context to use |
186 * @param document The document to operate on | 184 * @param document The document to operate on |
187 * @param offset The offset of the region to format | 185 * @param offset The offset of the region to format |
188 * @param length The length of the region to format | 186 * @param length The length of the region to format |
189 */ | 187 */ |
190 protected void formatMaster(final IFormattingContext context, final IDocument document, int offset, int length) { | 188 protected void formatMaster(IFormattingContext context, IDocument document, int offset, int length) { |
191 | 189 |
192 try { | 190 try { |
193 | 191 |
194 final int delta= offset - document.getLineInformationOfOffset(offset).getOffset(); | 192 final int delta= offset - document.getLineInformationOfOffset(offset).getOffset(); |
195 offset -= delta; | 193 offset -= delta; |
222 * @param document The document to operate on | 220 * @param document The document to operate on |
223 * @param offset The offset of the region to format | 221 * @param offset The offset of the region to format |
224 * @param length The length of the region to format | 222 * @param length The length of the region to format |
225 * @param type The content type of the region to format | 223 * @param type The content type of the region to format |
226 */ | 224 */ |
227 protected void formatSlave(final IFormattingContext context, final IDocument document, final int offset, final int length, final String type) { | 225 protected void formatSlave(IFormattingContext context, IDocument document, int offset, int length, String type) { |
228 | 226 |
229 final IFormattingStrategyExtension strategy= cast(IFormattingStrategyExtension)fSlaves.get(type); | 227 final IFormattingStrategyExtension strategy= cast(IFormattingStrategyExtension)fSlaves.get(type); |
230 if (strategy !is null) { | 228 if (strategy !is null) { |
231 | 229 |
232 context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, type)); | 230 context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, type)); |
250 * @param context The formatting context to use | 248 * @param context The formatting context to use |
251 * @param document The document to operate on | 249 * @param document The document to operate on |
252 * @param offset The offset of the region to format | 250 * @param offset The offset of the region to format |
253 * @param length The length of the region to format | 251 * @param length The length of the region to format |
254 */ | 252 */ |
255 protected void formatSlaves(final IFormattingContext context, final IDocument document, final int offset, final int length) { | 253 protected void formatSlaves(IFormattingContext context, IDocument document, int offset, int length) { |
256 | 254 |
257 Map partitioners= new HashMap(0); | 255 Map partitioners= new HashMap(0); |
258 try { | 256 try { |
259 | 257 |
260 final ITypedRegion[] partitions= TextUtilities.computePartitioning(document, fPartitioning, offset, length, false); | 258 final ITypedRegion[] partitions= TextUtilities.computePartitioning(document, fPartitioning, offset, length, false); |
290 } | 288 } |
291 | 289 |
292 /* | 290 /* |
293 * @see dwtx.jface.text.formatter.IContentFormatter#getFormattingStrategy(java.lang.String) | 291 * @see dwtx.jface.text.formatter.IContentFormatter#getFormattingStrategy(java.lang.String) |
294 */ | 292 */ |
295 public final IFormattingStrategy getFormattingStrategy(final String type) { | 293 public final IFormattingStrategy getFormattingStrategy(String type) { |
296 return null; | 294 return null; |
297 } | 295 } |
298 | 296 |
299 /** | 297 /** |
300 * Registers a master formatting strategy. | 298 * Registers a master formatting strategy. |
305 * is overridden by the new one. | 303 * is overridden by the new one. |
306 * | 304 * |
307 * @param strategy The master formatting strategy, must implement | 305 * @param strategy The master formatting strategy, must implement |
308 * {@link IFormattingStrategyExtension} | 306 * {@link IFormattingStrategyExtension} |
309 */ | 307 */ |
310 public final void setMasterStrategy(final IFormattingStrategy strategy) { | 308 public final void setMasterStrategy(IFormattingStrategy strategy) { |
311 Assert.isTrue( cast(IFormattingStrategyExtension)strategy ); | 309 Assert.isTrue( cast(IFormattingStrategyExtension)strategy ); |
312 fMaster= cast(IFormattingStrategyExtension) strategy; | 310 fMaster= cast(IFormattingStrategyExtension) strategy; |
313 } | 311 } |
314 | 312 |
315 /** | 313 /** |
323 * | 321 * |
324 * @param strategy The slave formatting strategy | 322 * @param strategy The slave formatting strategy |
325 * @param type The content type to register this strategy with, | 323 * @param type The content type to register this strategy with, |
326 * must implement {@link IFormattingStrategyExtension} | 324 * must implement {@link IFormattingStrategyExtension} |
327 */ | 325 */ |
328 public final void setSlaveStrategy(final IFormattingStrategy strategy, final String type) { | 326 public final void setSlaveStrategy(IFormattingStrategy strategy, String type) { |
329 Assert.isTrue( cast(IFormattingStrategyExtension)strategy ); | 327 Assert.isTrue( cast(IFormattingStrategyExtension)strategy ); |
330 if (!fType.equals(type)) | 328 if (!fType.equals(type)) |
331 fSlaves.put(type, strategy); | 329 fSlaves.put(type, strategy); |
332 } | 330 } |
333 } | 331 } |