001 /* 002 Copyright (C) 2003 Adam Olsen 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU General Public License as published by 006 the Free Software Foundation; either version 1, or (at your option) 007 any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details. 013 014 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 017 */ 018 019 package com.valhalla.jbother.groupchat; 020 021 import java.awt.Component; 022 import java.net.URL; 023 import javax.swing.*; 024 import com.valhalla.jbother.*; 025 import java.util.*; 026 import org.jivesoftware.smack.*; 027 import org.jivesoftware.smack.packet.*; 028 029 import com.valhalla.gui.*; 030 import com.valhalla.jbother.jabber.BuddyStatus; 031 import com.valhalla.settings.Settings; 032 033 /** 034 * Renders the JList that represents the nickname list in a groupchat 035 * 036 * @author Adam Olsen 037 * @version 1.0 038 */ 039 public class NickListRenderer extends JLabel implements ListCellRenderer 040 { 041 private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault() ); 042 private ChatRoomPanel window; 043 044 /** 045 * Sets up the renderer 046 * @param window the window that this nicklist belongs to 047 */ 048 public NickListRenderer( ChatRoomPanel window ) 049 { 050 this.window = window; 051 setOpaque( true ); 052 } 053 054 /** 055 * @see ListCellRenderer 056 */ 057 public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) 058 { 059 BuddyStatus buddy = window.getBuddyStatus( (String)value ); 060 061 String nick = ""; 062 String room = ""; 063 String parts[] = null; 064 parts = buddy.getUser().split( "\\/" ); 065 066 if( parts.length >= 2 ) 067 { 068 nick = parts[1]; 069 room = parts[0]; 070 } 071 else { //just in case 072 nick = buddy.getUser(); 073 room = buddy.getUser(); 074 } 075 076 if( Settings.getInstance().getProperty( "statusTheme" ) == null ) Settings.getInstance().setProperty( "statusTheme", "default" ); 077 ImageIcon icon = StatusIconCache.getStatusIcon( buddy.getPresence( buddy.getHighestResource() ) ); 078 if ( icon != null ) setIcon( icon ); 079 080 String tooltip = "<html><table border='0'><tr><td valign='top'></td><td>" + 081 "<b><font size='+1'>" + nick + "</font></b>" + 082 "<table border='0' cellpadding='2' cellspacing='2'>"; 083 084 String statusMessage = buddy.getStatusMessage( buddy.getHighestResource() ); 085 if( statusMessage != null && !statusMessage.equals( "" ) ) 086 { 087 tooltip += "<tr><td><b>" + this.resources.getString( "status" ) + 088 ":</b></td><td>" + statusMessage + 089 "</td></tr>"; 090 } 091 092 String using = buddy.getVersionInfo(); 093 if( using != null ) 094 { 095 tooltip += "<tr><td nowrap><b>" + this.resources.getString( "using" ) + 096 ":</b></td><td nowrap>" + using + "</td></tr>"; 097 } 098 099 tooltip += "</table></td></tr></table></html>"; 100 101 setToolTipText( tooltip ); 102 103 setText( nick ); 104 105 setBackground( isSelected ? list.getSelectionBackground() : list.getBackground() ); 106 setForeground( isSelected ? list.getSelectionForeground() : list.getForeground() ); 107 list.validate(); 108 109 return this; 110 } 111 }