package com.example.client.service;
|
|
import com.example.client.dto.ColumnDto;
|
import com.example.client.utils.CommonTable;
|
import com.example.server.progressTrack.Dto.NetworkNodeStatusDto;
|
import com.example.server.progressTrack.model.DjJdgzNetworkLevel3;
|
import com.example.server.progressTrack.service.DjJdgzNetworkLevel3Service;
|
import com.example.server.progressTrack.service.NetWorkDiagramService;
|
import com.mxgraph.swing.mxGraphComponent;
|
import com.mxgraph.view.mxGraph;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.swing.*;
|
import java.awt.*;
|
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelListener;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
@Service
|
public class Level3ViewService {
|
@Autowired
|
private DjJdgzNetworkLevel3Service level3Service;
|
@Autowired
|
private NetWorkDiagramService netWorkDiagramService;
|
|
public JPanel createTable(Integer width, Integer height) {
|
height = height - 100;
|
JPanel panel = new JPanel();
|
|
JPanel jLeft = new JPanel(new BorderLayout());
|
jLeft.setPreferredSize(new Dimension(width / 4 - 20, height));
|
|
JPanel diagram = new JPanel(new BorderLayout());
|
diagram.setPreferredSize(new Dimension(width - width / 4, height));
|
|
|
// 创建子表格
|
List<ColumnDto> columnDto = new ArrayList<>();
|
List<DjJdgzNetworkLevel3> list = level3Service.getList(null, null, null, null, null,null);
|
//columnDto.add(new ColumnDto("ID", "id", -1, null,false));
|
|
|
columnDto.add(new ColumnDto("序号", "", width / 20 - 10, "autoCreate", false, null,null));
|
columnDto.add(new ColumnDto("工程", "ProjectName", width / 16, null, false, null,null));
|
columnDto.add(new ColumnDto("一级节点", "level1NodeName", width / 16, null, false, null,null));
|
columnDto.add(new ColumnDto("二级节点", "level2NodeName", width / 16, null, false, null,null));
|
columnDto.add(new ColumnDto("网络图名称", "name", width / 16, null, false, null,null));
|
|
JTable subTable = CommonTable.createCommonTable(list, columnDto);
|
subTable.setRowHeight(25);
|
subTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
|
|
JScrollPane scrollTable = new JScrollPane(subTable);
|
jLeft.add(scrollTable, BorderLayout.CENTER);
|
|
// 创建水平分割面板
|
JSplitPane hSplitPane = new JSplitPane(
|
JSplitPane.HORIZONTAL_SPLIT,
|
jLeft,
|
diagram
|
);
|
hSplitPane.setDividerLocation(width / 4);
|
hSplitPane.setDividerSize(10);
|
hSplitPane.setOneTouchExpandable(true);
|
hSplitPane.setContinuousLayout(true);
|
|
panel.add(hSplitPane, BorderLayout.CENTER);
|
|
mxGraph graph = new mxGraph();
|
String json = "";
|
Long id = null ;
|
if (list!=null && list.size()>0){
|
json = list.get(0).getContent();
|
id = list.get(0).getId();
|
}
|
|
List<NetworkNodeStatusDto> nodeStatusList = level3Service.getNodeStatusData(id);
|
|
graph = netWorkDiagramService.getCsDiagram(graph, json, nodeStatusList, diagram.getPreferredSize().width, diagram.getPreferredSize().height);
|
|
mxGraphComponent graphComponent = new mxGraphComponent(graph);
|
graphComponent.setConnectable(false);
|
graphComponent.setDragEnabled(false);
|
graphComponent.zoomTo(2, true);
|
diagram.add(graphComponent);
|
|
mxGraph finalGraph = graph;
|
graphComponent.getViewport().addMouseWheelListener(new MouseWheelListener() {
|
@Override
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
int notches = e.getWheelRotation();
|
double zoomFactor = 1.1; // 缩放因子
|
Point pt = e.getPoint();
|
double zoom = finalGraph.getView().getScale() * (notches < 0 ? zoomFactor : 1 / zoomFactor);
|
graphComponent.zoomTo(zoom, true); // 缩放视图
|
}
|
});
|
|
final mxGraph[] graph2 = {graph};
|
subTable.addMouseListener(new MouseAdapter() {
|
public void mouseClicked(MouseEvent e) {
|
// 仅当鼠标左键单击时响应
|
if (e.getButton() == MouseEvent.BUTTON1) {
|
// 得到选中的行列的索引值
|
int r = subTable.getSelectedRow();
|
DjJdgzNetworkLevel3 data = list.get(r);
|
List<NetworkNodeStatusDto> nodeStatusList = level3Service.getNodeStatusData(data.getId());
|
graph2[0] = netWorkDiagramService.getCsDiagram(graph2[0], data.getContent(), nodeStatusList, diagram.getPreferredSize().width, diagram.getPreferredSize().height);
|
}
|
}
|
});
|
|
return panel;
|
}
|
|
}
|