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