package com.java.service;
import java.util.Random;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swtchart.Chart;
import org.eclipse.swtchart.ILineSeries;
import org.eclipse.swtchart.ISeries.SeriesType;
import org.eclipse.swtchart.LineStyle;
public class TestUIService
{
public static void main(String[] args) {
startUI();
}
public static void startUI() {
Display display = createDisplay();// 显示
Shell shellCpu = createShell(display);
SashForm sashForm = new SashForm(shellCpu, SWT.NONE);//表单
//可以调整顺序,修改展示顺序
addChartComposite(display, sashForm);
createTable1(sashForm);// 数据分页表格
createTable2(shellCpu);
openShell(display, shellCpu,sashForm);
}
public static Display createDisplay() {
final Display display = new Display();// 显示
return display;
}
public static void openShell(Display display,Shell shellCpu,SashForm sashForm) {
sashForm.setWeights(new int[] {600, 600});// 表单,宽度,左宽,右宽
shellCpu.open();// 打开
// 保持界面,持续打开
while (!shellCpu.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public static Shell createShell(Display display) {
Shell shellCpu = new Shell(display);// 窗体
shellCpu.setSize(1000, 900);// 大小
shellCpu.setText("cpu\u4F7F\u7528\u60C5\u51B5");
shellCpu.setLayout(new FillLayout(SWT.VERTICAL));// 设置布局,才能添加组件
return shellCpu;
}
public static void createTable1(SashForm sashForm) {
{
Composite composite = new Composite(sashForm, SWT.NONE);
composite.setLayout(new FillLayout(SWT.HORIZONTAL));// 必须设置布局,否则不显示
//addButton(composite);
CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
Table table = checkboxTableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
// 创建表头的字符串数组
TestService.createTable1(sashForm, table);
}
}
public static void createTable2(Shell shell) {
{
Composite composite_1 = new Composite(shell, SWT.NONE);
composite_1.setLayout(new FillLayout(SWT.HORIZONTAL));
Table table_1 = new Table(composite_1, SWT.BORDER | SWT.FULL_SELECTION);
table_1.setHeaderVisible(true);
table_1.setLinesVisible(true);
String[] tableHeader1 = {"名称", "坐标"};
for (int i = 0; i < tableHeader1.length; i++)
{
TableColumn tableColumn = new TableColumn(table_1, SWT.NONE);
tableColumn.setText(tableHeader1[i]);
// 设置表头可移动,默认为false
tableColumn.setMoveable(true);
}
TableItem item1;
for(int i=1;i<6;i++){
item1 = new TableItem(table_1, SWT.NONE);
item1.setText(new String[]{"重型泡沫车"+i ,2650+3*(i-1)+",8400"});
}
for(int i=1;i<5;i++){
item1 = new TableItem(table_1, SWT.NONE);
item1.setText(new String[]{"救护车"+i , 2666+3*(i-1)+",8400"});
}
// 重新布局表格
for (int i = 0; i < tableHeader1.length; i++)
{
table_1.getColumn(i).pack();
}
}
}
public static void addChartComposite(Display display,SashForm sashForm) {
Composite composite = new Composite(sashForm, SWT.NONE);
composite.setLayout(new FillLayout(SWT.HORIZONTAL));// 必须设置布局,否则不显示
Chart chart = new Chart(composite, SWT.NONE);
// set titles
chart.getTitle().setText("xxxx");
chart.getAxisSet().getXAxis(0).getTitle().setText("xx");
chart.getAxisSet().getYAxis(0).getTitle().setText("");
Random r = new Random();
int td = 1;
// create scatter series
{
ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "LINE");
scatterSeries.setLineStyle(LineStyle.SOLID);//线条样式:NONE显示圆点;DASH显示线条
scatterSeries.setLineWidth(1);
org.eclipse.swt.graphics.Color color = new org.eclipse.swt.graphics.Color(display, 0,0,0);
scatterSeries.setSymbolColor(color);
scatterSeries.setLineColor(color);
scatterSeries.setSymbolSize(1);
scatterSeries.setXSeries(new double[] {
0,90,180,270,360
});
scatterSeries.setYSeries(new double[] {
0,0,0,0,0
});
}
/*
{
ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "range");
scatterSeries.setLineStyle(LineStyle.NONE);//线条样式:NONE显示圆点;DASH显示线条
// scatterSeries.setLineWidth(1);
org.eclipse.swt.graphics.Color color = new org.eclipse.swt.graphics.Color(display, 0,0,0);
scatterSeries.setSymbolColor(color);
scatterSeries.setLineColor(color);
scatterSeries.setSymbolSize(0);
scatterSeries.setXSeries(new double[] {
0,90,180,270,360
});
scatterSeries.setYSeries(new double[] {
-200,0,0,0,200
});
}*/
{
ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "测试"+td++);
scatterSeries.setLineStyle(LineStyle.NONE);//线条样式:NONE显示圆点;DASH显示线条
scatterSeries.setLineWidth(1);
org.eclipse.swt.graphics.Color color = new org.eclipse.swt.graphics.Color(display, 250,0,0);
scatterSeries.setSymbolColor(color);
//scatterSeries.setSymbolSize(10);
//scatterSeries.setXDateSeries(new Date[]{new Date(),new Date()});
//scatterSeries.setXAxisId(0);
scatterSeries.setXSeries(new double[] {
1,2,3,4,5
});
scatterSeries.setYSeries(new double[] {
300,300,300,300,300
});
}
{
ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "测试"+td++);
scatterSeries.setLineStyle(LineStyle.NONE);//线条样式:NONE显示圆点;DASH显示线条
scatterSeries.setLineWidth(1);
org.eclipse.swt.graphics.Color color = new org.eclipse.swt.graphics.Color(display, 250,0,0);
scatterSeries.setSymbolColor(color);
//scatterSeries.setSymbolSize(10);
//scatterSeries.setXDateSeries(new Date[]{new Date(),new Date()});
//scatterSeries.setXAxisId(0);
scatterSeries.setXSeries(new double[] {
1,2,3,4,5
});
scatterSeries.setYSeries(new double[] {
100,100,100,100,100
});
}
{
ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "测试"+td++);
scatterSeries.setLineStyle(LineStyle.NONE);//线条样式:NONE显示圆点;DASH显示线条
scatterSeries.setLineWidth(1);
org.eclipse.swt.graphics.Color color = new org.eclipse.swt.graphics.Color(display, 250,0,0);
scatterSeries.setSymbolColor(color);
//scatterSeries.setSymbolSize(10);
//scatterSeries.setXDateSeries(new Date[]{new Date(),