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
|
public class FileAfficher extends JFrame {
private JTextPane texte;
private boolean texteModifie = false;
private String reponse;
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();
HTMLDocument doc = (HTMLDocument)k.createDefaultDocument();
texte.setEditorKit(k);
texte.setDocument(doc);
//texte.setFont(new Font("Monospaced", Font.PLAIN, 12));
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 JMenuBar barreMenus() {
[...]
menu.addSeparator();
JMenuItem information = new JMenuItem("Information");
menu.add(information);
information.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reponse = JOptionPane.showInputDialog("Nom du centre hospitalier?");
try {
FicheRecapi(reponse);
texteModifie =true;
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
return barre;
}
private void FicheRecapi(String reponse) throws IOException{
String[] initString =
{ /* ... fill array with initial text ...*/ };
Style defaut = texte.getStyle("default");
Style as = texte.addStyle("stylePerso",defaut);
//SimpleAttributeSet as = new SimpleAttributeSet();
StyleConstants.setFontFamily(as, "Monospaced");
StyleConstants.setFontSize(as, 20);
StyleConstants.setAlignment(as, 1);
StyledDocument doc = texte.getStyledDocument();
//Load the text pane with styled text.
try {
//insertion de l'entête de la Fiche Récapitulative qui reste inchangée
//texte.insertIcon(new ImageIcon("logo_biotech.jpg"));
String file ="/home/fripette/Desktop/FilePrinter/enteteFicheRecap.html";
FileReader enteteFicheRecap= new FileReader(file);
doc.insertString(doc.getLength(),String.valueOf(enteteFicheRecap),as);
/**concernant la partie variable de cette Fiche
for (int i=0; i < initString.length; i++) {
doc.insertString(doc.getLength(), initString[i],as);
}**/
//insertion de la fin de la Fiche Récapitulative qui reste inchangée
String filename ="/home/fripette/Desktop/FilePrinter/finFicheRecap.html";
FileReader finFichRecap= new FileReader(filename);
doc.insertString(doc.getLength(),String.valueOf(finFichRecap),as);
//doc.getStyle(as));
}
catch (BadLocationException ble) {
System.err.println("Couldn't insert initial text into text pane.");
}
}
} |
Partager