129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 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.source.projection.ProjectionAnnotation;
|
|
14
|
131
|
15 import dwtx.jface.text.source.projection.ProjectionViewer; // packageimport
|
|
16 import dwtx.jface.text.source.projection.ProjectionSupport; // packageimport
|
|
17 import dwtx.jface.text.source.projection.IProjectionPosition; // packageimport
|
|
18 import dwtx.jface.text.source.projection.AnnotationBag; // packageimport
|
|
19 import dwtx.jface.text.source.projection.ProjectionSummary; // packageimport
|
|
20 import dwtx.jface.text.source.projection.ProjectionAnnotationHover; // packageimport
|
|
21 import dwtx.jface.text.source.projection.ProjectionRulerColumn; // packageimport
|
|
22 import dwtx.jface.text.source.projection.ProjectionAnnotationModel; // packageimport
|
|
23 import dwtx.jface.text.source.projection.SourceViewerInformationControl; // packageimport
|
|
24 import dwtx.jface.text.source.projection.IProjectionListener; // packageimport
|
|
25
|
|
26
|
129
|
27 import dwt.dwthelper.utils;
|
|
28
|
|
29
|
|
30
|
|
31
|
|
32 import dwt.DWT;
|
|
33 import dwt.graphics.FontMetrics;
|
|
34 import dwt.graphics.GC;
|
|
35 import dwt.graphics.Image;
|
|
36 import dwt.graphics.Rectangle;
|
|
37 import dwt.widgets.Canvas;
|
|
38 import dwt.widgets.Display;
|
|
39 import dwtx.jface.resource.ImageDescriptor;
|
|
40 import dwtx.jface.text.source.Annotation;
|
|
41 import dwtx.jface.text.source.IAnnotationPresentation;
|
|
42 import dwtx.jface.text.source.ImageUtilities;
|
|
43
|
|
44 /**
|
|
45 * Annotation used to represent the projection of a master document onto a
|
|
46 * {@link dwtx.jface.text.projection.ProjectionDocument}. A projection
|
|
47 * annotation can be either expanded or collapsed. If expanded it corresponds to
|
|
48 * a segment of the projection document. If collapsed, it represents a region of
|
|
49 * the master document that does not have a corresponding segment in the
|
|
50 * projection document.
|
|
51 * <p>
|
|
52 * Clients may subclass or use as is.
|
|
53 * </p>
|
|
54 *
|
|
55 * @since 3.0
|
|
56 */
|
|
57 public class ProjectionAnnotation : Annotation , IAnnotationPresentation {
|
|
58
|
|
59 private static class DisplayDisposeRunnable : Runnable {
|
|
60
|
|
61 public void run() {
|
|
62 if (fgCollapsedImage !is null) {
|
|
63 fgCollapsedImage.dispose();
|
|
64 fgCollapsedImage= null;
|
|
65 }
|
|
66 if (fgExpandedImage !is null) {
|
|
67 fgExpandedImage.dispose();
|
|
68 fgExpandedImage= null;
|
|
69 }
|
|
70 }
|
|
71 }
|
|
72
|
|
73 /**
|
|
74 * The type of projection annotations.
|
|
75 */
|
|
76 public static final String TYPE= "dwtx.projection"; //$NON-NLS-1$
|
|
77
|
|
78
|
|
79 private static final int COLOR= DWT.COLOR_GRAY;
|
|
80 private static Image fgCollapsedImage;
|
|
81 private static Image fgExpandedImage;
|
|
82
|
|
83
|
|
84 /** The state of this annotation */
|
|
85 private bool fIsCollapsed= false;
|
|
86 /** Indicates whether this annotation should be painted as range */
|
|
87 private bool fIsRangeIndication= false;
|
|
88
|
|
89 /**
|
|
90 * Creates a new expanded projection annotation.
|
|
91 */
|
|
92 public ProjectionAnnotation() {
|
|
93 this(false);
|
|
94 }
|
|
95
|
|
96 /**
|
|
97 * Creates a new projection annotation. When <code>isCollapsed</code>
|
|
98 * is <code>true</code> the annotation is initially collapsed.
|
|
99 *
|
|
100 * @param isCollapsed <code>true</code> if the annotation should initially be collapsed, <code>false</code> otherwise
|
|
101 */
|
|
102 public ProjectionAnnotation(bool isCollapsed) {
|
|
103 super(TYPE, false, null);
|
|
104 fIsCollapsed= isCollapsed;
|
|
105 }
|
|
106
|
|
107 /**
|
|
108 * Enables and disables the range indication for this annotation.
|
|
109 *
|
|
110 * @param rangeIndication the enable state for the range indication
|
|
111 */
|
|
112 public void setRangeIndication(bool rangeIndication) {
|
|
113 fIsRangeIndication= rangeIndication;
|
|
114 }
|
|
115
|
|
116 private void drawRangeIndication(GC gc, Canvas canvas, Rectangle r) {
|
|
117 final int MARGIN= 3;
|
|
118
|
|
119 /* cap the height - at least on GTK, large numbers are converted to
|
|
120 * negatives at some point */
|
|
121 int height= Math.min(r.y + r.height - MARGIN, canvas.getSize().y);
|
|
122
|
|
123 gc.setForeground(canvas.getDisplay().getSystemColor(COLOR));
|
|
124 gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance
|
|
125 gc.drawLine(r.x + 4, r.y + 12, r.x + 4, height);
|
|
126 gc.drawLine(r.x + 4, height, r.x + r.width - MARGIN, height);
|
|
127 }
|
|
128
|
|
129 /*
|
|
130 * @see dwtx.jface.text.source.IAnnotationPresentation#paint(dwt.graphics.GC, dwt.widgets.Canvas, dwt.graphics.Rectangle)
|
|
131 */
|
|
132 public void paint(GC gc, Canvas canvas, Rectangle rectangle) {
|
|
133 Image image= getImage(canvas.getDisplay());
|
|
134 if (image !is null) {
|
|
135 ImageUtilities.drawImage(image, gc, canvas, rectangle, DWT.CENTER, DWT.TOP);
|
|
136 if (fIsRangeIndication) {
|
|
137 FontMetrics fontMetrics= gc.getFontMetrics();
|
|
138 int delta= (fontMetrics.getHeight() - image.getBounds().height)/2;
|
|
139 rectangle.y += delta;
|
|
140 rectangle.height -= delta;
|
|
141 drawRangeIndication(gc, canvas, rectangle);
|
|
142 }
|
|
143 }
|
|
144 }
|
|
145
|
|
146 /*
|
|
147 * @see dwtx.jface.text.source.IAnnotationPresentation#getLayer()
|
|
148 */
|
|
149 public int getLayer() {
|
|
150 return IAnnotationPresentation.DEFAULT_LAYER;
|
|
151 }
|
|
152
|
|
153 private Image getImage(Display display) {
|
|
154 initializeImages(display);
|
|
155 return isCollapsed() ? fgCollapsedImage : fgExpandedImage;
|
|
156 }
|
|
157
|
|
158 private void initializeImages(Display display) {
|
|
159 if (fgCollapsedImage is null) {
|
|
160
|
|
161 ImageDescriptor descriptor= ImageDescriptor.createFromFile(ProjectionAnnotation.class, "images/collapsed.gif"); //$NON-NLS-1$
|
|
162 fgCollapsedImage= descriptor.createImage(display);
|
|
163 descriptor= ImageDescriptor.createFromFile(ProjectionAnnotation.class, "images/expanded.gif"); //$NON-NLS-1$
|
|
164 fgExpandedImage= descriptor.createImage(display);
|
|
165
|
|
166 display.disposeExec(new DisplayDisposeRunnable());
|
|
167 }
|
|
168 }
|
|
169
|
|
170 /**
|
|
171 * Returns the state of this annotation.
|
|
172 *
|
|
173 * @return <code>true</code> if collapsed
|
|
174 */
|
|
175 public bool isCollapsed() {
|
|
176 return fIsCollapsed;
|
|
177 }
|
|
178
|
|
179 /**
|
|
180 * Marks this annotation as being collapsed.
|
|
181 */
|
|
182 public void markCollapsed() {
|
|
183 fIsCollapsed= true;
|
|
184 }
|
|
185
|
|
186 /**
|
|
187 * Marks this annotation as being unfolded.
|
|
188 */
|
|
189 public void markExpanded() {
|
|
190 fIsCollapsed= false;
|
|
191 }
|
|
192 }
|