draw2d 在Figure上绘图

圆形

		//设置圆形
		Ellipse ellipse =new Ellipse();
		//20 ,20 代表x和y ;50,50代表宽高
		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) );
					}
				}

根据坐标画线

//重写paintFigure方法
	@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);
		
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值