| 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
 
 | public class Vue extends JFrame {
	private static final long serialVersionUID = 1L;
	Controleur firewall = new Controleur();	
	JPanel panel = new JPanel();
	JPanel paneln = new JPanel();
	JPanel panels = new JPanel();
	JPanel panelw = new JPanel();
	JPanel panelc = new JPanel();
	JPanel panele = new JPanel();
	JLabel image = new JLabel(new ImageIcon(this.getClass().getResource("logoVPN.png")));
	JButton refresh = new JButton("Actualiser");
	
	public Vue(){
		barre b = new barre();
		Color background = new Color(255,228,202);
		panel.setLayout(new BorderLayout(6,12));
		panel.add(paneln, BorderLayout.NORTH);
		panel.add(panelw, BorderLayout.WEST);
		panel.add(panelc, BorderLayout.CENTER);
		panel.add(panele, BorderLayout.EAST);
		panel.add(panels, BorderLayout.SOUTH);
		paneln.add(image);
		panelw.setLayout(new GridLayout(firewall.getListAcces().size(),1,0,3));
		panelc.setLayout(new GridLayout(firewall.getListAcces().size(),1,0,3));
		panele.setLayout(new GridLayout(firewall.getListAcces().size(),1,0,3));
		int[] varHeightWidthFrameSize = buildComponent();
		refresh.addActionListener(new GestionActionRefreshListener(firewall));
		panels.add(refresh);
		panelw.setPreferredSize(new Dimension(varHeightWidthFrameSize[1]*7,300));
		panel.setBackground(background);
		paneln.setBackground(background);
		panels.setBackground(background);
		panele.setBackground(background);
		panelw.setBackground(background);
		panelc.setBackground(background);
		this.setTitle("Gestion Accès VPN");
		this.setSize(190+(varHeightWidthFrameSize[1]*7),125+(varHeightWidthFrameSize[0]*31));
		this.setResizable(false);
		this.addWindowListener(new GestionWindowListener(firewall));
		this.setLocationRelativeTo(null);
		this.setContentPane(panel);
		this.setVisible(true);
		defaultPopup();
	}
	
	private int[] buildComponent(){
		int varFrameSize[] = {0,0};
		for(int j=0 ; j<firewall.getListAcces().size() ; j++){
			Controleur.Acces acces = firewall.getListAcces().get(j);
			boolean etatConnexion = firewall.getEtatAcces(acces);
			panelw.add(new JLabel(acces.getLabel(),javax.swing.SwingConstants.CENTER));
			for(int i=0 ; i<acces.getBoutons().length ; i++){
				acces.getBoutons()[i].addActionListener(new GestionActionListener(firewall,acces,acces.getBoutons()[i].getText()));
				panelc.add(acces.getBoutons()[i]);
			}
			panele.add(acces.getEtat());
			firewall.actualiserEtat(acces,etatConnexion);
			firewall.actualiserBoutons(acces,etatConnexion);
			if(acces.getLabel().length()>varFrameSize[1]){
				varFrameSize[1] = acces.getLabel().length();
			}
			varFrameSize[0]++;
		}
		return varFrameSize;
	}
	
	private void defaultPopup(){
		if(firewall.getModeDefault()){
			String message_default = "       Le fichier de configuration des accès est introuvable.\r\n";
			message_default+= "           Vous ne bénéfiecierez que des accès par défaut.\r\n";
			message_default+= "Si le problème persiste : contactez l'Activité Informatique";
			String titre_default = "Fichier de configuration introuvable";
			JOptionPane.showMessageDialog(this,message_default,titre_default,JOptionPane.WARNING_MESSAGE);
		}
	}
	
	public class barre extends JFrame{
		private static final long serialVersionUID = 1L;
		private Thread t;
	  	private JProgressBar bar;
	   
	  	public barre(){      
	  		this.setSize(300, 60);
	  		this.setTitle("Chargement...");
	  		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	  		this.setLocationRelativeTo(null);      
	      
	  		t = new Thread(new Traitement(this));
	  		bar  = new JProgressBar();
	  		bar.setMaximum(400);
	  		bar.setMinimum(0);
	  		bar.setStringPainted(true);
	      
	  		this.getContentPane().add(bar, BorderLayout.CENTER);      
	  		t.start();      
	  		this.setVisible(true);  
	  	}
	  	class Traitement implements Runnable{  
		  
	  		JFrame jf = new JFrame();
		
	  		public Traitement(JFrame jfr){
	  			jf = jfr;
	  		}
		
	  		public void run(){       
	  			for(int val = 0; val <= 400; val++){
	  				bar.setValue(val);
	  				try {
	  					t.sleep(11);
	  				}catch (InterruptedException e) {
	  					e.printStackTrace();
	  				}
	  			}
	  			jf.dispose();
	  		}   
	  	}
	}	
	public static void main(String[] args){
		new Vue();
	}
} | 
Partager