jinlin
2025-04-28 efce7ce3e63712ecc8b4c3039a73b508fc3ea880
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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,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,null);
 
        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        graphComponent.setConnectable(false);
        graphComponent.setDragEnabled(false);
        graphComponent.zoomTo(1, 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,null);
                }
            }
        });
 
        return panel;
    }
 
}