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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
| package graphique;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jfree.ui.RefineryUtilities;
import fichier.RecupFichier;
import graphique2.Graph;
public class Formulaire extends JFrame implements ActionListener, WindowListener {
JLabel jLabelNom_Graph = new JLabel("Nom du graphique :");
JTextField jTextFieldNom_Graph = new JTextField(12);
JButton jButtonAdd = new JButton("Add");
JButton jButtonDlt = new JButton("Dlt");
JButton jButtonGene = new JButton("Générer");
JLabel jLabelParam = new JLabel("Paramètre(s)");
List listParam = new List();
JLabel jLabelGraph = new JLabel("Mes graphique(s)");
List listGraph = new List();
JLabel jLabelSt = new JLabel("Statut du traitement");
ArrayList graphe = new ArrayList();
RecupFichier rf = new RecupFichier();
JFrame jFrameGraphes = new JFrame();
JPanel jPanelGraphes = new JPanel();
JButton jButtonGraphes = new JButton("Graphe");
public Formulaire() {
//Construction de ma JFrame pour l'affichage des graphes
jFrameGraphes.setLayout(new BorderLayout());
jPanelGraphes.setLayout(new GridLayout(2,1));
jFrameGraphes.setBounds(900,250,750,600);
//----------------------------------------
//Gestion de la disposition des éléments
this.setLayout(new BorderLayout());
JPanel jPanelN = new JPanel();
jPanelN.setLayout(new FlowLayout());
jPanelN.add(jLabelNom_Graph);
jPanelN.add(jTextFieldNom_Graph);
jPanelN.add(jButtonAdd);
jPanelN.add(jButtonDlt);
jPanelN.add(jButtonGene);
this.add(jPanelN, BorderLayout.NORTH);
JPanel jPanelC = new JPanel();
jPanelC.setLayout(new GridLayout());
jPanelC.add(jLabelGraph);
jPanelC.add(listParam);
jPanelC.add(listGraph);
this.add(jPanelC, BorderLayout.CENTER);
this.add(jLabelParam, BorderLayout.WEST);
this.add(jLabelGraph, BorderLayout.EAST);
this.add(jLabelSt, BorderLayout.SOUTH);
//--------------------------------------------
//Gestion des évènements sur les boutons
jButtonAdd.addActionListener(this);
jButtonDlt.addActionListener(this);
jButtonGene.addActionListener(this);
//--------------------------------------------
//Gestion des évènements sur la fenêtre
this.addWindowListener(this);
//--------------------------------------------
//Elements spécifique à* ma fenetre
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setBounds(900,250,750,600);
this.setAlwaysOnTop(true);
this.setVisible(true);
//--------------------------------------------
}
/*private void chargParam() {
listParam.add("MASSE");
listParam.add("PSI");
listParam.add("CAP VENT");
listParam.add("VIT VENT");
listParam.add("FORCE MER");
}*/
public void afficherGraphes(){
//System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
ArrayList afficher = new ArrayList();
for(int i=0;i<graphe.size();i++ ){
afficher.add(graphe.get(i));
System.out.println("index"+i+" : "+afficher.get(i));
}
//System.out.println(graphe);
}
public void actionPerformed(ActionEvent e){
jLabelSt.setText("OK");
if(e.getSource() == jButtonAdd){
//try{
if((jTextFieldNom_Graph.getText().length() == 0) && (listParam.getSelectedIndex() == -1)){
jLabelSt.setText("Erreur: Veuillez entrer un nom pour le graphique et choisir un paramètre");
}else if(jTextFieldNom_Graph.getText().length() == 0){
jLabelSt.setText("Erreur: Veuillez entrer un nom pour le graphique");
}
else if(listParam.getSelectedIndex() == -1){
jLabelSt.setText("Erreur: Veuillez choisir un paramètre");
}
//index0: le nom du graph
//index1: le nom du paramètre
//index2: la position du paramètre dans la liste
//index3: L'unité
//index4: data
ArrayList cons_Graph = new ArrayList();
cons_Graph.add(jTextFieldNom_Graph.getText());
cons_Graph.add(listParam.getSelectedItem());
cons_Graph.add(listParam.getSelectedIndex());
cons_Graph.add(rf.unite(listParam.getSelectedIndex()));
if((jTextFieldNom_Graph.getText().length() > 0) && (listParam.getSelectedIndex() != -1)){
listGraph.add(jTextFieldNom_Graph.getText());
/*ArrayList child_para = (ArrayList) data.get(0);
for(int i=0; i<child_para.size();i++){
madata.add(child_para.get(i));
}*/
cons_Graph.add(rf.paramData(listParam.getSelectedIndex()));
graphe.add(cons_Graph);
}
//}
/*catch(Exception e2){
if(listParam.getSelectedIndex() == -1){
jLabelSt.setText("Erreur: Veuillez choisir un paramètre ici");
}
System.out.println("bug");
}*/
afficherGraphes()
}
if(e.getSource() == jButtonDlt){
int indexGraph = listGraph.getSelectedIndex();
try{
//System.out.println(listGraph.getSelectedIndex());
listGraph.remove(indexGraph);
graphe.remove(indexGraph);
}
catch(Exception e2){
if(indexGraph == -1){
jLabelSt.setText("Erreur: Veuillez choisir un graphique à* supprimer");
}
}
afficherGraphes();
}
if(e.getSource() == jButtonGene){
if(listGraph.countItems()>0)
{
for(int i=0;i<graphe.size();i++){
ArrayList mongraphe = (ArrayList) graphe.get(i);
//index0: le nom du graph
//index1: le nom du paramètre
//index2: la position du paramètre dans la liste
//index3: L'unité
//index4: résultats
//Récupère les résultats
String resultat[] = new String[100];
ArrayList mesresultats = (ArrayList) mongraphe.get(4);
for(int j=0;j<mesresultats.size();j++){
resultat[j] = (String) mesresultats.get(j);
//System.out.println(resultat[j]);
}
final Graph demo = new Graph("Résultat",(String)mongraphe.get(1), resultat, "unité",mesresultats.size());
/*demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
demo.setAlwaysOnTop(true);*/
jPanelGraphes.add(demo.chartPanel);
jFrameGraphes.setVisible(true);
jFrameGraphes.add(jPanelGraphes, BorderLayout.CENTER);
}
}
else{
jLabelSt.setText("Erreur: Vous avez construit aucun graphique");
}
}
}
//Gestion des évènements sur la fenêtre----------------------
public void windowActivated(WindowEvent arg0) {
}
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowOpened(WindowEvent arg0) {
ArrayList parentList = new ArrayList();
ArrayList childList = new ArrayList();
parentList.add(rf.parametresFichier());
ArrayList child = (ArrayList) parentList.get(0);
for(int j=0 ;j<child.size();j++){
listParam.add((String) child.get(j));
}
}
//------------------------------------------------------
} |
Partager