Mercurial > projects > dwt-addons
annotate dwtx/jface/text/source/ImageUtilities.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 02cd5f1224d3 |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 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.ImageUtilities; | |
14 | |
131 | 15 import dwtx.jface.text.source.ISharedTextColors; // packageimport |
16 import dwtx.jface.text.source.ILineRange; // packageimport | |
17 import dwtx.jface.text.source.IAnnotationPresentation; // packageimport | |
18 import dwtx.jface.text.source.IVerticalRulerInfoExtension; // packageimport | |
19 import dwtx.jface.text.source.ICharacterPairMatcher; // packageimport | |
20 import dwtx.jface.text.source.TextInvocationContext; // packageimport | |
21 import dwtx.jface.text.source.LineChangeHover; // packageimport | |
22 import dwtx.jface.text.source.IChangeRulerColumn; // packageimport | |
23 import dwtx.jface.text.source.IAnnotationMap; // packageimport | |
24 import dwtx.jface.text.source.IAnnotationModelListenerExtension; // packageimport | |
25 import dwtx.jface.text.source.ISourceViewerExtension2; // packageimport | |
26 import dwtx.jface.text.source.IAnnotationHover; // packageimport | |
27 import dwtx.jface.text.source.ContentAssistantFacade; // packageimport | |
28 import dwtx.jface.text.source.IAnnotationAccess; // packageimport | |
29 import dwtx.jface.text.source.IVerticalRulerExtension; // packageimport | |
30 import dwtx.jface.text.source.IVerticalRulerColumn; // packageimport | |
31 import dwtx.jface.text.source.LineNumberRulerColumn; // packageimport | |
32 import dwtx.jface.text.source.MatchingCharacterPainter; // packageimport | |
33 import dwtx.jface.text.source.IAnnotationModelExtension; // packageimport | |
34 import dwtx.jface.text.source.ILineDifferExtension; // packageimport | |
35 import dwtx.jface.text.source.DefaultCharacterPairMatcher; // packageimport | |
36 import dwtx.jface.text.source.LineNumberChangeRulerColumn; // packageimport | |
37 import dwtx.jface.text.source.IAnnotationAccessExtension; // packageimport | |
38 import dwtx.jface.text.source.ISourceViewer; // packageimport | |
39 import dwtx.jface.text.source.AnnotationModel; // packageimport | |
40 import dwtx.jface.text.source.ILineDifferExtension2; // packageimport | |
41 import dwtx.jface.text.source.IAnnotationModelListener; // packageimport | |
42 import dwtx.jface.text.source.IVerticalRuler; // packageimport | |
43 import dwtx.jface.text.source.DefaultAnnotationHover; // packageimport | |
44 import dwtx.jface.text.source.SourceViewer; // packageimport | |
45 import dwtx.jface.text.source.SourceViewerConfiguration; // packageimport | |
46 import dwtx.jface.text.source.AnnotationBarHoverManager; // packageimport | |
47 import dwtx.jface.text.source.CompositeRuler; // packageimport | |
48 import dwtx.jface.text.source.VisualAnnotationModel; // packageimport | |
49 import dwtx.jface.text.source.IAnnotationModel; // packageimport | |
50 import dwtx.jface.text.source.ISourceViewerExtension3; // packageimport | |
51 import dwtx.jface.text.source.ILineDiffInfo; // packageimport | |
52 import dwtx.jface.text.source.VerticalRulerEvent; // packageimport | |
53 import dwtx.jface.text.source.ChangeRulerColumn; // packageimport | |
54 import dwtx.jface.text.source.ILineDiffer; // packageimport | |
55 import dwtx.jface.text.source.AnnotationModelEvent; // packageimport | |
56 import dwtx.jface.text.source.AnnotationColumn; // packageimport | |
57 import dwtx.jface.text.source.AnnotationRulerColumn; // packageimport | |
58 import dwtx.jface.text.source.IAnnotationHoverExtension; // packageimport | |
59 import dwtx.jface.text.source.AbstractRulerColumn; // packageimport | |
60 import dwtx.jface.text.source.ISourceViewerExtension; // packageimport | |
61 import dwtx.jface.text.source.AnnotationMap; // packageimport | |
62 import dwtx.jface.text.source.IVerticalRulerInfo; // packageimport | |
63 import dwtx.jface.text.source.IAnnotationModelExtension2; // packageimport | |
64 import dwtx.jface.text.source.LineRange; // packageimport | |
65 import dwtx.jface.text.source.IAnnotationAccessExtension2; // packageimport | |
66 import dwtx.jface.text.source.VerticalRuler; // packageimport | |
67 import dwtx.jface.text.source.JFaceTextMessages; // packageimport | |
68 import dwtx.jface.text.source.IOverviewRuler; // packageimport | |
69 import dwtx.jface.text.source.Annotation; // packageimport | |
70 import dwtx.jface.text.source.IVerticalRulerListener; // packageimport | |
71 import dwtx.jface.text.source.ISourceViewerExtension4; // packageimport | |
72 import dwtx.jface.text.source.AnnotationPainter; // packageimport | |
73 import dwtx.jface.text.source.IAnnotationHoverExtension2; // packageimport | |
74 import dwtx.jface.text.source.OverviewRuler; // packageimport | |
75 import dwtx.jface.text.source.OverviewRulerHoverManager; // packageimport | |
76 | |
77 | |
129 | 78 import dwt.dwthelper.utils; |
79 | |
80 import dwt.DWT; | |
81 import dwt.graphics.FontMetrics; | |
82 import dwt.graphics.GC; | |
83 import dwt.graphics.Image; | |
84 import dwt.graphics.Rectangle; | |
85 import dwt.widgets.Canvas; | |
86 | |
87 /** | |
88 * Provides methods for drawing images onto a canvas. | |
89 * <p> | |
90 * This class is neither intended to be instantiated nor subclassed. | |
91 * </p> | |
92 * | |
93 * @since 3.0 | |
94 * @noinstantiate This class is not intended to be instantiated by clients. | |
95 * @noextend This class is not intended to be subclassed by clients. | |
96 */ | |
97 public class ImageUtilities { | |
98 | |
99 /** | |
100 * Draws an image aligned inside the given rectangle on the given canvas. | |
101 * | |
102 * @param image the image to be drawn | |
103 * @param gc the drawing GC | |
104 * @param canvas the canvas on which to draw | |
105 * @param r the clipping rectangle | |
106 * @param halign the horizontal alignment of the image to be drawn | |
107 * @param valign the vertical alignment of the image to be drawn | |
108 */ | |
109 public static void drawImage(Image image, GC gc, Canvas canvas, Rectangle r, int halign, int valign) { | |
110 if (image !is null) { | |
111 | |
112 Rectangle bounds= image.getBounds(); | |
113 | |
114 int x= 0; | |
115 switch(halign) { | |
116 case DWT.LEFT: | |
117 break; | |
118 case DWT.CENTER: | |
119 x= (r.width - bounds.width) / 2; | |
120 break; | |
121 case DWT.RIGHT: | |
122 x= r.width - bounds.width; | |
123 break; | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
145
diff
changeset
|
124 default: |
129 | 125 } |
126 | |
127 int y= 0; | |
128 switch (valign) { | |
129 case DWT.TOP: { | |
130 FontMetrics fontMetrics= gc.getFontMetrics(); | |
131 y= (fontMetrics.getHeight() - bounds.height)/2; | |
132 break; | |
133 } | |
134 case DWT.CENTER: | |
135 y= (r.height - bounds.height) / 2; | |
136 break; | |
137 case DWT.BOTTOM: { | |
138 FontMetrics fontMetrics= gc.getFontMetrics(); | |
139 y= r.height - (fontMetrics.getHeight() + bounds.height)/2; | |
140 break; | |
141 } | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
145
diff
changeset
|
142 default: |
129 | 143 } |
144 | |
145 gc.drawImage(image, r.x+x, r.y+y); | |
146 } | |
147 } | |
148 | |
149 /** | |
150 * Draws an image aligned inside the given rectangle on the given canvas. | |
151 * | |
152 * @param image the image to be drawn | |
153 * @param gc the drawing GC | |
154 * @param canvas the canvas on which to draw | |
155 * @param r the clipping rectangle | |
156 * @param align the alignment of the image to be drawn | |
157 */ | |
145 | 158 public static void drawImage(Image image, GC gc, Canvas canvas, Rectangle r, int align_) { |
159 drawImage(image, gc, canvas, r, align_, DWT.CENTER); | |
129 | 160 } |
161 } |