00001
00002
00003
00004
00005
00006
00007 package org.swtchart.internal;
00008
00009 import org.eclipse.swt.SWT;
00010 import org.eclipse.swt.graphics.Font;
00011 import org.eclipse.swt.graphics.GC;
00012 import org.eclipse.swt.graphics.Image;
00013 import org.eclipse.swt.graphics.Point;
00014 import org.eclipse.swt.widgets.Display;
00015 import org.swtchart.LineStyle;
00016
00020 public final class Util {
00021
00033 public static Point getExtentInGC(Font font, String text) {
00034
00035 if (text == null || font == null || font.isDisposed()) {
00036 return new Point(0, 0);
00037 }
00038
00039
00040 int ARBITRARY_WIDTH = 10;
00041 int ARBITRARY_HEIGHT = 10;
00042 Image image = new Image(Display.getCurrent(), ARBITRARY_WIDTH,
00043 ARBITRARY_HEIGHT);
00044 GC gc = new GC(image);
00045
00046
00047 gc.setFont(font);
00048 Point p = gc.textExtent(text);
00049
00050
00051 image.dispose();
00052 gc.dispose();
00053
00054 return p;
00055 }
00056
00064 public static int getIndexDefinedInSWT(LineStyle lineStyle) {
00065 switch (lineStyle) {
00066 case NONE:
00067 return SWT.NONE;
00068 case SOLID:
00069 return SWT.LINE_SOLID;
00070 case DASH:
00071 return SWT.LINE_DASH;
00072 case DOT:
00073 return SWT.LINE_DOT;
00074 case DASHDOT:
00075 return SWT.LINE_DASHDOT;
00076 case DASHDOTDOT:
00077 return SWT.LINE_DASHDOTDOT;
00078 default:
00079 return SWT.LINE_SOLID;
00080 }
00081 }
00082 }