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
| public class GOV_Remisage extends JPanel {
private String Nom, JourE;
private String[][] Trains, Trains_Dep;
private Vector Voies;
private int NbColonne_Heure,Nb_Voie,pos,PosBD;
public Graphics2D g;
public static int Pixel_heure=120;
public int Pixel_Voie=500;
private JButton BFermer, BEnregistrer,BImprimer;
public GOV_Remisage(String nom2,String jour,Vector Voie,String[][] trains,String[][] trains_Dep) {
// TODO Auto-generated constructor stub
this.Nom=nom2;
this.JourE=jour;
this.Voies=Voie;
this.Trains=trains;
this.Trains_Dep=trains_Dep;
// Dimensione la en fonction du nb heure et du nb voie
NbColonne_Heure=Pixel_heure*26; // 20h à 20h
Nb_Voie=Voies.size(); // Nb voies par site
int NbColonne_HeureBarre=NbColonne_Heure+200;
int Nb_VoieBarre=(Nb_Voie*Pixel_Voie)+Pixel_Voie;
setPreferredSize(new Dimension(NbColonne_HeureBarre, Nb_VoieBarre));
// Ajout d'une barre à outils pour enregistrer et imprimer le graphique
JToolBar tlbr = new JToolBar();
//Création des boutons
BEnregistrer=new JButton(new ImageIcon ("C:/Users/9006478A/Desktop/Remisage_TechniCentre/Outils_GestionRemisage/JAVA/Images/Enregistrer.png"));
BImprimer=new JButton(new ImageIcon ("C:/Users/9006478A/Desktop/Remisage_TechniCentre/Outils_GestionRemisage/JAVA/Images/Imprimer.png"));
BFermer=new JButton("Fermer");
// Ajout bouton à la barre d'outil
tlbr.add(BEnregistrer);
tlbr.add(BImprimer);
tlbr.add(BFermer);
//Ajout barre d'outil à la frame
this.add(tlbr);
//Enregistre la Frame
BEnregistrer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Window window = SwingUtilities.windowForComponent(BEnregistrer);
if (window instanceof JFrame) {
JFrame frame = (JFrame) window;
// Déinie ou on enregistre l'image
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Specify a file to save");
int userSelection = fileChooser.showSaveDialog(frame);
if (userSelection == JFileChooser.APPROVE_OPTION) {
File fileToSave = fileChooser.getSelectedFile();
System.out.println("Save as file: " + fileToSave.getAbsolutePath());
BufferedImage image = new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB);
frame.paint(g);
g.dispose();
try {
ImageIO.write(image, "JPEG", fileToSave);
} catch (Exception e) { }
}
}
}
});
//Ferme la Frame
BFermer.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0) {
setVisible(false); // Ferme le graphique
// Ferme la frame contenant le graphique
Window window = SwingUtilities.windowForComponent(BFermer);
if (window instanceof JFrame) {
JFrame frame = (JFrame) window;
frame.setVisible(false);
frame.dispose();
}
}
});
//Imprime le graphique
BImprimer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Print p = new Print(g);
System.out.println(g);
p.imprime_ssA(g,null,1);
}
});
}
public void paintComponent(Graphics g1) {
super.paintComponent(g1);
g = (Graphics2D) g1;
g.setStroke(new BasicStroke(2));
// ---------------------------------------------
// Code qui dessine le graphique
} |
Partager