Mercurial > projects > dwt-addons
comparison dwtx/jface/text/formatter/MultiPassContentFormatter.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 25f1f92fa3df |
children |
comparison
equal
deleted
inserted
replaced
161:f8d52b926852 | 162:1a5b8f8129df |
---|---|
114 /** The master formatting strategy */ | 114 /** The master formatting strategy */ |
115 private IFormattingStrategyExtension fMaster= null; | 115 private IFormattingStrategyExtension fMaster= null; |
116 /** The partitioning of this content formatter */ | 116 /** The partitioning of this content formatter */ |
117 private const String fPartitioning; | 117 private const String fPartitioning; |
118 /** The slave formatting strategies */ | 118 /** The slave formatting strategies */ |
119 private const Map fSlaves= new HashMap(); | 119 private const Map fSlaves; |
120 /** The default content type */ | 120 /** The default content type */ |
121 private const String fType; | 121 private const String fType; |
122 | 122 |
123 /** | 123 /** |
124 * Creates a new content formatter. | 124 * Creates a new content formatter. |
125 * | 125 * |
126 * @param partitioning the document partitioning for this formatter | 126 * @param partitioning the document partitioning for this formatter |
127 * @param type the default content type | 127 * @param type the default content type |
128 */ | 128 */ |
129 public this(String partitioning, String type) { | 129 public this(String partitioning, String type) { |
130 fSlaves= new HashMap(); | |
131 | |
130 fPartitioning= partitioning; | 132 fPartitioning= partitioning; |
131 fType= type; | 133 fType= type; |
132 } | 134 } |
133 | 135 |
134 /* | 136 /* |
135 * @see dwtx.jface.text.formatter.IContentFormatterExtension#format(dwtx.jface.text.IDocument, dwtx.jface.text.formatter.IFormattingContext) | 137 * @see dwtx.jface.text.formatter.IContentFormatterExtension#format(dwtx.jface.text.IDocument, dwtx.jface.text.formatter.IFormattingContext) |
136 */ | 138 */ |
137 public final void format(IDocument medium, IFormattingContext context) { | 139 public final void format(IDocument medium, IFormattingContext context) { |
138 | 140 |
139 context.setProperty(FormattingContextProperties.CONTEXT_MEDIUM, medium); | 141 context.setProperty(stringcast(FormattingContextProperties.CONTEXT_MEDIUM), cast(Object)medium); |
140 | 142 |
141 final Boolean document= cast(Boolean)context.getProperty(FormattingContextProperties.CONTEXT_DOCUMENT); | 143 final Boolean document= cast(Boolean)context.getProperty(stringcast(FormattingContextProperties.CONTEXT_DOCUMENT)); |
142 if (document is null || !document.booleanValue()) { | 144 if (document is null || !document.booleanValue()) { |
143 | 145 |
144 final IRegion region= cast(IRegion)context.getProperty(FormattingContextProperties.CONTEXT_REGION); | 146 final IRegion region= cast(IRegion)context.getProperty(stringcast(FormattingContextProperties.CONTEXT_REGION)); |
145 if (region !is null) { | 147 if (region !is null) { |
146 try { | 148 try { |
147 formatMaster(context, medium, region.getOffset(), region.getLength()); | 149 formatMaster(context, medium, region.getOffset(), region.getLength()); |
148 } finally { | 150 } finally { |
149 formatSlaves(context, medium, region.getOffset(), region.getLength()); | 151 formatSlaves(context, medium, region.getOffset(), region.getLength()); |
163 */ | 165 */ |
164 public final void format(IDocument medium, IRegion region) { | 166 public final void format(IDocument medium, IRegion region) { |
165 | 167 |
166 final FormattingContext context= new FormattingContext(); | 168 final FormattingContext context= new FormattingContext(); |
167 | 169 |
168 context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE); | 170 context.setProperty(stringcast(FormattingContextProperties.CONTEXT_DOCUMENT), Boolean.FALSE); |
169 context.setProperty(FormattingContextProperties.CONTEXT_REGION, region); | 171 context.setProperty(stringcast(FormattingContextProperties.CONTEXT_REGION), cast(Object)region); |
170 | 172 |
171 format(medium, context); | 173 format(medium, context); |
172 } | 174 } |
173 | 175 |
174 /** | 176 /** |
197 // Do nothing | 199 // Do nothing |
198 } | 200 } |
199 | 201 |
200 if (fMaster !is null) { | 202 if (fMaster !is null) { |
201 | 203 |
202 context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, fType)); | 204 context.setProperty(stringcast(FormattingContextProperties.CONTEXT_PARTITION), new TypedPosition(offset, length, fType)); |
203 | 205 |
204 fMaster.formatterStarts(context); | 206 fMaster.formatterStarts(context); |
205 fMaster.format(); | 207 fMaster.format(); |
206 fMaster.formatterStops(); | 208 fMaster.formatterStops(); |
207 } | 209 } |
225 protected void formatSlave(IFormattingContext context, IDocument document, int offset, int length, String type) { | 227 protected void formatSlave(IFormattingContext context, IDocument document, int offset, int length, String type) { |
226 | 228 |
227 final IFormattingStrategyExtension strategy= cast(IFormattingStrategyExtension)fSlaves.get(type); | 229 final IFormattingStrategyExtension strategy= cast(IFormattingStrategyExtension)fSlaves.get(type); |
228 if (strategy !is null) { | 230 if (strategy !is null) { |
229 | 231 |
230 context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, type)); | 232 context.setProperty(stringcast(FormattingContextProperties.CONTEXT_PARTITION), new TypedPosition(offset, length, type)); |
231 | 233 |
232 strategy.formatterStarts(context); | 234 strategy.formatterStarts(context); |
233 strategy.format(); | 235 strategy.format(); |
234 strategy.formatterStops(); | 236 strategy.formatterStops(); |
235 } | 237 } |
304 * | 306 * |
305 * @param strategy The master formatting strategy, must implement | 307 * @param strategy The master formatting strategy, must implement |
306 * {@link IFormattingStrategyExtension} | 308 * {@link IFormattingStrategyExtension} |
307 */ | 309 */ |
308 public final void setMasterStrategy(IFormattingStrategy strategy) { | 310 public final void setMasterStrategy(IFormattingStrategy strategy) { |
309 Assert.isTrue( cast(IFormattingStrategyExtension)strategy ); | 311 Assert.isTrue( null !is cast(IFormattingStrategyExtension)strategy ); |
310 fMaster= cast(IFormattingStrategyExtension) strategy; | 312 fMaster= cast(IFormattingStrategyExtension) strategy; |
311 } | 313 } |
312 | 314 |
313 /** | 315 /** |
314 * Registers a slave formatting strategy for a certain content type. | 316 * Registers a slave formatting strategy for a certain content type. |
322 * @param strategy The slave formatting strategy | 324 * @param strategy The slave formatting strategy |
323 * @param type The content type to register this strategy with, | 325 * @param type The content type to register this strategy with, |
324 * must implement {@link IFormattingStrategyExtension} | 326 * must implement {@link IFormattingStrategyExtension} |
325 */ | 327 */ |
326 public final void setSlaveStrategy(IFormattingStrategy strategy, String type) { | 328 public final void setSlaveStrategy(IFormattingStrategy strategy, String type) { |
327 Assert.isTrue( cast(IFormattingStrategyExtension)strategy ); | 329 Assert.isTrue( null !is cast(IFormattingStrategyExtension)strategy ); |
328 if (!fType.equals(type)) | 330 if (!fType.equals(type)) |
329 fSlaves.put(type, strategy); | 331 fSlaves.put(type, cast(Object)strategy); |
330 } | 332 } |
331 } | 333 } |