PDA

Voir la version complète : Export JGraph


NewbiZ
08/11/2007, 08h07
Bonjour à tous,

Je dispose d'un graphe sous la forme d'un objet JGraph (de la library du même nom) et je souhaiterais l'exporter en XML. Le site de JGraph dit que c'est possible, mais impossible de trouver comment ...

De ce que j'ai compris, il faudrait utiliser un mécanisme "standard" de java pour exporter les objets, mais je ne l'ai pas trouvé :/ J'ai farfouillé autour de org.w3c.dom.* mais rien trouvé de concluant.

Si quelqu'un a une idée, je suis preneur.

NewbiZ
08/11/2007, 09h39
Ecriture :
public void actionPerformed(ActionEvent e)
{
String path = javax.swing.JOptionPane.showInputDialog( "Type in the (relative or absolute) path to the saved dialog (XML):", "C:\\dialog.xml" );
if ( path == null )
return;
try
{
XMLEncoder xe;
xe = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(path)));
xe.setPersistenceDelegate(DefaultGraphModel.class,
new DefaultPersistenceDelegate(new String[] { "roots","attributes" }));
xe.writeObject(MainWindow.instance.graph.getModel());
xe.close();
}
catch (Exception IgnoreMe)
{
javax.swing.JOptionPane.showMessageDialog(
null,
IgnoreMe.toString(),
"Erreur lors de l'enregistrement",
javax.swing.JOptionPane.ERROR_MESSAGE );
}
}Ouverture :
public void actionPerformed(ActionEvent e)
{
String path = javax.swing.JOptionPane.showInputDialog( "Type in the (relative or absolute) path to the saved dialog (XML):", "C:\\dialog.xml" );
if ( path == null )
return;
try
{
XMLDecoder xd;
xd = new XMLDecoder(new BufferedInputStream(new FileInputStream(path)));
MainWindow.instance.graph.setModel( (GraphModel)xd.readObject() );
xd.close();
}
catch (Exception IgnoreMe)
{
javax.swing.JOptionPane.showMessageDialog(
null,
IgnoreMe.toString(),
"Erreur lors de l'enregistrement",
javax.swing.JOptionPane.ERROR_MESSAGE );
}
MainWindow.instance.graph.setAntiAliased(true); // L'export ne converve pas l'antialiasing
}
}En espérant que ca servira à quelqu'un :)