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; 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 encodeEdges(List 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)(List)(List)(List)paramList); } } /* Location: C:\Users\platform-001\Desktop\新建文件夹 (2)\jgraphx.jar * Qualified Name: com.mxgraph.io.mxGmlCodec * JD-Core Version: 0.5.3 */