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 253 254 255 256 257 258 259 260 261
|
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Label;
import java.awt.LayoutManager;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
public class TheApplet extends JApplet {
public void init (){
parser v =new parser();
//Container cp = getContentPane();
//v.princ().setVisible(true);
// Container cp = getContentPane();
// cp.setLayout(new FlowLayout());
add(v.princ());
//add(new Label("rrrrrrrrrr"));
}
public static void main(String args []) {
}
}
class BarChart extends JFrame {
public JPanel pnl;
public BarChart() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
pnl = new JPanel(new BorderLayout());
setContentPane(pnl);
// setSize(400, 250);
}
}
class parser {
//repertoire contenant les fichiers sources
private static final String dir="MONITOR/";
// private static FileOutputStream MyFile;
// private static FileOutputStream MyFile_2;
private static DefaultCategoryDataset dataset = new DefaultCategoryDataset();
// constructeur de la classe parser et methode
// l'option try car il se peut que il y aura une exception
// try et catch utiliser par eclipse potomycto on nam oblegcaet
/* public parser(){
try {
MyFile= new FileOutputStream("FINALm");
MyFile_2= new FileOutputStream("FINAL_2");
}
catch (FileNotFoundException e) {
System.err.println("Fichier introuvable !");
System.err.println("Fichier introuvable !");
}
} */
public void parsing(String f){
try
{
BufferedReader b = new BufferedReader(new FileReader(f));
// pour retrouver le nom de la ville si on est dans CatapultC Synthesis et afficher dans FINAL
String c;
// true si on est dans le cas de CatapultC Synthesis
boolean catapult=false;
boolean ville=false;
// ---------------------------
int gnx=0;
int gva=0;
int tun=0;
int h;
String bis, date=null;
//je recherche le mot Date
while((c=b.readLine())!=null){
if(c.contains("Date")){
date=c.substring(90,109);
// MyFile.write((c.substring(90,109)+" ").getBytes());
// MyFile_2.write((c.substring(90,109)+" ").getBytes());
}
//si je suis dans catapult alors je regarde
//si le mot LICENSE MAX et used se trouve dans la ligne
//et j'ecrits gras a methode write
if(catapult && ville){
if ((c.contains("LICENSE MAX")&& c.contains("catapultsl_c"))){
// on recuper "licence max"
// MyFile.write((" "+c.substring(66,67)).getBytes());
//parsetInt converti en entier
dataset.addValue(Integer.parseInt(c.substring(66,67)), "MAX", date);
}
else if((c.contains("LICENSE MAX")&& c.contains("catapultflpwr_c"))){
//on recuper "licence max" de grenoble et de catapultflpwr_c
// MyFile_2.write((" "+c.substring(66,67)).getBytes());
}
//meme chose avec tous info used + grenoble + catapult
if (c.contains(" used")&& c.contains("catapultsl_c")){
// on recuper le nb used
// MyFile.write((" "+c.substring(66,67)).getBytes());
dataset.addValue(Integer.parseInt(c.substring(66,67)), "USED", date);
//pour recupere le nom catapultsl_c
//MyFile.write((c.substring(1,20)+"\n").getBytes());
//}
}
else if ((c.contains(" used")&& c.contains("catapultflpwr_c"))){
// MyFile_2.write((" "+c.substring(66,67)+"\n").getBytes());
}
//si on est dans la --->
if(c.contains("--->")){
// on cherche des espace dan la chaine de case 20 a 50
//indexOf return index du tab. cdec indexOf vas prendre 2espace
//entre chaine 20 et 50
h=c.substring(20, 50).indexOf(" ");
//bis un string qui vas recupere premier espace + la chaine a partir de 21
//puis espase + la chaine a partir de 21 + 3(gnx)
bis=c.substring(h+21, h+21+3);
if(bis.contains("gnx"))
{
gnx++;
}
else if(bis.contains("tun")){
tun++;
}
else if (bis.contains("gva")){
gva++;
}
}
}
if (c.contains("GRENOBLE")){
ville=true;
// System.out.println("Je suis a Grenoble");
}
if(c.contains("NOIDA")||c.contains("CROLLES")){
ville=false;
}
//true si CatapultC Synthesis faux sinon
if(c.contains("CatapultC Synthesis")) {
catapult=true;
}
if(c.contains("Mentor SLEC")||c.contains("Library Builder")||c.contains("SLEC")||c.contains("SYNFORA")){
catapult=false;
}
}
//on affiche espase gnx, gva, tun, total
int total=gnx+gva+tun;
/* MyFile.write((" "+gnx).getBytes());
MyFile.write((" "+gva).getBytes());
MyFile.write((" "+tun).getBytes());
MyFile.write((" "+total+"\n").getBytes());*/
dataset.addValue(gnx, "grenoble", date);
dataset.addValue(gva, "geneve", date);
dataset.addValue(tun, "tunis", date);
}
catch (FileNotFoundException e1) {
System.err.println("Fichier introuvable !");
e1.printStackTrace();
System.exit(-1);
} catch (IOException e2) {
System.err.println("Problème de lecture !");
System.exit(-1);
}
}
public JPanel princ() {
//declaration et creation de mon objet de type parser
parser fich=new parser ();
File cour = new File(dir);
File[] fichs = cour.listFiles();
// try {
// MyFile.write((" Date"+" MAX"+" Used"+" Gnx"+" Gva"+" Tun"+" Total"+"\n").getBytes());
// MyFile_2.write((" Date"+" MAX"+" Used"+"\n").getBytes());
long x = System.currentTimeMillis();
for (int i=0; i<fichs.length;i++){
fich.parsing(dir+fichs[i].getName());}
x = System.currentTimeMillis() - x;
System.out.println("Temps de traitement: "+x+" ms");
//}
//catch(IOException e) {
// System.err.println("ERROR...");
//}
BarChart vv=new BarChart();
JFreeChart barChart = ChartFactory.createBarChart("Monitoring/CatapultC Synthesis", "Date",
"License Max Utiliser", dataset, PlotOrientation.HORIZONTAL, true, true, false);
ChartPanel cPanel = new ChartPanel(barChart);
// pour add sur panel
vv.pnl.add(cPanel);
// pour visualiser sur panel
//vv.setVisible(true);
File fichier =new File("image.jpg");
try {
ChartUtilities.saveChartAsPNG(fichier,barChart,300,200);
}catch (IOException e){
e.printStackTrace();
}
return vv.pnl; // voila ce que j'ai changeé
}
} |
Partager