📄 nicklistrenderer.java
字号:
/* Copyright (C) 2003 Adam Olsen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */package com.valhalla.jbother.groupchat;import java.awt.Component;import java.net.URL;import java.util.Locale;import java.util.ResourceBundle;import javax.swing.ImageIcon;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.ListCellRenderer;import com.valhalla.jbother.StatusIconCache;import com.valhalla.jbother.jabber.MUCBuddyStatus;import com.valhalla.settings.Settings;/** * Renders the JList that represents the nickname list in a groupchat * * @author Adam Olsen * @version 1.0 */public class NickListRenderer extends JLabel implements ListCellRenderer { private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault()); private ChatRoomPanel window; /** * Sets up the renderer * * @param window * the window that this nicklist belongs to */ public NickListRenderer(ChatRoomPanel window) { this.window = window; setOpaque(true); } /** * @see ListCellRenderer */ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { MUCBuddyStatus buddy = window.getBuddyStatus((String) value); String nick = ""; String room = ""; int a = buddy.getUser().indexOf("/"); if (a > -1) { room = buddy.getUser().substring(0, a); nick = buddy.getUser().substring(a + 1); } else { //just in case nick = buddy.getUser(); room = buddy.getUser(); } if (Settings.getInstance().getProperty("statusTheme") == null) Settings.getInstance().setProperty("statusTheme", "default"); ImageIcon icon = StatusIconCache.getStatusIcon(buddy.getPresence(buddy .getHighestResource())); if (icon != null) setIcon(icon); URL light = getClass().getClassLoader().getResource( "images/lightbulb.png"); String tooltip = "<html><table border='0'><tr><td valign='top'><img src='" + light.toString() + "'></td><td>" + "<b><font size='+1'>" + nick + "</font></b>" + "<table border='0' cellpadding='2' cellspacing='2'>"; // role and affiliation information String role = buddy.getRole(); if (role == null || role.equals("")) role = "none"; String affiliation = buddy.getAffiliation(); if (affiliation == null || affiliation.equals("")) affiliation = "none"; if (buddy.getJid() != null) tooltip += "<tr><td><b>JID:</b></td><td>" + buddy.getJid() + "</td></tr>\n"; tooltip += "<tr><td><b>Role:</b></td><td>" + role + "</td></tr>\n"; tooltip += "<tr><td><b>Affiliation:</b></td><td>" + affiliation + "</td></tr>\n"; String statusMessage = buddy.getStatusMessage(buddy .getHighestResource()); if (statusMessage != null && !statusMessage.equals("")) { tooltip += "<tr><td><b>" + this.resources.getString("status") + ":</b></td><td>" + statusMessage + "</td></tr>"; } String using = buddy.getVersionInfo(); if (using != null) { tooltip += "<tr><td nowrap><b>" + this.resources.getString("using") + ":</b></td><td nowrap>" + using + "</td></tr>"; } tooltip += "</table></td></tr></table></html>"; setToolTipText(tooltip); URL type = getClass().getClassLoader().getResource( "imagethemes/muc/default/" + buddy.getRole() + ".png"); if (getClass().getClassLoader().getResource( "imagethemes/muc/default/" + buddy.getAffiliation() + ".png") != null) { type = getClass().getClassLoader().getResource( "imagethemes/muc/default/" + buddy.getAffiliation() + ".png"); } if (type == null) { type = getClass().getClassLoader().getResource( "imagethemes/muc/default/blank.png"); } if (type != null) { nick = "<html><img src='" + type.toString() + "'> " + nick + "</html>"; } setText(nick); setBackground(isSelected ? list.getSelectionBackground() : list .getBackground()); setForeground(isSelected ? list.getSelectionForeground() : list .getForeground()); list.validate(); return this; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -