Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/projection/ProjectionAnnotation.d @ 147:000f9136b8f7
final
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 22:35:05 +0200 |
parents | 02cd5f1224d3 |
children | 1a5b8f8129df |
rev | line source |
---|---|
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 */ | |
147 | 76 public static const String TYPE= "dwtx.projection"; //$NON-NLS-1$ |
129 | 77 |
78 | |
147 | 79 private static const int COLOR= DWT.COLOR_GRAY; |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
92 public this() { |
129 | 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 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
102 public this(bool isCollapsed) { |
129 | 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; | |
145 | 118 |
129 | 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); | |
145 | 122 |
129 | 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; | |
145 | 140 rectangle.height -= delta; |
129 | 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 | |
145 | 161 ImageDescriptor descriptor= ImageDescriptor.createFromFile( getImportData!("images/collapsed.gif")); //$NON-NLS-1$ |
129 | 162 fgCollapsedImage= descriptor.createImage(display); |
145 | 163 descriptor= ImageDescriptor.createFromFile( getImportData!( "images/expanded.gif")); //$NON-NLS-1$ |
129 | 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 } |