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 128 129 130 131 132 133 134 135 136 137 138 139
|
public class FileAfficher extends JFrame {
private JTextPane texte;
private boolean texteModifie = false;
private HTMLDocument doc;
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
new FileAfficher();
}
FileAfficher() {
super("File Printer");
setSize(new Dimension(800, 800));
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
quitter();
}
});
texte = new JTextPane();
texte.setContentType("text/html" );
HTMLEditorKit k = new HTMLEditorKit();
//L'unité de base de la structure est un Element, qui a un ensemble d'attributs.
//Les éléments st de natures différentes suivant qu'on a affaire un texte HTML : html, body, p, content, etc...
doc = (HTMLDocument)k.createDefaultDocument();
texte.setEditorKit(k);
texte.setDocument(doc);
//texte.setFont(Monospaced);
/**
Style defaut = texte.getStyle("default");
Style as = texte.addStyle("stylePerso",defaut);
StyleConstants.setFontFamily(as, "Monospaced");
StyleConstants.setFontSize(as, 20);
StyleConstants.setAlignment(as, 1);
StyledDocument docStyled = texte.getStyledDocument();**/
texte.setBackground(Color.WHITE);
texte.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent evt) {
texteModifie = true;
}
});
getContentPane().add(new JScrollPane(texte));
setJMenuBar(barreMenus());
setVisible(true);
}
private void FicheRecapi(String nomCentre,String idCentre,String nomPreleveur,String datePrelev,String heureArrivee,
String heureDepart,String numeroPage) throws IOException{
//Partie concernant l'entête non variable de cette Fiche
/* Ouverture des flux */
FileInputStream debutfilename =new FileInputStream("/home/fripette/workspace/FilePrinter/enteteFicheRecap.html");
FileOutputStream fichierFinal = new FileOutputStream("/home/fripette/workspace/FilePrinter/FinalFicheRecap.html");
/* Lecture par segment de 0.5Mo */
byte buffer[]=new byte[512*1024];
/* Ecriture du début du fichier dans le fichier final */
WriteHTML(debutfilename,fichierFinal,buffer,0);
/* Fermeture des flux */
debutfilename.close();
/**
for (int i=0; i < initString.length; i++) {
doc.insertString(doc.getLength(), initString[i],as);
}**/
/*Partie concernant la partie variable de cette Fiche*/
/* Ecriture des données variables dans un fichier qi va être relu après */
FileWriter milieufilename =new FileWriter("/home/fripette/workspace/FilePrinter/milieuFicheRecap.html");
String intro="Codification des échantillons prélevés";
milieufilename.write(intro);
String baliseDebut="<br><br><TABLE cols=\"3\" colspan=\"3\" width=\"75%\">";
milieufilename.write(baliseDebut);
String borneDebut="1.";
String borneDEBUT=borneDebut+datePrelev+"."+idCentre+"."+numeroPage;
String borneFin="";
String borneFIN=borneFin+datePrelev+"."+idCentre+"."+numeroPage;
String un= "<TR><TD width=\"40%\"align=\"left\">";
String trois="</TD><TD width=\"10%\" align=\"center\">à</TD><TD width=\"40%\" align=\"right\">";
String cinq="</TD></TR>";
for(int repetition=0; repetition<=9;repetition++){
String reslt=un+borneDEBUT+trois+borneFIN+cinq;
milieufilename.write(reslt);
}
String baliseFin="</TABLE><br><br>";
milieufilename.write(baliseFin);
milieufilename.close();
/* Ecriture de la partie variable dans le fichier final */
FileInputStream milieu =new FileInputStream("/home/fripette/workspace/FilePrinter/milieuFicheRecap.html");
byte buffer3[]=new byte[512*1024];
WriteHTML(milieu,fichierFinal,buffer3,0);
//Partie concernant la partie finale non variable de cette Fiche
FileInputStream finfilename =new FileInputStream("/home/fripette/workspace/FilePrinter/finFicheRecap.html");
byte buffer2[]=new byte[512*1024];
WriteHTML(finfilename,fichierFinal,buffer2,0);
/* Fermeture des flux */
finfilename.close();
fichierFinal.close();
//IMPORTANT :pour insérer une page .html dans le JTextPane texte.read(fichierFinal,doc);
FileInputStream ficheFinal = new FileInputStream("/home/fripette/workspace/FilePrinter/FinalFicheRecap.html");
// au final : on relit le fichier final en .html dans lequel j'ai ajouté mes bouts de .html
texte.read(ficheFinal,doc);
} |
Partager