⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buddytree.java

📁 java版本的MSN,供大家交流学习使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		{			String loginName = join.getLoginName();			if( ss.getSessionId()==null )				return;			ChatDialog cd = null;			if( (cd=(ChatDialog)sessionMap.get(ss.getSessionId()))==null )			{				if( (cd=(ChatDialog)dialogMap.get(loginName))==null )					return;				sessionMap.put( ss.getSessionId(), cd );				cd.setSession( ss );			}			if( ss.getFriendCount()>1 )			{				MimeMessage msg = new MimeMessage();				msg.setMessage( Msg.get("chatdlg.msg.whojoin", loginName,					join.getFormattedFriendlyName()) );				cd.appendMessage( msg );			}		}		public void whoPartSession( SwitchboardSession ss, final MsnFriend part )		{		    String loginName = part.getLoginName();			ChatDialog cd = null;			if( (cd=(ChatDialog)sessionMap.get(ss.getSessionId()))!=null )			{				MimeMessage msg = new MimeMessage();			    // 富绝捞 5盒 版苞窍搁 SS俊辑 磊悼栏肺 楷搬阑 谗绢滚赴促.				// 酒贰狼 炼扒篮 泅犁矫埃焊促 5盒救俊 皋矫瘤啊 档馒窍瘤 臼疽阑锭 true捞促.				if( (System.currentTimeMillis() - 300000L) > cd.getLastMessagingTime() )					msg.setMessage( Msg.get("chatdlg.msg.timeout", "5") );				else				    msg.setMessage( Msg.get("chatdlg.msg.whopart", loginName,						part.getFormattedFriendlyName()) );			    cd.appendMessage( msg );			}		}		public void switchboardSessionStarted( SwitchboardSession ss )		{			ss.setTimeout( 0 );			final MsnFriend friend = ss.getMsnFriend();			if( friend!=null )			{				SwingUtilities.invokeLater( new Runnable() {					public void run()					{						main.addEvent( Msg.get("event.ring", friend.getLoginName(),							friend.getFormattedFriendlyName()), friend );					}				});			}		}		public void switchboardSessionEnded( SwitchboardSession ss )		{			ChatDialog cd = (ChatDialog)sessionMap.remove(ss.getSessionId());			if( cd!=null )			{				cd.sessionClosed();				return;			}		}		public void switchboardSessionAbandon( SwitchboardSession ss, String targetName )		{		    ChatDialog cd = (ChatDialog)dialogMap.get( targetName );			if( cd!=null )			{				cd.sessionClosed();				MimeMessage msg = new MimeMessage();				msg.setMessage( Msg.get("chatdlg.msg.ssclose") );				cd.appendMessage( msg );			}		}		public void buddyListModified()		{			nonUpdateCount--;			if( nonUpdateCount < 0 )			{				SwingUtilities.invokeLater( new Runnable() {					public void run()					{						syncAllUsers();					}				});			}		    if( nonUpdateCount < 0 )				nonUpdateCount = 0;		}		public void progressTyping( SwitchboardSession ss, MsnFriend friend, String view )		{			String sid = ss.getSessionId();			ChatDialog cd = (ChatDialog)sessionMap.get(sid);			if( cd!=null )			{				cd.whoTyping( view );			}		}		public void filePosted( SwitchboardSession ss, int cookie, String filename,			int filesize )		{			String sid = ss.getSessionId();			ChatDialog cd = (ChatDialog)sessionMap.get(sid);			if( cd==null )			{				cd = new ChatDialog(main, msnm, ss, me);				cd.setIconImage( chatIcon );				cd.addWindowListener( new DisposeAdapter() );				sessionMap.put( sid, cd );				String ln = ss.getMsnFriend().getLoginName();				if( !dialogMap.containsKey(ln) )					dialogMap.put( ln, cd );				cd.setVisible(true);				cd.requestFocus();			}			cd.addFileItem( new FileItem(ss,cookie,filename,filesize) );		}		public void allListUpdated()		{			SwingUtilities.invokeLater( new Runnable() {				public void run()				{					syncAllUsers();				}			});		}		public void logoutNotify()		{		    SwingUtilities.invokeLater( new Runnable() {				public void run()				{				    main.logout();				}			});		}		public void photoContextUpdated( MsnFriend friend, String ctx )		{			ChatDialog cd = (ChatDialog)dialogMap.get(friend.getLoginName());			if( cd!=null )			{				try				{					cd.getSession().requestPhoto();				}				catch( IOException e )				{					e.printStackTrace();				}			}			System.out.println( "* Photo Context Updated: " + friend.getLoginName() + ", ctx=" + ctx );		}		public void photoUpdated( SwitchboardSession ss, final MsnFriend friend, final Image img )		{			final ChatDialog cd = (ChatDialog)dialogMap.get(friend.getLoginName());						SwingUtilities.invokeLater( new Runnable() {				public void run()				{					if( cd!=null )					{						cd.setFriendPhoto( img );					}					else					{						friend.setPhoto( img );					}				}			});		}	}	private class DisposeAdapter extends WindowAdapter	{		/**		 * sessionMap俊辑 sid俊 秦寸窍绰 Dialog甫 力芭窍绊,		 * dialogMap俊辑 loginName俊 秦寸窍绰 Dialog甫 力芭窍绰 格利		 */		public void windowClosing( WindowEvent e )		{			ChatDialog cd = (ChatDialog)e.getSource();			SwitchboardSession ss = cd.getSession();			if( ss!=null )			{				sessionMap.remove( ss.getSessionId() );				try				{					ss.close();				}				catch( IOException ex ) {}			}			cd.close();			dialogMap.remove( cd.getTitle() );		}	}	public void updateAllDialogs()	{		for(Enumeration e=dialogMap.elements(); e.hasMoreElements(); )		{			ChatDialog cd = (ChatDialog)e.nextElement();			SwingUtilities.updateComponentTreeUI( cd );		}	}    public void dragEnter(DragSourceDragEvent dsde)    {    }    public void dragOver(DragSourceDragEvent dsde)    {	}    public void dropActionChanged(DragSourceDragEvent dsde)    {    }    public void dragExit(DragSourceEvent dse)    {    }    public void dragDropEnd(DragSourceDropEvent dsde)    {    }	private int dragStartGroup = -1;	/**	 * 靛贰弊甫 矫累窍妨绊 且锭, 捞霸 dnd甫 秦具登绰巴牢瘤 酒囱巴牢瘤	 * 魄喊窍绊 父距 MsnFriend 牢胶畔胶啊 嘎促搁, startDrag 皋家靛肺	 * 靛贰弊甫 矫累茄促.	 *	 * @param dge 捞亥飘 按眉	 */    public void dragGestureRecognized(DragGestureEvent dge)    {		Point p = dge.getDragOrigin();		TreePath path = getPathForLocation( p.x, p.y );		if( path==null )	   		return;		Object o = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();		if( o instanceof MsnFriend )		{		    MsnFriend friend = (MsnFriend)o;			dragStartGroup = friend.getGroupIndex().intValue();			String ln = friend.getLoginName();			Transferable t = new StringSelection(ln);			dragSource.startDrag( dge, DragSource.DefaultCopyDrop, t, this );		}    }	// 咯扁辑何磐绰 DragTargetListener interface 狼 implement 何盒捞促.    public void dragEnter(DropTargetDragEvent e)    {    }	private int oldDraggingIndex = -1;    public void dragOver(DropTargetDragEvent e)    {		Point p = e.getLocation();		TreePath path = getPathForLocation( p.x, p.y );		if( path==null )	   		return;		Object o = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();		int groupIndex = -1;		if( o instanceof MsnFriend )		{		    MsnFriend f = (MsnFriend)o;		    groupIndex = f==this.me ? -1 : f.getGroupIndex().intValue();		}		else		if( o instanceof Group )		{			Group g = (Group)o;			groupIndex = g.getIndexInt();		}		if( dragStartGroup==groupIndex )		{			groupIndex = -1;			e.rejectDrag();		}		renderer.setDraggingGroup(groupIndex);		if( oldDraggingIndex!=groupIndex )		{			oldDraggingIndex = groupIndex;		    repaint();		}    }    public void dropActionChanged(DropTargetDragEvent e)    {    }    public void dragExit(DropTargetEvent e)    {		oldDraggingIndex = -1;		renderer.setDraggingGroup(-1);		repaint();    }    public void drop(DropTargetDropEvent e)    {		Point p = e.getLocation();		TreePath path = getPathForLocation( p.x, p.y );		if( path==null )	   		return;		oldDraggingIndex = -1;		renderer.setDraggingGroup(-1);		repaint();		Object o = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();		int groupIndex = -1;		if( o instanceof MsnFriend )			groupIndex = ((MsnFriend)o).getGroupIndex().intValue();		else		if( o instanceof Group )			groupIndex = ((Group)o).getIndexInt();		if( dragStartGroup==groupIndex )			return;		try		{			String loginName = (String)e.getTransferable().getTransferData( DataFlavor.stringFlavor );			e.acceptDrop( DnDConstants.ACTION_MOVE );			e.getDropTargetContext().dropComplete( true );		    BuddyList list = msnm.getBuddyGroup().getForwardList();			MsnFriend friend = list.get(loginName);			friend.setGroupIndex(groupIndex);			nonUpdateCount = 2;			// 角力肺 函版窍档废 瘤矫		    msnm.moveGroupAsFriend( friend, dragStartGroup, groupIndex );			// 捞哩 Tree俊辑 函版窍咯具 窃			DefaultMutableTreeNode oldGroup = findGroupNode( new Integer(dragStartGroup) );			DefaultMutableTreeNode newGroup = findGroupNode( new Integer(groupIndex) );			DefaultMutableTreeNode nodeFriend = this.findTreeNode(friend);			oldGroup.remove( nodeFriend );			insertPreferredIndex( newGroup, friend, nodeFriend );			model.reload( oldGroup );			model.reload( newGroup );		}		catch( Exception ex )		{			e.rejectDrop();		}    }	public void paintComponent( Graphics g )	{		g.setColor( Color.white );		g.fillRect( 0, 0, getWidth(), getHeight() );		if( backImage!=null )		{			JViewport view = (JViewport)getParent();			Point p = view.getViewPosition();			int w = view.getWidth();			int h = view.getHeight();			int iw = backImage.getWidth(null);			int ih = backImage.getHeight(null);			g.drawImage( backImage, w-iw+p.x, h-ih+p.y, null );		}		super.paintComponent( g );	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -