| 12
 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
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 
 | package Carte;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.IOException;
 
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
 
public class PanneauPeinture extends JPanel{
 
	private static final long serialVersionUID = 1L;
	BufferedImage image = null;
	BufferedImage image2 = null;
	BufferedImage image3 = null;
	BufferedImage image4 = null;
	Image alerte;
	String[] Switchs;
	String[] AccessPoint;
	String[] PCFlexnet;
	String[] equipemnt;
	String[] serveurs;
	String desc = "";
	int width;
	int height;
	Boolean[] test = {false,false,false};
	Boolean alerteRouge = false;
	int[][] table1;
	int[][] table2;
	int[][] table3;
	JScrollPane scroll;
	JTable table;
	/** initialise les images et determine leur taille **/
	BufferedImage imag;
 
	public PanneauPeinture(BufferedImage img) {
    imag=img;
		width = img.getWidth();
        height = img.getHeight();
 
        setSize(new Dimension(width, height));
        image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = (Graphics2D) image.getGraphics();     
        g2.drawImage(imag, 0, 0, this);
 
 
        repaint();
	}
 
	/** dessinne les differents elements et images **/
 
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
 
 
        if (image != null & image2 != null & image3 != null & image4 != null) {
            g.drawImage(image,0,0,null);
            if(test[0]){
            	g.drawImage(image2,0,0,null);
            }
            if(test[1]){
            	g.drawImage(image3,0,0,null);
            }
    	    if(test[2]){
            	g.drawImage(image4,0,0,null);
            }
            g.setColor(new Color(-27036));
            g.fillRect(width/2,10,8,8);
            g.setColor(Color.black);
            g.drawString("Switch",width/2 + 15,17);
 
 
 
            g.setColor(new Color(-16711681));
            g.fillRect(width/2,30,8,8);
            g.setColor(Color.black);
            g.drawString("AccessPoint",width/2 + 15,37);
 
 
 
            g.setColor(new Color(-16711936));
            g.fillRect(width/2,50,8,8);
            g.setColor(Color.black);
            g.drawString("Flexnet",width/2 + 15,57);
 
            g.setColor(new Color(-100));
            g.fillRect(width/2,70,8,8);
            g.setColor(Color.black);
            g.drawString("Pas de données",width/2 + 15,77);
 
 
        }
    }
 
    /** permet d'effectuer un zoom sur le graphique
     *  actuellement non utilisé 
     *  se referrer à echelle **/
 
    public void redimensionner(int largeur,int hauteur){
        double valueY = (double)hauteur/height;
        double valueX = (double)largeur/width;
        width = largeur;
        height = hauteur;
    	image = PanneauPeinture.echelle(image,valueX,valueY);
        image2 = PanneauPeinture.echelle(image2,valueX,valueY);
        image3 = PanneauPeinture.echelle(image3,valueX,valueY);
        image4 = PanneauPeinture.echelle(image4,valueX,valueY);
        table1 = new int[width][height];
        table2 = new int[width][height];
        table3 = new int[width][height];
        repaint();
    }
 
    /** permet d'ajouter une image
     *  jusqu'a 3 images ajoutées **/
 
    public void addImage(BufferedImage img,int index){	
		if(index == 1){
			image2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
			Graphics2D g2 = (Graphics2D) image2.getGraphics();
			g2.drawImage(img, 0, 0, this);
			repaint();
		}
 
		if(index == 2){
			image3 = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
			Graphics2D g3 = (Graphics2D) image3.getGraphics();
			g3.drawImage(img, 0, 0, this);
			repaint();
		}
 
		if(index == 3){
			image4 = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
			Graphics2D g4 = (Graphics2D) image4.getGraphics();
			g4.drawImage(img, 0, 0, this);
			repaint();
		}	
    }
 
    /** initialise les differentes variables **/
    public void reinitialiser()throws IOException{
        for(int i = 0;i<width;i++){
            for(int j = 0;j<height;j++){
                table1[i][j] = 0;
                table2[i][j] = 0;
                table3[i][j] = 0;
            }
        }
		int w = width;
		int h = height;
		int[] rgbs2 = new int[w*h];
		image2.getRGB(0,0,w,h,rgbs2,0,w);
                int dim = 0;
                int index = 0;
                boolean test = true;
                while(test){
                    if(rgbs2[index] == -32704){
                        dim++;
                        if(rgbs2[index+1] != -32704){
                            test = false;
                        }
                    }
                    index++;
                }
		int v = 1;
		for(int i = 1;i<width + 1;i++){
                    for(int j = 1;j<height;j++){
                        if(rgbs2[w*j - width + i] == -32704){
                            if(table1[i-1][j-1] == 0){
                                for(int a = 0;a<dim;a++){
                                    for(int b = 0;b<dim;b++){
                                        table1[i+a-1][j+b-1] = v;
                                    }
                                }
                                v++;
                            }		
                        }
                    }
		}
		int[] rgbs3 = new int[w*h];
		image3.getRGB(0,0,w,h,rgbs3,0,w);
		v = 1;
		for(int i = 1;i<width + 1;i++){
			for(int j = 1;j<height;j++){
				if(rgbs3[w*j - width + i] == -16711681){				
					if(table2[i-1][j-1] == 0){
						for(int a = 0;a<dim;a++){
							for(int b = 0;b<dim;b++){
                                                            table2[i+a-1][j+b-1] = v;
							}
						}
						v++;
					}		
				}
			}
		}
		int[] rgbs = new int[w*h];
		image4.getRGB(0,0,w,h,rgbs,0,w);
		v = 1;
		for(int i = 1;i<width + 1;i++){
			for(int j = 1;j<height;j++){
				if(rgbs[w*j - width + i] == -16711936){					
					if(table3[i-1][j-1] == 0){
						for(int a = 0;a<dim;a++){
							for(int b = 0;b<dim;b++){
								table3[i+a-1][j+b-1] = v;
							}
						}
						v++;
					}		
				}
			}
		}
    }
    public void initialiser(String[] equipement)throws IOException{
 
    	Switchs = Fichier.Lire(equipement[0]);
    	AccessPoint = Fichier.Lire(equipement[1]);
    	PCFlexnet = Fichier.Lire(equipement[2]);
    	serveurs = Fichier.Lire(equipement[3]);
    	equipemnt = new String[Switchs.length + AccessPoint.length + PCFlexnet.length];
    	for(int i = 0;i<equipemnt.length;i++){
    		equipemnt[i]= "";
    	}
 
    }
 
    /** retourne un tableau contenant les differents equipements **/
 
    public String[] retourner(){
    	int index = Switchs.length;
    	for(int i = 0;i<index;i++){
    		equipemnt[i] = Switchs[i];
    	}
    	int i = 0; 
    	for(int j = index;j< (index + AccessPoint.length);j++){
    		equipemnt[j] = AccessPoint[i++];
    	}
    	i = 0;
    	index = Switchs.length + AccessPoint.length;
    	for(int k = index;k< (index + PCFlexnet.length);k++){
    		equipemnt[k] = PCFlexnet[i++];
    	}
    	return equipemnt;
    }
 
    /** permet de selectionner les equipements 
     *  à afficher sur le graphique **/
 
    public void Selection(Boolean[] test){
    	this.test = test;
    	repaint();
    }
 
    /** permet de recuperer l'equipement pointé par la souris **/
 
    public String getPixelCouleur(int x,int y){
        if(table1[x][y] != 0 & test[0]){
    		return Switchs[table1[x][y]-1];	
    	}
    	if(table2[x][y] != 0 & test[1]){
    		return AccessPoint[table2[x][y]-1];	
    	}
    	if(table3[x][y] != 0 & test[2]){
    		return PCFlexnet[table3[x][y]-1];	
    	}
    	else return "";	
	}
 
	/** se referrer à "Alerte de FenetrePrincipale" 
         *      permet de recolorier les equipements defectueux **/
    public void recolorier(String element,int num,int couleur){
		if(element == "switch"){ 
			for(int i = 0; i<width;i++){
				for(int j = 0;j<height;j++){
					if(table1[i][j] == num){
						image2.setRGB(i+1,j,couleur);
					}
				}	
			}
		}
		if(element == "accesspoint"){ 
			for(int i = 0; i<width;i++){
				for(int j = 0;j<height;j++){
					if(table2[i][j] == num){
						image3.setRGB(i+1,j,couleur);
					}
				}	
			}
		}
		if(element == "flex"){ 
			for(int i = 0; i<width;i++){
				for(int j = 0;j<height;j++){
					if(table3[i][j] == num){
						image4.setRGB(i+1,j,couleur);
					}
				}	
			}
		}
		repaint();
	}
 
    /** Methode de Developpez.com**/
 
    public static BufferedImage echelle(BufferedImage bi,double tailleL,double tailleh) {
        AffineTransform tx = new AffineTransform();
        tx.scale(tailleL, tailleh);
        AffineTransformOp op = new AffineTransformOp(tx,AffineTransformOp.TYPE_BILINEAR);
        BufferedImage biNew = new BufferedImage((int)(bi.getWidth()*tailleL),
        (int)(bi.getHeight()*tailleh),bi.getType());
        return op.filter(bi, biNew);
	}	
} |