Mercurial > projects > dwt-addons
diff dwtx/jface/text/formatter/ContextBasedFormattingStrategy.d @ 129:eb30df5ca28b
Added JFace Text sources
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 23 Aug 2008 19:10:48 +0200 |
parents | |
children | c4fb132a086c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/text/formatter/ContextBasedFormattingStrategy.d Sat Aug 23 19:10:48 2008 +0200 @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + *******************************************************************************/ + +module dwtx.jface.text.formatter.ContextBasedFormattingStrategy; + +import dwt.dwthelper.utils; + +import java.util.LinkedList; +import java.util.Map; + +/** + * Formatting strategy for context based content formatting. Retrieves the preferences + * set on the formatting context's {@link FormattingContextProperties#CONTEXT_PREFERENCES} + * property and makes them available to subclasses. + * <p> + * + * @since 3.0 + */ +public abstract class ContextBasedFormattingStrategy : IFormattingStrategy, IFormattingStrategyExtension { + + /** The current preferences for formatting */ + private Map fCurrentPreferences= null; + + /** The list of preferences for initiated the formatting steps */ + private final LinkedList fPreferences= new LinkedList(); + + /* + * @see dwtx.jface.text.formatter.IFormattingStrategyExtension#format() + */ + public void format() { + fCurrentPreferences= (Map)fPreferences.removeFirst(); + } + + /* + * @see dwtx.jface.text.formatter.IFormattingStrategy#format(java.lang.String, bool, java.lang.String, int[]) + */ + public String format(String content, bool start, String indentation, int[] positions) { + return null; + } + + /* + * @see dwtx.jface.text.formatter.IFormattingStrategyExtension#formatterStarts(dwtx.jface.text.formatter.IFormattingContext) + */ + public void formatterStarts(final IFormattingContext context) { + fPreferences.addLast(context.getProperty(FormattingContextProperties.CONTEXT_PREFERENCES)); + } + + /* + * @see IFormattingStrategy#formatterStarts(String) + */ + public void formatterStarts(final String indentation) { + // Do nothing + } + + /* + * @see dwtx.jface.text.formatter.IFormattingStrategyExtension#formatterStops() + */ + public void formatterStops() { + fPreferences.clear(); + + fCurrentPreferences= null; + } + + /** + * Returns the preferences used for the current formatting step. + * + * @return The preferences for the current formatting step + */ + public final Map getPreferences() { + return fCurrentPreferences; + } +}