package voxo.client.views;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EtchedBorder;
import voxo.client.actions.CancelVoiceAction;
import voxo.client.actions.ConfirmVoiceAction;
import voxo.client.actions.LogoutAction;
import voxo.client.controllers.ClientController;
import voxo.client.interfaces.GUIEventInterface;
import voxo.client.listeners.ButtonLoginListener;
import voxo.client.listeners.ButtonLogoutListener;
import voxo.client.listeners.ButtonRegisterListener;
import voxo.client.listeners.ButtonRemoveListener;
import voxo.client.listeners.ButtonSearchListener;
import voxo.client.listeners.MenuItemBlackEye;
import voxo.client.listeners.MenuItemGTK;
import voxo.client.listeners.MenuItemMetal;
import voxo.client.listeners.MenuItemMotif;
import voxo.client.listeners.MenuItemNimbus;
import voxo.client.listeners.MenuItemOS;
import voxo.client.listeners.MenuItemOrange;
import voxo.client.listeners.MenuItemWindow;
import voxo.client.listeners.SelectingUserListener;
import voxo.client.views.components.CustomChatWindow;
import voxo.client.views.components.CustomContact;
import voxo.client.views.components.CustomRequest;
import voxo.client.views.components.CustomUserList;
import voxo.common.entities.User;
import voxo.common.enums.EnumVerbose;
import voxo.common.packets.ChatPacket;
import voxo.common.packets.ContactListPacket;
import voxo.common.packets.VoiceConnexionPacket;
import javax.swing.JPopupMenu;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
//import de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel;
//import de.javasoft.plaf.synthetica.SyntheticaOrangeMetallicLookAndFeel;
@SuppressWarnings("serial")
public class MainView extends JFrame implements GUIEventInterface, WindowListener {
private JPasswordField passwordField;
private JTextField usernameField;
private JTextField textField;
private int newNodeSuffix = 1;
private JLabel lblWelcome;
private User me;
private JLabel lblUsername;
private JComponent lblPassword;
private JButton btnLogIn;
private JButton btnLogOut;
private JToggleButton tBtnTalk;
private JButton btnSend;
private boolean log;
private JTextField searchField;
private JPanel middleLogInPanel;
private JPanel westLogInPanel;
private JPanel eastLogInPanel;
private JPanel treePanels;
private JPanel contactList;
private JButton btnRemoveContact;
private HashMap<String, CustomChatWindow> contactHash;
private JPanel listSeparator;
private JPanel friendRequestList;
private JPanel friendResquestPanel;
private JDesktopPane chatDesk;
public User selectedUser;
private JButton btnAddContact;
private JPanel searchHolder;
private ClientController c;
private JPanel chatPanels;
private JButton btnRegister;
private JPanel searchPanels;
private JLabel lblChatWith;
private HashMap<String, CustomContact> contactListHash;
private JScrollPane searchPanelScroll;
private JPanel searchPanelsHolder;
private Color backGroundcolor;
private Color textColor;
private JLabel lblSearchForContact;
private JLabel lblcontact;
private JLabel lblFriendRequest;
private JLabel lblsearch;
private JButton btnSearch;
// *********************
// ** Constructor **
// *********************
public MainView(ClientController c) {
// main view customisation
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
setMinimumSize(new Dimension(600, 400));
getContentPane().setLayout(new BorderLayout(0, 0));
this.c = c;
// this.backGroundcolor = new Color(214, 217, 223);
// this.textColor = Color.BLACK;
// *******************************
// ** create north login panels **
// *******************************
// main loging panel
JPanel logingPanel = new JPanel();
getContentPane().add(logingPanel, BorderLayout.NORTH);
logingPanel.setLayout(new BorderLayout(0, 0));
// add the button to a holder for easy visible/hidden
setMiddleLogInPanel(new JPanel());
logingPanel.add(getMiddleLogInPanel(), BorderLayout.CENTER);
lblUsername = new JLabel("Username : ");
getMiddleLogInPanel().add(lblUsername);
lblUsername.setForeground(textColor);
lblUsername.setFont(new Font("Segoe UI", Font.PLAIN, 11));
usernameField = new JTextField();
getMiddleLogInPanel().add(usernameField);
usernameField.setColumns(10);
JLabel empty_1 = new JLabel(" ");
getMiddleLogInPanel().add(empty_1);
lblPassword = new JLabel("Password : ");
getMiddleLogInPanel().add(lblPassword);
lblPassword.setAlignmentX(Component.CENTER_ALIGNMENT);
lblPassword.setForeground(textColor);
lblPassword.setFont(new Font("Segoe UI", Font.PLAIN, 11));
passwordField = new JPasswordField();
getMiddleLogInPanel().add(passwordField);
passwordField.setEchoChar('*');
passwordField.setColumns(8);
JLabel empty_3 = new JLabel(" ");
getMiddleLogInPanel().add(empty_3);
btnLogIn = new JButton("Log In");
getMiddleLogInPanel().add(btnLogIn);
btnLogIn.setHorizontalTextPosition(SwingConstants.CENTER);
btnRegister = new JButton("Register");
getMiddleLogInPanel().add(btnRegister);
btnRegister.setHorizontalTextPosition(SwingConstants.CENTER);
// west holder for welcome message+logout
setWestLogInPanel(new JPanel());
getWestLogInPanel().setVisible(false);
logingPanel.add(getWestLogInPanel(), BorderLayout.WEST);
setLblWelcome(new JLabel("Welcome"));
getWestLogInPanel().add(getLblWelcome());
getLblWelcome().setFont(new Font("Segoe UI", Font.PLAIN, 15));
btnLogOut = new JButton("Log Out");
getWestLogInPanel().add(btnLogOut);
btnLogOut.setHorizontalTextPosition(SwingConstants.CENTER);
// east holder for search feature
setEastLogInPanel(new JPanel());
getEastLogInPanel().setVisible(false);
logingPanel.add(getEastLogInPanel(), BorderLayout.EAST);
lblSearchForContact = new JLabel("Search for Contact : ");
getEastLogInPanel().add(lblSearchForContact);
lblSearchForContact.setForeground(textColor);
lblSearchForContact.setFont(new Font("Segoe UI", Font.PLAIN, 11));
lblSearchForContact.setAlignmentX(0.5f);
searchField = new JTextField();
getEastLogInPanel().add(searchField);
searchField.setColumns(8);
setBtnSearch(new JButton("Search"));
eastLogInPanel.add(getBtnSearch());
// *********************
// ** chat panels **
// *********************
setChatPanels(new JPanel());
getContentPane().add(getChatPanels(), BorderLayout.CENTER);
getChatPanels().setLayout(new BorderLayout(0, 0));
chatDesk = new JDesktopPane();
chatDesk.setFocusable(false);
chatDesk.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
getChatPanels().add(chatDesk);
chatDesk.setLayout(null);
setLblChatWith(new JLabel());
getChatPanels().add(getLblChatWith(), BorderLayout.NORTH);
// *************************
// ** PoP up menu **
// *************************
JPopupMenu popupMenu = new JPopupMenu();
addPopup(this, popupMenu);
JLabel lblSelectYourWanted = new JLabel(" Select your Skin");
lblSelectYourWanted.setHorizontalAlignment(SwingConstants.CENTER);
popupMenu.add(lblSelectYourWanted);
JSeparator separator = new JSeparator();
popupMenu.add(separator);
JMenuItem mntmYourDefaultOs = new JMenuItem("Your Default OS");
popupMenu.add(mntmYourDefaultOs);
JMenuItem mntmnimbus = new JMenuItem("\"Nimbus\"");
popupMenu.add(mntmnimbus);
JMenuItem metal = new JMenuItem("Ocean(Metal)");
popupMenu.add(metal);
JMenuItem orange = new JMenuItem("Orange");
popupMenu.add(orange);
JMenuItem blackeye = new JMenuItem("Black Eyes");
popupMenu.add(blackeye);
JMenuItem window = new JMenuItem("Windows");
popupMenu.add(window);
JMenuItem gtk = new JMenuItem("GTK");
popupMenu.add(gtk);
JMenuItem motif = new JMenuItem("Motif");
popupMenu.add(motif);
// set popup listeners
mntmYourDefaultOs.addActionListener(new MenuItemOS(this));
gtk.addActionListener(new MenuItemGTK(this));
window.addActionListener(new MenuItemWindow(this));
motif.addActionListener(new MenuItemMotif(this));
mntmnimbus.addActionListener(new MenuItemNimbus(this));
metal.addActionListener(new MenuItemMetal(this));
orange.addActionListener(new MenuItemOrange(this));
blackeye.addActionListener(new MenuItemBlackEye(this));
// *************************
// ** contact List panel; **
// *************************
// main contactlist panel
treePanels = new JPanel();
treePanels.setPreferredSize(new Dimension(200, 485));
treePanels.setLayout(new BorderLayout(0, 0));
// add it to the main view
getContentPane().add(treePanels, BorderLayout.WEST);
// the contact label and its icon
lblcontact = new JLabel();
lblcontact.setIcon(new ImageIcon("resources/images/icon.jpg"));
lblcontact.setHorizontalAlignment(SwingConstants.CENTER);
lblcontact.setText("Contact List");
// adding the label to contactlist panel
treePanels.add(lblcontact, BorderLayout.NORTH);
// creating a panel for UI looks which will separate the 2 lists panel
listSeparator = new JPanel();
listSeparator.setLayout(new BorderLayout(0, 0));
// adding it to the tree panels
treePanels.add(listSeparator, BorderLayout.CENTER);
// create the holder of the friend request panel
friendResquestPanel = new JPanel();
friendResquestPanel.setLayout(new BorderLayout(0, 0));
// adding to separator panel
listSeparator.add(friendResquestPanel, BorderLayout.SOUTH);
// creating the friend request label
lblFriendRequest = new JLabel();
lblFriendRequest.setText("Friend Request");
lblFriendRequest.setHorizontalAlignment(SwingConstants.CENTER);
// creating the friendrequest list
setFriendRequestList(new JPanel());
// adding them to the holder
friendResquestPanel.add(getFriendRequestList(), BorderLayout.CENTER);
friendResquestPanel.add(lblFriendRequest, BorderLayout.NORTH);
// setting it invisible until you actually have a request
friendResquestPanel.setVisible(false);
// button( to erase a contact)
setBtnRemoveContact(new JButton("Remove"));
getBtnRemoveContact().setIcon(new ImageIcon("resources/images/remove.png"));
getBtnRemoveContact().setEnabled(false);
// putting the button in a panel for UI looks purpose
JPanel btnHolder = new JPanel();
btnHolder.setLayout(new BorderLayout(0, 0));
// adding the button to the btn holder
btnHolder.add(getBtnRemoveContact(), BorderLayout.CENTER);
// add it to the contactlist main panel
treePanels.add(btnHolder, BorderLayout.SOUTH);
// *************************************
// search feature **
// *************************************
// adding texts
lblsearch = new JLabel();
lblsearch.setIcon(new ImageIcon("resources/images/search.png"));
lblsearch.setHorizontalAlignment(SwingConstants.CENTER);
lblsearch.setText("Search Results");
// creating the results holder
searchPanels = new JPanel();
searchPanels.setPreferredSize(new Dimension(200, 485));
// setting the scroll down
setSearchHolder(new JPanel());
searchPanelScroll = new JScrollPane(searchPanels);
searchPanelScroll.setPreferredSize(new Dimension(200, 485));
// setting up holders
setSearchPanelsHolder(new JPanel());
getSearchPanelsHolder().setLayout(new BorderLayout());
getSearchPanelsHolder().add(lblsearch, BorderLayout.NORTH);
getSearchPanelsHolder().add(searchPanelScroll, BorderLayout.CENTER);
getSearchPanelsHolder().setPreferredSize(new Dimension(200, 485));
// adding it to the main frame
getContentPane().add(getSearchPanelsHolder(), BorderLayout.EAST);
// setting up the holder of the search results
getSearchHolder().setLayout(new BoxLayout(getSearchHolder(), BoxLayout.PAGE_AXIS));
// set visible to false
getSearchPanelsHolder().setVisible(false);
// *************************************
// Ajout de listeners pour boutons **
// *************************************
btnLogIn.addActionListener(new ButtonLoginListener(c, this));
btnLogOut.addActionListener(new ButtonLogoutListener(this, c));
getBtnRemoveContact().addActionListener(new ButtonRemoveListener(this, c));
getBtnSearch().addActionListener(new ButtonSearchListener(this, searchField));
btnRegister.addActionListener(new ButtonRegisterListener(this, c));
this.setVisible(true);
setDefaultLook();
}
// *******************************************
// ** Override pour action du controlleur **
// *******************************************
@Override
public void voiceConfirmationDenied(VoiceConnexionPacket vcp) {
JOptionPane.showMessageDialog(this, "The other user have cancel the chatting proccess", "Chat refuse", JOptionPane.ERROR_MESSAGE);
getContactListHash().get(vcp.getUsername()).swapChat(false);
getContactListHash().get(vcp.getUsername()).getCust().setVisible(false);
}
@Override
public void loginAccepted(User me) {
this.setMe(me);
setLog(true);
getEastLogInPanel().setVisible(isLog());
getWestLogInPanel().setVisible(isLog());
getMiddleLogInPanel().setVisible(!isLog());
getLblWelcome().setText("Welcome " + usernameField.getText());
}
@Override
public void voiceReceived(VoiceConnexionPacket clp) {
JOptionPane.showMessageDialog(this, "Communication started", "Phone Call initiated", JOptionPane.INFORMATION_MESSAGE);
}
@Override
public void contactModified(ContactListPacket newLists) {
c.getVerbose().addConsoleMsg("MainView.contactModified()", EnumSet.of(EnumVerbose.ToConsole));
// erase the previous lists
if (getContactList() != null) {
this.listSeparator.remove(getContactList());
this.friendResquestPanel.remove(getFriendRequestList());
this.listSeparator.revalidate();
}
setContactList(new JPanel());
setFriendRequestList(new JPanel());
getContactList().setVisible(true);
getFriendRequestList().setVisible(true);
friendResquestPanel.add(getFriendRequestList());
listSeparator.add(getContactList());
listSeparator.add(friendResquestPanel, BorderLayout.SOUTH);
// create a new list
getContactList().setLayout(new BoxLayout(getContactList(), BoxLayout.PAGE_AXIS));
getFriendRequestList().setLayout(new BoxLayout(getFriendRequestList(), BoxLayout.PAGE_AXIS));
contactHash = new HashMap<String, CustomChatWindow>();
setContactListHash(new HashMap<String, CustomContact>());
ArrayList<User> alContacts = newLists.getAlContacts();
// add each user into the list
for (User u : alContacts) {
// add user panel to main branch
CustomContact cc = new CustomContact(u, c);
cc.addMouseListener(new SelectingUserListener(this));
getContactListHash().put(u.getUsername(), cc);
getContactList().add(cc);
// create new chatWindow
if (!contactHash.containsKey(u.getUsername())) {
CustomChatWindow cw = new CustomChatWindow(u, this);
contactHash.put(u.getUsername(), cw);
chatDesk.add((contactHash.get(u.getUsername())));
}
}
// adding to separator panel
ArrayList<User> AlContactRequests = newLists.getAlContactRequests();
listSeparator.add(getContactList(), BorderLayout.NORTH);
for (User u : AlContactRequests) {
// add user panel to main branch
getFriendRequestList().add(new CustomRequest(this, u));
}
getFriendRequestList().setVisible(true);
// show the requests if needed
friendResquestPanel.add(getFriendRequestList());
if (!newLists.getAlContactRequests().isEmpty()) {
friendResquestPanel.setVisible(true);
}
listSeparator.revalidate();
}
@Override
public void voiceRequest(VoiceConnexionPacket clp) {
c.getVerbose().addConsoleMsg("MainView.voiceRequest()", EnumSet.of(EnumVerbose.ToConsole));
// notice user who want to talk with you
final JOptionPane optionPane = new JOptionPane("Do you want to talk with : " + clp.getContactName(), JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
final JDialog dialog = new JDialog(this, "Incoming Call ... ", true);
dialog.setContentPane(optionPane);
// listener for user response user
optionPane.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
dialog.setVisible(false);
}
}
});
// afficher le dialogue
dialog.pack();
dialog.setVisible(true);
// if yes, contact user
int value = ((Integer) optionPane.getValue()).intValue();
if (value == JOptionPane.YES_OPTION) {
new ConfirmVoiceAction(c, clp.getUserIp(), new VoiceConnexionPacket(me.getUsername(), me.getIp(), clp.getUsername()));
getContactListHash().get(clp.getUsername()).swapChat(true);
} else {
// if no, ignore demands
new CancelVoiceAction(c, clp.getUserIp(), new VoiceConnexionPacket(me.getUsername(), me.getIp(), clp.getUsername()));
getContactListHash().get(clp.getUsername()).swapChat(false);
}
}
@Override
public void chatMsgReceived(ChatPacket p) {
c.getVerbose().addConsoleMsg("MainView.chatMsgReceived()", EnumSet.of(EnumVerbose.ToConsole));
newMessage(p);
if (contactHash.get(p.getUsername()).isIcon()) {
try {
contactHash.get(p.getUsername()).setIcon(false);
} catch (PropertyVetoException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}
}
}
@Override
public void serverError(String msg) {
JOptionPane.showMessageDialog(this, msg, "Error", JOptionPane.ERROR_MESSAGE);
}
@Override
public void receiveSearchResults(ArrayList<User> alu) {
searchPanels.remove(searchHolder);
searchPanels.revalidate();
searchHolder = new JPanel();
searchHolder.setLayout(new BoxLayout(searchHolder, BoxLayout.PAGE_AXIS));
searchPanels.add(searchHolder);
for (User u : alu) {
if (!(getContactListHash().containsKey(u.getUsername())) && u.getUserId() != me.getUserId()) {
CustomUserList cs = new CustomUserList(this, u);
getSearchHolder().add(cs);
}
}
getSearchPanelsHolder().setVisible(true);
searchPanels.revalidate();
}
@Override
public void openChatEvent(User u) {
// Si la fenetre du user existe pas, la creer et l.ajouter au desk
if (!contactHash.containsKey(u.getUsername()) && u.getOnline()) {
CustomChatWindow cw = new CustomChatWindow(u, this);
contactHash.put(u.getUsername(), cw);
chatDesk.add((contactHash.get(u.getUsername())));
cw.setVisible(true);
} else if(u.getOnline()){
if (contactHash.get(u.getUsername()).isIcon()) {
try {
contactHash.get(u.getUsername()).setIcon(false);
} catch (PropertyVetoException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}
}
contactHash.get(u.getUsername()).setVisible(true);
}
}
// ****************************************
// ** method to simplify text and code ; **
// ****************************************
private void newMessage(ChatPacket p) {
//find the related user chat window
CustomChatWindow chatWindow = contactHash.get(p.getUsername());
//add the message to it
chatWindow.addMessage(p);
//show the window if invisible
if (!chatWindow.isVisible()) {
chatWindow.setVisible(true);
chatWindow.setTitle("new message from " + p.getUsername());
}
//refresh the look
chatWindow.revalidate();
}
public void setDefaultLook() {
this.textColor = Color.RED;
try {
// Set cross-platform Java L&F (also called "Metal")
UIManager.setLookAndFeel(
UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (UnsupportedLookAndFeelException e) {
// handle exception
}
catch (ClassNotFoundException e) {
// handle exception
}
catch (InstantiationException e) {
// handle exception
}
catch (IllegalAccessException e) {
// handle exception
}
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setBlackEyeLook(){
this.textColor = Color.yellow;
/*try
{
UIManager.setLookAndFeel(new SyntheticaBlackEyeLookAndFeel());
}
catch (Exception e)
{
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}*/
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setOrangeLook() {
this.textColor = Color.ORANGE;
/*
try {
UIManager.setLookAndFeel(new SyntheticaOrangeMetallicLookAndFeel());
} catch (Exception e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}*/
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setGTKLook(){
this.textColor = Color.gray;
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
} catch (ClassNotFoundException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (InstantiationException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (IllegalAccessException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (UnsupportedLookAndFeelException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setMotifLook(){
this.textColor = Color.BLACK;
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
} catch (ClassNotFoundException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (InstantiationException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (IllegalAccessException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (UnsupportedLookAndFeelException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setWindowLook(){
this.textColor = Color.CYAN;
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (InstantiationException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (IllegalAccessException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (UnsupportedLookAndFeelException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setNimbusLook() {
this.textColor = Color.darkGray;
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (ClassNotFoundException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (InstantiationException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (IllegalAccessException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
} catch (UnsupportedLookAndFeelException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setOSLook() {
this.textColor = Color.BLUE;
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
}
SwingUtilities.updateComponentTreeUI(this);
this.revalidate();
setLabelColor(textColor);
}
public void setLabelColor(Color textColor){
lblUsername.setForeground(textColor);
lblPassword.setForeground(textColor);
lblChatWith.setForeground(textColor);
lblWelcome.setForeground(textColor);
lblSearchForContact.setForeground(textColor);
lblcontact.setForeground(textColor);
lblFriendRequest.setForeground(textColor);
lblsearch.setForeground(textColor);
}
// ***********************
// ** Getter & Setter ; **
// ***********************
public JPasswordField getPasswordField() {
return passwordField;
}
public void setPasswordField(JPasswordField passwordField) {
this.passwordField = passwordField;
}
public JTextField getUsernameField() {
return usernameField;
}
public void setUsernameField(JTextField usernameField) {
this.usernameField = usernameField;
}
public JTextField getTextField() {
return textField;
}
public void setTextField(JTextField textField) {
this.textField = textField;
}
/**
* @return the newNodeSuffix
*/
public int getNewNodeSuffix() {
return newNodeSuffix;
}
/**
* @param newNodeSuffix
* the newNodeSuffix to set
*/
public void setNewNodeSuffix(int newNodeSuffix) {
this.newNodeSuffix = newNodeSuffix;
}
/**
* @return the middleLogInPanel
*/
public JPanel getMiddleLogInPanel() {
return middleLogInPanel;
}
/**
* @param middleLogInPanel
* the middleLogInPanel to set
*/
public void setMiddleLogInPanel(JPanel middleLogInPanel) {
this.middleLogInPanel = middleLogInPanel;
}
/**
* @return the log
*/
public boolean isLog() {
return log;
}
/**
* @param log
* the log to set
*/
public void setLog(boolean log) {
this.log = log;
}
/**
* @return the eastLogInPanel
*/
public JPanel getEastLogInPanel() {
return eastLogInPanel;
}
/**
* @param eastLogInPanel
* the eastLogInPanel to set
*/
public void setEastLogInPanel(JPanel eastLogInPanel) {
this.eastLogInPanel = eastLogInPanel;
}
/**
* @return the westLogInPanel
*/
public JPanel getWestLogInPanel() {
return westLogInPanel;
}
/**
* @param westLogInPanel
* the westLogInPanel to set
*/
public void setWestLogInPanel(JPanel westLogInPanel) {
this.westLogInPanel = westLogInPanel;
}
/**
* @return the lblWelcome
*/
public JLabel getLblWelcome() {
return lblWelcome;
}
/**
* @param lblWelcome
* the lblWelcome to set
*/
public void setLblWelcome(JLabel lblWelcome) {
this.lblWelcome = lblWelcome;
lblWelcome.setForeground(textColor);
}
/**
* @return the btnSend
*/
public JButton getBtnSend() {
return btnSend;
}
/**
* @param btnSend
* the btnSend to set
*/
public void setBtnSend(JButton btnSend) {
this.btnSend = btnSend;
}
/**
* @return the tBtnTalk
*/
public JToggleButton gettBtnTalk() {
return tBtnTalk;
}
/**
* @param tBtnTalk
* the tBtnTalk to set
*/
public void settBtnTalk(JToggleButton tBtnTalk) {
this.tBtnTalk = tBtnTalk;
}
/**
* @return the me
*/
public User getMe() {
return me;
}
/**
* @param me
* the me to set
*/
public void setMe(User me) {
this.me = me;
}
public JPanel getTreePanels() {
return treePanels;
}
public void setTreePanels(JPanel treePanels) {
this.treePanels = treePanels;
}
public JPanel getContactList() {
return contactList;
}
public void setContactList(JPanel contactList) {
this.contactList = contactList;
}
/**
* @return the friendRequestList
*/
public JPanel getFriendRequestList() {
return friendRequestList;
}
/**
* @param friendRequestList
* the friendRequestList to set
*/
public void setFriendRequestList(JPanel friendRequestList) {
this.friendRequestList = friendRequestList;
}
/**
* @return the searchHolder
*/
public JPanel getSearchHolder() {
return searchHolder;
}
/**
* @param searchHolder
* the searchHolder to set
*/
public void setSearchHolder(JPanel searchHolder) {
this.searchHolder = searchHolder;
searchHolder.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
}
public User getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(User selectedUser) {
c.getVerbose().updateContact(selectedUser);
this.selectedUser = selectedUser;
}
/**
* @return the btnRemoveContact
*/
public JButton getBtnRemoveContact() {
return btnRemoveContact;
}
/**
* @param btnRemoveContact
* the btnRemoveContact to set
*/
public void setBtnRemoveContact(JButton btnRemoveContact) {
this.btnRemoveContact = btnRemoveContact;
}
/**
* @return the chatPanels
*/
public JPanel getChatPanels() {
return chatPanels;
}
/**
* @param chatPanels
* the chatPanels to set
*/
public void setChatPanels(JPanel chatPanels) {
this.chatPanels = chatPanels;
}
public JLabel getLblUsername() {
return lblUsername;
}
public void setLblUsername(JLabel lblUsername) {
this.lblUsername = lblUsername;
}
public JButton getBtnLogIn() {
return btnLogIn;
}
public void setBtnLogIn(JButton btnLogIn) {
this.btnLogIn = btnLogIn;
}
public JButton getBtnLogOut() {
return btnLogOut;
}
public void setBtnLogOut(JButton btnLogOut) {
this.btnLogOut = btnLogOut;
}
public JTextField getSearchField() {
return searchField;
}
public void setSearchField(JTextField searchField) {
this.searchField = searchField;
}
public HashMap<String, CustomChatWindow> getContactHash() {
return contactHash;
}
public void setContactHash(HashMap<String, CustomChatWindow> contactHash) {
this.contactHash = contactHash;
}
public JPanel getListSeparator() {
return listSeparator;
}
public void setListSeparator(JPanel listSeparator) {
this.listSeparator = listSeparator;
}
public JPanel getFriendResquestPanel() {
return friendResquestPanel;
}
public void setFriendResquestPanel(JPanel friendResquestPanel) {
this.friendResquestPanel = friendResquestPanel;
}
public JDesktopPane getChatDesk() {
return chatDesk;
}
public void setChatDesk(JDesktopPane chatDesk) {
this.chatDesk = chatDesk;
}
public JButton getBtnAddContact() {
return btnAddContact;
}
public void setBtnAddContact(JButton btnAddContact) {
this.btnAddContact = btnAddContact;
}
public ClientController getC() {
return c;
}
public void setC(ClientController c) {
this.c = c;
}
/**
* @return the lblChatWith
*/
public JLabel getLblChatWith() {
return lblChatWith;
}
/**
* @param lblChatWith
* the lblChatWith to set
*/
public void setLblChatWith(JLabel lblChatWith) {
this.lblChatWith = lblChatWith;
}
public void windowDeactivated(java.awt.event.WindowEvent arg0) {};
@Override
public void windowClosing(WindowEvent e) {
new LogoutAction(c, me.getUsername(), this);
if (c.getServerReceiver() != null)
c.getServerReceiver().setGo(false);
System.exit(0);
}
@Override
public void windowActivated(WindowEvent arg0) {}
@Override
public void windowClosed(WindowEvent arg0) {}
@Override
public void windowDeiconified(WindowEvent arg0) {}
@Override
public void windowIconified(WindowEvent arg0) {}
@Override
public void windowOpened(WindowEvent arg0) {}
/**
* @return the contactListHash
*/
public HashMap<String, CustomContact> getContactListHash() {
return contactListHash;
}
/**
* @param contactListHash
* the contactListHash to set
*/
public void setContactListHash(HashMap<String, CustomContact> contactListHash) {
this.contactListHash = contactListHash;
}
/**
* @return the backGroundcolor
*/
public Color getBackGroundcolor() {
return backGroundcolor;
}
/**
* @param backGroundcolor
* the backGroundcolor to set
*/
public void setBackGroundcolor(Color backGroundcolor) {
this.backGroundcolor = backGroundcolor;
}
private static void addPopup(Component component, final JPopupMenu popup) {
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
showMenu(e);
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
showMenu(e);
}
}
private void showMenu(MouseEvent e) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
});
}
/**
* @return the btnSearch
*/
public JButton getBtnSearch() {
return btnSearch;
}
/**
* @param btnSearch the btnSearch to set
*/
public void setBtnSearch(JButton btnSearch) {
this.btnSearch = btnSearch;
}
/**
* @return the searchPanelsHolder
*/
public JPanel getSearchPanelsHolder() {
return searchPanelsHolder;
}
/**
* @param searchPanelsHolder the searchPanelsHolder to set
*/
public void setSearchPanelsHolder(JPanel searchPanelsHolder) {
this.searchPanelsHolder = searchPanelsHolder;
}
}