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