当前位置:网站首页>Draw2d custom dashboard
Draw2d custom dashboard
2022-04-22 01:11:00 【Cry】
draw2d Customize dashboard
A circle
Ellipse1 ellipse = new Ellipse1();
// Set coordinates
ellipse.setBounds(copy);
// Turn on background color settings
ellipse.setOpaque(true);
// Set background color
ellipse.setBackgroundColor(ColorConstants.white);
// Adds a circle to the current figure
add(ellipse);
Draw a dividing line
import org.eclipse.cdt.codan.core.model.cfg.IExitNode;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
/** * @author jg * Such inheritance draw2d Encapsulated circle drawing class * 2022 year 4 month 15 Japan */
public class Ellipse1 extends Ellipse {
@Override
public void paintFigure(Graphics graphics) {
// TODO Auto-generated method stub
super.paintFigure(graphics);
// Get the position of the circle
Rectangle copy = getBounds().getCopy();
drawScale(graphics,copy);
}
/** * Rendering content */
public void drawScale(Graphics graphics,Rectangle copy) {
// reduce 2 Because the circle's parent control border width
int x = copy.x-2;
int y = copy.y-2;
int width = copy.width;
int height = copy.height;
// Center position
int circleCenterX= x + (width/2);
int circleCenterY= y + (height/2);
graphics.setBackgroundColor(ColorConstants.black);
graphics.fillRoundRectangle(new Rectangle(circleCenterX,circleCenterY,10,10), 100, 100);
// radius -15 In order that the dividing line is not on the circle
int r = height/2 -15;
SplitObj splitObj = meter.getSplitObj();
// Line width
graphics.setLineWidth(splitObj.getSplitPointWidth());
ArrayList<Point> coordinate = new ArrayList<>();
//TextLayout layout = new TextLayout(null);
// Numerical calculation displayed on the split line
// Starting point value 、 Terminal value 、 Number of split lines 、 span , Such as : Starting point value 0、 Terminal value 100、 Number of split lines 41、 span 4
int interValValue = (100-0)/(40 /4);
// Display value
int num = 0;
// Custom scale , Such as : Display only 45 C to 315 Degree interval , Point of division 41 individual
double angle = 45;
for (int i = 0; i < 41; i++) {
// Calculate the radian of each scale
// First calculate the angle
if (i == 0) {
// Fixed start angle
angle = 45;
} else if (i == 40) {
// Fixed end angle ( It can be set or not )
angle = 315;
} else {
// Be sure to add a decimal point here , The clock responsible for the calculation result gets an integer ,41 A scale represents the need for 40 Bisection angle
angle += ((315.0 - 45.0) / 40.0);
}
double radian = angle * (Math.PI / 180);
// Set the property of large split point , They are span , Line width 、 Thread length 、 Color Such as : span 4 、 Line width 4、 Thread length 15 、 Color 0x0
int len = 10;
if (i % 4 ==0) {
// Line width
graphics.setLineWidth(4);
// The line length of the split point is
len = 15;
// Large split point position setting value
// graphics.drawLine( circleCenterX + (int) (Math.cos(radian) * (r-20)),
// circleCenterY + (int) (Math.sin(radian) * (r-20)),
// circleCenterX + (int) (Math.cos(radian) * (r - 25)),
// circleCenterY + (int) (Math.sin(radian) * (r - 25)));
// graphics.drawRectangle( circleCenterX + (int) (Math.cos(radian) * (r-15)),
// circleCenterY + (int) (Math.sin(radian) * (r-15))
// ,40,30);
// When the angle is 0 To 180 Between Put the coordinates up 15 spot
if (0.0 < angle && angle< 180.0) {
graphics.drawString(""+num, circleCenterX + (int) (Math.cos(radian) * (r -len-10)),
circleCenterY + (int) (Math.sin(radian) * (r -len-30)));
// layout.setText(""+num);
// graphics.drawTextLayout(layout, circleCenterX + (int) (Math.cos(radian) * (r -len-10)),
// circleCenterY + (int) (Math.sin(radian) * (r -len-10)),
// 0, -1, ColorConstants.red,
// ColorConstants.black);
}else {
graphics.drawString(""+num,circleCenterX + (int) (Math.cos(radian) * (r - len-5)),
circleCenterY + (int) (Math.sin(radian) * (r - len-5))
);
}
// Add radians
// Judge the starting point value
if (num == 0 ) {
graphics.setForegroundColor(Converter.Int2Color(Converter.Hex2Int("#ff0000")));
// Add radians
/*for (int i = 0; i < coordinate.size(); i+=2) { graphics.drawLine(coordinate.get(i), coordinate.get(i+1)); }*/
// Inner circle
Rectangle rectangle = new Rectangle();
//15 According to the above int r = height/2 -15; have to
rectangle.x = x + 15;
rectangle.y = y + 15;
//30 Subtract... From both sides of the middle circle 15 have to
rectangle.width =width -30;
rectangle.height =height-30;
// 0 Starting angle ,90 Arc length
//graphics.drawArc(rectangle, 0, 90);
// Note that the angle here is from 3 PM , Increase the angle counterclockwise , So everything is reversed
graphics.drawArc(rectangle, (int)(360-angle), -(270/10*4));
}else if (num == 80) {
graphics.setForegroundColor(Converter.Int2Color(Converter.Hex2Int("#0000ff")));
// Inner circle
Rectangle rectangle = new Rectangle();
//15 According to the above int r = height/2 -15; have to
rectangle.x = x + 15;
rectangle.y = y + 15;
//30 Subtract... From both sides of the middle circle 15 have to
rectangle.width =width -30;
rectangle.height =height-30;
// 0 Starting angle ,90 Arc length
//graphics.drawArc(rectangle, 0, 90);
// Note that the angle here is from 3 PM , Increase the angle counterclockwise
graphics.drawArc(rectangle, (int)(360-angle), -(270/10*2));
}
// Color 0xaaaaaa
graphics.setForegroundColor(Converter.Int2Color(0));
num += interValValue;
}else {
// Line width
graphics.setLineWidth(2);
// Color 0xaaaaaa
graphics.setForegroundColor(Converter.Int2Color(Converter.Hex2Int("#aaaaaa")));
// The line length of the split point is
len = 10;
}
// Be careful : Here I am with 3 Point as the starting point , The angle increases clockwise
graphics.drawLine(circleCenterX + (int) (Math.cos(radian) * r),
circleCenterY + (int) (Math.sin(radian) * r),
circleCenterX + (int) (Math.cos(radian) * (r - len)),
circleCenterY + (int) (Math.sin(radian) * (r - len))
);
}
}
}
effect :( There's another pointer that hasn't been drawn )

版权声明
本文为[Cry]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220034230921.html
边栏推荐
- 想要加盟智能家居,你需要了解些什么?
- 腾讯云数据库MYSQL备份失败原因
- MySQL数据库常识之储存引擎
- [observation] let the energy industry "dance with elephants", and the Chinese system build a digital base with hard core strength
- 13 bullish forms of K-line chart (Part 2)
- 3D 沙盒游戏之人物的点击行走移动
- . net core enterprise wechat web page authorization login
- I use ehcache to improve the query performance by 100 times. It's really fragrant
- The AOV function of R language is used for one-way ANOVA, the normality of the dependent variable of ANOVA is evaluated by Q-Q diagram, the equality (homogeneity) of Bartlett's verification variance,
- Finally, wechat scanning code login is completed. It's really fragrant..
猜你喜欢
Ideal one finally replaced? Brand new product sequence named L8, heavily camouflaged road test exposure

A simple and easy-to-use file upload scheme

Mysql database common sense storage engine
Lincoln Z vs. Audi A4L: the product power gap is actually the epitome of the two times

DPI released the latest progress report on AI drug research and development

Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
![[course summary] Hello harmonyos series of courses, take you to zero foundation introduction](/img/47/902a1a76991217dff0a89ee944a8d1.jpg)
[course summary] Hello harmonyos series of courses, take you to zero foundation introduction

L'Internet des objets n'a - t - il pas d'avenir?

While hoarding goods, it's time to recognize cans again

Under the catalysis of the epidemic, why can this product promote the commercialization of automatic distribution?
随机推荐
精品:千字长文手把手教你使用字节跳动的火山引擎veImageX
Hold these five points! On the job postgraduate entrance examination can also go ashore!
MySQL进阶之常用函数
What are the advantages of an automated testing framework?
kubernetes+prometheus+grafana
Finally, wechat scanning code login is completed. It's really fragrant..
Use of Prometheus
观测云登陆阿里云计算巢,共建ISV新生态
诚邀报名丨首期OpenHarmony开发者成长计划分享日
js数组对象去重
Force buckle 55 Jumping game
RPCX源码学习-server端
R language MANOVA function robust one-way MANOVA, Wilks in rrcov package Test function robust one-way MANOVA, Adonis function of vegan package, nonparametric MANOVA equivalent
Cloud security daily 220421: Cisco virtualization infrastructure manager software found a privilege upgrade vulnerability and needs to be upgraded as soon as possible
Observe cloud landing in Alibaba cloud computing nest and build a new ISV ecosystem
Addition, deletion, modification and query of MySQL advanced table
Build a personal blog (WordPress) on Alibaba cloud
Introduction to Haskell monoid
不能再简单的意向锁
Ivorysql unveiled at postgresconf SV 2022 Silicon Valley Postgres Conference