001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.chat.ui.roaster;
019:
020: import java.awt.Component;
021: import java.awt.Font;
022:
023: import javax.swing.ImageIcon;
024: import javax.swing.JTree;
025: import javax.swing.tree.DefaultMutableTreeNode;
026: import javax.swing.tree.DefaultTreeCellRenderer;
027:
028: import org.columba.chat.model.BuddyStatus;
029: import org.columba.chat.model.api.IBuddyStatus;
030: import org.columba.chat.resourceloader.ResourceLoader;
031: import org.jivesoftware.smack.RosterGroup;
032: import org.jivesoftware.smack.packet.Presence;
033:
034: /**
035: * @author fdietz
036: *
037: */
038: public class RoasterTreeRenderer extends DefaultTreeCellRenderer {
039:
040: private ImageIcon available = ResourceLoader
041: .getMiscIcon("available.png");
042:
043: private ImageIcon extendedaway = ResourceLoader
044: .getMiscIcon("extended-away.png");
045:
046: private ImageIcon busy = ResourceLoader.getMiscIcon("busy.png");
047:
048: private ImageIcon offline = ResourceLoader
049: .getMiscIcon("offline.png");
050:
051: /**
052: *
053: */
054: public RoasterTreeRenderer() {
055: super ();
056:
057: }
058:
059: /**
060: * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree,
061: * java.lang.Object, boolean, boolean, boolean, int, boolean)
062: */
063: public Component getTreeCellRendererComponent(JTree arg0,
064: Object arg1, boolean arg2, boolean arg3, boolean arg4,
065: int arg5, boolean arg6) {
066:
067: super .getTreeCellRendererComponent(arg0, arg1, arg2, arg3,
068: arg4, arg5, arg6);
069:
070: Object o = ((DefaultMutableTreeNode) arg1).getUserObject();
071:
072: setIcon(null);
073:
074: if (o instanceof BuddyStatus) {
075: // contact
076: IBuddyStatus entry = (IBuddyStatus) o;
077:
078: String name = entry.getName();
079: Presence.Mode presence = entry.getPresenceMode();
080:
081: setFont(getFont().deriveFont(Font.PLAIN));
082:
083: if (presence != null) {
084: if (presence.equals(Presence.Mode.AVAILABLE)) {
085: setIcon(available);
086: } else if (presence.equals(Presence.Mode.AWAY)) {
087: setIcon(offline);
088: }
089: if (presence.equals(Presence.Mode.EXTENDED_AWAY)) {
090: setIcon(extendedaway);
091: }
092: if (presence.equals(Presence.Mode.CHAT)) {
093:
094: }
095: if (presence.equals(Presence.Mode.DO_NOT_DISTURB)) {
096: setIcon(busy);
097: }
098:
099: }
100:
101: StringBuffer buf = new StringBuffer();
102: if (name != null)
103: buf.append(name + " (" + entry.getJabberId() + ")");
104: else
105: buf.append(entry.getJabberId());
106:
107: if (presence != null) {
108: buf.append(" - " + presence.toString());
109: if (presence.equals(Presence.Mode.EXTENDED_AWAY)) {
110: setToolTipText(entry.getStatusMessage());
111: } else {
112: setToolTipText(presence.toString());
113: }
114: }
115:
116: setText(buf.toString());
117: } else if (o instanceof RosterGroup) {
118: // group
119: RosterGroup group = (RosterGroup) o;
120:
121: setFont(getFont().deriveFont(Font.BOLD));
122: setText(group.getName());
123:
124: } else {
125: setFont(getFont().deriveFont(Font.BOLD));
126: setText(arg1.toString());
127: }
128:
129: return this;
130: }
131: }
|