KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > formatter > ContextBasedFormattingStrategy


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  *******************************************************************************/

11
12 package org.eclipse.jface.text.formatter;
13
14 import java.util.LinkedList JavaDoc;
15 import java.util.Map JavaDoc;
16
17 /**
18  * Formatting strategy for context based content formatting. Retrieves the preferences
19  * set on the formatting context's {@link FormattingContextProperties#CONTEXT_PREFERENCES}
20  * property and makes them available to subclasses.
21  * <p>
22  *
23  * @since 3.0
24  */

25 public abstract class ContextBasedFormattingStrategy implements IFormattingStrategy, IFormattingStrategyExtension {
26
27     /** The current preferences for formatting */
28     private Map JavaDoc fCurrentPreferences= null;
29
30     /** The list of preferences for initiated the formatting steps */
31     private final LinkedList JavaDoc fPreferences= new LinkedList JavaDoc();
32
33     /*
34      * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#format()
35      */

36     public void format() {
37         fCurrentPreferences= (Map JavaDoc)fPreferences.removeFirst();
38     }
39
40     /*
41      * @see org.eclipse.jface.text.formatter.IFormattingStrategy#format(java.lang.String, boolean, java.lang.String, int[])
42      */

43     public String JavaDoc format(String JavaDoc content, boolean start, String JavaDoc indentation, int[] positions) {
44         return null;
45     }
46
47     /*
48      * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#formatterStarts(org.eclipse.jface.text.formatter.IFormattingContext)
49      */

50     public void formatterStarts(final IFormattingContext context) {
51         fPreferences.addLast(context.getProperty(FormattingContextProperties.CONTEXT_PREFERENCES));
52     }
53
54     /*
55      * @see IFormattingStrategy#formatterStarts(String)
56      */

57     public void formatterStarts(final String JavaDoc indentation) {
58         // Do nothing
59
}
60
61     /*
62      * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#formatterStops()
63      */

64     public void formatterStops() {
65         fPreferences.clear();
66
67         fCurrentPreferences= null;
68     }
69
70     /**
71      * Returns the preferences used for the current formatting step.
72      *
73      * @return The preferences for the current formatting step
74      */

75     public final Map JavaDoc getPreferences() {
76         return fCurrentPreferences;
77     }
78 }
79
Popular Tags