1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| public boolean SaveToDia (String strCheminFichier)
{
try
{
//Handle de fichiers
FileInputStream in=new FileInputStream("Header.dia");
FileOutputStream out=new FileOutputStream(strCheminFichier);
FileChannel src=in.getChannel();
FileChannel dest=out.getChannel();
BufferedReader br=null; //fichier en entrée
BufferedWriter bw=null; //fichier en sortie
String strNewLine="\n"; //saut de ligne
//chaînes préformatées au format dia
String strObjectBoxHead=" <dia:object type=\"Flowchart - Box\" version=\"0\" id=\"O";
String strEndLine="/>"+strNewLine;
String strRealVal=" <dia:real val=\"";
String strBoolVal=" <dia:boolean val=\"";
String strPointVal=" <dia:point val=\"";
String strEndString="#</dia:string>";
String strEndAttribute=" </dia:attribute>"+strNewLine;
String strAttributeName=" <dia:attribute name=\"";
//chaînes préformatées au format dia incluant plusieurs lignes
String strObjectPos=strAttributeName+"obj_pos\">"+strNewLine;
strObjectPos+=strPointVal;
String strObjectEltCorner=strEndAttribute;
strObjectEltCorner+=strAttributeName+"obj_bb\">"+strNewLine;
strObjectEltCorner+=" <dia:rectangle val=\"0.0,0.0;0.0,0.0\"/>"+strNewLine;
strObjectEltCorner+=strEndAttribute;
strObjectEltCorner+=strAttributeName+"elem_corner\">"+strNewLine;
strObjectEltCorner+=strPointVal;
String strObjectEltWidth=strEndAttribute;
strObjectEltWidth+=strAttributeName+"elem_width\">"+strNewLine;
strObjectEltWidth+=strRealVal;
String strObjectEltHeight=strEndAttribute;
strObjectEltHeight+=strAttributeName+"elem_height\">"+strNewLine;
strObjectEltHeight+=strRealVal;
String strBackground=strEndAttribute;
strBackground+=strAttributeName+"show_background\">"+strNewLine;
strBackground+=strBoolVal+"true\"/>"+strNewLine;
strBackground+=strEndAttribute;
strBackground+=strAttributeName+"padding\">"+strNewLine;
strBackground+=strRealVal+"0.5\"/>"+strNewLine;
strBackground+=strEndAttribute;
strBackground+=strAttributeName+"text\">"+strNewLine;
strBackground+=" <dia:composite type=\"text\">"+strNewLine;
strBackground+=strAttributeName+"string\">"+strNewLine;
strBackground+=" <dia:string>#";
String strEndObject=strEndAttribute;
strEndObject+=strAttributeName+"font\">"+strNewLine;
strEndObject+=" <dia:font family=\"sans\" style=\"0\" name=\"Helvetica\"/>"+strNewLine;
strEndObject+=strEndAttribute;
strEndObject+=strAttributeName+"height\">"+strNewLine;
strEndObject+=strRealVal+"0.80000000000000004\"/>"+strNewLine;
strEndObject+=strEndAttribute;
strEndObject+=strAttributeName+"pos\">"+strNewLine;
strEndObject+=strPointVal+"0.0,0.0\"/>"+strNewLine;
strEndObject+=strEndAttribute;
strEndObject+=strAttributeName+"color\">"+strNewLine;
strEndObject+=" <dia:color val=\"#000000\"/>"+strNewLine;
strEndObject+=strEndAttribute;
strEndObject+=strAttributeName+"alignment\">"+strNewLine;
strEndObject+=" <dia:enum val=\"1\"/>"+strNewLine;
strEndObject+=strEndAttribute;
strEndObject+=" </dia:composite>"+strNewLine;
strEndObject+=strEndAttribute;
strEndObject+=" </dia:object>"+strNewLine;
String strEndFile=" </dia:layer>"+strNewLine;
strEndFile+="</dia:diagram>";
String strTemp=null; //copie temporaire de la chaine a ecrire ds le fichier dia
int nbNoeud=this.taille; //nombre de noeuds contenus dans le graphe
Noeud currentNoeud=null; //noeud en cours de traitement
int numNoeud=0; //numéro de ce noeud
int x,y; //coordonnées de ce noeud
//copie de l'en-tête dia commun à tous les diagrammes
src.transferTo(0, src.size(), dest);
src.close();
dest.close();
//ajout des parties spécifiques : textbox et liens
//ouverture du fichier en mode 'append'
bw=new BufferedWriter(new FileWriter(new File(strCheminFichier), true));
strTemp="\n";
for (int i=0; i<nbNoeud; i++)
//parcours de tous les noeuds
{
numNoeud=i+1;
currentNoeud=this.eltAt(i);
x=currentNoeud.getX();
y=currentNoeud.getY();
//ajout d'un objet Box
strTemp+=strObjectBoxHead+i+"\">"+strNewLine;
//ajout des coordonnées
strTemp+=strObjectPos+x+".0,"+y+".0\""+strEndLine;
//ajout des caractéristiques 'corner'
strTemp+=strObjectEltCorner+x+".0,"+y+".0\""+strEndLine;
//calculer dynamiquement le EW
strTemp+=strObjectEltWidth+"5"+"\""+strEndLine;
//calculer dynamiquement le EH
strTemp+=strObjectEltHeight+"1.9000000000000004"+"\""+strEndLine;
//ajout du texte
strTemp+=strBackground+currentNoeud.getConstat()+strEndString+strNewLine;
//fermeture de l'objet
strTemp+=strEndObject;
}
//fermeture de la feuille dia
strTemp+=strEndFile;
bw.write(strTemp);
bw.flush();
bw.close();
return true;
}
catch (Exception e)
{
System.out.println("Erreur inattendue"+e.toString());
return false;
}
} |
Partager