{
if (!editor.isModified()
|| JOptionPane.showConfirmDialog(editor,
mxResources.get("loseChanges")) == JOptionPane.YES_OPTION)
{
mxGraph graph = editor.getGraphComponent().getGraph();
if (graph != null)
{
String wd = (lastDir != null) ? lastDir : System
.getProperty("user.dir");
JFileChooser fc = new JFileChooser(wd);
// Adds file filter for supported file format
DefaultFileFilter defaultFilter = new DefaultFileFilter(
".mxe", mxResources.get("allSupportedFormats")
+ " (.mxe, .png, .vdx)")
{
public boolean accept(File file)
{
String lcase = file.getName().toLowerCase();
return super.accept(file)
|| lcase.endsWith(".png")
|| lcase.endsWith(".vdx");
}
};
fc.addChoosableFileFilter(defaultFilter);
fc.addChoosableFileFilter(new DefaultFileFilter(".mxe",
"mxGraph Editor " + mxResources.get("file")
+ " (.mxe)"));
fc.addChoosableFileFilter(new DefaultFileFilter(".png",
"PNG+XML " + mxResources.get("file")
+ " (.png)"));
// Adds file filter for VDX import
fc.addChoosableFileFilter(new DefaultFileFilter(".vdx",
"XML Drawing " + mxResources.get("file")
+ " (.vdx)"));
// Adds file filter for GD import
fc.addChoosableFileFilter(new DefaultFileFilter(".txt",
"Graph Drawing " + mxResources.get("file")
+ " (.txt)"));
fc.setFileFilter(defaultFilter);
int rc = fc.showDialog(null,
mxResources.get("openFile"));
if (rc == JFileChooser.APPROVE_OPTION)
{
lastDir = fc.getSelectedFile().getParent();
try
{
if (fc.getSelectedFile().getAbsolutePath()
.toLowerCase().endsWith(".png"))
{
openXmlPng(editor, fc.getSelectedFile());
}
else if (fc.getSelectedFile().getAbsolutePath()
.toLowerCase().endsWith(".txt"))
{
mxGdDocument document = new mxGdDocument();
document.parse(mxUtils.readFile(fc
.getSelectedFile()
.getAbsolutePath()));
openGD(editor, fc.getSelectedFile(),
document);
}
else
{
Document document = mxUtils
.parseXml(mxUtils.readFile(fc
.getSelectedFile()
.getAbsolutePath()));
if (fc.getSelectedFile().getAbsolutePath()
.toLowerCase().endsWith(".vdx"))
{
openVdx(editor, fc.getSelectedFile(),
document);
}
else
{
mxCodec codec = new mxCodec(document);
codec.decode(
document.getDocumentElement(),
graph.getModel());
editor.setCurrentFile(fc
.getSelectedFile());
}
resetEditor(editor);