Package voxo.client.views.components

Source Code of voxo.client.views.components.CustomContact

/**
*
*/
package voxo.client.views.components;

import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import voxo.client.controllers.ClientController;
import voxo.client.listeners.ButtonAskForChat;
import voxo.client.listeners.ButtonCancelChat;
import voxo.common.entities.User;

/**
* @author Thierry
*
*/
@SuppressWarnings("serial")
public class CustomContact extends JPanel {

  private User  u;
  private JLabel  aUserName;
  private JPanel  friendActionPanel;
  private JButton  PhoneCall;
  private ButtonCancelChat  cancelChat;
  private ButtonAskForChat  askChat;
  private CustomWait  cust;


  public CustomContact(User u, ClientController c) {
    this.setU(u);

    this.setLayout(new BorderLayout(0, 0));
   
    setCust(new CustomWait(getU().getUsername()));
    cust.setVisible(false);

    // label for his name and icon
    aUserName = new JLabel(u.getUsername());

    ContactOnline(u.getOnline());

    // add icon to label, and label to a user

    this.add(aUserName, BorderLayout.CENTER);

    // panel for interaction with friend
    friendActionPanel = new JPanel();

    // 2 main action with online friend
    //chat = new JButton();
    setPhoneCall(new JButton());

    // add listeners
    cancelChat = new ButtonCancelChat(c,this);
    askChat = new ButtonAskForChat(c, this);
   
    getPhoneCall().addActionListener(askChat);
    getPhoneCall().setVisible(u.getOnline());
   
    // set action icons

    getPhoneCall().setIcon(new ImageIcon("resources/images/phone.png"));

    //add button
    friendActionPanel.add(getPhoneCall(), BorderLayout.WEST);

    // add friend action to user
    this.add(friendActionPanel, BorderLayout.EAST);

  }

  private void ContactOnline(boolean online2) {
    ImageIcon isheLog;

    if (online2) {
      isheLog = new ImageIcon("resources/images/green_dot.png");
    } else {
      isheLog = new ImageIcon("resources/images/red_dot.png");
    }
    aUserName.setIcon(isheLog);
  }

  public String toString() {
    return "CustomContact";
  }

  /**
   * @return the u
   */
  public User getU() {
    return u;
  }

  /**
   * @param u
   *            the u to set
   */
  public void setU(User u) {
    this.u = u;
  }
 
  public void swapChat(boolean swap){
    if(swap){
      getPhoneCall().addActionListener(cancelChat);
      getPhoneCall().removeActionListener(askChat);
      }
    else {
      getPhoneCall().addActionListener(askChat);
      getPhoneCall().removeActionListener(cancelChat);
      }
   
  }

  /**
   * @return the cust
   */
  public CustomWait getCust() {
    return cust;
  }

  /**
   * @param cust the cust to set
   */
  public void setCust(CustomWait cust) {
    this.cust = cust;
  }

  /**
   * @return the phoneCall
   */
  public JButton getPhoneCall() {
    return PhoneCall;
  }

  /**
   * @param phoneCall the phoneCall to set
   */
  public void setPhoneCall(JButton phoneCall) {
    PhoneCall = phoneCall;
  }

}
TOP

Related Classes of voxo.client.views.components.CustomContact

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.