comparison org.eclipse.jface.text/src/org/eclipse/jface/text/revisions/Revision.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children dbfb303e8fb0
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 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 module org.eclipse.jface.text.revisions.Revision;
14
15 import org.eclipse.jface.text.revisions.IRevisionListener; // packageimport
16 import org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension; // packageimport
17 import org.eclipse.jface.text.revisions.RevisionRange; // packageimport
18 import org.eclipse.jface.text.revisions.IRevisionRulerColumn; // packageimport
19 import org.eclipse.jface.text.revisions.RevisionEvent; // packageimport
20 import org.eclipse.jface.text.revisions.RevisionInformation; // packageimport
21
22
23 import java.lang.all;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.Set;
29 import org.eclipse.dwtxhelper.Date;
30
31 import org.eclipse.swt.graphics.RGB;
32 import org.eclipse.jface.internal.text.revisions.ChangeRegion;
33 import org.eclipse.jface.internal.text.revisions.Hunk;
34 import org.eclipse.jface.text.IInformationControlCreator;
35 import org.eclipse.jface.text.source.ILineRange;
36
37 /**
38 * Describes a revision of a document. A revision consists of one ore more {@link ILineRange}s.
39 * <p>
40 * Clients may subclass.
41 * </p>
42 *
43 * @since 3.2
44 */
45 public abstract class Revision {
46 /** The original list of change regions, element type: {@link ChangeRegion}. */
47 private const List fChangeRegions;
48 /**
49 * The cached list of adjusted ranges, element type: {@link RevisionRange}. <code>null</code>
50 * if the list must be re-computed. Unmodifiable.
51 *
52 * @since 3.3
53 */
54 private List fRanges= null;
55
56 /**
57 * Creates a new revision.
58 */
59 protected this() {
60 fChangeRegions= new ArrayList();
61 }
62
63 /**
64 * Adds a line range to this revision. The range must be non-empty and have a legal start line
65 * (not -1).
66 *
67 * @param range a line range that was changed with this revision
68 * @throws IndexOutOfBoundsException if the line range is empty or has a negative start line
69 */
70 public final void addRange(ILineRange range) {
71 fChangeRegions.add(new ChangeRegion(this, range));
72 }
73
74 /**
75 * Returns the contained {@link RevisionRange}s adapted to the current diff state. The returned
76 * information is only valid at the moment it is returned, and may change as the annotated
77 * document is modified.
78 *
79 * @return an unmodifiable view of the contained ranges (element type: {@link RevisionRange})
80 */
81 public final List getRegions() {
82 if (fRanges is null) {
83 List ranges= new ArrayList(fChangeRegions.size());
84 for (Iterator it= fChangeRegions.iterator(); it.hasNext();) {
85 ChangeRegion region= cast(ChangeRegion) it.next();
86 for (Iterator inner= region.getAdjustedRanges().iterator(); inner.hasNext();) {
87 ILineRange range= cast(ILineRange) inner.next();
88 ranges.add(new RevisionRange(this, range));
89 }
90 }
91 fRanges= Collections.unmodifiableList(ranges);
92 }
93 return fRanges;
94 }
95
96 /**
97 * Adjusts the revision information to the given diff information. Any previous diff information
98 * is discarded.
99 *
100 * @param hunks the diff hunks to adjust the revision information to
101 * @since 3.3
102 */
103 final void applyDiff(Hunk[] hunks) {
104 fRanges= null; // mark for recomputation
105 for (Iterator regions= fChangeRegions.iterator(); regions.hasNext();) {
106 ChangeRegion region= cast(ChangeRegion) regions.next();
107 region.clearDiff();
108 for (int i= 0; i < hunks.length; i++) {
109 Hunk hunk= hunks[i];
110 region.adjustTo(hunk);
111 }
112 }
113 }
114
115 /**
116 * Returns the hover information that will be shown when the user hovers over the a change
117 * region of this revision.
118 * <p>
119 * <strong>Note:</strong> The hover information control which is used to display the information
120 * must be able process the given object. If the default information control creator is used
121 * the supported format is simple text, full HTML or an HTML fragment.
122 * </p>
123 *
124 * @return the hover information for this revision or <code>null</code> for no hover
125 * @see RevisionInformation#setHoverControlCreator(IInformationControlCreator)
126 */
127 public abstract Object getHoverInfo();
128
129 /**
130 * Returns the author color for this revision. This color can be used to visually distinguish
131 * one revision from another, for example as background color.
132 * <p>
133 * Revisions from the same author must return the same color and revisions from different authors
134 * must return distinct colors.</p>
135 *
136 * @return the RGB color for this revision's author
137 */
138 public abstract RGB getColor();
139
140 /**
141 * Returns the unique (within the document) id of this revision. This may be the version string
142 * or a different identifier.
143 *
144 * @return the id of this revision
145 */
146 public abstract String getId();
147
148 /**
149 * Returns the modification date of this revision.
150 *
151 * @return the modification date of this revision
152 */
153 public abstract Date getDate();
154
155 /*
156 * @see java.lang.Object#toString()
157 */
158 public override String toString() {
159 return "Revision " ~ getId(); //$NON-NLS-1$
160 }
161
162 /**
163 * Returns the display string for the author of this revision.
164 * <p>
165 * Subclasses should replace - the default implementation returns the empty string.
166 * </p>
167 *
168 * @return the author name
169 * @since 3.3
170 */
171 public String getAuthor() {
172 return ""; //$NON-NLS-1$
173 }
174 }