1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| import java.awt.Graphics2D;
import org.bpy.stamp.philaeditor.gef.model.TextNode;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Font;
public class TextFigure extends Figure {
private Rectangle rect;
private Font font;
private String textToDisplay;
public TextFigure() {
}
public void setCurrentFont(Font f) {
font = f;
// super.setFont(f);
}
public void setText(String text) {
textToDisplay = text;
super.setText(text);
}
public void setLayout(Rectangle rect) {
this.rect = rect;
setBounds(rect);
rect.width += 2;
rect.height += 2;
getParent().setConstraint(this, rect);
}
protected void paintFigure(Graphics g) {
g.setForegroundColor(ColorConstants.black);
g.setFont(font);
g.scale (0.35); //scales about the origin
g.drawString(textToDisplay, 0,0);
}
} |
Partager