Amélioration interface + corrections bugs

This commit is contained in:
Morgane Foussats 2021-02-09 16:31:34 +01:00
parent 26a0c1341c
commit 5be454e081
98 changed files with 379 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -16,5 +16,10 @@
<attribute name="module" value="true"/> <attribute name="module" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="lib" path="C:/Users/momof/eclipse-workspace/chatGitElise/lib/JTattoo-1.6.13.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

@ -5,8 +5,8 @@
"port": 8080 "port": 8080
}, },
"config":{ "config":{
"interface": "wlan2", "interface": "wlan3",
"portSrc": 26000, "portSrc": 26001,
"portDest":26001 "portDest":26000
} }
} }

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

@ -1,6 +1,8 @@
package controller; package controller;
import java.awt.Color; import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport; import java.beans.PropertyChangeSupport;
@ -11,6 +13,7 @@ import java.net.SocketException;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultCaret;
import javax.swing.text.SimpleAttributeSet; import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants; import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument; import javax.swing.text.StyledDocument;
@ -38,6 +41,7 @@ public class Agent implements PropertyChangeListener{
private PropertyChangeSupport support; private PropertyChangeSupport support;
private boolean open = true;
public Agent(InetAddress address, int portIn, int portOut) throws IOException { public Agent(InetAddress address, int portIn, int portOut) throws IOException {
@ -97,9 +101,10 @@ public class Agent implements PropertyChangeListener{
break; break;
case "Msg TCP Recu" : case "Msg TCP Recu" :
Color c = new Color(25, 94, 125);
SimpleAttributeSet left = new SimpleAttributeSet(); SimpleAttributeSet left = new SimpleAttributeSet();
StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT); StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT);
StyleConstants.setForeground(left, Color.RED); StyleConstants.setForeground(left, c.brighter());
//System.out.println("dans property change"); //System.out.println("dans property change");
TCPChat tcpChatCo = this.listTCPOk.get(0); TCPChat tcpChatCo = this.listTCPOk.get(0);
MessageChat msgRecu = tcpChatCo.getMessageRecu(); MessageChat msgRecu = tcpChatCo.getMessageRecu();
@ -169,6 +174,7 @@ public class Agent implements PropertyChangeListener{
case 3 : case 3 :
MessagePseudo messageNewPseudo = (MessagePseudo) msg; MessagePseudo messageNewPseudo = (MessagePseudo) msg;
this.open = false;
//Contact contact = list.findContact(messageNewPseudo.getPseudo()); //Contact contact = list.findContact(messageNewPseudo.getPseudo());
//int id = this.db.getIdFromPseudo(contact.getPseudo()); //int id = this.db.getIdFromPseudo(contact.getPseudo());
for(int i = 0 ; i<FenetreMenu.getCb().getItemCount() ; i++){//Combo étant ton JComboBox for(int i = 0 ; i<FenetreMenu.getCb().getItemCount() ; i++){//Combo étant ton JComboBox
@ -178,7 +184,6 @@ public class Agent implements PropertyChangeListener{
FenetreMenu.getCb().addItem(messageNewPseudo.getPseudo()); FenetreMenu.getCb().addItem(messageNewPseudo.getPseudo());
} }
} }
//FenetreMenu.getCb().removeItem(messageNewPseudo.getPseudo());
} }
} }
@ -359,4 +364,12 @@ public class Agent implements PropertyChangeListener{
return this.listTCPDeg.remove(0); return this.listTCPDeg.remove(0);
} }
public boolean getOpen() {
return this.open;
}
public void setOpen(boolean res) {
this.open = res;
}
} }

View file

@ -6,6 +6,7 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.sql.SQLException; import java.sql.SQLException;
@ -17,6 +18,7 @@ import java.util.List;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultCaret;
import javax.swing.text.SimpleAttributeSet; import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants; import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument; import javax.swing.text.StyledDocument;
@ -32,13 +34,15 @@ import java.awt.*;
public class FenetreChat extends JFrame implements PropertyChangeListener{ public class FenetreChat extends JFrame implements PropertyChangeListener{
static JFrame frame; static JFrame frame;
Agent agent; static Agent agent;
static Contact dest; //destinataire du message static Contact dest; //destinataire du message
Contact user; //utilisateur Contact user; //utilisateur
WindowAdapter wa; WindowAdapter wa;
JPanel panel; JPanel panel;
static JTextArea ta; static JTextArea text;
private TCPChat t=null;
static StyledDocument doc; static StyledDocument doc;
private static boolean ouvert=false; private static boolean ouvert=false;
@ -54,7 +58,6 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
this.dest = Request.getUser(userString, "getUser"); this.dest = Request.getUser(userString, "getUser");
InetAddress adr = dest.getAddress(); InetAddress adr = dest.getAddress();
TCPChat t=null;
for(TCPChat tcp : agent.getListeTCPChat()) { for(TCPChat tcp : agent.getListeTCPChat()) {
if(tcp.getSocket().getInetAddress().equals(adr)) { if(tcp.getSocket().getInetAddress().equals(adr)) {
t=tcp; t=tcp;
@ -71,13 +74,24 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
int quitter = FenetreMenu.fenetreFermeture(); int quitter = FenetreMenu.fenetreFermeture();
if(quitter == 0) { if(quitter == 0) {
/*try {
t.getSocket().close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/
frame.dispose(); frame.dispose();
} }
}}; }};
addWidgets(); this.panel = new JPanel();
this.panel.setOpaque(false);
this.addWidgets();
//frame.getContentPane().add(panel, BorderLayout.CENTER);
afficherHistorique(); afficherHistorique();
frame.addWindowListener(wa); frame.addWindowListener(wa);
frame.setVisible(true); frame.setVisible(true);
@ -86,18 +100,21 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
private void addWidgets() { private void addWidgets() {
Color c = new Color(25, 94, 125);
JTextPane textPane = new JTextPane(); JTextPane textPane = new JTextPane();
textPane.setEditable(false); textPane.setEditable(false);
textPane.setOpaque(true);
this.doc = textPane.getStyledDocument(); this.doc = textPane.getStyledDocument();
SimpleAttributeSet right = new SimpleAttributeSet(); SimpleAttributeSet right = new SimpleAttributeSet();
StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT); StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
StyleConstants.setForeground(right, Color.BLUE); StyleConstants.setForeground(right, Color.WHITE);
SimpleAttributeSet left = new SimpleAttributeSet(); SimpleAttributeSet left = new SimpleAttributeSet();
StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT); StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT);
StyleConstants.setForeground(left, Color.RED); StyleConstants.setForeground(left, c.brighter());
GridBagLayout gridBagLayout = new GridBagLayout(); GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{394, 0}; gridBagLayout.columnWidths = new int[]{394, 0};
@ -105,19 +122,19 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE}; gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
this.frame.getContentPane().setLayout(gridBagLayout); this.frame.getContentPane().setLayout(gridBagLayout);
this.panel = new JPanel();
//zone pour rentrer les message à envoyer //zone pour rentrer les message à envoyer
JTextArea text = new JTextArea(10, 3); text = new JTextArea(10, 3);
text.setForeground(Color.BLACK); text.setForeground(Color.WHITE);
text.setFont(new Font("Century Schoolbook", Font.PLAIN, 11)); text.setFont(new Font("Century Schoolbook", Font.PLAIN, 11));
text.setText("Enter your message"); text.setText("Enter your message");
text.setLineWrap(true); text.setOpaque(false);
JScrollPane sp = new JScrollPane(text); JScrollPane sp = new JScrollPane(text);
//zone affichage texte //zone affichage texte
JScrollPane sp2 = new JScrollPane(textPane); JScrollPane sp2 = new JScrollPane(textPane);
new SmartScroller(sp2);
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 0, 5, 0); gbc.insets = new Insets(0, 0, 5, 0);
@ -127,6 +144,7 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
//bouton envoyer //bouton envoyer
JButton envoyer = new JButton("Send"); JButton envoyer = new JButton("Send");
envoyer.setOpaque(false);
frame.getRootPane().setDefaultButton(envoyer); frame.getRootPane().setDefaultButton(envoyer);
envoyer.addActionListener(new ActionListener() { envoyer.addActionListener(new ActionListener() {
private Date date; private Date date;
@ -153,6 +171,7 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
tcpChat.sendMsg(message); tcpChat.sendMsg(message);
doc.insertString(doc.getLength(), "\n"+message+dateString, right ); doc.insertString(doc.getLength(), "\n"+message+dateString, right );
doc.setParagraphAttributes(doc.getLength(), 1, right, false); doc.setParagraphAttributes(doc.getLength(), 1, right, false);
text.setCaretPosition(text.getDocument().getLength());
if(agent.getDb().tableChatExists(idUser, idDest)) { if(agent.getDb().tableChatExists(idUser, idDest)) {
agent.getDb().addMessage(idUser, idDest, message); agent.getDb().addMessage(idUser, idDest, message);
}else { }else {
@ -184,12 +203,12 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
public static JTextArea getTa() { public static JTextArea getTa() {
return ta; return text;
} }
public void setTa(JTextArea ta) { public void setTa(JTextArea ta) {
this.ta = ta; this.text = ta;
} }
@ -203,13 +222,15 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
} }
public void afficherHistorique() { public void afficherHistorique() {
Color c = new Color(25, 94, 125);
SimpleAttributeSet right = new SimpleAttributeSet(); SimpleAttributeSet right = new SimpleAttributeSet();
StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT); StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
StyleConstants.setForeground(right, Color.BLUE); StyleConstants.setForeground(right, Color.WHITE);
SimpleAttributeSet left = new SimpleAttributeSet(); SimpleAttributeSet left = new SimpleAttributeSet();
StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT); StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT);
StyleConstants.setForeground(left, Color.RED); StyleConstants.setForeground(left, c.brighter());
int idUser = agent.getDb().getIdFromPseudo(user.getPseudo()); int idUser = agent.getDb().getIdFromPseudo(user.getPseudo());
//System.out.println("IDuser = "+idUser); //System.out.println("IDuser = "+idUser);
int idDest = agent.getDb().getIdFromPseudo(dest.getPseudo()); int idDest = agent.getDb().getIdFromPseudo(dest.getPseudo());
@ -268,6 +289,20 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
} }
public static void fermer() { public static void fermer() {
TCPChat t = null;
/*try {
InetAddress adr = dest.getAddress();
for(TCPChat tcp : agent.getListeTCPChat()) {
if(tcp.getSocket().getInetAddress().equals(adr)) {
t=tcp;
}
}
t.getSocket().close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/
frame.dispose(); frame.dispose();
} }

View file

@ -1,8 +1,11 @@
package gui; package gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -13,8 +16,10 @@ import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import controller.*; import controller.*;
@ -35,6 +40,19 @@ public class FenetreConnexion implements ActionListener {
* Cette fenetre sera munie d'un bouton de connexion et d'une zone de saisie de pseudo. * Cette fenetre sera munie d'un bouton de connexion et d'une zone de saisie de pseudo.
*/ */
public FenetreConnexion() { public FenetreConnexion() {
try {
//here you can put the selected theme class name in JTattoo
UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel");
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//creer une instance JFrame //creer une instance JFrame
frame = new JFrame("Fenetre connexion"); frame = new JFrame("Fenetre connexion");
//sortir quand lutilisateur ferme le frame //sortir quand lutilisateur ferme le frame
@ -43,8 +61,19 @@ public class FenetreConnexion implements ActionListener {
frame.setSize(new Dimension(120, 40)); frame.setSize(new Dimension(120, 40));
//Creer le JPanel //Creer le JPanel
panel = new JPanel(new GridLayout(4,1)); panel = new JPanel(new GridLayout(4,1));
panel.setOpaque(false);
//Ajouter les elements //Ajouter les elements
this.addWidgets(); this.addWidgets();
try {
final Image backgroundImage = javax.imageio.ImageIO.read(new File("b1.jpg"));
frame.setContentPane(new JPanel(new BorderLayout()) {
@Override public void paintComponent(Graphics g) {
g.drawImage(backgroundImage, 0, 0, null);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
//Set the default button. //Set the default button.
frame.getRootPane().setDefaultButton(Connexion); frame.getRootPane().setDefaultButton(Connexion);
//Ajouter le panel a la window //Ajouter le panel a la window
@ -61,6 +90,8 @@ public class FenetreConnexion implements ActionListener {
this.pseudofield = new JTextField(2); this.pseudofield = new JTextField(2);
// creation d'un label qui contiendra un txt au centre // creation d'un label qui contiendra un txt au centre
this.Text = new JLabel("Type your login", SwingConstants.CENTER); this.Text = new JLabel("Type your login", SwingConstants.CENTER);
this.Text.setForeground(Color.white);
this.Text.setOpaque(false);
//Ajout d'un bouton Connexion //Ajout d'un bouton Connexion
this.Connexion = new JButton("Connexion"); this.Connexion = new JButton("Connexion");
this.Cancel = new JButton("Cancel"); this.Cancel = new JButton("Cancel");
@ -107,7 +138,12 @@ public class FenetreConnexion implements ActionListener {
new FenetreConnexion(); new FenetreConnexion();
} }
}else if(loginEstActif){ }else if(loginEstActif){
if(!Connexion.isSelected()) { try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(!Connexion.isSelected() && !FenetreMenu.ouvert) {
JOptionPane.showMessageDialog(frame, "This login is used by an active user", "Error", JOptionPane.WARNING_MESSAGE) ; JOptionPane.showMessageDialog(frame, "This login is used by an active user", "Error", JOptionPane.WARNING_MESSAGE) ;
Connexion.setSelected(true); Connexion.setSelected(true);
frame.dispose(); frame.dispose();

View file

@ -1,8 +1,11 @@
package gui; package gui;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -13,10 +16,12 @@ import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import controller.*; import controller.*;
@ -37,6 +42,19 @@ public class FenetreInscription implements ActionListener {
* Cette fenetre sera munie d'un bouton de connexion et d'une zone de saisie de pseudo. * Cette fenetre sera munie d'un bouton de connexion et d'une zone de saisie de pseudo.
*/ */
public FenetreInscription() { public FenetreInscription() {
try {
//here you can put the selected theme class name in JTattoo
UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel");
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//creer une instance JFrame //creer une instance JFrame
frame = new JFrame("Fenetre inscription"); frame = new JFrame("Fenetre inscription");
//sortir quand lutilisateur ferme le frame //sortir quand lutilisateur ferme le frame
@ -45,8 +63,19 @@ public class FenetreInscription implements ActionListener {
frame.setSize(new Dimension(40, 100)); frame.setSize(new Dimension(40, 100));
//Creer le JPanel //Creer le JPanel
panel = new JPanel(new GridLayout(7,1)); panel = new JPanel(new GridLayout(7,1));
panel.setOpaque(false);
//Ajouter les elements //Ajouter les elements
this.addWidgets(); this.addWidgets();
try {
final Image backgroundImage = javax.imageio.ImageIO.read(new File("b1.jpg"));
frame.setContentPane(new JPanel(new BorderLayout()) {
@Override public void paintComponent(Graphics g) {
g.drawImage(backgroundImage, 0, 0, null);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
frame.getRootPane().setDefaultButton(inscription); frame.getRootPane().setDefaultButton(inscription);
//Ajouter le panel a la window //Ajouter le panel a la window
frame.getContentPane().add(panel, BorderLayout.CENTER); frame.getContentPane().add(panel, BorderLayout.CENTER);
@ -63,8 +92,14 @@ public class FenetreInscription implements ActionListener {
this.pseudofield = new JTextField(2); this.pseudofield = new JTextField(2);
// creation d'un label qui contiendra un txt au centre // creation d'un label qui contiendra un txt au centre
this.Text = new JLabel("Forbidden characters: space, '?','&', '/', '=' ", SwingConstants.CENTER); this.Text = new JLabel("Forbidden characters: space, '?','&', '/', '=' ", SwingConstants.CENTER);
this.Text.setForeground(Color.WHITE);
this.Text.setOpaque(false);
JLabel text = new JLabel("Login: ", SwingConstants.CENTER); JLabel text = new JLabel("Login: ", SwingConstants.CENTER);
text.setForeground(Color.WHITE);
text.setOpaque(false);
JLabel text2 = new JLabel("Pseudo: ", SwingConstants.CENTER); JLabel text2 = new JLabel("Pseudo: ", SwingConstants.CENTER);
text2.setForeground(Color.WHITE);
text2.setOpaque(false);
//Ajout d'un bouton Connexion //Ajout d'un bouton Connexion
this.inscription = new JButton("Sign Up"); this.inscription = new JButton("Sign Up");
this.connexion = new JButton("Sign In"); this.connexion = new JButton("Sign In");

View file

@ -5,9 +5,12 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import java.awt.Image; import java.awt.Image;
import java.awt.Insets;
import java.awt.SystemColor; import java.awt.SystemColor;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -32,6 +35,7 @@ import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.UIManager;
import controller.Agent; import controller.Agent;
import model.Contact; import model.Contact;
@ -45,6 +49,7 @@ public class FenetreMenu {
JLabel jlabel; JLabel jlabel;
JLabel texte; JLabel texte;
JLabel liste; JLabel liste;
JLabel vide;
static JComboBox cb; static JComboBox cb;
WindowAdapter wa ; WindowAdapter wa ;
@ -53,10 +58,24 @@ public class FenetreMenu {
public FenetreMenu(Agent agent) throws IOException { public FenetreMenu(Agent agent) throws IOException {
FenetreMenu.ouvert=true; FenetreMenu.ouvert=true;
this.agent = agent; this.agent = agent;
try {
//here you can put the selected theme class name in JTattoo
UIManager.setLookAndFeel("com.jtattoo.plaf.noire.NoireLookAndFeel");
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FenetreMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
frame = new JFrame("Fenêtre menu"); frame = new JFrame("Fenêtre menu");
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setSize(new Dimension(500, 800)); frame.setSize(new Dimension(600, 800));
frame.setResizable(false);
wa = new WindowAdapter(){ wa = new WindowAdapter(){
public void windowClosing(WindowEvent e){ public void windowClosing(WindowEvent e){
@ -77,14 +96,14 @@ public class FenetreMenu {
frame.addWindowListener(wa); frame.addWindowListener(wa);
menu = new JMenuBar(); menu = new JMenuBar();
//Creation d'un JPanel //Creation d'un JPanel
panel = new JPanel(new GridLayout(3,1)); panel = new JPanel(new GridBagLayout());
panel.setForeground(SystemColor.menuText); panel.setForeground(SystemColor.menuText);
panel.setOpaque(false); panel.setOpaque(false);
// Ajouter tout les elements a la fenetre // Ajouter tout les elements a la fenetre
this.addWidgets(); this.addWidgets();
try { try {
final Image backgroundImage = javax.imageio.ImageIO.read(new File("background.jpg")); final Image backgroundImage = javax.imageio.ImageIO.read(new File("background2.jpg"));
frame.setContentPane(new JPanel(new BorderLayout()) { frame.setContentPane(new JPanel(new BorderLayout()) {
@Override public void paintComponent(Graphics g) { @Override public void paintComponent(Graphics g) {
g.drawImage(backgroundImage, 0, 0, null); g.drawImage(backgroundImage, 0, 0, null);
@ -119,19 +138,29 @@ public class FenetreMenu {
liste = new JLabel("Active users", JLabel.LEFT); liste = new JLabel("Active users", JLabel.LEFT);
liste.setOpaque(false); liste.setOpaque(false);
vide = new JLabel();
vide.setOpaque(false);
Color c = new Color(25, 94, 125);
JMenu contenu = new JMenu("Actions"); JMenu contenu = new JMenu("Actions");
contenu.setForeground(Color.BLUE); contenu.setForeground(Color.WHITE);
contenu.setBackground(c.darker());
contenu.setHorizontalAlignment(SwingConstants.CENTER); contenu.setHorizontalAlignment(SwingConstants.CENTER);
//JMenuItem usersActifs = new JMenuItem("Active users"); //JMenuItem usersActifs = new JMenuItem("Active users");
JMenuItem modifierPseudo = new JMenuItem("Modify your pseudo"); JMenuItem modifierPseudo = new JMenuItem("Modify your pseudo");
modifierPseudo.setBackground(c.darker());
modifierPseudo.setForeground(Color.WHITE);
JMenuItem deco = new JMenuItem("Deconnection"); JMenuItem deco = new JMenuItem("Deconnection");
deco.setBackground(c.darker());
deco.setForeground(Color.WHITE);
//contenu.add(usersActifs); //contenu.add(usersActifs);
contenu.add(modifierPseudo); contenu.add(modifierPseudo);
contenu.add(deco); contenu.add(deco);
menu.setBackground(c);
menu.add(contenu); menu.add(contenu);
frame.setJMenuBar(menu); frame.setJMenuBar(menu);
@ -150,6 +179,10 @@ public class FenetreMenu {
} }
cb = new JComboBox(v); cb = new JComboBox(v);
cb.setSelectedItem(agent.getUser().getPseudo());
cb.setBackground(c);
cb.setForeground(Color.WHITE);
cb.setFocusable(false);
cb.addActionListener(new ActionListener() { cb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
Object selected = cb.getSelectedItem(); Object selected = cb.getSelectedItem();
@ -169,11 +202,29 @@ public class FenetreMenu {
} }
}); });
cb.setPreferredSize(new Dimension(500, 30));
panel.add(BorderLayout.CENTER, jlabel); GridBagConstraints con = new GridBagConstraints();
panel.add(BorderLayout.SOUTH , texte ); Insets i = new Insets(150, 0, 5, 0);
panel.add(BorderLayout.WEST, cb); con.weightx = 200;
con.gridx = 1;
con.gridy = 0;
panel.add(jlabel, con);
con.weightx = 100;
con.gridx=1;
con.gridy=1;
panel.add(texte, con);
con.weightx=50;
con.fill = GridBagConstraints.HORIZONTAL;
con.gridx=1;
con.gridy = 3;
con.insets = i;
panel.add(cb, con);

View file

@ -0,0 +1,173 @@
package gui;
import java.awt.Component;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
/**
* The SmartScroller will attempt to keep the viewport positioned based on
* the users interaction with the scrollbar. The normal behaviour is to keep
* the viewport positioned to see new data as it is dynamically added.
*
* Assuming vertical scrolling and data is added to the bottom:
*
* - when the viewport is at the bottom and new data is added,
* then automatically scroll the viewport to the bottom
* - when the viewport is not at the bottom and new data is added,
* then do nothing with the viewport
*
* Assuming vertical scrolling and data is added to the top:
*
* - when the viewport is at the top and new data is added,
* then do nothing with the viewport
* - when the viewport is not at the top and new data is added, then adjust
* the viewport to the relative position it was at before the data was added
*
* Similiar logic would apply for horizontal scrolling.
*/
public class SmartScroller implements AdjustmentListener
{
public final static int HORIZONTAL = 0;
public final static int VERTICAL = 1;
public final static int START = 0;
public final static int END = 1;
private int viewportPosition;
private JScrollBar scrollBar;
private boolean adjustScrollBar = true;
private int previousValue = -1;
private int previousMaximum = -1;
/**
* Convenience constructor.
* Scroll direction is VERTICAL and viewport position is at the END.
*
* @param scrollPane the scroll pane to monitor
*/
public SmartScroller(JScrollPane scrollPane)
{
this(scrollPane, VERTICAL, END);
}
/**
* Convenience constructor.
* Scroll direction is VERTICAL.
*
* @param scrollPane the scroll pane to monitor
* @param viewportPosition valid values are START and END
*/
public SmartScroller(JScrollPane scrollPane, int viewportPosition)
{
this(scrollPane, VERTICAL, viewportPosition);
}
/**
* Specify how the SmartScroller will function.
*
* @param scrollPane the scroll pane to monitor
* @param scrollDirection indicates which JScrollBar to monitor.
* Valid values are HORIZONTAL and VERTICAL.
* @param viewportPosition indicates where the viewport will normally be
* positioned as data is added.
* Valid values are START and END
*/
public SmartScroller(JScrollPane scrollPane, int scrollDirection, int viewportPosition)
{
if (scrollDirection != HORIZONTAL
&& scrollDirection != VERTICAL)
throw new IllegalArgumentException("invalid scroll direction specified");
if (viewportPosition != START
&& viewportPosition != END)
throw new IllegalArgumentException("invalid viewport position specified");
this.viewportPosition = viewportPosition;
if (scrollDirection == HORIZONTAL)
scrollBar = scrollPane.getHorizontalScrollBar();
else
scrollBar = scrollPane.getVerticalScrollBar();
scrollBar.addAdjustmentListener( this );
// Turn off automatic scrolling for text components
Component view = scrollPane.getViewport().getView();
if (view instanceof JTextComponent)
{
JTextComponent textComponent = (JTextComponent)view;
DefaultCaret caret = (DefaultCaret)textComponent.getCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}
}
@Override
public void adjustmentValueChanged(final AdjustmentEvent e)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
checkScrollBar(e);
}
});
}
/*
* Analyze every adjustment event to determine when the viewport
* needs to be repositioned.
*/
private void checkScrollBar(AdjustmentEvent e)
{
// The scroll bar listModel contains information needed to determine
// whether the viewport should be repositioned or not.
JScrollBar scrollBar = (JScrollBar)e.getSource();
BoundedRangeModel listModel = scrollBar.getModel();
int value = listModel.getValue();
int extent = listModel.getExtent();
int maximum = listModel.getMaximum();
boolean valueChanged = previousValue != value;
boolean maximumChanged = previousMaximum != maximum;
// Check if the user has manually repositioned the scrollbar
if (valueChanged && !maximumChanged)
{
if (viewportPosition == START)
adjustScrollBar = value != 0;
else
adjustScrollBar = value + extent >= maximum;
}
// Reset the "value" so we can reposition the viewport and
// distinguish between a user scroll and a program scroll.
// (ie. valueChanged will be false on a program scroll)
if (adjustScrollBar && viewportPosition == END)
{
// Scroll the viewport to the end.
scrollBar.removeAdjustmentListener( this );
value = maximum - extent;
scrollBar.setValue( value );
scrollBar.addAdjustmentListener( this );
}
if (adjustScrollBar && viewportPosition == START)
{
// Keep the viewport at the same relative viewportPosition
scrollBar.removeAdjustmentListener( this );
value = value + maximum - previousMaximum;
scrollBar.setValue( value );
scrollBar.addAdjustmentListener( this );
}
previousValue = value;
previousMaximum = maximum;
}
}

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB