de.jaret.util.swt
Class SwtGraphicsHelper

java.lang.Object
  extended by de.jaret.util.swt.SwtGraphicsHelper

public class SwtGraphicsHelper
extends Object

A simple class containing several static methods for convenient painting with a SWT gc.

Version:
$Id: SwtGraphicsHelper.java 726 2008-03-18 21:06:14Z kliem $
Author:
Peter Kliem

Constructor Summary
SwtGraphicsHelper()
           
 
Method Summary
static void drawArrowLine(org.eclipse.swt.graphics.GC gc, int x1, int y1, int x2, int y2, int dist, int height, boolean arrowLeft, boolean arrowRight)
           
static void drawArrowLineVertical(org.eclipse.swt.graphics.GC gc, int x1, int y1, int x2, int y2, int dist, int height, boolean arrowUp, boolean arrowDown)
           
static void drawStringCentered(org.eclipse.swt.graphics.GC gc, String string, int xCenter, int yBase)
           
static void drawStringCentered(org.eclipse.swt.graphics.GC gc, String string, int left, int right, int y)
          Draw a string centered between x,y at top y.
static void drawStringCentered(org.eclipse.swt.graphics.GC gc, String string, int x, int y, int width, int height)
          Draw the string centered in the given rectangle (specified by plain values)
static void drawStringCentered(org.eclipse.swt.graphics.GC gc, String string, org.eclipse.swt.graphics.Rectangle rect)
          Draw String centered in the given rectangle.
static void drawStringCenteredAroundPoint(org.eclipse.swt.graphics.GC gc, String string, int xCenter, int yCenter)
           
static void drawStringCenteredMidX(org.eclipse.swt.graphics.GC gc, String string, int midx, int y)
           
static void drawStringCenteredVCenter(org.eclipse.swt.graphics.GC gc, String string, int left, int right, int yCenter)
           
static void drawStringLeftAlignedVCenter(org.eclipse.swt.graphics.GC gc, String string, int x, int y)
           
static void drawStringRightAlignedVCenter(org.eclipse.swt.graphics.GC gc, String string, int x, int y)
           
static void drawStringRightAlignedVTop(org.eclipse.swt.graphics.GC gc, String string, int x, int yTop)
          Draws a String right aligned with the y coordinate denoting the top of the string.
static void drawStringVCentered(org.eclipse.swt.graphics.GC gc, String label, int x, int upperY, int lowerY)
          Draw a string vertical centered beetween upper and lower y left aligned to x.
static void drawStringVertical(org.eclipse.swt.graphics.GC gc, String string, int x, int y)
          Draw a String vertical.
static org.eclipse.swt.graphics.ImageData dropShadow(org.eclipse.swt.graphics.ImageData originalImageData, org.eclipse.swt.graphics.Color color, int radius, int highlightRadius, int opacity)
          Create an image with a drop shadow.
static int getStringDrawingHeight(org.eclipse.swt.graphics.GC gc, String string)
           
static int getStringDrawingWidth(org.eclipse.swt.graphics.GC gc, String string)
           
static org.eclipse.swt.graphics.ImageData glow(org.eclipse.swt.graphics.ImageData originalImageData, org.eclipse.swt.graphics.Color color, int radius, int highlightRadius, int opacity)
          Create an image with a glow effect.
static org.eclipse.swt.graphics.Image reflect(org.eclipse.swt.graphics.Image img, org.eclipse.swt.graphics.Device device)
          Create a reflection image (Idea taken from Daniel Spiewak: see http://www.eclipsezone.com/eclipse/forums/t91013.html?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwtGraphicsHelper

public SwtGraphicsHelper()
Method Detail

drawStringCentered

public static void drawStringCentered(org.eclipse.swt.graphics.GC gc,
                                      String string,
                                      int left,
                                      int right,
                                      int y)
Draw a string centered between x,y at top y.

Parameters:
gc - gc
string - string
left - left bound
right - right bound
y - top y

drawStringCenteredMidX

public static void drawStringCenteredMidX(org.eclipse.swt.graphics.GC gc,
                                          String string,
                                          int midx,
                                          int y)

drawStringCenteredVCenter

public static void drawStringCenteredVCenter(org.eclipse.swt.graphics.GC gc,
                                             String string,
                                             int left,
                                             int right,
                                             int yCenter)

drawStringRightAlignedVCenter

public static void drawStringRightAlignedVCenter(org.eclipse.swt.graphics.GC gc,
                                                 String string,
                                                 int x,
                                                 int y)

drawStringLeftAlignedVCenter

public static void drawStringLeftAlignedVCenter(org.eclipse.swt.graphics.GC gc,
                                                String string,
                                                int x,
                                                int y)

drawStringCentered

public static void drawStringCentered(org.eclipse.swt.graphics.GC gc,
                                      String string,
                                      int xCenter,
                                      int yBase)

drawStringCenteredAroundPoint

public static void drawStringCenteredAroundPoint(org.eclipse.swt.graphics.GC gc,
                                                 String string,
                                                 int xCenter,
                                                 int yCenter)

drawStringCentered

public static void drawStringCentered(org.eclipse.swt.graphics.GC gc,
                                      String string,
                                      int x,
                                      int y,
                                      int width,
                                      int height)
Draw the string centered in the given rectangle (specified by plain values)

Parameters:
gc -
string -
x -
y -
width -
height -

drawStringCentered

public static void drawStringCentered(org.eclipse.swt.graphics.GC gc,
                                      String string,
                                      org.eclipse.swt.graphics.Rectangle rect)
Draw String centered in the given rectangle.

Parameters:
gc -
string -
rect -

getStringDrawingWidth

public static int getStringDrawingWidth(org.eclipse.swt.graphics.GC gc,
                                        String string)

getStringDrawingHeight

public static int getStringDrawingHeight(org.eclipse.swt.graphics.GC gc,
                                         String string)

drawStringRightAlignedVTop

public static void drawStringRightAlignedVTop(org.eclipse.swt.graphics.GC gc,
                                              String string,
                                              int x,
                                              int yTop)
Draws a String right aligned with the y coordinate denoting the top of the string.

Parameters:
gc - GC
string - string to draw
x - right x position
yTop - top y position

drawArrowLine

public static void drawArrowLine(org.eclipse.swt.graphics.GC gc,
                                 int x1,
                                 int y1,
                                 int x2,
                                 int y2,
                                 int dist,
                                 int height,
                                 boolean arrowLeft,
                                 boolean arrowRight)

drawArrowLineVertical

public static void drawArrowLineVertical(org.eclipse.swt.graphics.GC gc,
                                         int x1,
                                         int y1,
                                         int x2,
                                         int y2,
                                         int dist,
                                         int height,
                                         boolean arrowUp,
                                         boolean arrowDown)

drawStringVCentered

public static void drawStringVCentered(org.eclipse.swt.graphics.GC gc,
                                       String label,
                                       int x,
                                       int upperY,
                                       int lowerY)
Draw a string vertical centered beetween upper and lower y left aligned to x.

Parameters:
gc - GC
label - label to draw
x - left x
upperY - upper y bound
lowerY - lower y bound

drawStringVertical

public static void drawStringVertical(org.eclipse.swt.graphics.GC gc,
                                      String string,
                                      int x,
                                      int y)
Draw a String vertical. This method might be quite costly since it uses an image to buffer.

Parameters:
gc - gc
string - strin gto to draw
x - upper left x
y - upper left y

dropShadow

public static org.eclipse.swt.graphics.ImageData dropShadow(org.eclipse.swt.graphics.ImageData originalImageData,
                                                            org.eclipse.swt.graphics.Color color,
                                                            int radius,
                                                            int highlightRadius,
                                                            int opacity)
Create an image with a drop shadow. This method is (c) 2007 Nicholas Rajendram, IBM Canada, see http://www.eclipse.org/articles/article.php?file=Article-SimpleImageEffectsForSWT/index.html.

Parameters:
originalImageData - The original image. Transparency information will be ignored.
color - The color of the drop shadow
radius - The radius of the drop shadow in pixels
highlightRadius - The radius of the highlight area
opacity - The opacity of the drop shadow
Returns:
The drop shadowed image. This image data will be larger than the original. The same image data will be returned if the shadow radius is 0, or null if an error occured.

glow

public static org.eclipse.swt.graphics.ImageData glow(org.eclipse.swt.graphics.ImageData originalImageData,
                                                      org.eclipse.swt.graphics.Color color,
                                                      int radius,
                                                      int highlightRadius,
                                                      int opacity)
Create an image with a glow effect. This method is (c) 2007 Nicholas Rajendram, IBM Canada, see http://www.eclipse.org/articles/article.php?file=Article-SimpleImageEffectsForSWT/index.html.

Parameters:
originalImageData - The original image. Transparency information will be ignored.
color - The color of the glow
radius - The radius of the glow in pixels
highlightRadius - The radius of the highlight area
opacity - The opacity of the glow
Returns:
The glowing image. This image data will be larger than the original. The same image data will be returned if the glow radius is 0, or null if an error occured.

reflect

public static org.eclipse.swt.graphics.Image reflect(org.eclipse.swt.graphics.Image img,
                                                     org.eclipse.swt.graphics.Device device)
Create a reflection image (Idea taken from Daniel Spiewak: see http://www.eclipsezone.com/eclipse/forums/t91013.html?start=0).

Parameters:
img - image to reflect
device - device
Returns:
image (larger than the original) containing a reflectd version of the original image


Copyright © 2013. All Rights Reserved.