contactlist tree ongoing work: load the tree from a server contactlist, show the status of the contacts,etc.

cusax-fix
Yana Stamcheva 20 years ago
parent 4bff318284
commit ef0834ca30

@ -73,15 +73,14 @@ public Component getTreeCellRendererComponent(JTree tree, Object value,
// Find out which node we are rendering and get its text
ContactNode node = (ContactNode) value;
if(leaf){
if(leaf){
if (node.getUserObject() instanceof MetaContact) {
MetaContact contactItem = (MetaContact) node.getUserObject();
this.nameLabel.setText(contactItem.getDisplayName());
//this.nameLabel.setIcon(contactItem.getUserIcon());
this.nameLabel.setIcon(new ImageIcon(node.getIcon()));
this.nameLabel.setFont(this.getFont().deriveFont(Font.PLAIN));
@ -95,7 +94,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value,
else{
if (node.getUserObject() instanceof MetaContactGroup) {
GroupItem groupItem = (GroupItem) node.getUserObject();
MetaContactGroup groupItem = (MetaContactGroup) node.getUserObject();
this.nameLabel.setText(groupItem.getGroupName());

@ -21,6 +21,7 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
@ -38,13 +39,7 @@
*/
public class ContactListPanel extends JScrollPane
implements MouseListener {
private MetaContactListService contactList;
private MetaContactGroup root;
private ContactNode rootNode;
private MainFrame parent;
private ContactListTree contactListTree;
@ -62,19 +57,6 @@ public ContactListPanel(MainFrame parent) {
this.treePanel.setBackground(Color.WHITE);
}
private void initTree() {
this.root = this.contactList.getRoot();
this.rootNode = new ContactNode(this.root);
this.contactListTree = new ContactListTree(rootNode);
this.contactListTree.addMouseListener(this);
this.treePanel.add(contactListTree, BorderLayout.NORTH);
}
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
@ -208,7 +190,6 @@ public void run() {
}
}
private class RunInfoWindow implements Runnable {
@ -237,15 +218,18 @@ public void run() {
}
}
public MetaContactListService getContactList() {
return contactList;
}
public void setContactList(MetaContactListService contactList) {
public void initTree(MetaContactListService contactList) {
this.contactList = contactList;
this.contactListTree = new ContactListTree(contactList);
this.initTree();
this.contactListTree.addMouseListener(this);
this.treePanel.add(contactListTree, BorderLayout.NORTH);
}
public ContactListTree getContactListTree(){
return this.contactListTree;
}
}

@ -8,6 +8,7 @@
package net.java.sip.communicator.impl.gui.main.contactlist;
import java.awt.Cursor;
import java.util.Enumeration;
import java.util.Iterator;
import javax.swing.BorderFactory;
@ -19,17 +20,33 @@
import net.java.sip.communicator.impl.gui.main.ui.SIPCommTreeUI;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.contactlist.MetaContactGroup;
import net.java.sip.communicator.service.contactlist.MetaContactListService;
import net.java.sip.communicator.service.contactlist.event.MetaContactEvent;
import net.java.sip.communicator.service.contactlist.event.MetaContactGroupEvent;
import net.java.sip.communicator.service.contactlist.event.MetaContactListListener;
import net.java.sip.communicator.service.protocol.Contact;
public class ContactListTree extends JTree {
public class ContactListTree extends JTree
implements MetaContactListListener {
private ContactListTreeModel treeModel;
private ContactNode rootNode;
private MetaContactListService contactList;
private MetaContactGroup root;
public ContactListTree(ContactNode rootNode){
public ContactListTree(MetaContactListService contactList){
this.rootNode = rootNode;
this.contactList = contactList;
this.contactList.addContactListListener(this);
this.root = contactList.getRoot();
this.rootNode = new ContactNode(this.root);
this.treeModel = new ContactListTreeModel(rootNode);
this.setModel(this.treeModel);
@ -55,7 +72,7 @@ public ContactListTree(ContactNode rootNode){
((BasicTreeUI)this.getUI()).setRightChildIndent(0);
}
/**
* Adds a child directly to the root node.
*
@ -138,4 +155,75 @@ public void addAllContacts(ContactNode groupNode, MetaContactGroup group){
}
}
}
public void metaContactAdded(MetaContactEvent evt) {
this.addChild(this.rootNode, evt.getSourceContact(), true);
}
public void metaContactRemoved(MetaContactEvent evt) {
}
public void metaContactGroupAdded(MetaContactGroupEvent evt) {
MetaContactGroup contactGroup = evt.getSourceContactGroup();
ContactNode newGroupNode
= this.addChild(this.rootNode, contactGroup, true);
Iterator childContacts = contactGroup.getChildContacts();
while (childContacts.hasNext()){
MetaContact childContact
= (MetaContact)childContacts.next();
this.addChild(newGroupNode, childContact, true);
}
}
public void metaContactGroupRemoved(MetaContactGroupEvent evt) {
// TODO Auto-generated method stub
}
public MetaContactGroup getRoot() {
return root;
}
public ContactNode getRootNode() {
return rootNode;
}
public ContactNode contains(Contact contact){
return this.contains(this.rootNode, contact);
}
private ContactNode contains( ContactNode parentNode,
Contact contact){
Enumeration childNodes = parentNode.children();
while(childNodes.hasMoreElements()){
ContactNode node = (ContactNode)childNodes.nextElement();
if(node.getUserObject() instanceof MetaContact){
MetaContact currentContact = (MetaContact)node.getUserObject();
if(currentContact.getDefaultContact().getAlias()
.equals(contact.getAlias())){
return node;
}
}
else if(node.getUserObject() instanceof MetaContactGroup){
return this.contains(node, contact);
}
}
return null;
}
}

@ -7,8 +7,11 @@
package net.java.sip.communicator.impl.gui.main.contactlist;
import java.awt.Image;
import javax.swing.tree.DefaultMutableTreeNode;
import net.java.sip.communicator.impl.gui.main.utils.ImageLoader;
import net.java.sip.communicator.service.contactlist.MetaContact;
import net.java.sip.communicator.service.contactlist.MetaContactGroup;
@ -16,6 +19,8 @@ public class ContactNode extends DefaultMutableTreeNode {
private boolean leafExpanded = false;
private Image icon = ImageLoader.getImage(ImageLoader.USER_OFFLINE_ICON);
public ContactNode(){
}
@ -50,5 +55,13 @@ public boolean isLeafExpanded() {
public void setLeafExpanded(boolean leafExpanded) {
this.leafExpanded = leafExpanded;
}
public Image getIcon() {
return icon;
}
public void setIcon(Image icon) {
this.icon = icon;
}
}

Loading…
Cancel
Save