mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 11:43:53 +00:00
feat(contacts): ajout de la classe Contact.java, ContactMap.java, gestion des objets Contact dans l'interface graphique
This commit is contained in:
parent
45f18e9309
commit
e9480590a7
14 changed files with 649 additions and 36 deletions
|
|
@ -1,18 +1,65 @@
|
|||
package rtgre.modeles;
|
||||
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Contact {
|
||||
protected String login;
|
||||
protected java.awt.Image avatar;
|
||||
protected boolean connected;
|
||||
protected String currentRoom;
|
||||
|
||||
Contact(String login, java.awt.Image avatar) {
|
||||
public Contact(String login, java.awt.Image avatar) {
|
||||
/**
|
||||
* Crée un objet Contact
|
||||
* @param: String login
|
||||
* @param: java.awt.Image avatar
|
||||
*/
|
||||
this.login = login;
|
||||
this.avatar = avatar;
|
||||
this.connected = false;
|
||||
this.currentRoom = null;
|
||||
}
|
||||
public Contact(String login, boolean connected, java.awt.Image avatar) {
|
||||
/**
|
||||
* Crée un objet Contact
|
||||
* @param: String login
|
||||
* @param: boolean connected
|
||||
* @param: java.awt.Image avatar
|
||||
*/
|
||||
this.login = login;
|
||||
this.avatar = avatar;
|
||||
this.connected = connected;
|
||||
this.currentRoom = null;
|
||||
}
|
||||
|
||||
public String getCurrentRoom() {
|
||||
return currentRoom;
|
||||
}
|
||||
|
||||
public Contact(String login, boolean connected, File banques_avatars) {
|
||||
/**
|
||||
* Crée un objet Contact
|
||||
* @param: String login
|
||||
* @param: boolean connected
|
||||
* @param: File banques_avatars
|
||||
*/
|
||||
this.login = login;
|
||||
try {
|
||||
this.avatar = avatarFromLogin(banques_avatars, login);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Impossible de créer l'utilisateur " + login);
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println(banques_avatars);
|
||||
}
|
||||
this.connected = connected;
|
||||
this.currentRoom = null;
|
||||
}
|
||||
|
||||
|
||||
public String getLogin() {
|
||||
return this.login;
|
||||
|
|
@ -24,20 +71,52 @@ public class Contact {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
return "@" + this.login;
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return this.connected;
|
||||
}
|
||||
|
||||
public void setConnected(boolean connected) {
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Contact contact = (Contact) o;
|
||||
return Objects.equals(login, contact.login);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {return true;}
|
||||
/*if (this.login == o.login) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(login);
|
||||
}
|
||||
|
||||
public int getUnreadCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static BufferedImage avatarFromLogin(File fichier, String login) throws IOException {
|
||||
/**
|
||||
* Renvoie une sous-image en fonction d'une banque d'image et d'un login.
|
||||
* @param: File fichier
|
||||
* @param: String login
|
||||
*/
|
||||
BufferedImage img = ImageIO.read(fichier);
|
||||
int width = img.getWidth() / 9;
|
||||
int height = img.getHeight();
|
||||
int n = Integer.remainderUnsigned(login.hashCode(), 9);
|
||||
return img.getSubimage(n*width, 0, width, height);
|
||||
}
|
||||
|
||||
public void setAvatarFromFile(File f) {
|
||||
try {
|
||||
this.avatar = avatarFromLogin(f, this.login);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Erreur : " + e.getMessage());
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue