📄 buddylist.java
字号:
* Sets whether or not we have signed off * *@param value true if we have signed off */ public void setSignoff( boolean value ) { this.signoff = value; } /** * Gets whether or not we have signed off * *@return true if we have signed off */ public boolean getSignoff() { return signoff; } /** * Gets the displayed name, or "me" * *@return the myDisplayedName setting */ public String getMyName() { if( Settings.getInstance().getProperty( "myDisplayedName" ) != null ) { return Settings.getInstance().getProperty( "myDisplayedName" ); } return connection.getUser(); } /** * Listens for user input events. If JBother is set to go "Away" on idle, * this will restart the idle timer. * *@author Adam Olsen *@created October 26, 2004 *@version 1.0 */ public class MyAWTEventListener implements AWTEventListener { /** * Called by the event listener * *@param evt the event */ public void eventDispatched( AWTEvent evt ) { setLastActive(); if( awayTimer.isRunning() ) { awayTimer.restart(); } else if( idleAway ) { setStatus( Presence.Mode.AVAILABLE, getCurrentStatusString(), false ); awayTimer.start(); idleAway = false; } } } /** * Closes the application */ public void quitHandler() { saveSettings(); if( connection != null && connection.isConnected() ) { connection.close(); } //and finally close the connection com.valhalla.Logger.closeLog(); System.exit( 0 ); } /** * signs off, clears the buddy list */ public void signOff() { pingTimer.stop(); signoff = false; buddyListTree.clearBuddies(); awayTimer.stop(); currentMode = null; sendStatusChangedEvent(); if( connection != null ) { if( !statusMenu.blinkTimerIsRunning() ) { statusMenu.startBlinkTimer(); } Thread thread = new Thread( new ConnectionCloseThread() ); thread.start(); } if( buddyStatuses != null ) { Iterator iterator = buddyStatuses.keySet().iterator(); while( iterator.hasNext() ) { String user = (String)iterator.next(); BuddyStatus buddy = (BuddyStatus)buddyStatuses.get( user ); buddy.resetBuddy(); if( buddy.getConversation() != null && buddy.getConversation() instanceof ChatPanel ) { ( (ChatPanel)buddy.getConversation() ).disconnected(); } } } if( tabFrame != null ) { ArrayList remove = new ArrayList(); TabbedPanel pane = tabFrame.getTabPane(); for( int i = 0; i < pane.getTabCount(); i++ ) { TabFramePanel panel = (TabFramePanel)pane.getTabAt(i).getContentComponent(); if( panel instanceof ChatRoomPanel ) { remove.add( panel ); } } for( int i = 0; i < remove.size(); i++ ) { TabFramePanel panel = (TabFramePanel)remove.get( i ); removeTabPanel( panel ); ( (ChatRoomPanel)panel ).leave(); } } } /** * Description of the Class * *@author synic *@created April 12, 2005 */ class ConnectionCloseThread implements Runnable { /** * Main processing method for the ConnectionCloseThread object */ public void run() { connection.close(); SwingUtilities.invokeLater( new Runnable() { public void run() { statusMenu.stopBlinkTimer(); statusMenu.setIcon( (Presence.Mode)null ); } } ); connection = null; } } /** * Close down the buddy list. Also closes down any other windows that might * be open */ public void kill() { if( tabFrame != null ) { tabFrame.leaveAll(); } saveSettings(); setVisible( false ); currentMode = Presence.Mode.AVAILABLE; currentStatusString = resources.getString( "available" ); connection = null; awayTimer.stop(); Vector panels = MessageDelegator.getInstance().getPanels(); int size = panels.size(); for( int i = 0; i < size; i++ ) { ConversationPanel panel = (ConversationPanel)panels.get( 0 ); panel.closeHandler(); } panels.removeAllElements(); DialogTracker.kill(); signoff = false; } /** * Gets a list of blocked users * *@return the list of blocked users */ public Hashtable getBlockedUsers() { return blockedUsers; } /** * Sets the list of blocked users * *@param users the list of blocked users */ public void setBlockedUsers( Hashtable users ) { this.blockedUsers = users; } /** * Gets the GnuPG password * *@return GnuPG password */ public String getGnuPGPassword() { return gnupgPassword; } /** * Sets the GnuPG password * *@param gnupgPassword GnuPG password */ public void setGnuPGPassword( String gnupgPassword ) { this.gnupgPassword = gnupgPassword; } /** * Gets the encryption status * *@return encryption status */ public boolean isEncrypting() { return encrypting; } /** * Sets the encryption status * *@param variant encryption status */ public void isEncrypting( boolean variant ) { this.encrypting = variant; } /** * Updates all the dialogs window icons */ public void updateIcons() { StatusIconCache.clearStatusIconCache(); ImageIcon icon = StatusIconCache.getStatusIcon( org.jivesoftware.smack.packet.Presence.Mode.AVAILABLE ); if( icon != null ) {// statusMenu.setIcon(icon); } statusMenu.reloadStatusIcons(); } /** * send StatusChanged event to plugins (and mb elsewhere too) */ private void sendStatusChangedEvent() { StatusChangedEvent event = new StatusChangedEvent( getInstance() ); PluginChain.fireEvent( event ); } /** * Set the current status by sending a Jabber packet * *@param mode the mode to set it to *@param defaultMessage the status message to set it to *@param getMessage whether or not to get a new message *@return true if the status packet was sent successfully */ public boolean setStatus( Presence.Mode mode, String defaultMessage, boolean getMessage ) { String result; if( getMessage ) { StatusDialog statusDlg = new StatusDialog( mode ); return false; } else { result = defaultMessage; } if( result == null || result.equals( "" ) ) { return false; } else { if( Settings.getInstance().getBoolean( "autoAway" ) ) { if( mode == Presence.Mode.AVAILABLE ) { awayTimer.start(); } else { awayTimer.stop(); } } int priority = 5; try { priority = Integer.parseInt( Settings.getInstance().getProperty( "priority", "5" ) ); } catch( NumberFormatException nfe ) { } com.valhalla.Logger.debug( "priority " + priority ); if( !checkConnection() ) { ConnectorThread.getInstance().init( mode, result, idleAway ).start(); return true; } Presence presence = new Presence( Presence.Type.AVAILABLE, result, priority, mode ); GnuPG gnupg = new GnuPG(); String signedData = null; SecureExtension signedExtension = new SecureExtension( "signed" ); String gnupgSecretKey = Settings.getInstance().getProperty( "gnupgSecretKeyID" ); if( JBotherLoader.isGPGEnabled() && Settings.getInstance().getBoolean( "gnupgSignPresence" ) && gnupgSecretKey != null ) { signedData = gnupg.signExtension( result, gnupgSecretKey ); if( signedData != null ) { signedData = signedData.replaceAll( "(\n)+$", "" ); signedExtension.setData( signedData ); presence.addExtension( signedExtension ); } } connection.sendPacket( presence ); setCurrentPresenceMode( mode ); if( !idleAway ) { setCurrentStatusString( result ); } // if the group chat window is open, set the status there too if( getTabFrame() != null ) { getTabFrame().setStatus( mode, result ); } ParsedBuddyInfo info = new ParsedBuddyInfo( connection.getUser() ); BuddyStatus buddy = BuddyList.getInstance().getBuddyStatus( info.getUserId() ); buddy.addResource( info.getResource(), priority, mode, result ); statusMenu.loadSelfStatuses(); updateIcons(); sendStatusChangedEvent(); statusMenu.setModeChecked( mode ); statusButton.setText( resources.getString( mode.toString() ) ); statusButton.repaint(); } return true; } /** * Gets the sendFileChooser attribute of the BuddyList object * *@return The sendFileChooser value */ public JFileChooser getSendFileChooser() { return sendFileChooser; } /** * Gets the receiveFileChooser attribute of the BuddyList object * *@return The receiveFileChooser value */ public JFileChooser getReceiveFileChooser() { return receiveFileChooser; } /** * Gets the statusMenu attribute of the BuddyList object * *@return The statusMenu value */ public SetStatusMenu getStatusMenu() { return statusMenu; } /** * Gets the buddiesMenu attribute of the BuddyList object * *@return The buddiesMenu value */ public BuddyListBuddiesMenu getBuddiesMenu() { return jbMenu; } /** * Sets the lastActive attribute of the BuddyList object */ public void setLastActive() { this.date = new Date().getTime(); } /** * Gets the lastActive attribute of the BuddyList object * *@return The lastActive value */ public long getLastActive() { return this.date/1000; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -