圆形
Ellipse ellipse =new Ellipse();
ellipse.setBounds(new Rectangle(20,20,50,50));
ellipse.setVisible(false);
add(ellipse);
方形
RectangleFigure rectangleFigure = new RectangleFigure();
rectangleFigure.setBounds(new Rectangle(20,20,50,50));
add(rectangleFigure);
背景色颜色
List<?> figureChildren = f.getChildren();
for (Object object : figureChildren ) {
if (object instanceof Ellipse || object instanceof RectangleFigure) {
((IFigure)object).setBackgroundColor(new Color(null, 颜色的RGB对象);
}
}
边框颜色
for (Object object : figureChildren ) {
if (object instanceof Ellipse ||
object instanceof RectangleFigure) {
((IFigure)object).setForegroundColor(
new Color(null,
Converter.Int2RGB(Long.parseLong(evt.getNewValue()+""))));
((IFigure)object).setBorder(
new
LineBorder(Converter.Int2Color(Long.parseLong(evt.getNewValue()+"")), 5) );
}
}
根据坐标画线
@Override
public void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
drawWave(graphics);
}
protected void drawWave(Graphics graphics){
setForegroundColor(ColorConstants.red);
graphics.setLineWidth(mPenWidth);
Rectangle bounds = getBounds().getCopy();
if (bounds.width == 0) {
return;
}
int index = getParent().getChildren().indexOf(this);
graphics.setAntialias(SWT.ON);
PointList points = new PointList();
double w = 2 * Math.PI / bounds.width;
double offset = (index * 10 ) * Math.PI / 180.0;
if (mStyle == Diagram.STYLE_LINE_BROKEN) {
double[] p = new double[]{0, ((Math.PI/2 + offset) / w) , ((Math.PI/2*3 + offset) / w), bounds.width};
int first = (int) ((Math.sin(w * p[0] - offset)*bounds.height/2) + bounds.height/2);
points.addPoint((int) (bounds.x + p[0]), bounds.y + first);
points.addPoint((int) (bounds.x + p[1]), bounds.y + bounds.height);
points.addPoint((int) (bounds.x + p[2]), bounds.y + 0);
int last = (int) ((Math.sin(w * p[3] - offset)*bounds.height/2) + bounds.height/2);
points.addPoint((int) (bounds.x + p[3]), bounds.y + last);
} else {
for(int i = 0; i <= bounds.width; i += 1){
int funy = (int) (Math.sin(w * i - offset)*bounds.height/2);
int y = funy + bounds.y + bounds.height/2;
int x = bounds.x + i;
points.addPoint(x, y);
}
}
graphics.drawPolyline(points);
}