public class IOManager
extends Object
Modifier and Type | Class and Description |
---|---|
static class |
IOManager.TransferableImage |
Modifier and Type | Field and Description |
---|---|
static ArrayList<String> |
imageFormats
Holds the list of image formats supported by the current image writer
|
(package private) static Hashtable |
OldNewMapping
This table is used by IOManager instances to maintain an old-new mapping.
|
protected JFrame |
ownerFrame |
Constructor and Description |
---|
IOManager(JFrame f) |
Modifier and Type | Method and Description |
---|---|
static File |
chooseViaFileSaveDialog(Frame owner,
File initialChoiceFile,
String promptstring)
Runs the file dialog that lets the user choose the filename and location.
|
static File |
FileToGraph(File absFile,
Graph targetGraph)
Loads a graph from a file to a graph.
|
static File |
FileToGraph(File absFile,
Graph targetGraph,
Point2D.Double translateBy)
Loads from a cgx file to a graph.
|
static File |
getAbsoluteFile(String filename,
chargerlib.FileFormat format)
Establish the absolute file for a given filename and its intended format.
|
static File |
GraphToFile(Graph g,
chargerlib.FileFormat format,
String filename,
Frame owner)
Saves a CharGer Graph to a file.
|
static BufferedImage |
graphToImage(Graph g)
Takes an entire graph and formats it as a bitmap image.
|
static GNode |
hookUp(GEdge ge,
GraphObjectID oldID,
Graph gr,
boolean keepIDs)
uses the old-to-new mapping to attach an edge to its new ends
|
static void |
initializeImageFormatList()
Sets up the imageFormats array list with all the valid image types
supported by the local image writer.
|
protected static void |
loadGraph2(BufferedReader f,
Graph targetGraph)
Loads (reads) a graph from a file and attaches it to an existing (i.e.,
non-null, but possibly empty) graph
|
protected static void |
loadGraph2(BufferedReader f,
Graph targetGraph,
Point translateBy)
Loads (reads) a graph from a file in CharGer version 2 format and
attaches it to an existing (i.e., non-null, but possibly empty) graph
|
protected static void |
loadGraph3(BufferedReader f,
Graph targetGraph)
Loads (reads) a graph from a file and attaches it to an existing (i.e.,
non-null, but possibly empty) graph
|
protected static void |
loadGraph3(BufferedReader f,
Graph targetGraph,
Point translateBy)
Loads (reads) a graph from a file and attaches it to an existing (i.e.,
non-null, but possibly empty) graph, using the "new" version 3 format
|
protected static void |
loadGraphCGX(File f,
Graph targetGraph,
Point2D.Double translateBy)
Loads (reads) a graph from a file and attaches it to an existing (i.e.,
non-null, but possibly empty) graph, using the XML version 3.8 format
|
protected static void |
loadGraphXML(File f,
Graph target)
Loads (reads) a graph from a file and attaches it to an existing (i.e.,
non-null, but possibly empty) graph
|
static GraphObject |
parseOneObject(String s,
Graph rootGraph,
boolean ignoreOwner,
Point translateBy,
boolean keepIDs)
Tokenizes and parses a string assuming it was written using the
saveGraph2 rules, then creates a correct CharGer graph object based on
what was parsed.
|
static GraphObject |
parseOneObject2(String s,
Graph rootGraph,
boolean ignoreNesting,
Point translateBy,
boolean keepIDs)
Tokenizes and parses a string assuming it was written using the saveGraph
rules for version 2, then creates a correct CharGer graph object based on
what was parsed.
|
static void |
saveGraph2(BufferedWriter writer,
Graph gr)
EditFrame makes the header, but GraphObject makes each object's string
all found in toString methods in the GraphObject classes.
|
static void |
saveGraph38XML(BufferedWriter f,
Graph gr)
The output routine for versions 3.8 and later.
|
static void |
saveGraph4(OutputStream os,
Graph gr)
EditFrame makes the header, but GraphObject makes each object's string
all found in toString methods in the GraphObject classes.
|
static void |
saveGraphAsBitmapImage(Graph g,
chargerlib.FileFormat format,
File f)
Uses the ImageIO methods to write the graph in the given format This
overwrites the file; use chooseViaFileSaveDialog if you need the user to
confirm overwriting.
|
static void |
saveGraphAsTextFormat(Graph g,
chargerlib.FileFormat format,
File chosenOne)
Save as one of the text or export formats.
|
static void |
saveGraphAsVectorGraphic(Graph g,
chargerlib.FileFormat format,
String filename)
Uses the ImageIO methods to write the graph in pdf, svg or eps format.
|
private static void |
saveGraphCGIF2007(BufferedWriter f,
Graph gr,
boolean includeCharGerInfo) |
static ArrayList<GraphObject> |
StringToGraph(String s,
Graph targetGraph,
Point translateBy,
boolean keepIDs)
Loads a graph from a CharGer formatted string
|
static Hashtable OldNewMapping
protected JFrame ownerFrame
public static ArrayList<String> imageFormats
public static File FileToGraph(File absFile, Graph targetGraph, Point2D.Double translateBy) throws CGFileException, CGStorageError
absFile
- contains the absolute non-null File from which graph is to
be loadedtargetGraph
- The graph to which the loaded objects will be addedtranslateBy
- The offset on the canvas by which the new parsed
objects are translated. If null, then all layout information is ignored.
If (0,0), perhaps the two-argument version should be used.CGFileException
CGStorageError
loadGraph3(java.io.BufferedReader, charger.obj.Graph, java.awt.Point)
,
FileToGraph(java.io.File, charger.obj.Graph, java.awt.geom.Point2D.Double)
public static File FileToGraph(File absFile, Graph targetGraph) throws CGFileException, CGStorageError
absFile
- contains fully-qualified file name from which graph is to
be loadedtargetGraph
- The graph to which the loaded objects will be addedCGFileException
CGStorageError
loadGraph3(java.io.BufferedReader, charger.obj.Graph, java.awt.Point)
protected static void loadGraph2(BufferedReader f, Graph targetGraph, Point translateBy) throws CGFileException, CGSyntaxException
f
- An already-opened file object pointing to a CharGer formatted
version of the graph desiredtargetGraph
- An already existing graph to which the new contents
will be attachedtranslateBy
- An x,y offset by which the loaded objects will be
translated.CGFileException
CGSyntaxException
saveGraph2(java.io.BufferedWriter, charger.obj.Graph)
protected static void loadGraph2(BufferedReader f, Graph targetGraph) throws CGFileException
f
- A text file containing a text version of the graph desiredtargetGraph
- An already existing graph to which the new contents
will be attachedCGFileException
GraphToFile(charger.obj.Graph, chargerlib.FileFormat, java.lang.String, java.awt.Frame)
protected static void loadGraph3(BufferedReader f, Graph targetGraph, Point translateBy) throws CGFileException
f
- An already-opened file object pointing to a CharGer formatted
version of the graph desiredtargetGraph
- An already existing graph to which the new contents
will be attachedtranslateBy
- An x,y offset by which the loaded objects will be
translated.CGFileException
saveGraph2(java.io.BufferedWriter, charger.obj.Graph)
protected static void loadGraph3(BufferedReader f, Graph targetGraph) throws CGFileException
f
- A text file containing a text version of the graph desiredCGFileException
GraphToFile(charger.obj.Graph, chargerlib.FileFormat, java.lang.String, java.awt.Frame)
protected static void loadGraphCGX(File f, Graph targetGraph, Point2D.Double translateBy)
f
- An already-opened file object pointing to a XML formatted
version of the graph desiredtargetGraph
- An already existing graph to which the new contents
will be attachedtranslateBy
- An x,y offset by which the loaded objects will be
translated. If null, then ignore any layout information.. This is
not the same as translating by (0,0).saveGraph38XML(java.io.BufferedWriter, charger.obj.Graph)
protected static void loadGraphXML(File f, Graph target) throws CGFileException
f
- A text file containing a text version of the graph desiredCGFileException
GraphToFile(charger.obj.Graph, chargerlib.FileFormat, java.lang.String, java.awt.Frame)
public static ArrayList<GraphObject> StringToGraph(String s, Graph targetGraph, Point translateBy, boolean keepIDs) throws CGStorageError
s
- String containing one or more lines of parsable texttargetGraph
- The graph in which to store the found objectstranslateBy
- The x,y coordinates to use in translating the parsed
objectskeepIDs
- Whether to keep existing IDs or create new onesCGStorageError
loadGraph3(java.io.BufferedReader, charger.obj.Graph, java.awt.Point)
public static GraphObject parseOneObject2(String s, Graph rootGraph, boolean ignoreNesting, Point translateBy, boolean keepIDs) throws CGSyntaxException
s
- a CharGer object string representing some graph object (not
including a line.separator)rootGraph
- an already-allocated (empty or non-empty) graph node
that will be filled inignoreNesting
- disregard any owner graph information in the string;
i.e., don't try to connect this object to an owning graph.translateBy
- an amount to translate the parsed object's positionkeepIDs
- whether to keep the internal IDs or create new onesCGSyntaxException
saveGraph2(java.io.BufferedWriter, charger.obj.Graph)
public static GraphObject parseOneObject(String s, Graph rootGraph, boolean ignoreOwner, Point translateBy, boolean keepIDs)
s
- a CharGer object string representing some graph object (not
including a line.separator)rootGraph
- an already-allocated (empty or non-empty) graph node
that will be filled inignoreOwner
- whether to consider the object's owner in creating the
objecttranslateBy
- an amount to translate the parsed object's positionkeepIDs
- whether to keep the existing IDs or create new onessaveGraph2(java.io.BufferedWriter, charger.obj.Graph)
public static GNode hookUp(GEdge ge, GraphObjectID oldID, Graph gr, boolean keepIDs)
ge
- the edge to be attached to its appropriate (new) nodesoldID
- the object's ID assigned when the line's info was writtengr
- the (new) graph which will own the new edgekeepIDs
- whether to keep the old ident or lookup a new onepublic static File getAbsoluteFile(String filename, chargerlib.FileFormat format)
filename
- original filename, may be either absolute or relativeformat
- used for replacing the extension of the given filenameGlobal.GraphFolderFile
public static File chooseViaFileSaveDialog(Frame owner, File initialChoiceFile, String promptstring) throws CGFileException
owner
- the frame that will own the modal dialog.initialChoiceFile
- the initial file display informationpromptstring
- The string to cue the user what is expectedCGFileException
public static File GraphToFile(Graph g, chargerlib.FileFormat format, String filename, Frame owner) throws CGFileException
format
- What type of output format is to be written.filename
- The name of the file to which the graph is to be written.
either relative to whever Java thinks is the current directory or else
absoluteg
- The graph to be savedowner
- Frame to own the file dialogs; null if no user input is
needed or requiredCGFileException
ImageIO.getWriterFormatNames()
public static void saveGraph38XML(BufferedWriter f, Graph gr)
public static void saveGraph4(OutputStream os, Graph gr)
public static void saveGraph2(BufferedWriter writer, Graph gr)
GraphObject.toString()
private static void saveGraphCGIF2007(BufferedWriter f, Graph gr, boolean includeCharGerInfo)
public static BufferedImage graphToImage(Graph g)
g
- the graph to be imaged; does not have to be in a frame.GraphToFile(charger.obj.Graph, chargerlib.FileFormat, java.lang.String, java.awt.Frame)
public static void initializeImageFormatList()
public static void saveGraphAsTextFormat(Graph g, chargerlib.FileFormat format, File chosenOne) throws CGFileException
g
- the graph to be saved/exportedformat
- the format of the output file desiredchosenOne
- the file (already confirmed) that will be used.CGFileException
public static void saveGraphAsBitmapImage(Graph g, chargerlib.FileFormat format, File f)
g
- the Charger graph to be savedformat
- one of the strings returned by
ImageIO.getWriterFormatNames()f
- The file in which to save it. Any extension (if any) is replaced
by the format string (lower case)public static void saveGraphAsVectorGraphic(Graph g, chargerlib.FileFormat format, String filename)
g
- the Charger graph to be savedformat
- one of the strings returned byfilename
- The completely qualified path/file in which to save it.
Any extension (if any) is replaced by the format string (lower case)