KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > revisions > Revision


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  *******************************************************************************/

11 package org.eclipse.jface.text.revisions;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collections JavaDoc;
15 import java.util.Date JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.swt.graphics.RGB;
20
21 import org.eclipse.jface.text.source.ILineRange;
22
23 import org.eclipse.jface.internal.text.revisions.ChangeRegion;
24 import org.eclipse.jface.internal.text.revisions.Hunk;
25
26 /**
27  * Describes a revision of a document. A revision consists of one ore more {@link ILineRange}s.
28  * <p>
29  * Clients may subclass.
30  * </p>
31  *
32  * @since 3.2
33  */

34 public abstract class Revision {
35     /** The original list of change regions, element type: {@link ChangeRegion}. */
36     private final List JavaDoc fChangeRegions= new ArrayList JavaDoc();
37     /**
38      * The cached list of adjusted ranges, element type: {@link RevisionRange}. <code>null</code>
39      * if the list must be re-computed. Unmodifiable.
40      *
41      * @since 3.3
42      */

43     private List JavaDoc fRanges= null;
44
45     /**
46      * Creates a new revision.
47      */

48     protected Revision() {
49     }
50
51     /**
52      * Adds a line range to this revision. The range must be non-empty and have a legal start line
53      * (not -1).
54      *
55      * @param range a line range that was changed with this revision
56      * @throws IndexOutOfBoundsException if the line range is empty or has a negative start line
57      */

58     public final void addRange(ILineRange range) throws IndexOutOfBoundsException JavaDoc {
59         fChangeRegions.add(new ChangeRegion(this, range));
60     }
61
62     /**
63      * Returns the contained {@link RevisionRange}s adapted to the current diff state. The returned
64      * information is only valid at the moment it is returned, and may change as the annotated
65      * document is modified.
66      *
67      * @return an unmodifiable view of the contained ranges (element type: {@link RevisionRange})
68      */

69     public final List JavaDoc getRegions() {
70         if (fRanges == null) {
71             List JavaDoc ranges= new ArrayList JavaDoc(fChangeRegions.size());
72             for (Iterator JavaDoc it= fChangeRegions.iterator(); it.hasNext();) {
73                 ChangeRegion region= (ChangeRegion) it.next();
74                 for (Iterator JavaDoc inner= region.getAdjustedRanges().iterator(); inner.hasNext();) {
75                     ILineRange range= (ILineRange) inner.next();
76                     ranges.add(new RevisionRange(this, range));
77                 }
78             }
79             fRanges= Collections.unmodifiableList(ranges);
80         }
81         return fRanges;
82     }
83
84     /**
85      * Adjusts the revision information to the given diff information. Any previous diff information
86      * is discarded.
87      *
88      * @param hunks the diff hunks to adjust the revision information to
89      * @since 3.3
90      */

91     final void applyDiff(Hunk[] hunks) {
92         fRanges= null; // mark for recomputation
93
for (Iterator JavaDoc regions= fChangeRegions.iterator(); regions.hasNext();) {
94             ChangeRegion region= (ChangeRegion) regions.next();
95             region.clearDiff();
96             for (int i= 0; i < hunks.length; i++) {
97                 Hunk hunk= hunks[i];
98                 region.adjustTo(hunk);
99             }
100         }
101     }
102
103     /**
104      * Returns the hover information that will be shown when the user hovers over the a change
105      * region of this revision.
106      *
107      * @return the hover information for this revision or <code>null</code> for no hover
108      */

109     public abstract Object JavaDoc getHoverInfo();
110
111     /**
112      * Returns the color definition to be used for this revision. The color may be used to visually
113      * distinguish one revision from another, for example as background color. The colors of any two
114      * revisions should be as distinct as possible.
115      *
116      * @return the RGB color description for this revision
117      */

118     public abstract RGB getColor();
119
120     /**
121      * Returns the unique (within the document) id of this revision. This may be the version string
122      * or a different identifier.
123      *
124      * @return the id of this revision
125      */

126     public abstract String JavaDoc getId();
127
128     /**
129      * Returns the modification date of this revision.
130      *
131      * @return the modification date of this revision
132      */

133     public abstract Date JavaDoc getDate();
134
135     /*
136      * @see java.lang.Object#toString()
137      */

138     public String JavaDoc toString() {
139         return "Revision " + getId(); //$NON-NLS-1$
140
}
141
142     /**
143      * Returns the display string for the author of this revision.
144      * <p>
145      * Subclasses should replace - the default implementation returns the empty string.
146      * </p>
147      *
148      * @return the author name
149      * @since 3.3
150      */

151     public String JavaDoc getAuthor() {
152         return ""; //$NON-NLS-1$
153
}
154 }
155
Popular Tags