protocol contact selector box modified

cusax-fix
Yana Stamcheva 20 years ago
parent f15054e138
commit e4ed7ec902

@ -257,7 +257,7 @@ public void updateContactStatus(Contact protoContact) {
PresenceStatus status = protocolContact.getPresenceStatus();
this.chatConferencePanel.updateContactStatus(status);
this.sendPanel.setSelectedProtocolContact(protoContact);
this.sendPanel.updateContactStatus(protoContact);
String message = this.conversationPanel.processMessage(
this.metaContact.getDisplayName(),
new Date(System.currentTimeMillis()),
@ -517,7 +517,7 @@ public String getTextFromWriteArea(){
/**
* Stops typing notifications sending.
*/
public void stopTypingNotifications(){
public void stopTypingNotifications(){
this.writeMessagePanel.stopTypingTimer();
}

@ -42,10 +42,7 @@ public class ChatSendPanel extends JPanel implements ActionListener {
private ChatPanel chatPanel;
private ArrayList protocolCList = new ArrayList();
private SIPCommSelectorBox contactSelectorBox
= new SIPCommSelectorBox();
private ProtocolContactSelectorBox contactSelectorBox;
/**
* Creates an instance of <tt>ChatSendPanel</tt>.
@ -57,6 +54,7 @@ public ChatSendPanel(ChatPanel chatPanel) {
this.chatPanel = chatPanel;
contactSelectorBox = new ProtocolContactSelectorBox(this);
this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
this.statusPanel.add(statusLabel);
@ -97,9 +95,10 @@ public void actionPerformed(ActionEvent e) {
chatPanel.stopTypingNotifications();
chatPanel.requestFocusInWriteArea();
try {
im.sendInstantMessage(contact, msg);
} catch (IllegalStateException ex) {
} catch (IllegalStateException ex) {
SIPCommMsgTextArea errorMsg = new SIPCommMsgTextArea(
Messages.getString("msgSendConnectionProblem"));
@ -130,26 +129,8 @@ public void addProtocolContacts(MetaContact metaContact) {
Iterator protocolContacts = metaContact.getContacts();
while (protocolContacts.hasNext()) {
Contact contact = (Contact) protocolContacts.next();
if (!protocolCList.contains(contact))
protocolCList.add(contact);
Image statusImage = ImageLoader.getBytesInImage(
contact.getPresenceStatus().getStatusIcon());
int index = this.chatPanel.getChatWindow().getMainFrame()
.getProviderIndex(contact.getProtocolProvider());
Image img;
if(index > 0) {
img = createIndexedImage(statusImage, index);
}
else {
img = statusImage;
}
contactSelectorBox.addItem(contact.getDisplayName(),
new ImageIcon(img),
new ProtocolItemListener());
contactSelectorBox.addContact(contact);
}
}
@ -188,48 +169,16 @@ public void setStatusMessage(String statusMessage) {
*/
public void setSelectedProtocolContact(Contact protoContact)
{
Image statusImage = ImageLoader.getBytesInImage(
protoContact.getPresenceStatus().getStatusIcon());
int index = this.chatPanel.getChatWindow().getMainFrame()
.getProviderIndex(protoContact.getProtocolProvider());
Image img;
if(index > 0) {
img = createIndexedImage(statusImage, index);
}
else {
img = statusImage;
}
contactSelectorBox.setSelected(
protoContact,
new ImageIcon(img));
contactSelectorBox.setSelected(protoContact);
}
/**
* The listener of the protocol contact's selector box.
*
* @param protoContact
*/
private class ProtocolItemListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JMenuItem menuItem = (JMenuItem) e.getSource();
String itemTitle = menuItem.getText();
for (int i = 0; i < protocolCList.size(); i++) {
Contact protocolContact = (Contact) protocolCList.get(i);
if (protocolContact.getDisplayName().equals(itemTitle)) {
OperationSetBasicInstantMessaging im = chatPanel
.getChatWindow().getMainFrame().getProtocolIM(
protocolContact.getProtocolProvider());
chatPanel.setImOperationSet(im);
chatPanel.setProtocolContact(protocolContact);
contactSelectorBox.setSelected(
protocolContact, menuItem.getIcon());
}
}
}
public void updateContactStatus(Contact protoContact)
{
contactSelectorBox.updateContactStatus(protoContact);
}
/**
@ -258,29 +207,9 @@ public void paint(Graphics g) {
g2.drawRoundRect(3, 4, this.statusPanel.getWidth() - 2,
this.statusPanel.getHeight() - 2, 8, 8);
}
/**
* Adds the protocol provider index to the given source image.
* @param sourceImage
* @param index
* @return
*/
private Image createIndexedImage(Image sourceImage, int index)
{
BufferedImage buffImage = new BufferedImage(
22, 16, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D)buffImage.getGraphics();
AlphaComposite ac =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
AntialiasingManager.activateAntialiasing(g);
g.setColor(Color.DARK_GRAY);
g.setFont(Constants.FONT.deriveFont(Font.BOLD, 9));
g.drawImage(sourceImage, 0, 0, null);
g.setComposite(ac);
g.drawString(new Integer(index).toString(), 14, 8);
return buffImage;
public ChatPanel getChatPanel()
{
return chatPanel;
}
}

@ -14,6 +14,8 @@
import javax.swing.text.*;
import javax.swing.undo.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.main.message.menus.*;
import net.java.sip.communicator.impl.gui.utils.*;
@ -146,11 +148,16 @@ else if ((e.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK
redo();
}
}
else if (chatPanel.getChatWindow().isTypingNotificationEnabled()
else if (chatPanel.getProtocolContact()
.getProtocolProvider().isRegistered()
&& chatPanel.getChatWindow().isTypingNotificationEnabled()
&& e.getKeyCode() != KeyEvent.VK_ESCAPE) {
if (typingState != OperationSetTypingNotifications.STATE_TYPING) {
stoppedTypingTimer.setDelay(2 * 1000);
stoppedTypingTimer.setDelay(2 * 1000);
typingState = OperationSetTypingNotifications.STATE_TYPING;
chatPanel.getTnOperationSet().sendTypingNotification(
chatPanel.getProtocolContact(), typingState);
typingTimer.start();
@ -203,11 +210,15 @@ public void actionPerformed(ActionEvent e) {
* Stops the timer and sends a notification message.
*/
public void stopTypingTimer() {
chatPanel.getTnOperationSet().sendTypingNotification(
chatPanel.getProtocolContact(),
OperationSetTypingNotifications.STATE_STOPPED);
typingState = OperationSetTypingNotifications.STATE_STOPPED;
stoppedTypingTimer.stop();
if (chatPanel.getProtocolContact()
.getProtocolProvider().isRegistered()) {
chatPanel.getTnOperationSet().sendTypingNotification(
chatPanel.getProtocolContact(),
OperationSetTypingNotifications.STATE_STOPPED);
typingState = OperationSetTypingNotifications.STATE_STOPPED;
stoppedTypingTimer.stop();
}
}
/**

@ -0,0 +1,144 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.message;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.util.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
public class ProtocolContactSelectorBox
extends SIPCommSelectorBox
implements ActionListener
{
private ChatSendPanel sendPanel;
private Hashtable contactsTable = new Hashtable();
public ProtocolContactSelectorBox(ChatSendPanel sendPanel)
{
this.sendPanel = sendPanel;
}
public void addContact(Contact contact)
{
Image img = createContactStatusImage(contact);
JMenuItem menuItem = new JMenuItem(
contact.getDisplayName(),
new ImageIcon(img));
menuItem.addActionListener(this);
this.contactsTable.put(contact, menuItem);
this.addItem(menuItem);
}
/**
* The listener of the protocol contact's selector box.
*/
public void actionPerformed(ActionEvent e) {
JMenuItem menuItem = (JMenuItem) e.getSource();
ChatPanel chatPanel = sendPanel.getChatPanel();
MainFrame mainFrame = chatPanel.getChatWindow().getMainFrame();
Enumeration i = contactsTable.keys();
while(i.hasMoreElements()) {
Contact protocolContact = (Contact) i.nextElement();
if (contactsTable.get(protocolContact).equals(menuItem)) {
OperationSetBasicInstantMessaging im
= mainFrame.getProtocolIM(
protocolContact.getProtocolProvider());
OperationSetTypingNotifications tn
= mainFrame.getTypingNotifications(
protocolContact.getProtocolProvider());
chatPanel.setImOperationSet(im);
chatPanel.setTnOperationSet(tn);
chatPanel.setProtocolContact(protocolContact);
setSelected(
protocolContact, menuItem.getIcon());
break;
}
}
}
/**
* Obtains the status icon for the given protocol contact and
* adds to it the account index information.
* @param protoContact the proto contact for which to create the image
* @return the indexed status image
*/
public Image createContactStatusImage(Contact protoContact)
{
Image statusImage = ImageLoader.getBytesInImage(
protoContact.getPresenceStatus().getStatusIcon());
int index = sendPanel.getChatPanel().getChatWindow().getMainFrame()
.getProviderIndex(protoContact.getProtocolProvider());
Image img = null;
if(index > 0) {
BufferedImage buffImage = new BufferedImage(
22, 16, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D)buffImage.getGraphics();
AlphaComposite ac =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
AntialiasingManager.activateAntialiasing(g);
g.setColor(Color.DARK_GRAY);
g.setFont(Constants.FONT.deriveFont(Font.BOLD, 9));
g.drawImage(statusImage, 0, 0, null);
g.setComposite(ac);
g.drawString(new Integer(index).toString(), 14, 8);
img = buffImage;
}
else {
img = statusImage;
}
return img;
}
/**
* Updates the protocol contact status.
* @param protoContact the protocol contact to update
*/
public void updateContactStatus(Contact protoContact)
{
JMenuItem menuItem = (JMenuItem)contactsTable.get(protoContact);
Icon icon = new ImageIcon(createContactStatusImage(protoContact));
menuItem.setIcon(icon);
if(getSelectedObject().equals(protoContact))
{
this.setIcon(icon);
}
}
/**
* Sets the selected contact to the given proto contact.
* @param protoContact the proto contact to select
*/
public void setSelected(Contact protoContact)
{
this.setSelected(protoContact,
new ImageIcon(createContactStatusImage(protoContact)));
}
}
Loading…
Cancel
Save