use of org.eclipse.swt.graphics.Transform in project netxms by netxms.
the class Title method drawVerticalTitle.
/**
* Draws the vertical title.
*
* @param gc
* The graphics context
*/
private void drawVerticalTitle(GC gc) {
boolean useStyleRanges = styleRanges != null;
int textWidth;
int textHeight;
if (useStyleRanges) {
textWidth = textLayout.getBounds().width;
textHeight = textLayout.getBounds().height;
} else {
textWidth = gc.textExtent(text).x;
textHeight = gc.textExtent(text).y;
}
// create image to draw text
Image image = new Image(Display.getCurrent(), textWidth, textHeight);
GC tmpGc = new GC(image);
if (useStyleRanges) {
textLayout.draw(tmpGc, 0, 0);
} else {
tmpGc.setForeground(getForeground());
tmpGc.setBackground(getBackground());
tmpGc.setFont(getFont());
tmpGc.drawText(text, 0, 0);
}
// set transform to rotate
Transform transform = new Transform(gc.getDevice());
transform.translate(0, textWidth);
transform.rotate(270);
gc.setTransform(transform);
// draw the image on the rotated graphics context
int height = getSize().y;
int y = (int) (height / 2d - textWidth / 2d);
if (y < 0) {
y = 0;
}
gc.drawImage(image, -y, 0);
// dispose resources
tmpGc.dispose();
transform.dispose();
image.dispose();
}
use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method scale.
/**
* Applies a scale transform.
*
* @param scaleX the scale factor along the x-axis.
* @param scaleY the scale factor along the y-axis.
*/
public void scale(double scaleX, double scaleY) {
Transform swtTransform = new Transform(this.gc.getDevice());
this.gc.getTransform(swtTransform);
swtTransform.scale((float) scaleX, (float) scaleY);
this.gc.setTransform(swtTransform);
swtTransform.dispose();
}
use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method translate.
/**
* Applies a translation.
*
* @param x the translation along the x-axis.
* @param y the translation along the y-axis.
*/
public void translate(int x, int y) {
Transform swtTransform = new Transform(this.gc.getDevice());
this.gc.getTransform(swtTransform);
swtTransform.translate(x, y);
this.gc.setTransform(swtTransform);
swtTransform.dispose();
}
use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method getSwtTransformFromPool.
/**
* Internal method to convert a AWT transform object into
* a SWT transform resource. If a corresponding SWT transform
* instance is already in the pool, it will be used
* instead of creating a new one. This is used in
* {@link #setTransform()} for instance.
*
* @param awtTransform The AWT transform to convert.
* @return A SWT transform instance.
*/
private Transform getSwtTransformFromPool(AffineTransform awtTransform) {
Transform t = (Transform) this.transformsPool.get(awtTransform);
if (t == null) {
t = new Transform(this.gc.getDevice());
double[] matrix = new double[6];
awtTransform.getMatrix(matrix);
t.setElements((float) matrix[0], (float) matrix[1], (float) matrix[2], (float) matrix[3], (float) matrix[4], (float) matrix[5]);
addToResourcePool(t);
this.transformsPool.put(awtTransform, t);
}
return t;
}
use of org.eclipse.swt.graphics.Transform in project SIMVA-SoS by SESoS.
the class SWTGraphics2D method getTransform.
/**
* Returns the current transform.
*
* @return The current transform.
*/
public AffineTransform getTransform() {
Transform swtTransform = new Transform(this.gc.getDevice());
this.gc.getTransform(swtTransform);
AffineTransform awtTransform = toAwtTransform(swtTransform);
swtTransform.dispose();
return awtTransform;
}
Aggregations