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