Gui.MainGuiBuilder.java Source code

Java tutorial

Introduction

Here is the source code for Gui.MainGuiBuilder.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Gui;

import BLL.UserService;
import BLL.statsService;
import BLL.postService;
import Entite.User;
import Entite.top;
import Entite.Post;
import java.awt.CardLayout;
import java.awt.Color;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import Gui.GestUser;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

/**
 *
 * @author halloul
 */
public class MainGuiBuilder extends javax.swing.JFrame {

    /**
     * Creates new form MainGuiBuilder
     */
    User appUser, updateUser;
    Post updatePost;
    public static String SelectedId = "-1";
    public static ArrayList<User> listUser;
    public static ArrayList<Post> listPost;
    public static DefaultPieDataset dataset;//Dataset qui va contenir les Donnes
    public static JFreeChart graphe; //Graphe
    public static ChartPanel piePanel, pie2panel; //Panel
    public static ArrayList<top> top5List;
    public static int nbrPost, nbrUser;

    public MainGuiBuilder() {
        initComponents();

    }

    public static UserService uService = new UserService();
    public static statsService sService = new statsService();
    public static postService pService = new postService();

    // table stuff
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    //@SuppressWarnings("unchecked");
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        MainJpanel = new javax.swing.JPanel();
        LoginJpanel = new javax.swing.JPanel();
        loginText = new javax.swing.JTextField();
        passwordText = new javax.swing.JPasswordField();
        LoginButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        msqLabel = new javax.swing.JLabel();
        ContainerJpanel = new javax.swing.JPanel();
        welcomeWagon = new javax.swing.JLabel();
        tabPanel = new javax.swing.JPanel();
        tabContainer = new javax.swing.JTabbedPane();
        ConsultationOffres = new javax.swing.JPanel();
        searchPost = new javax.swing.JTextField();
        addPostBtn = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        FilterGouvernorat = new javax.swing.JComboBox();
        PostTableScroll = new javax.swing.JScrollPane();
        PostTable = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        FiltreRubrique = new javax.swing.JComboBox();
        FilterNature = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        FilterType = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        filterPrix = new javax.swing.JSlider();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        msgPost = new javax.swing.JLabel();
        Statistiques = new javax.swing.JPanel();
        msgnbrPost = new javax.swing.JLabel();
        msgnbrUser = new javax.swing.JLabel();
        NewsLetter = new javax.swing.JPanel();
        GestionUtilisateurs = new javax.swing.JPanel();
        UserTableScroll = new javax.swing.JScrollPane();
        UserTable = new javax.swing.JTable();
        searchUser = new javax.swing.JTextField();
        addUserButton = new javax.swing.JButton();
        filterUser = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        MonCompte = new javax.swing.JPanel();
        msgChangePassword = new javax.swing.JLabel();
        MonCompteNewPass = new javax.swing.JPasswordField();
        NewPasswordBtn = new javax.swing.JButton();
        LogoutBtn = new javax.swing.JButton();
        msgMonCompte1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        MainJpanel.setLayout(new java.awt.CardLayout());

        LoginJpanel.setPreferredSize(new java.awt.Dimension(800, 600));

        loginText.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N

        passwordText.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N

        LoginButton.setText("Valider");
        LoginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoginButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
        jLabel1.setText("Mot de passe");

        jLabel2.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
        jLabel2.setText("E-M@il");

        msqLabel.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N

        javax.swing.GroupLayout LoginJpanelLayout = new javax.swing.GroupLayout(LoginJpanel);
        LoginJpanel.setLayout(LoginJpanelLayout);
        LoginJpanelLayout.setHorizontalGroup(LoginJpanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LoginJpanelLayout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 164,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
                        .addGroup(LoginJpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(msqLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 356,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(LoginJpanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(LoginButton, javax.swing.GroupLayout.DEFAULT_SIZE, 300,
                                                Short.MAX_VALUE)
                                        .addComponent(passwordText, javax.swing.GroupLayout.DEFAULT_SIZE, 300,
                                                Short.MAX_VALUE)
                                        .addComponent(loginText)))
                        .addGap(155, 155, 155))
                .addGroup(LoginJpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(LoginJpanelLayout.createSequentialGroup().addGap(80, 80, 80)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(634, Short.MAX_VALUE))));
        LoginJpanelLayout.setVerticalGroup(LoginJpanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(LoginJpanelLayout.createSequentialGroup().addGap(145, 145, 145)
                        .addComponent(loginText, javax.swing.GroupLayout.PREFERRED_SIZE, 55,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39)
                        .addGroup(LoginJpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(passwordText, javax.swing.GroupLayout.PREFERRED_SIZE, 57,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 55,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(28, 28, 28)
                        .addComponent(msqLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                        .addGap(26, 26, 26)
                        .addComponent(LoginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 41,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(169, 169, 169))
                .addGroup(LoginJpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(LoginJpanelLayout.createSequentialGroup().addGap(150, 150, 150)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 55,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(458, Short.MAX_VALUE))));

        MainJpanel.add(LoginJpanel, "loginPanel");

        welcomeWagon.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        welcomeWagon.setText("Bonjour lol");
        welcomeWagon.setToolTipText("");

        tabContainer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabContainerMouseClicked(evt);
            }
        });

        ConsultationOffres.setPreferredSize(new java.awt.Dimension(800, 584));

        searchPost.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        searchPost.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchPostKeyReleased(evt);
            }
        });

        addPostBtn.setText("Ajouter offre/demande");
        addPostBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPostBtnMouseClicked(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel4.setText("Recherche Offre/demande :");

        FilterGouvernorat.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "*", "Ariana", "Bja",
                "Ben Arous", "Bizerte", "Gabs", "Gafsa", "Jendouba", "Kairouan", "Kasserine", "Kbili",
                "La Manouba", "Le Kef", "Mahdia", "Mdenine", "Monastir", "Nabeul", "Sfax", "Sidi Bouzi",
                "Siliana", "Sousse", "Tataouine", "Tozeur", "Tunis", "Zaghouan" }));
        FilterGouvernorat.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                FilterGouvernoratItemStateChanged(evt);
            }
        });

        PostTableScroll.setEnabled(false);

        PostTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, null, null, null, null, null, null, null, null } },
                new String[] { "ID", "Titre", "Text", "Date Creation", "Gouvernorat", "Rubrique", "Nature", "Type",
                        "Prix", "User" }) {
            Class[] types = new Class[] { java.lang.Integer.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false, false,
                    false };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        PostTable.setCellSelectionEnabled(true);
        PostTable.setEditingColumn(1);
        PostTable.setEditingRow(1);
        PostTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                PostTableMouseClicked(evt);
            }
        });
        PostTableScroll.setViewportView(PostTable);

        jLabel6.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel6.setText("Rubrique : ");

        FiltreRubrique.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "*", "Offres", "Demandes" }));
        FiltreRubrique.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                FiltreRubriqueItemStateChanged(evt);
            }
        });

        FilterNature.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "*", "Achat", "Location", "Terrain", "Vente" }));
        FilterNature.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                FilterNatureItemStateChanged(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel7.setText("Nature :");

        FilterType.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "*", "Appartement", "Duplex", "Maison", "Terrain agricole", "Terrain nu" }));
        FilterType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                FilterTypeItemStateChanged(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel8.setText("Type :");

        filterPrix.setValue(100);
        filterPrix.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                filterPrixStateChanged(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel9.setText("Gouvernorat :");

        jLabel10.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel10.setText("Prix :");

        msgPost.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        msgPost.setText("1000000 DT");

        javax.swing.GroupLayout ConsultationOffresLayout = new javax.swing.GroupLayout(ConsultationOffres);
        ConsultationOffres.setLayout(ConsultationOffresLayout);
        ConsultationOffresLayout.setHorizontalGroup(ConsultationOffresLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(ConsultationOffresLayout.createSequentialGroup().addContainerGap()
                        .addGroup(ConsultationOffresLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(ConsultationOffresLayout.createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 208,
                                                Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(searchPost, javax.swing.GroupLayout.PREFERRED_SIZE, 176,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(226, 226, 226)
                                        .addComponent(addPostBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 155,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(21, 21, 21))
                                .addGroup(ConsultationOffresLayout.createSequentialGroup()
                                        .addGroup(ConsultationOffresLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        ConsultationOffresLayout.createSequentialGroup()
                                                                .addComponent(jLabel10).addGap(18, 18, 18)
                                                                .addComponent(filterPrix,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(20, 20, 20).addComponent(msgPost,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE))
                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        ConsultationOffresLayout.createSequentialGroup()
                                                                .addComponent(jLabel9)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                .addComponent(FilterGouvernorat,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 99,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(20, 20, 20).addComponent(jLabel6)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                .addComponent(FiltreRubrique,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 99,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(FilterNature, javax.swing.GroupLayout.PREFERRED_SIZE, 99,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(FilterType, javax.swing.GroupLayout.PREFERRED_SIZE, 99,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGroup(ConsultationOffresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(PostTableScroll, javax.swing.GroupLayout.DEFAULT_SIZE, 800,
                                Short.MAX_VALUE)));
        ConsultationOffresLayout.setVerticalGroup(
                ConsultationOffresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(ConsultationOffresLayout.createSequentialGroup().addContainerGap()
                                .addGroup(ConsultationOffresLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(searchPost, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(addPostBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(
                                        ConsultationOffresLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(FilterGouvernorat)
                                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(FiltreRubrique)
                                                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(FilterNature)
                                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(FilterType).addComponent(jLabel9,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(ConsultationOffresLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(msgPost, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(ConsultationOffresLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addComponent(filterPrix, javax.swing.GroupLayout.DEFAULT_SIZE, 37,
                                                        Short.MAX_VALUE)
                                                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addGap(450, 450, 450))
                        .addGroup(ConsultationOffresLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(ConsultationOffresLayout.createSequentialGroup().addGap(147, 147, 147)
                                        .addComponent(PostTableScroll, javax.swing.GroupLayout.PREFERRED_SIZE, 364,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(78, Short.MAX_VALUE))));

        tabContainer.addTab("Consultation des offres", ConsultationOffres);

        Statistiques.setPreferredSize(new java.awt.Dimension(800, 584));

        msgnbrPost.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        msgnbrPost.setToolTipText("");

        msgnbrUser.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        msgnbrUser.setToolTipText("");

        javax.swing.GroupLayout StatistiquesLayout = new javax.swing.GroupLayout(Statistiques);
        Statistiques.setLayout(StatistiquesLayout);
        StatistiquesLayout.setHorizontalGroup(StatistiquesLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(StatistiquesLayout.createSequentialGroup().addGap(28, 28, 28)
                        .addGroup(StatistiquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(msgnbrPost, javax.swing.GroupLayout.PREFERRED_SIZE, 685,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(msgnbrUser, javax.swing.GroupLayout.PREFERRED_SIZE, 681,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(87, Short.MAX_VALUE)));
        StatistiquesLayout
                .setVerticalGroup(StatistiquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                StatistiquesLayout.createSequentialGroup().addContainerGap(478, Short.MAX_VALUE)
                                        .addComponent(msgnbrUser, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(msgnbrPost, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(35, 35, 35)));

        tabContainer.addTab("Statistiques", Statistiques);

        NewsLetter.setName(""); // NOI18N
        NewsLetter.setPreferredSize(new java.awt.Dimension(800, 584));

        javax.swing.GroupLayout NewsLetterLayout = new javax.swing.GroupLayout(NewsLetter);
        NewsLetter.setLayout(NewsLetterLayout);
        NewsLetterLayout.setHorizontalGroup(NewsLetterLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 800, Short.MAX_VALUE));
        NewsLetterLayout.setVerticalGroup(NewsLetterLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 589, Short.MAX_VALUE));

        tabContainer.addTab("Gestion NewsLetter", NewsLetter);

        GestionUtilisateurs.setPreferredSize(new java.awt.Dimension(800, 584));

        UserTableScroll.setEnabled(false);

        UserTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object[][] { { null, null, null, null, null, null, null, null } },
                new String[] { "ID", "Nom", "Prenom", "Mail", "Password", "Adresse", "Telephone", "Type" }) {
            Class[] types = new Class[] { java.lang.Integer.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class,
                    java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        UserTable.setCellSelectionEnabled(true);
        UserTable.setEditingColumn(1);
        UserTable.setEditingRow(1);
        UserTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UserTableMouseClicked(evt);
            }
        });
        UserTableScroll.setViewportView(UserTable);

        searchUser.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        searchUser.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchUserKeyReleased(evt);
            }
        });

        addUserButton.setText("Ajouter Utilisateur");
        addUserButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addUserButtonMouseClicked(evt);
            }
        });

        filterUser.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "nom", "prenom", "mail", "adresse", "telephone", "type" }));

        jLabel3.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel3.setText("Recherche utilisateur");

        javax.swing.GroupLayout GestionUtilisateursLayout = new javax.swing.GroupLayout(GestionUtilisateurs);
        GestionUtilisateurs.setLayout(GestionUtilisateursLayout);
        GestionUtilisateursLayout.setHorizontalGroup(GestionUtilisateursLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(UserTableScroll)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        GestionUtilisateursLayout.createSequentialGroup().addGap(31, 31, 31)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(filterUser, javax.swing.GroupLayout.PREFERRED_SIZE, 99,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(44, 44, 44)
                                .addComponent(searchUser, javax.swing.GroupLayout.PREFERRED_SIZE, 176,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(224, 224, 224))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        GestionUtilisateursLayout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(addUserButton, javax.swing.GroupLayout.PREFERRED_SIZE, 138,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28)));
        GestionUtilisateursLayout.setVerticalGroup(
                GestionUtilisateursLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(GestionUtilisateursLayout.createSequentialGroup().addGap(37, 37, 37)
                                .addGroup(GestionUtilisateursLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(filterUser)
                                        .addComponent(searchUser, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(11, 11, 11)
                                .addComponent(addUserButton, javax.swing.GroupLayout.PREFERRED_SIZE, 34,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26).addComponent(UserTableScroll,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)));

        tabContainer.addTab("Gestion Utilisateurs", GestionUtilisateurs);

        MonCompte.setPreferredSize(new java.awt.Dimension(800, 584));

        msgChangePassword.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        msgChangePassword.setForeground(new java.awt.Color(255, 0, 0));

        MonCompteNewPass.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N

        NewPasswordBtn.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        NewPasswordBtn.setText("Valider");
        NewPasswordBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                NewPasswordBtnMouseClicked(evt);
            }
        });

        LogoutBtn.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        LogoutBtn.setText("Dconnexion");
        LogoutBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                LogoutBtnMouseClicked(evt);
            }
        });

        msgMonCompte1.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
        msgMonCompte1.setText("Changement mot de passe :");

        javax.swing.GroupLayout MonCompteLayout = new javax.swing.GroupLayout(MonCompte);
        MonCompte.setLayout(MonCompteLayout);
        MonCompteLayout.setHorizontalGroup(MonCompteLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(MonCompteLayout.createSequentialGroup().addGroup(MonCompteLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(msgChangePassword, javax.swing.GroupLayout.PREFERRED_SIZE, 610,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(MonCompteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(MonCompteLayout.createSequentialGroup().addGap(50, 50, 50)
                                        .addComponent(msgMonCompte1, javax.swing.GroupLayout.PREFERRED_SIZE, 271,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(MonCompteNewPass, javax.swing.GroupLayout.PREFERRED_SIZE, 229,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(55, 55, 55).addComponent(NewPasswordBtn,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 98,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(MonCompteLayout.createSequentialGroup().addGap(281, 281, 281)
                                        .addComponent(LogoutBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 212,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(87, Short.MAX_VALUE)));
        MonCompteLayout.setVerticalGroup(MonCompteLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(MonCompteLayout.createSequentialGroup().addGap(148, 148, 148)
                        .addGroup(MonCompteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(MonCompteNewPass, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(NewPasswordBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(msgMonCompte1, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addComponent(msgChangePassword, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18).addComponent(LogoutBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 53,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(269, Short.MAX_VALUE)));

        tabContainer.addTab("Mon Compte", MonCompte);

        javax.swing.GroupLayout tabPanelLayout = new javax.swing.GroupLayout(tabPanel);
        tabPanel.setLayout(tabPanelLayout);
        tabPanelLayout.setHorizontalGroup(tabPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(tabContainer));
        tabPanelLayout
                .setVerticalGroup(tabPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tabContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 617, Short.MAX_VALUE));

        javax.swing.GroupLayout ContainerJpanelLayout = new javax.swing.GroupLayout(ContainerJpanel);
        ContainerJpanel.setLayout(ContainerJpanelLayout);
        ContainerJpanelLayout.setHorizontalGroup(
                ContainerJpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(tabPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                ContainerJpanelLayout.createSequentialGroup()
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(welcomeWagon, javax.swing.GroupLayout.PREFERRED_SIZE, 502,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(42, 42, 42)));
        ContainerJpanelLayout.setVerticalGroup(ContainerJpanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(ContainerJpanelLayout.createSequentialGroup().addContainerGap()
                        .addComponent(welcomeWagon, javax.swing.GroupLayout.PREFERRED_SIZE, 29,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(tabPanel,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));

        MainJpanel.add(ContainerJpanel, "containerPanel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(MainJpanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addComponent(MainJpanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoginButtonActionPerformed
        // TODO add your handling code here:
        //check empty login

        if (loginText.getText().equals("")) {
            loginText.setBorder(BorderFactory.createLineBorder(Color.RED, 2));
            msqLabel.setVisible(true);
            msqLabel.setText("Merci de verifer les champs !");

        } else {
            loginText.setBorder(BorderFactory.createLineBorder(Color.GREEN, 2));
            msqLabel.setVisible(false);
        }
        // check pass
        if (passwordText.getText().equals("")) {
            passwordText.setBorder(BorderFactory.createLineBorder(Color.RED, 2));
            msqLabel.setVisible(true);
            msqLabel.setText("Merci de verifer les champs !");
            return;
        } else {
            passwordText.setBorder(BorderFactory.createLineBorder(Color.GREEN, 2));
            msqLabel.setVisible(false);
        }

        // go for login 
        appUser = uService.loginByMail(loginText.getText(), passwordText.getText());
        //appUser = uService.loginByMail("Admin@admin.com", "1234");
        if (appUser != null) {
            CardLayout card = (CardLayout) MainJpanel.getLayout();
            card.show(MainJpanel, "containerPanel");
            tabContainer.setSelectedIndex(0);
            // 0 : offre 
            // 1 : stats
            // 2 : newletter 
            // 3 : gestion user 
            // 4  :mon compte 

            tabContainer.setEnabledAt(0, true);
            tabContainer.setEnabledAt(4, true);

            if (appUser.getUserType().equals("Admin")) {
                tabContainer.setEnabledAt(1, true);
                tabContainer.setEnabledAt(2, true);
                tabContainer.setEnabledAt(3, true);

            } else if (appUser.getUserType().equals("User")) {
                tabContainer.setEnabledAt(1, false);
                tabContainer.setEnabledAt(2, false);
                tabContainer.setEnabledAt(3, false);
            }

            welcomeWagon.setVisible(true);
            welcomeWagon.setText("Bonjour " + appUser.getNom());
        } else {
            loginText.setBorder(BorderFactory.createLineBorder(Color.RED, 2));
            passwordText.setBorder(BorderFactory.createLineBorder(Color.RED, 2));
            msqLabel.setVisible(true);
            msqLabel.setText("Authentification choue !");
        }
    }//GEN-LAST:event_LoginButtonActionPerformed

    public static void moreStats() {
        nbrPost = sService.getTotalPost();
        nbrUser = sService.getTotalUser();
        msgnbrPost.setVisible(true);
        msgnbrUser.setVisible(true);
        msgnbrPost.setText("Le nombre total des offres est : " + nbrPost);
        msgnbrUser.setText("Le nombre total des utilisateurs est : " + nbrUser);
    }

    public static void genTop5Gov() {
        top5List = sService.getTop5Gouvernorat();
        dataset = new DefaultPieDataset();
        for (top top5List1 : top5List) {
            dataset.setValue(top5List1.element, top5List1.nb);
        }
        graphe = ChartFactory.createPieChart3D("Top 5 gouvernorat", dataset, true, true, false);

        piePanel = new ChartPanel(graphe);

        piePanel.setSize(400, 400);

        Statistiques.add(piePanel);

        piePanel.setVisible(true);

        Statistiques.setVisible(true);

    }

    public static void genTop5User() {
        top5List = sService.getTop5User();
        dataset = new DefaultPieDataset();
        for (top top5List1 : top5List) {
            dataset.setValue(top5List1.element, top5List1.nb);
        }
        graphe = ChartFactory.createPieChart3D("Top 5 user", dataset, true, true, false);
        pie2panel = new ChartPanel(graphe);

        pie2panel.setSize(400, 400);
        pie2panel.setBounds(400, 0, 400, 400);
        Statistiques.add(pie2panel);

        pie2panel.setVisible(true);
        Statistiques.setVisible(true);

    }

    private void tabContainerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabContainerMouseClicked
        // TODO add your handling code here:
        // dude to stupid java we have to do this : 

        // consultation des offre 

        if (tabContainer.getSelectedIndex() == 0) {

            PostTableUpdate();
        } // stats
        else if (tabContainer.getSelectedIndex() == 1) {
            genTop5Gov();
            genTop5User();
            moreStats();
        } // news letter
        else if (tabContainer.getSelectedIndex() == 2) {
        } // gestion utilisateurs
        else if (tabContainer.getSelectedIndex() == 3) {
            UserTableUpdate();
        } // mon compte 
        else if (tabContainer.getSelectedIndex() == 4) {
        }

    }//GEN-LAST:event_tabContainerMouseClicked

    private void UserTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UserTableMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 1) {
            updateUser = new User((int) UserTable.getValueAt(UserTable.getSelectedRow(), 0),
                    String.valueOf(UserTable.getValueAt(UserTable.getSelectedRow(), 1)),
                    String.valueOf(UserTable.getValueAt(UserTable.getSelectedRow(), 2)),
                    String.valueOf(UserTable.getValueAt(UserTable.getSelectedRow(), 3)),
                    String.valueOf(UserTable.getValueAt(UserTable.getSelectedRow(), 4)),
                    String.valueOf(UserTable.getValueAt(UserTable.getSelectedRow(), 5)),
                    String.valueOf(UserTable.getValueAt(UserTable.getSelectedRow(), 6)),
                    String.valueOf(UserTable.getValueAt(UserTable.getSelectedRow(), 7)));
        }
        new GestUser(updateUser).setVisible(true);
    }//GEN-LAST:event_UserTableMouseClicked

    private void searchUserKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchUserKeyReleased
        // TODO add your handling code here:
        // getting filter selection first ! 
        String filter = (String) filterUser.getSelectedItem();
        String text = searchUser.getText();
        DefaultTableModel userTabelModel = (DefaultTableModel) UserTable.getModel();

        listUser = uService.searchUser(filter, text);
        //userTableModel.
        userTabelModel.setRowCount(listUser.size());
        for (int i = 0; i < listUser.size(); i++) {

            UserTable.setValueAt(listUser.get(i).getId(), i, 0);
            UserTable.setValueAt(listUser.get(i).getNom(), i, 1);
            UserTable.setValueAt(listUser.get(i).getPrenom(), i, 2);
            UserTable.setValueAt(listUser.get(i).getMail(), i, 3);
            UserTable.setValueAt(listUser.get(i).getPassword(), i, 4);
            UserTable.setValueAt(listUser.get(i).getAdresse(), i, 5);
            UserTable.setValueAt(listUser.get(i).getTelephone(), i, 6);
            UserTable.setValueAt(listUser.get(i).getUserType(), i, 7);
        }
    }//GEN-LAST:event_searchUserKeyReleased

    private void addUserButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addUserButtonMouseClicked
        // TODO add your handling code here:
        new addUser().setVisible(true);
    }//GEN-LAST:event_addUserButtonMouseClicked

    private void searchPostKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchPostKeyReleased
        // TODO add your handling code here:
        recherchePost();
    }//GEN-LAST:event_searchPostKeyReleased

    private void addPostBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addPostBtnMouseClicked
        // TODO add your handling code here:
        new addPost(appUser.getId()).setVisible(true);
    }//GEN-LAST:event_addPostBtnMouseClicked

    private void filterPrixStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_filterPrixStateChanged
        // TODO add your handling code here:
        int pf = filterPrix.getValue();
        msgPost.setText(pf * 10000 + " DT");
        recherchePost();
    }//GEN-LAST:event_filterPrixStateChanged

    private void LogoutBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LogoutBtnMouseClicked
        // TODO add your handling code here:
        logout();
    }//GEN-LAST:event_LogoutBtnMouseClicked

    private void NewPasswordBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_NewPasswordBtnMouseClicked
        // TODO add your handling code here:
        String newPass = MonCompteNewPass.getText();
        if (newPass.length() == 0 && newPass.length() < 4) {
            MonCompteNewPass.setBorder(BorderFactory.createLineBorder(Color.RED, 2));
            msgChangePassword.setVisible(true);
            msgChangePassword.setText("le password doit tre de 4 caractres ou plus.");
            MonCompteNewPass.setText("");
            msgChangePassword.setVisible(false);
        } else {
            appUser.setPassword(newPass);
            uService.updateUser(appUser);
            MonCompteNewPass.setText("");
            logout();
        }
    }//GEN-LAST:event_NewPasswordBtnMouseClicked

    private void FilterGouvernoratItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_FilterGouvernoratItemStateChanged
        // TODO add your handling code here:
        recherchePost();
    }//GEN-LAST:event_FilterGouvernoratItemStateChanged

    private void FiltreRubriqueItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_FiltreRubriqueItemStateChanged
        // TODO add your handling code here:
        recherchePost();
    }//GEN-LAST:event_FiltreRubriqueItemStateChanged

    private void FilterNatureItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_FilterNatureItemStateChanged
        // TODO add your handling code here:
        recherchePost();
    }//GEN-LAST:event_FilterNatureItemStateChanged

    private void FilterTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_FilterTypeItemStateChanged
        // TODO add your handling code here:
        recherchePost();
    }//GEN-LAST:event_FilterTypeItemStateChanged

    private void PostTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PostTableMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 1 && appUser.getMail()
                .equalsIgnoreCase(String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 9)))) {
            updatePost = new Post((int) PostTable.getValueAt(PostTable.getSelectedRow(), 0),
                    String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 1)),
                    String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 2)),
                    String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 3)),
                    String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 4)),
                    String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 5)),
                    String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 6)),
                    String.valueOf(PostTable.getValueAt(PostTable.getSelectedRow(), 7)),
                    (int) PostTable.getValueAt(PostTable.getSelectedRow(), 8));
        }
        new GestPost(updatePost).setVisible(true);
    }//GEN-LAST:event_PostTableMouseClicked

    public void recherchePost() {

        String titre = searchPost.getText();
        String gouvernorat = (String) FilterGouvernorat.getSelectedItem();
        String rubrique = (String) FiltreRubrique.getSelectedItem();
        String nature = (String) FilterNature.getSelectedItem();
        String type = (String) FilterType.getSelectedItem();
        int prix = filterPrix.getValue() * 10000;
        System.out.println(prix);
        ArrayList<Post> pList = pService.searchPost(titre, gouvernorat, rubrique, nature, type, prix);

        DefaultTableModel postTabelModel = (DefaultTableModel) PostTable.getModel();

        //userTableModel.
        postTabelModel.setRowCount(pList.size());
        for (int i = 0; i < pList.size(); i++) {

            PostTable.setValueAt(pList.get(i).getId(), i, 0);
            PostTable.setValueAt(pList.get(i).getTitre(), i, 1);
            PostTable.setValueAt(pList.get(i).getText(), i, 2);
            PostTable.setValueAt(pList.get(i).getDateCreation(), i, 3);
            PostTable.setValueAt(pList.get(i).getGouvernorat(), i, 4);
            PostTable.setValueAt(pList.get(i).getRubrique(), i, 5);
            PostTable.setValueAt(pList.get(i).getNature(), i, 6);
            PostTable.setValueAt(pList.get(i).getType(), i, 7);
            PostTable.setValueAt(pList.get(i).getPrix(), i, 8);
            PostTable.setValueAt(pList.get(i).getUserMail(), i, 9);
        }

    }

    public void logout() {

        CardLayout card = (CardLayout) MainJpanel.getLayout();
        card.show(MainJpanel, "loginPanel");
    }

    public static void UserTableUpdate() {

        DefaultTableModel userTabelModel = (DefaultTableModel) UserTable.getModel();

        listUser = uService.getUserList();
        //userTableModel.
        userTabelModel.setRowCount(listUser.size());
        for (int i = 0; i < listUser.size(); i++) {

            UserTable.setValueAt(listUser.get(i).getId(), i, 0);
            UserTable.setValueAt(listUser.get(i).getNom(), i, 1);
            UserTable.setValueAt(listUser.get(i).getPrenom(), i, 2);
            UserTable.setValueAt(listUser.get(i).getMail(), i, 3);
            UserTable.setValueAt(listUser.get(i).getPassword(), i, 4);
            UserTable.setValueAt(listUser.get(i).getAdresse(), i, 5);
            UserTable.setValueAt(listUser.get(i).getTelephone(), i, 6);
            UserTable.setValueAt(listUser.get(i).getUserType(), i, 7);
        }
    }

    public static void PostTableUpdate() {

        DefaultTableModel postTabelModel = (DefaultTableModel) PostTable.getModel();

        listPost = pService.getPostList();

        postTabelModel.setRowCount(listPost.size());
        for (int i = 0; i < listPost.size(); i++) {

            PostTable.setValueAt(listPost.get(i).getId(), i, 0);
            PostTable.setValueAt(listPost.get(i).getTitre(), i, 1);
            PostTable.setValueAt(listPost.get(i).getText(), i, 2);
            PostTable.setValueAt(listPost.get(i).getDateCreation(), i, 3);
            PostTable.setValueAt(listPost.get(i).getGouvernorat(), i, 4);
            PostTable.setValueAt(listPost.get(i).getRubrique(), i, 5);
            PostTable.setValueAt(listPost.get(i).getNature(), i, 6);
            PostTable.setValueAt(listPost.get(i).getType(), i, 7);
            PostTable.setValueAt(listPost.get(i).getPrix(), i, 8);
            PostTable.setValueAt(listPost.get(i).getUserMail(), i, 9);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainGuiBuilder.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainGuiBuilder.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainGuiBuilder.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainGuiBuilder.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainGuiBuilder().setVisible(true);
                genTop5Gov();
                genTop5User();
                moreStats();
                PostTableUpdate();

            }
        });

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ConsultationOffres;
    private javax.swing.JPanel ContainerJpanel;
    private javax.swing.JComboBox FilterGouvernorat;
    private javax.swing.JComboBox FilterNature;
    private javax.swing.JComboBox FilterType;
    private javax.swing.JComboBox FiltreRubrique;
    private javax.swing.JPanel GestionUtilisateurs;
    private javax.swing.JButton LoginButton;
    private javax.swing.JPanel LoginJpanel;
    private javax.swing.JButton LogoutBtn;
    private javax.swing.JPanel MainJpanel;
    private javax.swing.JPanel MonCompte;
    private javax.swing.JPasswordField MonCompteNewPass;
    private javax.swing.JButton NewPasswordBtn;
    private javax.swing.JPanel NewsLetter;
    public static javax.swing.JTable PostTable;
    javax.swing.JScrollPane PostTableScroll;
    private static javax.swing.JPanel Statistiques;
    public static javax.swing.JTable UserTable;
    javax.swing.JScrollPane UserTableScroll;
    private javax.swing.JButton addPostBtn;
    private javax.swing.JButton addUserButton;
    private javax.swing.JSlider filterPrix;
    private javax.swing.JComboBox filterUser;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField loginText;
    private javax.swing.JLabel msgChangePassword;
    private javax.swing.JLabel msgMonCompte1;
    private javax.swing.JLabel msgPost;
    private static javax.swing.JLabel msgnbrPost;
    private static javax.swing.JLabel msgnbrUser;
    private javax.swing.JLabel msqLabel;
    private javax.swing.JPasswordField passwordText;
    private javax.swing.JTextField searchPost;
    private javax.swing.JTextField searchUser;
    private javax.swing.JTabbedPane tabContainer;
    private javax.swing.JPanel tabPanel;
    private javax.swing.JLabel welcomeWagon;
    // End of variables declaration//GEN-END:variables
}