Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-04-27 12:27:31 +0000
committerKai Maetzel2004-04-27 12:27:31 +0000
commit091c888df446f35691b55285ae7d22f973f1f34a (patch)
tree88f08467dd6a2543ec8098527365cb0360e02242 /org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java
parentda86ac494b1d1715c5507abf343d8d9c223d7082 (diff)
downloadeclipse.platform.text-091c888df446f35691b55285ae7d22f973f1f34a.tar.gz
eclipse.platform.text-091c888df446f35691b55285ae7d22f973f1f34a.tar.xz
eclipse.platform.text-091c888df446f35691b55285ae7d22f973f1f34a.zip
prepare headless annotation support
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java
new file mode 100644
index 00000000000..3ba24ff7a59
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.FontMetrics;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Canvas;
+
+/**
+ * Provides methods for drawing images onto a canvas.
+ *
+ * @since 3.0
+ */
+public class ImageUtilities {
+
+ /**
+ * Draws an image aligned inside the given rectangle on the given canvas.
+ *
+ * @param image the image to be drawn
+ * @param gc the drawing GC
+ * @param canvas the canvas on which to draw
+ * @param r the clipping rectangle
+ * @param halign the horizontal alignment of the image to be drawn
+ * @param valign the vertical alignment of the image to be drawn
+ */
+ public static void drawImage(Image image, GC gc, Canvas canvas, Rectangle r, int halign, int valign) {
+ if (image != null) {
+
+ Rectangle bounds= image.getBounds();
+
+ int x= 0;
+ switch(halign) {
+ case SWT.LEFT:
+ break;
+ case SWT.CENTER:
+ x= (r.width - bounds.width) / 2;
+ break;
+ case SWT.RIGHT:
+ x= r.width - bounds.width;
+ break;
+ }
+
+ int y= 0;
+ switch (valign) {
+ case SWT.TOP: {
+ FontMetrics fontMetrics= gc.getFontMetrics();
+ y= (fontMetrics.getHeight() - bounds.height)/2;
+ break;
+ }
+ case SWT.CENTER:
+ y= (r.height - bounds.height) / 2;
+ break;
+ case SWT.BOTTOM: {
+ FontMetrics fontMetrics= gc.getFontMetrics();
+ y= r.height - (fontMetrics.getHeight() + bounds.height)/2;
+ break;
+ }
+ }
+
+ gc.drawImage(image, r.x+x, r.y+y);
+ }
+ }
+
+ /**
+ * Draws an image aligned inside the given rectangle on the given canvas.
+ *
+ * @param image the image to be drawn
+ * @param gc the drawing GC
+ * @param canvas the canvas on which to draw
+ * @param r the clipping rectangle
+ * @param align the alignment of the image to be drawn
+ */
+ public static void drawImage(Image image, GC gc, Canvas canvas, Rectangle r, int align) {
+ drawImage(image, gc, canvas, r, align, SWT.CENTER);
+ }
+}

Back to the top