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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.print.*;
import java.awt.geom.*;
import java.util.*;
import java.io.*;
import org.jfree.chart.JFreeChart;
public class Impression extends JFrame implements Printable {
protected JFreeChart graphe;
protected VueModel vue;
protected Model m;
protected JTable table;
protected JPanel panel, infor, haut, entete, ligne1, ligne2, ligne3, g, tab;
protected BufferedImage image;
protected JLabel labChart = new JLabel();
protected TitledBorder info, per;
protected Calendar c;
protected Properties prop = new Properties();
protected FileInputStream in;
protected String s = "";
protected boolean test = true;
public Impression (VueModel vue, Model m) {
this.vue = vue;
this.m = m;
// Creation du panel général
panel = new JPanel();
panel.setLayout(new BorderLayout());
haut = new JPanel();
haut.setLayout(new BoxLayout(haut, BoxLayout.Y_AXIS));
entete = new JPanel();
entete.setLayout(new FlowLayout());
// Récuperation du path de l'image et du service
try {
in = new FileInputStream("Property.ini");
prop.load(in);
in.close();
s = prop.getProperty("pathimage");
if (s != null) { entete.add(new ImageResized(Toolkit.getDefaultToolkit().getImage(s),new Dimension(200,100))); }
//si l'image n'est pas enregistré dans le fichier Property le booleen est a faux
else { test = false; }
s = prop.getProperty("service");
if (s != null) { entete.add(new JLabel(" ")); entete.add(new JLabel("Service de " + s)); }
else { test = false; }
}
catch(IOException ex) { System.out.println("IOEx"); }
//Mise en place des informations patients
ligne1 = new JPanel();
ligne1.setLayout(new FlowLayout());
ligne1.add(new JLabel("Nom de jeune fille : " + vue.nom1.getText() + " "));
ligne1.add(new JLabel("Prenom : " + vue.prenom.getText() + " "));
ligne1.add(new JLabel("Nom d'epouse : " + vue.nom2.getText() + " "));
ligne1.add(new JLabel("Date de naissance : " + vue.dg.getText() + " "));
ligne1.add(new JLabel("Date de debut de grossesse : " + vue.dg.getText()));
ligne2 = new JPanel();
ligne2.setLayout(new FlowLayout());
ligne2.add(new JLabel("Taille : " + vue.taille.getText() + " cm "));
ligne2.add(new JLabel("Poids : " + vue.poids.getText() + " kg "));
ligne2.add(new JLabel("Parite : " + vue.parite.getText() + " "));
if (vue.check.isSelected()) {
if (vue.sexe1.isSelected()) { ligne2.add(new JLabel("Sexe du foetus : Garcon")); }
if (vue.sexe2.isSelected()) { ligne2.add(new JLabel("Sexe du foetus : Fille")); }
}
ligne3 = new JPanel();
ligne3.setLayout(new FlowLayout());
c = new GregorianCalendar();
ligne3.add(new JLabel("Date du jour : " + c.get(Calendar.DATE) + ".0" + (1 + c.get(Calendar.MONTH)) + "." + c.get(Calendar.YEAR)));
infor = new JPanel();
infor.setLayout(new BoxLayout(infor, BoxLayout.Y_AXIS));
infor.add(ligne1);
infor.add(ligne2);
infor.add(ligne3);
info = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(85, 175, 255)), "Informations Patient");
infor.setBorder(info);
// Si l'image était enregistrée on ajoute l'entete + les infos patient, puis on ajoute haut au panel general
if (test) {
haut.add(entete);
haut.add(infor);
panel.add(haut, BorderLayout.NORTH);
}
else { panel.add(infor, BorderLayout.NORTH); }
g = new JPanel();
g.setLayout(new FlowLayout());
// les if qui suivent servent a imprimer le bon onglet
if ( vue.onglet.getSelectedIndex() == 1 ) {
graphe = m.getGraphe();
image = graphe.createBufferedImage(1280, 1792);
labChart.setIcon(new ImageIcon(image));
g.add(labChart);
panel.add(g, BorderLayout.CENTER);
}
else if ( vue.onglet.getSelectedIndex() == 2 ) {
graphe = m.getGraphe2();
image = graphe.createBufferedImage(1280, 1792);
labChart.setIcon(new ImageIcon(image));
g.add(labChart);
panel.add(g, BorderLayout.CENTER);
}
else if ( vue.onglet.getSelectedIndex() == 4 ) {
tab = new JPanel();
tab.setLayout(new FlowLayout());
table = Graphe.getTable(m.getPer());
per = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(85, 175, 255)), "Tableau percentile");
tab.setBorder(per);
tab.add(table);
panel.add(tab);
}
this.getContentPane().add(panel);
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if(pageIndex != 0) {
System.out.println("Probleme de page index: " + pageIndex);
return NO_SUCH_PAGE;
}
Dimension dim = this.getSize();
double scaleX = pageFormat.getImageableWidth() / dim.width;
double scaleY = pageFormat.getImageableHeight() / dim.height;
double scale = Math.min(scaleX, scaleY);
Graphics2D g2D = (Graphics2D)graphics;
g2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2D.scale(scale, scale);
this.pack();
this.setVisible(true);
this.print(g2D);
this.setVisible(false);
return PAGE_EXISTS;
}
} |
Partager