Mercurial > projects > dwt-addons
diff dwtx/jface/text/source/VisualAnnotationModel.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/source/VisualAnnotationModel.d Sat Aug 23 19:10:48 2008 +0200 @@ -0,0 +1,148 @@ +/******************************************************************************* + * 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.source.VisualAnnotationModel; + +import dwt.dwthelper.utils; + + +import java.util.ArrayList; +import java.util.Iterator; + +import dwtx.jface.text.IDocument; +import dwtx.jface.text.Position; + + + +/** + * Annotation model for visual annotations. Assume a viewer's input element is annotated with + * some semantic annotation such as a breakpoint and that it is simultaneously shown in multiple + * viewers. A source viewer, e.g., supports visual range indication for which it utilizes + * annotations. The range indicating annotation is specific to the visual presentation + * of the input element in this viewer and thus should only be visible in this viewer. The + * breakpoints however are independent from the input element's presentation and thus should + * be shown in all viewers in which the element is shown. As a viewer supports one vertical + * ruler which is based on one annotation model, there must be a visual annotation model for + * each viewer which all wrap the same element specific model annotation model. + */ +class VisualAnnotationModel : AnnotationModel , IAnnotationModelListener { + + /** The wrapped model annotation model */ + private IAnnotationModel fModel; + + /** + * Constructs a visual annotation model which wraps the given + * model based annotation model + * + * @param modelAnnotationModel the model based annotation model + */ + public VisualAnnotationModel(IAnnotationModel modelAnnotationModel) { + fModel= modelAnnotationModel; + } + + /** + * Returns the visual annotation model's wrapped model based annotation model. + * + * @return the model based annotation model + */ + public IAnnotationModel getModelAnnotationModel() { + return fModel; + } + + /* + * @see IAnnotationModel#addAnnotationModelListener(IAnnotationModelListener) + */ + public void addAnnotationModelListener(IAnnotationModelListener listener) { + + if (fModel !is null && fAnnotationModelListeners.isEmpty()) + fModel.addAnnotationModelListener(this); + + super.addAnnotationModelListener(listener); + } + + /* + * @see IAnnotationModel#connect(IDocument) + */ + public void connect(IDocument document) { + super.connect(document); + if (fModel !is null) + fModel.connect(document); + } + + /* + * @see IAnnotationModel#disconnect(IDocument) + */ + public void disconnect(IDocument document) { + super.disconnect(document); + if (fModel !is null) + fModel.disconnect(document); + } + + /* + * @see IAnnotationModel#getAnnotationIterator() + */ + public Iterator getAnnotationIterator() { + + if (fModel is null) + return super.getAnnotationIterator(); + + ArrayList a= new ArrayList(20); + + Iterator e= fModel.getAnnotationIterator(); + while (e.hasNext()) + a.add(e.next()); + + e= super.getAnnotationIterator(); + while (e.hasNext()) + a.add(e.next()); + + return a.iterator(); + } + + /* + * @see IAnnotationModel#getPosition(Annotation) + */ + public Position getPosition(Annotation annotation) { + + Position p= (Position) getAnnotationMap().get(annotation); + if (p !is null) + return p; + + if (fModel !is null) + return fModel.getPosition(annotation); + + return null; + } + + /* + * @see IAnnotationModelListener#modelChanged(IAnnotationModel) + */ + public void modelChanged(IAnnotationModel model) { + if (model is fModel) { + Iterator iter= new ArrayList(fAnnotationModelListeners).iterator(); + while (iter.hasNext()) { + IAnnotationModelListener l= (IAnnotationModelListener)iter.next(); + l.modelChanged(this); + } + } + } + + /* + * @see IAnnotationModel#removeAnnotationModelListener(IAnnotationModelListener) + */ + public void removeAnnotationModelListener(IAnnotationModelListener listener) { + super.removeAnnotationModelListener(listener); + + if (fModel !is null && fAnnotationModelListeners.isEmpty()) + fModel.removeAnnotationModelListener(this); + } +}