田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.mxgraph.io;
 
import com.mxgraph.io.gml.mxGmlConstants;
import com.mxgraph.io.gml.mxGmlData;
import com.mxgraph.io.gml.mxGmlEdge;
import com.mxgraph.io.gml.mxGmlGraph;
import com.mxgraph.io.gml.mxGmlKey;
import com.mxgraph.io.gml.mxGmlKey.keyForValues;
import com.mxgraph.io.gml.mxGmlKey.keyTypeValues;
import com.mxgraph.io.gml.mxGmlKeyManager;
import com.mxgraph.io.gml.mxGmlNode;
import com.mxgraph.io.gml.mxGmlShapeEdge;
import com.mxgraph.io.gml.mxGmlShapeNode;
import com.mxgraph.io.gml.mxGmlUtils;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.model.mxIGraphModel;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxPoint;
import com.mxgraph.util.mxUtils;
import com.mxgraph.view.mxCellState;
import com.mxgraph.view.mxConnectionConstraint;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxGraphView;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.List<Lcom.mxgraph.io.gml.mxGmlEdge;>;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
 
public class mxGmlCodec
{
  public static void decode(Document paramDocument, mxGraph parammxGraph)
  {
    Object localObject = parammxGraph.getDefaultParent();
    parammxGraph.getModel().beginUpdate();
    mxGmlKeyManager.getInstance().initialise(paramDocument);
    NodeList localNodeList = paramDocument.getElementsByTagName(mxGmlConstants.GRAPH);
    if (localNodeList.getLength() > 0)
    {
      Element localElement = (Element)localNodeList.item(0);
      mxGmlGraph localmxGmlGraph = new mxGmlGraph(localElement);
      localmxGmlGraph.addGraph(parammxGraph, localObject);
    }
    parammxGraph.getModel().endUpdate();
    cleanMaps();
  }
 
  private static void cleanMaps()
  {
    mxGmlKeyManager.getInstance().getKeyMap().clear();
  }
 
  public static Document encodeXML(mxGmlGraph parammxGmlGraph)
  {
    Document localDocument = mxUtils.createDocument();
    Element localElement1 = localDocument.createElement(mxGmlConstants.GRAPHML);
    localElement1.setAttribute("xmlns", "http://graphml.graphdrawing.org/xmlns");
    localElement1.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    localElement1.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:jGraph", mxGmlConstants.JGRAPH_URL);
    localElement1.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd");
    HashMap localHashMap = mxGmlKeyManager.getInstance().getKeyMap();
    Object localObject = localHashMap.values().iterator();
    while (((Iterator)localObject).hasNext())
    {
      mxGmlKey localmxGmlKey = (mxGmlKey)((Iterator)localObject).next();
      Element localElement2 = localmxGmlKey.generateElement(localDocument);
      localElement1.appendChild(localElement2);
    }
    localObject = parammxGmlGraph.generateElement(localDocument);
    localElement1.appendChild((Node)localObject);
    localDocument.appendChild(localElement1);
    cleanMaps();
    return ((Document)localDocument);
  }
 
  public static Document encode(mxGraph parammxGraph)
  {
    mxGmlGraph localmxGmlGraph = new mxGmlGraph();
    Object localObject = parammxGraph.getDefaultParent();
    createKeyElements();
    localmxGmlGraph = decodeGraph(parammxGraph, localObject, localmxGmlGraph);
    localmxGmlGraph.setEdgedefault(mxGmlConstants.EDGE_DIRECTED);
    Document localDocument = encodeXML(localmxGmlGraph);
    return localDocument;
  }
 
  private static void createKeyElements()
  {
    HashMap localHashMap = mxGmlKeyManager.getInstance().getKeyMap();
    mxGmlKey localmxGmlKey1 = new mxGmlKey(mxGmlConstants.KEY_NODE_ID, mxGmlKey.keyForValues.NODE, mxGmlConstants.KEY_NODE_NAME, mxGmlKey.keyTypeValues.STRING);
    localHashMap.put(mxGmlConstants.KEY_NODE_ID, localmxGmlKey1);
    mxGmlKey localmxGmlKey2 = new mxGmlKey(mxGmlConstants.KEY_EDGE_ID, mxGmlKey.keyForValues.EDGE, mxGmlConstants.KEY_EDGE_NAME, mxGmlKey.keyTypeValues.STRING);
    localHashMap.put(mxGmlConstants.KEY_EDGE_ID, localmxGmlKey2);
    mxGmlKeyManager.getInstance().setKeyMap(localHashMap);
  }
 
  public static mxGmlGraph decodeGraph(mxGraph parammxGraph, Object paramObject, mxGmlGraph parammxGmlGraph)
  {
    Object[] arrayOfObject1 = parammxGraph.getChildVertices(paramObject);
    List localList1 = parammxGmlGraph.getEdges();
    localList1 = encodeEdges(localList1, paramObject, parammxGraph);
    parammxGmlGraph.setEdges(localList1);
    for (Object localObject : arrayOfObject1)
    {
      List localList2 = parammxGmlGraph.getNodes();
      mxCell localmxCell = (mxCell)localObject;
      String str = localmxCell.getId();
      mxGmlNode localmxGmlNode = new mxGmlNode(str, null);
      addNodeData(localmxGmlNode, localmxCell);
      localList2.add(localmxGmlNode);
      parammxGmlGraph.setNodes(localList2);
      mxGmlGraph localmxGmlGraph = new mxGmlGraph();
      localmxGmlGraph = decodeGraph(parammxGraph, localObject, localmxGmlGraph);
      if (localmxGmlGraph.isEmpty())
        continue;
      List localList3 = localmxGmlNode.getNodeGraph();
      localList3.add(localmxGmlGraph);
      localmxGmlNode.setNodeGraph(localList3);
    }
    return parammxGmlGraph;
  }
 
  public static void addNodeData(mxGmlNode parammxGmlNode, mxCell parammxCell)
  {
    mxGmlData localmxGmlData = new mxGmlData();
    mxGmlShapeNode localmxGmlShapeNode = new mxGmlShapeNode();
    localmxGmlData.setDataKey(mxGmlConstants.KEY_NODE_ID);
    localmxGmlShapeNode.setDataHeight(String.valueOf(parammxCell.getGeometry().getHeight()));
    localmxGmlShapeNode.setDataWidth(String.valueOf(parammxCell.getGeometry().getWidth()));
    localmxGmlShapeNode.setDataX(String.valueOf(parammxCell.getGeometry().getX()));
    localmxGmlShapeNode.setDataY(String.valueOf(parammxCell.getGeometry().getY()));
    localmxGmlShapeNode.setDataLabel((parammxCell.getValue() != null) ? parammxCell.getValue().toString() : "");
    localmxGmlShapeNode.setDataStyle((parammxCell.getStyle() != null) ? parammxCell.getStyle() : "");
    localmxGmlData.setDataShapeNode(localmxGmlShapeNode);
    parammxGmlNode.setNodeData(localmxGmlData);
  }
 
  public static void addEdgeData(mxGmlEdge parammxGmlEdge, mxCell parammxCell)
  {
    mxGmlData localmxGmlData = new mxGmlData();
    mxGmlShapeEdge localmxGmlShapeEdge = new mxGmlShapeEdge();
    localmxGmlData.setDataKey(mxGmlConstants.KEY_EDGE_ID);
    localmxGmlShapeEdge.setText((parammxCell.getValue() != null) ? parammxCell.getValue().toString() : "");
    localmxGmlShapeEdge.setStyle((parammxCell.getStyle() != null) ? parammxCell.getStyle() : "");
    localmxGmlData.setDataShapeEdge(localmxGmlShapeEdge);
    parammxGmlEdge.setEdgeData(localmxGmlData);
  }
 
  private static String pointToPortString(mxPoint parammxPoint)
  {
    String str = "";
    if (parammxPoint != null)
    {
      double d1 = parammxPoint.getX();
      double d2 = parammxPoint.getY();
      if ((d1 == 0.0D) && (d2 == 0.0D))
        str = "NorthWest";
      else if ((d1 == 0.5D) && (d2 == 0.0D))
        str = "North";
      else if ((d1 == 1.0D) && (d2 == 0.0D))
        str = "NorthEast";
      else if ((d1 == 1.0D) && (d2 == 0.5D))
        str = "East";
      else if ((d1 == 1.0D) && (d2 == 1.0D))
        str = "SouthEast";
      else if ((d1 == 0.5D) && (d2 == 1.0D))
        str = "South";
      else if ((d1 == 0.0D) && (d2 == 1.0D))
        str = "SouthWest";
      else if ((d1 == 0.0D) && (d2 == 0.5D))
        str = "West";
      else
        str = "" + d1 + "," + d2;
    }
    return str;
  }
 
  private static List<mxGmlEdge> encodeEdges(List<mxGmlEdge> paramList, Object paramObject, mxGraph parammxGraph)
  {
    Object[] arrayOfObject1 = parammxGraph.getChildEdges(paramObject);
    for (Object localObject1 : arrayOfObject1)
    {
      mxCell localmxCell1 = (mxCell)localObject1;
      mxCell localmxCell2 = (mxCell)localmxCell1.getSource();
      mxCell localmxCell3 = (mxCell)localmxCell1.getTarget();
      String str1 = "";
      String str2 = "";
      String str3 = "";
      String str4 = "";
      str1 = (localmxCell2 != null) ? localmxCell2.getId() : "";
      str2 = (localmxCell3 != null) ? localmxCell3.getId() : "";
      mxGraphView localmxGraphView = parammxGraph.getView();
      mxPoint localmxPoint1 = null;
      mxPoint localmxPoint2 = null;
      if (localmxGraphView != null)
      {
        localObject2 = localmxGraphView.getState(localObject1);
        localObject3 = localmxGraphView.getState(localmxCell2);
        localObject4 = parammxGraph.getConnectionConstraint((mxCellState)localObject2, (mxCellState)localObject3, true);
        if (localObject4 != null)
          localmxPoint1 = ((mxConnectionConstraint)localObject4).getPoint();
        localObject5 = localmxGraphView.getState(localmxCell3);
        mxConnectionConstraint localmxConnectionConstraint = parammxGraph.getConnectionConstraint((mxCellState)localObject2, (mxCellState)localObject5, false);
        if (localmxConnectionConstraint != null)
          localmxPoint2 = localmxConnectionConstraint.getPoint();
      }
      str4 = pointToPortString(localmxPoint2);
      str3 = pointToPortString(localmxPoint1);
      Object localObject2 = new mxGmlEdge(str1, str2, str3, str4);
      Object localObject3 = localmxCell1.getStyle();
      if (localObject3 == null)
        localObject3 = "horizontal";
      Object localObject4 = mxGmlUtils.getStyleMap((String)localObject3, "=");
      Object localObject5 = (String)((HashMap)localObject4).get(mxConstants.STYLE_ENDARROW);
      if (((localObject5 != null) && (!(((String)localObject5).equals(mxConstants.NONE)))) || (localObject5 == null))
        ((mxGmlEdge)localObject2).setEdgeDirected("true");
      else
        ((mxGmlEdge)localObject2).setEdgeDirected("false");
      addEdgeData((mxGmlEdge)localObject2, localmxCell1);
      paramList.add(localObject2);
    }
    return ((List<mxGmlEdge>)(List<mxGmlEdge>)(List<mxGmlEdge>)(List<mxGmlEdge>)paramList);
  }
}
 
/* Location:           C:\Users\platform-001\Desktop\新建文件夹 (2)\jgraphx.jar
 * Qualified Name:     com.mxgraph.io.mxGmlCodec
 * JD-Core Version:    0.5.3
 */