Search this API

y.io
Class GMLIOHandler

java.lang.Object
  extended by y.io.IOHandler
      extended by y.io.GMLIOHandler
Direct Known Subclasses:
XGMLIOHandler

public class GMLIOHandler
extends IOHandler

Read and write a Graph2D in Graph Modeling Language (GML). This is mainly achieved by delegating the actual work to instances, that are created by EncoderFactory and ParserFactory.

For more information about GML refer to the official GML Page for the general format and compatibility and extension notes.

 

Constructor Summary
GMLIOHandler()
          Instantiates a new GMLIOHandler.
 
Method Summary
static java.lang.String convertColor(java.awt.Color col)
          Converts a java Color into standard string representation.
static java.awt.Color decodeColor(java.lang.String colorString)
          Decodes a color string produced by convertColor(Color).
static EncoderFactory getEncoderFactory()
          Getter for the ParserFactory (Singleton)
 java.lang.String getFileFormatString()
          Returns the GML file format string.
 java.lang.String getFileNameExtension()
          Returns the GML file name extension, i.e.
static ParserFactory getParserFactory()
          Getter for the ParserFactory (Singleton)
 void read(Graph2D graph, java.io.InputStream in)
          Adds the contents from the given stream to the given graph.
protected  void read(Graph2D graph, java.io.Reader reader)
          Fills the contents of the given graph from a reader.
 void read(Graph2D graph, java.lang.String name)
          Generates a FileReader and passes control to read(y.view.Graph2D, java.io.Reader)
static void setEncoderFactory(EncoderFactory _encoderFactory)
          Setter for the EncoderFactory (Singleton)
static void setParserFactory(ParserFactory _parserFactory)
          Setter for the ParserFactory (Singleton)
 void write(Graph2D graph, java.io.OutputStream out)
          Writes the contents of the given graph in GML format to a stream.
 
Methods inherited from class y.io.IOHandler
canRead, canWrite, canWriteSubset, createObjectInputStream, createObjectOutputStream, hide, read, shouldSerialize, shouldSerialize, write, writeSubset, writeSubset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GMLIOHandler

public GMLIOHandler()
Instantiates a new GMLIOHandler.

Method Detail

getFileFormatString

public java.lang.String getFileFormatString()
Returns the GML file format string.

Specified by:
getFileFormatString in class IOHandler
Returns:
the string

getFileNameExtension

public java.lang.String getFileNameExtension()
Returns the GML file name extension, i.e. "gml".

Specified by:
getFileNameExtension in class IOHandler
Returns:
"gml"

read

public void read(Graph2D graph,
                 java.io.InputStream in)
          throws java.io.IOException
Adds the contents from the given stream to the given graph.

Specified by:
read in class IOHandler
Parameters:
in - The input stream being read from
Throws:
java.io.IOException

read

public void read(Graph2D graph,
                 java.lang.String name)
          throws java.io.IOException
Generates a FileReader and passes control to read(y.view.Graph2D, java.io.Reader)

Overrides:
read in class IOHandler
Parameters:
graph - the graph
name - the filename
Throws:
java.io.IOException - in the case of an I/O error

read

protected void read(Graph2D graph,
                    java.io.Reader reader)
             throws java.io.IOException
Fills the contents of the given graph from a reader.

Parameters:
graph - the graph to be filled
reader - The reader being read from
Throws:
java.io.IOException - in case of an I/O Exception

getParserFactory

public static ParserFactory getParserFactory()
Getter for the ParserFactory (Singleton)

Returns:
a previously installed factory or DefaultParserFactory

setParserFactory

public static void setParserFactory(ParserFactory _parserFactory)
Setter for the ParserFactory (Singleton)

Parameters:
_parserFactory - the factory to be installed

getEncoderFactory

public static EncoderFactory getEncoderFactory()
Getter for the ParserFactory (Singleton)

Returns:
the previously installed factory or HierarchicGraphEncoderFactory

setEncoderFactory

public static void setEncoderFactory(EncoderFactory _encoderFactory)
Setter for the EncoderFactory (Singleton)

Parameters:
_encoderFactory - the factory to be installed

write

public void write(Graph2D graph,
                  java.io.OutputStream out)
           throws java.io.IOException
Writes the contents of the given graph in GML format to a stream. This is achieved by using the currently installed EncoderFactory, obtaining a ObjectEncoder for GML and invoking the ObjectEncoder.encode(Object, y.io.gml.GMLEncoder) method with the graph as the first argument.

Specified by:
write in class IOHandler
Parameters:
graph - the graph to be written
out - The OutputStream being written to.
Throws:
java.io.IOException - in case of an I/O Exception

convertColor

public static java.lang.String convertColor(java.awt.Color col)
Converts a java Color into standard string representation.

Parameters:
col - the color
Returns:
a String in the (GML) form #RRGGBB or #RRGGBBAA where each of the pairs is an hex value between 00 and FF.

decodeColor

public static java.awt.Color decodeColor(java.lang.String colorString)
Decodes a color string produced by convertColor(Color).

Parameters:
colorString - the color string
Returns:
an opaque color if the color string is of the form #RRGGBB and a transparent color if the input string is of the form #RRGGBBAA, where AA denotes the alpha component of the color.

© Copyright 2000-2021,
yWorks GmbH.
All rights reserved.