283 lines
7.4 KiB
Java
283 lines
7.4 KiB
Java
|
package fr.blankoworld.ihm;
|
||
|
|
||
|
// Importations automatiques
|
||
|
|
||
|
import java.awt.BorderLayout;
|
||
|
import java.awt.event.ActionEvent;
|
||
|
import java.awt.event.ActionListener;
|
||
|
import java.awt.event.WindowEvent;
|
||
|
import java.awt.event.WindowListener;
|
||
|
|
||
|
import javax.swing.BorderFactory;
|
||
|
import javax.swing.JFrame;
|
||
|
import javax.swing.JMenu;
|
||
|
import javax.swing.JMenuBar;
|
||
|
import javax.swing.JMenuItem;
|
||
|
import javax.swing.JOptionPane;
|
||
|
import javax.swing.JPanel;
|
||
|
import javax.swing.JTextArea;
|
||
|
import javax.swing.border.BevelBorder;
|
||
|
|
||
|
import fr.blankoworld.connexionBDD.Connexion;
|
||
|
import fr.blankoworld.donnees.JTableModel;
|
||
|
|
||
|
/**
|
||
|
* @author 3dossmanno
|
||
|
*/
|
||
|
public class IHMPrincipale extends JFrame {
|
||
|
|
||
|
private static final long serialVersionUID = 1L;
|
||
|
|
||
|
|
||
|
private JTextArea zoneTexteStatut;
|
||
|
|
||
|
private JMenuItem MenuBdd_Connexion;
|
||
|
private JMenuItem MenuBdd_Fermer;
|
||
|
|
||
|
private JMenu MenuAction;
|
||
|
private JPanel Panneau_Centre;
|
||
|
|
||
|
private boolean connecte = false;
|
||
|
|
||
|
private IHMConnexion conn;
|
||
|
private Connexion objetConnexion;
|
||
|
|
||
|
private JTableModel tableDonnees;
|
||
|
|
||
|
/**
|
||
|
* @param args
|
||
|
*/
|
||
|
public static void main(String[] args) {
|
||
|
// TODO Auto-generated method stub
|
||
|
new IHMPrincipale().setVisible(true);
|
||
|
}
|
||
|
|
||
|
private IHMPrincipale() {
|
||
|
|
||
|
// Creation du menu Base de donnees
|
||
|
JMenu MenuBdd = new JMenu("Base de donnees");
|
||
|
MenuBdd_Connexion = new JMenuItem("Connexion");
|
||
|
MenuBdd_Fermer = new JMenuItem("Fermer");
|
||
|
MenuBdd_Fermer.setEnabled(false);
|
||
|
JMenuItem MenuBdd_Quitter = new JMenuItem("Quitter");
|
||
|
MenuBdd.add(MenuBdd_Connexion);
|
||
|
MenuBdd.add(MenuBdd_Fermer);
|
||
|
MenuBdd.addSeparator();
|
||
|
MenuBdd.add(MenuBdd_Quitter);
|
||
|
|
||
|
// Creation du menu Action
|
||
|
MenuAction = new JMenu("Action");
|
||
|
JMenuItem MenuAction_Requete = new JMenuItem("Faire une requete");
|
||
|
MenuAction.add(MenuAction_Requete);
|
||
|
MenuAction.setVisible(false);
|
||
|
|
||
|
// Creation du menu Aide
|
||
|
JMenu MenuAide = new JMenu("Aide");
|
||
|
JMenuItem MenuAide_Apropos = new JMenuItem("A propos");
|
||
|
MenuAide.add(MenuAide_Apropos);
|
||
|
|
||
|
// Creation de la barre de menus
|
||
|
JMenuBar MenuPrincipal = new JMenuBar();
|
||
|
MenuPrincipal.add(MenuBdd);
|
||
|
MenuPrincipal.add(MenuAction);
|
||
|
MenuPrincipal.add(MenuAide);
|
||
|
|
||
|
//** Modification de la zone de texte
|
||
|
|
||
|
zoneTexteStatut = new JTextArea(6,60);
|
||
|
zoneTexteStatut.setEditable(false);
|
||
|
zoneTexteStatut.setBorder(new BevelBorder(BevelBorder.LOWERED));
|
||
|
|
||
|
//** Creation des panneaux **//
|
||
|
// Panneau au centre
|
||
|
Panneau_Centre = new JPanel();
|
||
|
Panneau_Centre.setLayout(new BorderLayout());
|
||
|
Panneau_Centre.setOpaque(true); // Apparemment utile pour le JTable
|
||
|
Panneau_Centre.setBorder(BorderFactory.createTitledBorder("Resultat des requetes"));
|
||
|
|
||
|
// Panneau en bas
|
||
|
JPanel Panneau_Bas = new JPanel();
|
||
|
Panneau_Bas.setBorder(BorderFactory.createTitledBorder("Statut"));
|
||
|
|
||
|
// Ajout des boutons et zones de texte au panneau bas
|
||
|
Panneau_Bas.add(zoneTexteStatut);
|
||
|
|
||
|
// Ajout des panneaux a la fenetre
|
||
|
this.getContentPane().setLayout(new BorderLayout());
|
||
|
this.add(Panneau_Centre, BorderLayout.CENTER);
|
||
|
this.add(Panneau_Bas, BorderLayout.SOUTH);
|
||
|
this.add(MenuPrincipal, BorderLayout.NORTH);
|
||
|
|
||
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
|
|
||
|
this.setSize(700,300);
|
||
|
this.setLocation(200,200);
|
||
|
this.setResizable(false);
|
||
|
this.setTitle("SQLNavigator v0.1");
|
||
|
|
||
|
|
||
|
// ***************************************************** //
|
||
|
// Creation des fenetres secondaires //
|
||
|
// ***************************************************** //
|
||
|
conn = new IHMConnexion(this, "grive.u-strasbg.fr", "1521", "v920", "dut", "dut");
|
||
|
conn.setLocation(400,350);
|
||
|
|
||
|
// ***************************************************** //
|
||
|
|
||
|
// menu Jeu - bouton Nouveau
|
||
|
MenuBdd_Connexion.addActionListener(new ActionListener(){
|
||
|
public void actionPerformed(ActionEvent ev){
|
||
|
menuBddConnexion();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
MenuBdd_Fermer.addActionListener(new ActionListener(){
|
||
|
public void actionPerformed(ActionEvent ev){
|
||
|
menuBddFermer();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// menu Jeu - bouton Quitter
|
||
|
MenuBdd_Quitter.addActionListener(new ActionListener(){
|
||
|
public void actionPerformed(ActionEvent ev){
|
||
|
menuBddQuitter();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
MenuAction_Requete.addActionListener(new ActionListener(){
|
||
|
public void actionPerformed(ActionEvent ev){
|
||
|
menuActionRequete();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// menu Apropos - bouton
|
||
|
MenuAide_Apropos.addActionListener(new ActionListener(){
|
||
|
public void actionPerformed(ActionEvent ev){
|
||
|
menuApropos();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
private void menuBddConnexion(){
|
||
|
// Affichage de la fenetre de connexion
|
||
|
conn.setVisible(true);
|
||
|
conn.driverExist();
|
||
|
|
||
|
// Mise en place d'une ecoute sur la fenetre
|
||
|
conn.addWindowListener(new WindowListener(){
|
||
|
public void windowActivated(WindowEvent ev){
|
||
|
|
||
|
}
|
||
|
public void windowClosed(WindowEvent ev){
|
||
|
|
||
|
}
|
||
|
public void windowClosing(WindowEvent ev){
|
||
|
conn.dispose();
|
||
|
|
||
|
}
|
||
|
public void windowDeactivated(WindowEvent ev){
|
||
|
|
||
|
}
|
||
|
public void windowDeiconified(WindowEvent ev){
|
||
|
|
||
|
}
|
||
|
public void windowIconified(WindowEvent ev){
|
||
|
|
||
|
}
|
||
|
public void windowOpened(WindowEvent ev){
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
private void menuBddFermer(){
|
||
|
String[] resultatFermeture;
|
||
|
|
||
|
resultatFermeture = new String[2];
|
||
|
resultatFermeture = this.objetConnexion.disconnect();
|
||
|
|
||
|
if(Integer.parseInt(resultatFermeture[0]) == 0){
|
||
|
this.MenuBdd_Fermer.setEnabled(false);
|
||
|
this.MenuBdd_Connexion.setEnabled(true);
|
||
|
this.zoneTexteStatut.setText("Base de donnees fermee: " + resultatFermeture[1]);
|
||
|
this.MenuAction.setVisible(false);
|
||
|
}
|
||
|
else{
|
||
|
this.zoneTexteStatut.setText("Impossible de fermer la base de donnees : " + resultatFermeture[1]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void menuBddQuitter(){
|
||
|
String[] resultatFermeture;
|
||
|
|
||
|
// On verifie si une connexion a une BDD est en cours
|
||
|
// - Si oui, on ferme d'abord la connexion
|
||
|
if(this.connecte){
|
||
|
resultatFermeture = new String[2];
|
||
|
resultatFermeture = this.objetConnexion.disconnect();
|
||
|
|
||
|
if(Integer.parseInt(resultatFermeture[0]) == 0){
|
||
|
System.exit(0);
|
||
|
}
|
||
|
else{
|
||
|
this.zoneTexteStatut.setText("Impossible de fermer la base de donnees : " + resultatFermeture[1]);
|
||
|
}
|
||
|
}
|
||
|
// - Si non, alors on peut quitter de suite
|
||
|
else{
|
||
|
System.exit(0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void menuActionRequete(){
|
||
|
IHMRequete ihmRequete = new IHMRequete(this);
|
||
|
ihmRequete.setLocation(800, 400);
|
||
|
ihmRequete.setVisible(true);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* <p>Action du bouton Apropos du menu Aide</p>
|
||
|
* @param args
|
||
|
*/
|
||
|
private void menuApropos(){
|
||
|
JOptionPane.showMessageDialog(null, "SQLNavigator\n\n" +
|
||
|
"Version 0.1\n" +
|
||
|
"Developpe par Olivier DOSSMANN\n\n",
|
||
|
"A propos de SQLNavigator",
|
||
|
JOptionPane.QUESTION_MESSAGE);
|
||
|
}
|
||
|
|
||
|
public void confirmationConnexion(Connexion objetConnexion){
|
||
|
String[] resultatConnexion;
|
||
|
|
||
|
this.objetConnexion = objetConnexion;
|
||
|
resultatConnexion = new String[2];
|
||
|
resultatConnexion = this.objetConnexion.connect();
|
||
|
|
||
|
this.zoneTexteStatut.setText(resultatConnexion[1]);
|
||
|
if(Integer.parseInt(resultatConnexion[0]) == 0){
|
||
|
this.MenuBdd_Connexion.setEnabled(false);
|
||
|
this.MenuBdd_Fermer.setEnabled(true);
|
||
|
this.MenuAction.setVisible(true);
|
||
|
this.MenuAction.setEnabled(true);
|
||
|
this.connecte = true;
|
||
|
this.repaint();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void envoiRequete(String laRequete){
|
||
|
if(Integer.parseInt(objetConnexion.sendQuery(laRequete)[0]) == 0){
|
||
|
|
||
|
// Tableau
|
||
|
tableDonnees = new JTableModel(objetConnexion, laRequete);
|
||
|
tableDonnees.setVisible(true);
|
||
|
Panneau_Centre.add(tableDonnees, BorderLayout.CENTER);
|
||
|
Panneau_Centre.validate();
|
||
|
}
|
||
|
else {
|
||
|
this.zoneTexteStatut.setText("L'envoi de la requete a echoue.");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|