Amélioration interface + corrections bugs
Before Width: | Height: | Size: 290 KiB |
|
@ -16,5 +16,10 @@
|
|||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</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"/>
|
||||
</classpath>
|
BIN
chatGitElise/background2.jpg
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
chatGitElise/bin/controller/Agent.class
Normal file
BIN
chatGitElise/bin/gui/FenetreChat$2.class
Normal file
BIN
chatGitElise/bin/gui/FenetreChat.class
Normal file
BIN
chatGitElise/bin/gui/FenetreConnexion$1.class
Normal file
BIN
chatGitElise/bin/gui/FenetreConnexion.class
Normal file
BIN
chatGitElise/bin/gui/FenetreInscription$1.class
Normal file
BIN
chatGitElise/bin/gui/FenetreInscription.class
Normal file
BIN
chatGitElise/bin/gui/FenetreMenu.class
Normal file
BIN
chatGitElise/bin/gui/SmartScroller$1.class
Normal file
BIN
chatGitElise/bin/gui/SmartScroller.class
Normal file
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
@ -5,8 +5,8 @@
|
|||
"port": 8080
|
||||
},
|
||||
"config":{
|
||||
"interface": "wlan2",
|
||||
"portSrc": 26000,
|
||||
"portDest":26001
|
||||
"interface": "wlan3",
|
||||
"portSrc": 26001,
|
||||
"portDest":26000
|
||||
}
|
||||
}
|
BIN
chatGitElise/lib/JTattoo-1.6.13.jar
Normal file
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
|
@ -1,6 +1,8 @@
|
|||
package controller;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
|
@ -11,6 +13,7 @@ import java.net.SocketException;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import javax.swing.text.SimpleAttributeSet;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.StyledDocument;
|
||||
|
@ -38,6 +41,7 @@ public class Agent implements PropertyChangeListener{
|
|||
|
||||
private PropertyChangeSupport support;
|
||||
|
||||
private boolean open = true;
|
||||
|
||||
|
||||
public Agent(InetAddress address, int portIn, int portOut) throws IOException {
|
||||
|
@ -97,9 +101,10 @@ public class Agent implements PropertyChangeListener{
|
|||
break;
|
||||
|
||||
case "Msg TCP Recu" :
|
||||
Color c = new Color(25, 94, 125);
|
||||
SimpleAttributeSet left = new SimpleAttributeSet();
|
||||
StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT);
|
||||
StyleConstants.setForeground(left, Color.RED);
|
||||
StyleConstants.setForeground(left, c.brighter());
|
||||
//System.out.println("dans property change");
|
||||
TCPChat tcpChatCo = this.listTCPOk.get(0);
|
||||
MessageChat msgRecu = tcpChatCo.getMessageRecu();
|
||||
|
@ -169,6 +174,7 @@ public class Agent implements PropertyChangeListener{
|
|||
|
||||
case 3 :
|
||||
MessagePseudo messageNewPseudo = (MessagePseudo) msg;
|
||||
this.open = false;
|
||||
//Contact contact = list.findContact(messageNewPseudo.getPseudo());
|
||||
//int id = this.db.getIdFromPseudo(contact.getPseudo());
|
||||
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().removeItem(messageNewPseudo.getPseudo());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -359,4 +364,12 @@ public class Agent implements PropertyChangeListener{
|
|||
return this.listTCPDeg.remove(0);
|
||||
}
|
||||
|
||||
public boolean getOpen() {
|
||||
return this.open;
|
||||
}
|
||||
|
||||
public void setOpen(boolean res) {
|
||||
this.open = res;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.awt.event.WindowAdapter;
|
|||
import java.awt.event.WindowEvent;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.sql.SQLException;
|
||||
|
@ -17,6 +18,7 @@ import java.util.List;
|
|||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import javax.swing.text.SimpleAttributeSet;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import javax.swing.text.StyledDocument;
|
||||
|
@ -32,13 +34,15 @@ import java.awt.*;
|
|||
public class FenetreChat extends JFrame implements PropertyChangeListener{
|
||||
|
||||
static JFrame frame;
|
||||
Agent agent;
|
||||
static Agent agent;
|
||||
static Contact dest; //destinataire du message
|
||||
Contact user; //utilisateur
|
||||
|
||||
WindowAdapter wa;
|
||||
JPanel panel;
|
||||
static JTextArea ta;
|
||||
static JTextArea text;
|
||||
|
||||
private TCPChat t=null;
|
||||
|
||||
static StyledDocument doc;
|
||||
private static boolean ouvert=false;
|
||||
|
@ -54,7 +58,6 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
|
|||
this.dest = Request.getUser(userString, "getUser");
|
||||
|
||||
InetAddress adr = dest.getAddress();
|
||||
TCPChat t=null;
|
||||
for(TCPChat tcp : agent.getListeTCPChat()) {
|
||||
if(tcp.getSocket().getInetAddress().equals(adr)) {
|
||||
t=tcp;
|
||||
|
@ -71,13 +74,24 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
|
|||
public void windowClosing(WindowEvent e) {
|
||||
int quitter = FenetreMenu.fenetreFermeture();
|
||||
if(quitter == 0) {
|
||||
/*try {
|
||||
t.getSocket().close();
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}*/
|
||||
frame.dispose();
|
||||
}
|
||||
}};
|
||||
|
||||
addWidgets();
|
||||
this.panel = new JPanel();
|
||||
this.panel.setOpaque(false);
|
||||
|
||||
this.addWidgets();
|
||||
//frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
afficherHistorique();
|
||||
|
||||
|
||||
frame.addWindowListener(wa);
|
||||
frame.setVisible(true);
|
||||
|
||||
|
@ -86,18 +100,21 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
|
|||
|
||||
private void addWidgets() {
|
||||
|
||||
Color c = new Color(25, 94, 125);
|
||||
|
||||
JTextPane textPane = new JTextPane();
|
||||
textPane.setEditable(false);
|
||||
textPane.setOpaque(true);
|
||||
|
||||
this.doc = textPane.getStyledDocument();
|
||||
|
||||
SimpleAttributeSet right = new SimpleAttributeSet();
|
||||
StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
|
||||
StyleConstants.setForeground(right, Color.BLUE);
|
||||
StyleConstants.setForeground(right, Color.WHITE);
|
||||
|
||||
SimpleAttributeSet left = new SimpleAttributeSet();
|
||||
StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT);
|
||||
StyleConstants.setForeground(left, Color.RED);
|
||||
StyleConstants.setForeground(left, c.brighter());
|
||||
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
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.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
this.frame.getContentPane().setLayout(gridBagLayout);
|
||||
this.panel = new JPanel();
|
||||
|
||||
//zone pour rentrer les message à envoyer
|
||||
JTextArea text = new JTextArea(10, 3);
|
||||
text.setForeground(Color.BLACK);
|
||||
text = new JTextArea(10, 3);
|
||||
text.setForeground(Color.WHITE);
|
||||
text.setFont(new Font("Century Schoolbook", Font.PLAIN, 11));
|
||||
text.setText("Enter your message");
|
||||
text.setLineWrap(true);
|
||||
text.setOpaque(false);
|
||||
|
||||
JScrollPane sp = new JScrollPane(text);
|
||||
|
||||
//zone affichage texte
|
||||
JScrollPane sp2 = new JScrollPane(textPane);
|
||||
new SmartScroller(sp2);
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.insets = new Insets(0, 0, 5, 0);
|
||||
|
@ -127,6 +144,7 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
|
|||
|
||||
//bouton envoyer
|
||||
JButton envoyer = new JButton("Send");
|
||||
envoyer.setOpaque(false);
|
||||
frame.getRootPane().setDefaultButton(envoyer);
|
||||
envoyer.addActionListener(new ActionListener() {
|
||||
private Date date;
|
||||
|
@ -153,6 +171,7 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
|
|||
tcpChat.sendMsg(message);
|
||||
doc.insertString(doc.getLength(), "\n"+message+dateString, right );
|
||||
doc.setParagraphAttributes(doc.getLength(), 1, right, false);
|
||||
text.setCaretPosition(text.getDocument().getLength());
|
||||
if(agent.getDb().tableChatExists(idUser, idDest)) {
|
||||
agent.getDb().addMessage(idUser, idDest, message);
|
||||
}else {
|
||||
|
@ -184,12 +203,12 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
|
|||
|
||||
|
||||
public static JTextArea getTa() {
|
||||
return ta;
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
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() {
|
||||
Color c = new Color(25, 94, 125);
|
||||
|
||||
SimpleAttributeSet right = new SimpleAttributeSet();
|
||||
StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
|
||||
StyleConstants.setForeground(right, Color.BLUE);
|
||||
StyleConstants.setForeground(right, Color.WHITE);
|
||||
|
||||
SimpleAttributeSet left = new SimpleAttributeSet();
|
||||
StyleConstants.setAlignment(left, StyleConstants.ALIGN_LEFT);
|
||||
StyleConstants.setForeground(left, Color.RED);
|
||||
StyleConstants.setForeground(left, c.brighter());
|
||||
int idUser = agent.getDb().getIdFromPseudo(user.getPseudo());
|
||||
//System.out.println("IDuser = "+idUser);
|
||||
int idDest = agent.getDb().getIdFromPseudo(dest.getPseudo());
|
||||
|
@ -268,6 +289,20 @@ public class FenetreChat extends JFrame implements PropertyChangeListener{
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
package gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
@ -13,8 +16,10 @@ import javax.swing.JLabel;
|
|||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
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.
|
||||
*/
|
||||
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
|
||||
frame = new JFrame("Fenetre connexion");
|
||||
//sortir quand l’utilisateur ferme le frame
|
||||
|
@ -43,8 +61,19 @@ public class FenetreConnexion implements ActionListener {
|
|||
frame.setSize(new Dimension(120, 40));
|
||||
//Creer le JPanel
|
||||
panel = new JPanel(new GridLayout(4,1));
|
||||
panel.setOpaque(false);
|
||||
//Ajouter les elements
|
||||
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.
|
||||
frame.getRootPane().setDefaultButton(Connexion);
|
||||
//Ajouter le panel a la window
|
||||
|
@ -61,6 +90,8 @@ public class FenetreConnexion implements ActionListener {
|
|||
this.pseudofield = new JTextField(2);
|
||||
// creation d'un label qui contiendra un txt au centre
|
||||
this.Text = new JLabel("Type your login", SwingConstants.CENTER);
|
||||
this.Text.setForeground(Color.white);
|
||||
this.Text.setOpaque(false);
|
||||
//Ajout d'un bouton Connexion
|
||||
this.Connexion = new JButton("Connexion");
|
||||
this.Cancel = new JButton("Cancel");
|
||||
|
@ -107,7 +138,12 @@ public class FenetreConnexion implements ActionListener {
|
|||
new FenetreConnexion();
|
||||
}
|
||||
}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) ;
|
||||
Connexion.setSelected(true);
|
||||
frame.dispose();
|
|
@ -1,8 +1,11 @@
|
|||
package gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
|
@ -13,10 +16,12 @@ import javax.swing.JLabel;
|
|||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
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.
|
||||
*/
|
||||
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
|
||||
frame = new JFrame("Fenetre inscription");
|
||||
//sortir quand l’utilisateur ferme le frame
|
||||
|
@ -45,8 +63,19 @@ public class FenetreInscription implements ActionListener {
|
|||
frame.setSize(new Dimension(40, 100));
|
||||
//Creer le JPanel
|
||||
panel = new JPanel(new GridLayout(7,1));
|
||||
panel.setOpaque(false);
|
||||
//Ajouter les elements
|
||||
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);
|
||||
//Ajouter le panel a la window
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
|
@ -63,8 +92,14 @@ public class FenetreInscription implements ActionListener {
|
|||
this.pseudofield = new JTextField(2);
|
||||
// creation d'un label qui contiendra un txt au centre
|
||||
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);
|
||||
text.setForeground(Color.WHITE);
|
||||
text.setOpaque(false);
|
||||
JLabel text2 = new JLabel("Pseudo: ", SwingConstants.CENTER);
|
||||
text2.setForeground(Color.WHITE);
|
||||
text2.setOpaque(false);
|
||||
//Ajout d'un bouton Connexion
|
||||
this.inscription = new JButton("Sign Up");
|
||||
this.connexion = new JButton("Sign In");
|
|
@ -5,9 +5,12 @@ import java.awt.Color;
|
|||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
@ -32,6 +35,7 @@ import javax.swing.JScrollPane;
|
|||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import controller.Agent;
|
||||
import model.Contact;
|
||||
|
@ -45,6 +49,7 @@ public class FenetreMenu {
|
|||
JLabel jlabel;
|
||||
JLabel texte;
|
||||
JLabel liste;
|
||||
JLabel vide;
|
||||
static JComboBox cb;
|
||||
WindowAdapter wa ;
|
||||
|
||||
|
@ -53,10 +58,24 @@ public class FenetreMenu {
|
|||
public FenetreMenu(Agent agent) throws IOException {
|
||||
FenetreMenu.ouvert=true;
|
||||
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.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
frame.setSize(new Dimension(500, 800));
|
||||
frame.setSize(new Dimension(600, 800));
|
||||
frame.setResizable(false);
|
||||
|
||||
wa = new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e){
|
||||
|
@ -77,14 +96,14 @@ public class FenetreMenu {
|
|||
frame.addWindowListener(wa);
|
||||
menu = new JMenuBar();
|
||||
//Creation d'un JPanel
|
||||
panel = new JPanel(new GridLayout(3,1));
|
||||
panel = new JPanel(new GridBagLayout());
|
||||
panel.setForeground(SystemColor.menuText);
|
||||
panel.setOpaque(false);
|
||||
// Ajouter tout les elements a la fenetre
|
||||
this.addWidgets();
|
||||
|
||||
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()) {
|
||||
@Override public void paintComponent(Graphics g) {
|
||||
g.drawImage(backgroundImage, 0, 0, null);
|
||||
|
@ -119,19 +138,29 @@ public class FenetreMenu {
|
|||
liste = new JLabel("Active users", JLabel.LEFT);
|
||||
liste.setOpaque(false);
|
||||
|
||||
vide = new JLabel();
|
||||
vide.setOpaque(false);
|
||||
|
||||
Color c = new Color(25, 94, 125);
|
||||
|
||||
JMenu contenu = new JMenu("Actions");
|
||||
contenu.setForeground(Color.BLUE);
|
||||
contenu.setForeground(Color.WHITE);
|
||||
contenu.setBackground(c.darker());
|
||||
contenu.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
//JMenuItem usersActifs = new JMenuItem("Active users");
|
||||
JMenuItem modifierPseudo = new JMenuItem("Modify your pseudo");
|
||||
modifierPseudo.setBackground(c.darker());
|
||||
modifierPseudo.setForeground(Color.WHITE);
|
||||
JMenuItem deco = new JMenuItem("Deconnection");
|
||||
deco.setBackground(c.darker());
|
||||
deco.setForeground(Color.WHITE);
|
||||
|
||||
//contenu.add(usersActifs);
|
||||
contenu.add(modifierPseudo);
|
||||
contenu.add(deco);
|
||||
|
||||
|
||||
menu.setBackground(c);
|
||||
menu.add(contenu);
|
||||
frame.setJMenuBar(menu);
|
||||
|
||||
|
@ -150,6 +179,10 @@ public class FenetreMenu {
|
|||
}
|
||||
|
||||
cb = new JComboBox(v);
|
||||
cb.setSelectedItem(agent.getUser().getPseudo());
|
||||
cb.setBackground(c);
|
||||
cb.setForeground(Color.WHITE);
|
||||
cb.setFocusable(false);
|
||||
cb.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
Object selected = cb.getSelectedItem();
|
||||
|
@ -169,11 +202,29 @@ public class FenetreMenu {
|
|||
|
||||
}
|
||||
});
|
||||
cb.setPreferredSize(new Dimension(500, 30));
|
||||
|
||||
|
||||
panel.add(BorderLayout.CENTER, jlabel);
|
||||
panel.add(BorderLayout.SOUTH , texte );
|
||||
panel.add(BorderLayout.WEST, cb);
|
||||
GridBagConstraints con = new GridBagConstraints();
|
||||
Insets i = new Insets(150, 0, 5, 0);
|
||||
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);
|
||||
|
||||
|
||||
|
173
chatGitElise/src/gui/SmartScroller.java
Normal 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;
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |