src/main/java/com/mxgraph/io/mxGdCodec.java
public static void decode(String input, mxGraph graph)
	{
		BufferedReader br = new BufferedReader(new StringReader(input));
		mxGDParseState state = mxGDParseState.START;
		Object parent = graph.getDefaultParent();

		graph.getModel().beginUpdate();
		
		try
		{
			String line = br.readLine().trim();
			while (line != null)
			{
				switch (state)
				{
					case START:
					{
						if (!line.startsWith("#"))
						{
							state = mxGDParseState.NUM_NODES;
						}
						else
						{
							break;
						}
					}
					case NUM_NODES:
					{
						if (!line.startsWith("#"))
						{
							int numVertices = Integer.valueOf(line);
							
							for (int i = 0; i < numVertices; i++)
							{
								String label = String.valueOf(i);
								Object vertex = graph.insertVertex(parent, label, label,
										0, 0, 10, 10);
								
								cellsMap.put(label, vertex);
							}
						}
						else
						{
							state = mxGDParseState.PARSING_EDGES;
						}
						
						break;
					}
					case PARSING_NODES:
					{
						if (line.startsWith("# Edges"))
						{
							state = mxGDParseState.PARSING_EDGES;
						}
						else if (!line.equals(""))
						{
							String[] items = line.split(",");
							if (items.length != 5)
							{
								throw new Exception("Error in parsing");
							}
							else
							{
								double x = Double.valueOf(items[1]);
								double y = Double.valueOf(items[2]);
								double width = Double.valueOf(items[3]);
								double height = Double.valueOf(items[4]);
								
								
								//Set the node name as label.
								String label = items[0];

								//Insert a new vertex in the graph
								Object vertex = graph.insertVertex(parent, label, label,
										x - width / 2.0, y - height / 2.0, width,
										height);
								
								cellsMap.put(label, vertex);
							}
						}
						break;
					}
					case PARSING_EDGES:
					{
						if (!line.equals(""))
						{
							String[] items = line.split(" ");
							if (items.length != 2)
							{
								throw new Exception("Error in parsing");
							}
							else
							{
								Object source = cellsMap.get(items[0]);
								Object target = cellsMap.get(items[1]);

								graph.insertEdge(parent, null, "", source, target);
							}
						}
						break;
					}
				}

				line = br.readLine();
			}
		}
		
		catch (Exception e)
		{
			log.log(Level.FINEST, "Failed to decode", e);
		}
		finally
		{
			graph.getModel().endUpdate();
		}
	}
/**
	 * Parses simple GD format and populate the specified graph
	 * @param input GD file to be parsed
	 * @param graph Graph where the parsed graph is included.
	 */
Parses simple GD format and populate the specified graph
@param input GD file to be parsed
@param graph Graph where the parsed graph is included.
Parses simple GD format and populate the specified graph @param input GD file to be parsed @param graph Graph where the parsed graph is included .
public static void decode(String input, mxGraph graph)
	{
		BufferedReader br = new BufferedReader(new StringReader(input));
		mxGDParseState state = mxGDParseState.START;
		Object parent = graph.getDefaultParent();
		graph.getModel().beginUpdate();
		try
		{
			String line = br.readLine().trim();
			while (line != null)
			{
				switch (state)
				{
					case START:
					{
						if (!line.startsWith("#"))
						{
							state = mxGDParseState.NUM_NODES;
						}
						else
						{
							break;
						}
					}
					case NUM_NODES:
					{
						if (!line.startsWith("#"))
						{
							int numVertices = Integer.valueOf(line);
							for (int i = 0; i < numVertices; i++)
							{
								String label = String.valueOf(i);
								Object vertex = graph.insertVertex(parent, label, label,
										0, 0, 10, 10);
								cellsMap.put(label, vertex);
							}
						}
						else
						{
							state = mxGDParseState.PARSING_EDGES;
						}
						break;
					}
					case PARSING_NODES:
					{
						if (line.startsWith("# Edges"))
						{
							state = mxGDParseState.PARSING_EDGES;
						}
						else if (!line.equals(""))
						{
							String[] items = line.split(",");
							if (items.length != 5)
							{
								throw new Exception("Error in parsing");
							}
							else
							{
								double x = Double.valueOf(items[1]);
								double y = Double.valueOf(items[2]);
								double width = Double.valueOf(items[3]);
								double height = Double.valueOf(items[4]);
								String label = items[0];
								Object vertex = graph.insertVertex(parent, label, label,
										x - width / 2.0, y - height / 2.0, width,
										height);
								cellsMap.put(label, vertex);
							}
						}
						break;
					}
					case PARSING_EDGES:
					{
						if (!line.equals(""))
						{
							String[] items = line.split(" ");
							if (items.length != 2)
							{
								throw new Exception("Error in parsing");
							}
							else
							{
								Object source = cellsMap.get(items[0]);
								Object target = cellsMap.get(items[1]);
								graph.insertEdge(parent, null, "", source, target);
							}
						}
						break;
					}
				}
				line = br.readLine();
			}
		}
		catch (Exception e)
		{
			log.log(Level.FINEST, "Failed to decode", e);
		}
		finally
		{
			graph.getModel().endUpdate();
		}
	}
public static void decode ( String input , mxGraph graph ) { BufferedReader br = new BufferedReader ( new StringReader ( input ) ) ; mxGDParseState state = mxGDParseState . START ; Object parent = graph . getDefaultParent ( ) ; graph . getModel ( ) . beginUpdate ( ) ; try { String line = br . readLine ( ) . trim ( ) ; while ( line != null ) { switch ( state ) { case START : { if ( ! line . startsWith ( "#" ) ) { state = mxGDParseState . NUM_NODES ; } else { break ; } } case NUM_NODES : { if ( ! line . startsWith ( "#" ) ) { int numVertices = Integer . valueOf ( line ) ; for ( int i = 0 ; i < numVertices ; i ++ ) { String label = String . valueOf ( i ) ; Object vertex = graph . insertVertex ( parent , label , label , 0 , 0 , 10 , 10 ) ; cellsMap . put ( label , vertex ) ; } } else { state = mxGDParseState . PARSING_EDGES ; } break ; } case PARSING_NODES : { if ( line . startsWith ( "# Edges" ) ) { state = mxGDParseState . PARSING_EDGES ; } else if ( ! line . equals ( "" ) ) { String [ ] items = line . split ( "," ) ; if ( items . length != 5 ) { throw new Exception ( "Error in parsing" ) ; } else { double x = Double . valueOf ( items [ 1 ] ) ; double y = Double . valueOf ( items [ 2 ] ) ; double width = Double . valueOf ( items [ 3 ] ) ; double height = Double . valueOf ( items [ 4 ] ) ; String label = items [ 0 ] ; Object vertex = graph . insertVertex ( parent , label , label , x - width / 2.0 , y - height / 2.0 , width , height ) ; cellsMap . put ( label , vertex ) ; } } break ; } case PARSING_EDGES : { if ( ! line . equals ( "" ) ) { String [ ] items = line . split ( " " ) ; if ( items . length != 2 ) { throw new Exception ( "Error in parsing" ) ; } else { Object source = cellsMap . get ( items [ 0 ] ) ; Object target = cellsMap . get ( items [ 1 ] ) ; graph . insertEdge ( parent , null , "" , source , target ) ; } } break ; } } line = br . readLine ( ) ; } } catch ( Exception e ) { log . log ( Level . FINEST , "Failed to decode" , e ) ; } finally { graph . getModel ( ) . endUpdate ( ) ; } }
Parses simple GD format and populate the specified graph
 @param input GD file to be parsed
 @param graph Graph where the parsed graph is included.
Parses simple GD format and populate the specified graph @param input GD file to be parsed @param graph Graph where the parsed graph is included .
//Set the node name as label. //Insert a new vertex in the graph