165 lines
6.4 KiB
Java
165 lines
6.4 KiB
Java
import java.awt.BorderLayout;
|
|
import java.awt.Dimension;
|
|
import java.awt.GridLayout;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.WindowAdapter;
|
|
import java.awt.event.WindowEvent;
|
|
import java.io.IOException;
|
|
|
|
import javax.swing.BoxLayout;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JTextArea;
|
|
import javax.swing.SwingConstants;
|
|
import com.jgoodies.forms.layout.FormLayout;
|
|
import com.jgoodies.forms.layout.ColumnSpec;
|
|
import com.jgoodies.forms.layout.RowSpec;
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.Font;
|
|
import java.awt.Color;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.Insets;
|
|
|
|
/*
|
|
* Classe representant la fenetre pour chaque session de clavardage.
|
|
*/
|
|
public class View_Clavardage {
|
|
JFrame frame ;
|
|
ChatApp app;
|
|
Utilisateur destination ; // Celui avec qui on va discuter
|
|
Utilisateur source; //Nous
|
|
WindowAdapter wa ;
|
|
JPanel panel ;
|
|
JTextArea textAreaAffichage ;
|
|
|
|
/*
|
|
* Constructeur d'une fenetre de session de clavardage.
|
|
* @param app Un objet de type ChatApp pour posseder toutes les informations de l'utilisateur
|
|
* @param User2 L'utilisateur avec qui l'on souhaite discuter et passer en parametre sous forme de String
|
|
*/
|
|
public View_Clavardage(ChatApp app, String User2) {
|
|
this.app = app ;
|
|
this.frame = new JFrame("ChatApp-AL-NM");
|
|
this.source = this.app.getMe();
|
|
this.destination = Utilisateur.stringToUtilisateur(User2);
|
|
this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
|
// fixer les dimensions de la fenetre
|
|
this.frame.setSize(new Dimension(394, 344));
|
|
this.frame.setResizable(false);
|
|
wa = new WindowAdapter(){
|
|
public void windowClosing(WindowEvent e){
|
|
int reponse = View_Menu.showConfirmDialog();
|
|
if (reponse==0){
|
|
frame.dispose();
|
|
}
|
|
}};
|
|
addWidgets();
|
|
frame.addWindowListener( wa ) ;
|
|
frame.setVisible(true);
|
|
}
|
|
|
|
/**
|
|
* Creer et ajouter les outils de la fenetre
|
|
*/
|
|
private void addWidgets() {
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
gridBagLayout.columnWidths = new int[]{394, 0};
|
|
gridBagLayout.rowHeights = new int[]{16, 220, 74, 0};
|
|
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
this.frame.getContentPane().setLayout(gridBagLayout);
|
|
this.panel = new JPanel();
|
|
// Zone pour ecrire de nouveau message
|
|
JTextArea textAreaSaisie = new JTextArea(5,3);
|
|
textAreaSaisie.setLineWrap(true);
|
|
textAreaSaisie.setForeground(Color.LIGHT_GRAY);
|
|
textAreaSaisie.setFont(new Font("Lucida Grande", Font.ITALIC, 11));
|
|
textAreaSaisie.setText("Entrer du texte ici !!!");
|
|
JScrollPane scrollPane = new JScrollPane(textAreaSaisie);
|
|
// Creation d'un bouton envoye
|
|
JButton send = new JButton("Envoye");
|
|
frame.getRootPane().setDefaultButton(send);
|
|
send.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent event) {
|
|
//UTILISER TCPENVOI
|
|
String AEnvoyer = textAreaSaisie.getText();
|
|
textAreaAffichage.append(AEnvoyer);
|
|
textAreaSaisie.setText("");
|
|
}});
|
|
// Creation d'un bouton vider la zone de saisie de texte
|
|
JButton reset = new JButton("Vider");
|
|
reset.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent event) {
|
|
textAreaSaisie.setText("");
|
|
}});
|
|
JLabel titre = new JLabel("Chat avec "+ this.destination.getPseudo(),SwingConstants.CENTER);
|
|
GridBagConstraints gbc_titre = new GridBagConstraints();
|
|
gbc_titre.anchor = GridBagConstraints.NORTH;
|
|
gbc_titre.fill = GridBagConstraints.HORIZONTAL;
|
|
gbc_titre.insets = new Insets(0, 0, 5, 0);
|
|
gbc_titre.gridx = 0;
|
|
gbc_titre.gridy = 0;
|
|
frame.getContentPane().add(titre, gbc_titre);
|
|
// Zone d'affichage de l'historique
|
|
this.textAreaAffichage = new JTextArea(10,5);
|
|
textAreaAffichage.setLineWrap(true);
|
|
this.textAreaAffichage.setText("");
|
|
JScrollPane scrollPaneAffichage = new JScrollPane(this.textAreaAffichage);
|
|
this.textAreaAffichage.setEditable(false); // il sert juste a afficher
|
|
GridBagConstraints gbc_textAreaAffichage = new GridBagConstraints();
|
|
gbc_textAreaAffichage.fill = GridBagConstraints.BOTH;
|
|
gbc_textAreaAffichage.insets = new Insets(0, 0, 5, 0);
|
|
gbc_textAreaAffichage.gridx = 0;
|
|
gbc_textAreaAffichage.gridy = 1;
|
|
frame.getContentPane().add(scrollPaneAffichage, gbc_textAreaAffichage);
|
|
panel.add(BorderLayout.CENTER, scrollPane);
|
|
panel.add(BorderLayout.SOUTH,send);
|
|
panel.add(BorderLayout.SOUTH,reset);
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
|
//Add the panel to the window.
|
|
GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
gbc_panel.anchor = GridBagConstraints.NORTH;
|
|
gbc_panel.fill = GridBagConstraints.HORIZONTAL;
|
|
gbc_panel.gridx = 0;
|
|
gbc_panel.gridy = 2;
|
|
frame.getContentPane().add(panel, gbc_panel);
|
|
/*
|
|
*
|
|
*JTextArea textAreaAffichage = new JTextArea(10,5);
|
|
textAreaAffichage.setEditable(false);
|
|
JTextArea textAreaSaisie = new JTextArea(10,5);
|
|
textAreaSaisie.setForeground(Color.LIGHT_GRAY);
|
|
textAreaSaisie.setFont(new Font("Lucida Grande", Font.ITALIC, 11));
|
|
textAreaSaisie.setText("Entrer du texte ici !!!");
|
|
JScrollPane scrollPane = new JScrollPane(textAreaSaisie);
|
|
JButton send = new JButton("Envoye");
|
|
frame.getRootPane().setDefaultButton(send);
|
|
send.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent event) {
|
|
//UTILISER TCPENVOI
|
|
textAreaSaisie.setText("");
|
|
}});
|
|
JButton reset = new JButton("Vider");
|
|
reset.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent event) {
|
|
textAreaSaisie.setText("");
|
|
}});
|
|
JLabel titre = new JLabel("Chat avec "+ this.destination.getPseudo(),SwingConstants.CENTER);
|
|
panel.add(BorderLayout.CENTER, scrollPane);
|
|
//panel.add(scrollPane);
|
|
panel.add(BorderLayout.SOUTH,send);
|
|
panel.add(BorderLayout.SOUTH,reset);
|
|
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
|
|
//Add the panel to the window.
|
|
frame.getContentPane().add(BorderLayout.SOUTH, panel);
|
|
frame.getContentPane().add(BorderLayout.CENTER, textAreaAffichage);
|
|
frame.getContentPane().add(BorderLayout.NORTH, titre);
|
|
*/
|
|
}
|
|
|
|
|
|
}
|