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
|
151
|
15 module dwtx.jface.text.formatter.ContextBasedFormattingStrategy;
|
|
16
|
131
|
17 import dwtx.jface.text.formatter.MultiPassContentFormatter; // packageimport
|
|
18 import dwtx.jface.text.formatter.FormattingContext; // packageimport
|
|
19 import dwtx.jface.text.formatter.IFormattingStrategy; // packageimport
|
|
20 import dwtx.jface.text.formatter.IContentFormatterExtension; // packageimport
|
|
21 import dwtx.jface.text.formatter.IFormattingStrategyExtension; // packageimport
|
|
22 import dwtx.jface.text.formatter.IContentFormatter; // packageimport
|
|
23 import dwtx.jface.text.formatter.FormattingContextProperties; // packageimport
|
|
24 import dwtx.jface.text.formatter.ContentFormatter; // packageimport
|
|
25 import dwtx.jface.text.formatter.IFormattingContext; // packageimport
|
|
26
|
129
|
27 import dwt.dwthelper.utils;
|
|
28
|
|
29 import java.util.LinkedList;
|
|
30 import java.util.Map;
|
|
31
|
|
32 /**
|
|
33 * Formatting strategy for context based content formatting. Retrieves the preferences
|
|
34 * set on the formatting context's {@link FormattingContextProperties#CONTEXT_PREFERENCES}
|
|
35 * property and makes them available to subclasses.
|
|
36 * <p>
|
|
37 *
|
|
38 * @since 3.0
|
|
39 */
|
|
40 public abstract class ContextBasedFormattingStrategy : IFormattingStrategy, IFormattingStrategyExtension {
|
|
41
|
|
42 /** The current preferences for formatting */
|
|
43 private Map fCurrentPreferences= null;
|
|
44
|
|
45 /** The list of preferences for initiated the formatting steps */
|
146
|
46 private const LinkedList fPreferences= new LinkedList();
|
129
|
47
|
|
48 /*
|
|
49 * @see dwtx.jface.text.formatter.IFormattingStrategyExtension#format()
|
|
50 */
|
|
51 public void format() {
|
134
|
52 fCurrentPreferences= cast(Map)fPreferences.removeFirst();
|
129
|
53 }
|
|
54
|
|
55 /*
|
|
56 * @see dwtx.jface.text.formatter.IFormattingStrategy#format(java.lang.String, bool, java.lang.String, int[])
|
|
57 */
|
|
58 public String format(String content, bool start, String indentation, int[] positions) {
|
|
59 return null;
|
|
60 }
|
|
61
|
|
62 /*
|
|
63 * @see dwtx.jface.text.formatter.IFormattingStrategyExtension#formatterStarts(dwtx.jface.text.formatter.IFormattingContext)
|
|
64 */
|
|
65 public void formatterStarts(final IFormattingContext context) {
|
|
66 fPreferences.addLast(context.getProperty(FormattingContextProperties.CONTEXT_PREFERENCES));
|
|
67 }
|
|
68
|
|
69 /*
|
|
70 * @see IFormattingStrategy#formatterStarts(String)
|
|
71 */
|
|
72 public void formatterStarts(final String indentation) {
|
|
73 // Do nothing
|
|
74 }
|
|
75
|
|
76 /*
|
|
77 * @see dwtx.jface.text.formatter.IFormattingStrategyExtension#formatterStops()
|
|
78 */
|
|
79 public void formatterStops() {
|
|
80 fPreferences.clear();
|
|
81
|
|
82 fCurrentPreferences= null;
|
|
83 }
|
|
84
|
|
85 /**
|
|
86 * Returns the preferences used for the current formatting step.
|
|
87 *
|
|
88 * @return The preferences for the current formatting step
|
|
89 */
|
|
90 public final Map getPreferences() {
|
|
91 return fCurrentPreferences;
|
|
92 }
|
|
93 }
|