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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
public class PlanningTask extends Canvas{
private static final int TASK_HEIGHT = 20;
private static final int TASK_TEXT_FONT_HEIGHT = 10;
public PlanningTask(final Composite parent, int style) {
super(parent, style);
addCanvasListener();
System.out.println("width parent " + parent.getSize().x);
this.setSize(parent.getSize().x, parent.getSize().y);
}
/**
* Ajoute un listener
*
*/
private void addCanvasListener() {
// ajoute un listener qui écoute les modifications sur le planning
this.addPaintListener(new PaintListener() {
public void paintControl(final PaintEvent event) {
PlanningTask.this.paint(event.gc);
}
});
}
/* Paint function */
private void paint(GC gc) {
System.out.println("width image in paint méthode " + getSize().x);
Image image = (Image) getData("double-buffer-image");
if (image == null || image.getBounds().width != getSize().x || image.getBounds().height != getSize().y) {
image = new Image(getDisplay(),getSize().x,getSize().y);
setData("double-buffer-image", image);
}
GC imageGC = new GC(image);
imageGC.setAntialias(SWT.ON);
paintTask(imageGC);
gc.drawImage(image, 0, 0);
imageGC.dispose();
gc.dispose();
}
/**
* <p>
* Paint the planning.
* </p>
*
*/
private void paintTask(GC gc) {
Color color = this.getDisplay().getSystemColor(
SWT.COLOR_YELLOW);
gc.setForeground(this.getDisplay().getSystemColor(
SWT.COLOR_BLACK));
gc.setBackground(color);
Font font = new Font(this.getDisplay(), "Arial",TASK_TEXT_FONT_HEIGHT,SWT.BOLD);
int x = this.getBounds().x;
int y = this.getBounds().y;
int width = this.getSize().x;
System.out.println("width "+width);
int height = TASK_HEIGHT;
gc.drawRoundRectangle( x,y,width,height,10,10);
gc.fillRoundRectangle(x+1,y+1,width-1, height-1,9,9);
gc.setFont(font);
Point textSize = gc.textExtent("task");
int xText = (int) ((x + width/ 2) - (textSize.x / 2));
int yText = (int) ((y + 25 / 2) - (textSize.y / 2));
gc.drawText("task", xText, yText);
gc.dispose();
}
} |
Partager