📄 buddylist.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;import java.awt.*;import java.awt.event.*;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.util.*;import java.lang.reflect.Array;import javax.swing.*;import com.valhalla.jbother.actions.*;import org.jivesoftware.smack.XMPPConnection;import org.jivesoftware.smack.packet.*;import com.valhalla.gui.DialogTracker;import com.valhalla.gui.Standard;import com.valhalla.jbother.groupchat.ChatRoomPanel;import com.valhalla.jbother.jabber.BuddyStatus;import com.valhalla.jbother.jabber.ParsedBuddyInfo;import com.valhalla.jbother.jabber.smack.SecureExtension;import com.valhalla.jbother.menus.BuddyListBuddiesMenu;import com.valhalla.jbother.menus.SetStatusMenu;import com.valhalla.jbother.plugins.events.ConnectEvent;import com.valhalla.jbother.plugins.events.StatusChangedEvent;import com.valhalla.misc.GnuPG;import com.valhalla.pluginmanager.PluginChain;import com.valhalla.settings.*;import net.infonode.tabbedpanel.*;import net.infonode.tabbedpanel.titledtab.*;import net.infonode.util.*;/** * BuddyList is the main controller for the buddy list, as as the buddy list is * the main component of the IM application it performs most of the work once * it's been initialized. * *@author Adam Olsen *@author Andrey Zakirov *@created October 26, 2004 *@update April 10, 2005 *@version 1.0 */public class BuddyList extends JPanel{ private static BuddyList singleton = null; private static JFrame frame; private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault() ); private XMPPConnection connection; //the connection to the jabber server private BuddyListTree buddyListTree; // file choosers used for sending & receiving files private static JFileChooser sendFileChooser = new JFileChooser(); private static JFileChooser receiveFileChooser = new JFileChooser(); private boolean signoff = false; private TabFrame tabFrame; private Hashtable buddyStatuses = null; private Presence.Mode currentMode = null; private String currentStatusString = resources.getString( "available" ); private AwayHandler awayHandler = new AwayHandler(); private javax.swing.Timer awayTimer = new javax.swing.Timer( 600000, awayHandler ); private javax.swing.Timer pingTimer = new javax.swing.Timer( 300000, new PingHandler() ); private boolean idleAway = false; private Hashtable blockedUsers = new Hashtable(); private static BuddyList buddyList = null; private boolean docked = false; private String gnupgPassword = null; private boolean encrypting = false; private Hashtable notDeliveredHash = new Hashtable(); private Hashtable notDisplayedHash = new Hashtable(); private Hashtable notOfflineHash = new Hashtable(); private JButton jbButton = new JButton(); private JButton statusButton = new JButton(); private BuddyListBuddiesMenu jbMenu = new BuddyListBuddiesMenu( this ); private SetStatusMenu statusMenu = new SetStatusMenu( this, true, statusButton ); private long date = new Date().getTime(); private JToggleButton showOffline = new JToggleButton( StatusIconCache.getStatusIcon( (Presence.Mode)null ) ); private JToggleButton showAway = new JToggleButton( StatusIconCache.getStatusIcon( Presence.Mode.AWAY ) ); private JToggleButton sound = new JToggleButton(Standard.getIcon("images/buttons/speaker.png")); /** * Constructor for the buddy list. BuddyList is a singleton, so it's * constructor is private */ private BuddyList() { initComponents(); } /** * Gets the containerFrame attribute of the BuddyList object * *@return The containerFrame value */ public JFrame getContainerFrame() { return frame; } /** * Gets the BuddyList singleton * *@return the BuddyList singleton *@deprecated Use getInstance() instead */ public static BuddyList getSingleton() { return getInstance(); } /** * Gets the BuddyList singleton * *@return the BuddyList singleton */ public static BuddyList getInstance() { if( singleton == null ) { singleton = new BuddyList(); } return singleton; } class PingHandler implements ActionListener { public void actionPerformed( ActionEvent e ) { if( !checkConnection() ) return; if( idleAway ) { BuddyList.getInstance().setStatus(Presence.Mode.AWAY, resources.getString("autoAway"), false); } else { BuddyList.getInstance().setStatus(currentMode,currentStatusString,false); } } } public void updateButtons( String mode ) { ImageIcon icon = Standard.getIcon("imagethemes/statusicons/" + mode + "/offline.png"); showOffline.setIcon( icon ); icon = Standard.getIcon("imagethemes/statusicons/" + mode + "/away.png"); showAway.setIcon( icon ); showOffline.validate(); showAway.validate(); } /** * Returns the top buddy menu * */ /** * Starts the away timer */ public void startTimer() { // start the idle detection timer if( Settings.getInstance().getBoolean( "autoAway" ) ) { com.valhalla.Logger.debug( "Starting away timer" ); awayTimer.start(); } buddyListTree.setConnection( this.connection ); AWTEventListener listener = new MyAWTEventListener(); Toolkit.getDefaultToolkit().addAWTEventListener( listener, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.KEY_EVENT_MASK ); } /** * Loads the blocked users information */ protected void loadBlockedUsers() { File file = new File( JBother.profileDir + File.separatorChar + "blocked" ); String line = ""; try { FileReader fr = new FileReader( file ); BufferedReader in = new BufferedReader( fr ); while( ( line = in.readLine() ) != null ) { blockedUsers.put( line, "blocked" ); com.valhalla.Logger.debug( "Blocked> " + line ); } fr.close(); } catch( IOException e ) { com.valhalla.Logger.debug( "Blocked users file was not found or could not be read." ); return; } } /** * Description of the Method */ private void loadNotDeliveredMessages() { final String notDeliveredMessages = Settings.getInstance().getProperty( "notDeliveredMessages" ); String[] notDeliveredMessage; String[] notDeliveredMessageLast; String[] info = new String[2]; if( notDeliveredMessages != null ) { notDeliveredMessage = notDeliveredMessages.split( ";" ); if( notDeliveredMessage.length > 0 ) { for( int i = 0; i < notDeliveredMessage.length; i++ ) { notDeliveredMessageLast = notDeliveredMessage[i].split( "," ); if( notDeliveredMessageLast.length == 3 ) { info[0] = notDeliveredMessageLast[1]; info[1] = notDeliveredMessageLast[2]; notDeliveredHash.put( notDeliveredMessageLast[0], info ); } } } } } /** * Gets the eventMessage attribute of the BuddyList object * *@param messageId Description of the Parameter *@param type Description of the Parameter *@return The eventMessage value */ public String[] getEventMessage( String messageId, int type ) { Hashtable tempHash; switch ( type ) { case 1: tempHash = notDeliveredHash; break; case 2: tempHash = notDisplayedHash; break; case 3: tempHash = notOfflineHash; break; default: return null; } String[] eventMessage = (String[])tempHash.get( messageId ); tempHash.remove( messageId ); return eventMessage; } /** * Description of the Method * *@param messageId Description of the Parameter *@param userJID Description of the Parameter *@param timeStamp Description of the Parameter *@param type Description of the Parameter *@return Description of the Return Value */ public boolean putEventMessage( String messageId, String userJID, String timeStamp, int type ) { Hashtable tempHash; switch ( type ) { case 1: tempHash = notDeliveredHash; break; case 2: tempHash = notDisplayedHash; break; case 3: tempHash = notOfflineHash; break; default: return false; } if( ( messageId != null ) && ( userJID != null ) && ( timeStamp != null ) ) { String[] info = new String[2]; info[0] = userJID; info[1] = timeStamp; tempHash.put( messageId, info ); return true; } return false; } /** * Gets the statusButton attribute of the BuddyList object * *@return The statusButton value */ public JButton getStatusButton() { return statusButton; } /** * Returns the away timer * *@return the away timer */ public javax.swing.Timer getAwayTimer() { return awayTimer; } /** * Sets the idleAway attribute of the BuddyList object * *@param idleAway The new idleAway value */ public void setIdleAway( boolean idleAway ) { this.idleAway = idleAway; } /** * Gets the idleAway attribute of the BuddyList object * *@return The idleAway value */ public boolean getIdleAway() { return idleAway; } /** * Gets the awayHandler attribute of the BuddyList object * *@return The awayHandler value */ public AwayHandler getAwayHandler() { return awayHandler; } /** * Sets up the current connection * *@param connection the current connection */ public void init( XMPPConnection connection ) { this.connection = connection; if( connection == null ) { return; } if( buddyStatuses == null ) { buddyStatuses = new Hashtable(); } ConnectEvent event = new ConnectEvent( connection ); PluginChain.fireEvent( event ); buddyListTree.setConnection( connection ); statusMenu.setIcon( Presence.Mode.AVAILABLE ); pingTimer.start(); } /** * Clears the buddy tree */ public void clearTree() { buddyListTree.clearBuddies(); } /** * initializes the buddy tree by loading the offline buddies */ public void initBuddies() { buddyListTree.loadOfflineBuddies(); } /** * Sets the current presence mode * *@param mode the mode to set it to */ public void setCurrentPresenceMode( Presence.Mode mode ) { this.currentMode = mode; } /** * Sets the current status string * *@param string the string to use */ public void setCurrentStatusString( String string ) { this.currentStatusString = string; } /** * Gets the current presence mode * *@return the current presence mode */ public Presence.Mode getCurrentPresenceMode() { return this.currentMode; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -