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

📄 buddytree.java

📁 java实现msn的功能
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	/**
	 * 荤侩磊俊霸 富阑 吧锭 荤侩茄促.
	 *
	 * Old implementation: <p>
	 *   秦寸 模备客 楷搬等 技记捞 乐绰瘤 茫酒夯 饶,
	 *   捞固 肝绢柳 技记捞 绝促搁, 悼扁皋家靛 doCallWait栏肺 技记阑 楷搬茄促.
	 *   父距 技记捞 楷搬登瘤 臼疽促搁, 梆官肺 return窍哥,
	 *   技记阑 茫疽芭唱 货肺 肝绰单 己傍窍看促搁, sessionMap(促捞倔肺弊 焊包甘)
	 *   俊辑 秦寸 sid甫 啊柳 Dialog啊 乐绰瘤 茫酒夯 饶, 绝栏搁 货肺 父甸绢 持绊,
	 *   乐栏搁 波郴辑 show茄促.
	 * <p>
	 * Current implementation: <p>
	 *   Pre-dialog啊 乐绰瘤 炼荤窍绊, 父距 绝促搁, 促捞倔肺弊 积己 饶,
	 *   PreDialog table俊 put茄饶, show 茄促.
	 */
	void createNewSession( MsnFriend friend )
	{
		if( friend.getStatus()==UserStatus.OFFLINE )
			return;

		String loginName = friend.getLoginName();

		ChatDialog cd = (ChatDialog)dialogMap.get(loginName);
		if( cd!=null )
		{
			cd.show();
			cd.requestFocus();
			return;
		}

		cd = new ChatDialog( main, msnm, loginName, me );
		cd.setIconImage( chatIcon );
		cd.addWindowListener( new DisposeAdapter() );
		dialogMap.put( loginName, cd );
		cd.show();

		try
		{
			msnm.doCall( loginName );
		}
		catch( IOException e )
		{
			cd.dispose();
		}
	}

	/**
	 * 惑措规栏肺何磐 皋矫瘤啊 吭阑版快, 茫绊磊 窍绰 荤侩磊啊 绝阑锭 荐青登绰 皋家靛捞促.
	 */
	protected void createNewSession(
		SwitchboardSession ss, final MsnFriend friend, final MimeMessage msg )
	{
		String loginName = friend.getLoginName();

		ChatDialog chat = null;
		if( (chat=(ChatDialog)dialogMap.get(loginName))==null )
		{
			chat = new ChatDialog(main, msnm, ss, me);
			chat.setIconImage( chatIcon );
			chat.addWindowListener( new DisposeAdapter() );
			dialogMap.put( loginName, chat );
		}
		else
			chat.setSession( ss );

		sessionMap.put( ss.getSessionId(), chat );
		final ChatDialog fChat = chat;
		chat.addComponentListener( new ComponentAdapter() {
			public void componentShown( ComponentEvent e )
			{
				fChat.appendMessage( friend, msg );
				fChat.removeComponentListener( this );
			}
		});
		SwingUtilities.invokeLater( new Runnable() {
			public void run()
			{
				fChat.show();
				fChat.requestFocus();
			}
		});
	}

	public MsnFriend getSelectedFriend()
	{
		TreePath path = getSelectionPath();
		if( path==null || path.getPathCount()!=3 )
			return null;

		Object o = path.getLastPathComponent();
		if( o instanceof DefaultMutableTreeNode )
			o = ((DefaultMutableTreeNode)o).getUserObject();
		if( o instanceof MsnFriend )
			return (MsnFriend)o;
		return null;
	}

	public Group getSelectedGroup()
	{
	    TreePath path = getSelectionPath();
		if( path==null || path.getPathCount()!=2 )
			return null;

		Object o = path.getLastPathComponent();
		if( o instanceof DefaultMutableTreeNode )
			o = ((DefaultMutableTreeNode)o).getUserObject();
		if( o instanceof Group )
			return (Group)o; 
		return null;
	}

	public void setMyStatus( String mode )
	{
		MsnFriend me = (MsnFriend)root.getUserObject();
		me.setStatus( mode );
		repaint();
	}

	public void toggleOfflineView()
	{
	    setOfflineView( !this.offView );
	}

	/**
	 * 坷橇扼牢 荤侩磊 钎矫 咯何甫 Toggle 茄促.
	 * 弊府绊 泅犁 惑怕 咯何绰 泅犁 荤侩磊 LocalCopy俊 历厘等促.
	 */
	public void setOfflineView( boolean offView )
	{
		this.offView = offView;

		LocalCopy lc = main.getMessenger().getLocalCopy();
		lc.setProperty( "View.buddy.offline", String.valueOf(offView) );
		lc.storeInformation();

		if( msnm.isLoggedIn() && isVisible() )
			syncAllUsers();
	}

	/**
	 * 模备甸阑 绢栋茄 mode肺 杭巴牢瘤 搬沥窍绰 巴栏肺,
	 * VIEW_FRIENDLY_NAME, VIEW_LOGIN_NAME阑 汲沥且 荐 乐促.
	 */
	public void setBuddyView( int mode )
	{
		renderer.setBuddyView( mode );
		comparator.setBuddyView( mode );

		if( msnm.isLoggedIn() )
			syncAllUsers();
	}

	/* ----------------------------------------------------------------
	 *                     Inner classes definition
	 * ----------------------------------------------------------------
	 */
	private class BuddyMouseAdapter extends MouseAdapter
	{
		public void mousePressed( MouseEvent e )
		{
			TreePath rootPath = null;
			if( (rootPath=getPathForLocation(e.getX(), e.getY()))!=null )
			{
				int row = getRowForPath( rootPath );

				DefaultMutableTreeNode node =
					(DefaultMutableTreeNode)rootPath.getLastPathComponent();
				if( node==root )
				{
					JPopupMenu pop = main.menuBar.getStatusPopupMenu();
					pop.show( BuddyTree.this, e.getX(), e.getY() );
					return;
				}
			}
		}
		public void mouseClicked( MouseEvent e )
		{
			if( getRowForLocation( e.getX(), e.getY() )==-1 )
				return;	
			TreePath path = getPathForLocation(e.getX(), e.getY());
			if( path==null )
				return;

			if( e.getClickCount() > 1 )
			{
				DefaultMutableTreeNode o = (DefaultMutableTreeNode)path.getLastPathComponent();
				Object uo = o.getUserObject();
				if( uo instanceof MsnFriend && o!=root )
				{
					MsnFriend friend = (MsnFriend)uo;
					createNewSession( friend );
				}
			}
		}
	};

	private class Listener extends MsnAdapter
	{
		public void renameNotify( MsnFriend i )
		{
			if( i==null )
			{
			    JOptionPane.showMessageDialog( BuddyTree.this,
				Msg.get("err.209"),
				Msg.get("title.alarm"), JOptionPane.ERROR_MESSAGE );
				return;
			}

			// 磊扁 磊脚狼 捞抚 函版等 巴阑 利侩茄促.
			if( i.getLoginName().equals(me.getLoginName()) )
			{
				me.setFriendlyName( i.getFriendlyName() );
				SwingUtilities.invokeLater( new Runnable() {
					public void run()
					{
						syncAllUsers();
					}
				});
			}
		}

		public void loginComplete( final MsnFriend owner )
		{
			SwingUtilities.invokeLater( new Runnable() {
				public void run()
				{
					start( owner );
					main.menuBar.enableLogin();
				}
			});
		}
 
		public void notifyUnreadMail( Properties Prop, int unread )
		{
			inboxUnread = unread;	
			main.addEvent( Msg.get("label.inboxunread")+ " : " + unread, null );
		}

		private void refreshGroupNode()
		{
			for(Enumeration e = root.children();e.hasMoreElements();)
			{
				DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement();
				model.reload( node );
			}
		}

		public void listOnline( final MsnFriend friend )
		{
			SwingUtilities.invokeLater( new Runnable() {
				public void run()
				{
					DefaultMutableTreeNode node = findTreeNode(friend);
					if( node==null )
					{
						node = new DefaultMutableTreeNode(friend);
						insertPreferredIndex( findGroupNode(friend.getGroupIndex()), friend, node );
					}
					else
					{
						MsnFriend old = (MsnFriend)node.getUserObject();
						Integer oldGroupIndex = old.getGroupIndex();
						node.setUserObject( friend );

						// 捞哩 Tree俊辑 函版窍咯具 窃
						DefaultMutableTreeNode oldGroup = findGroupNode( oldGroupIndex );
						DefaultMutableTreeNode newGroup = findGroupNode( friend.getGroupIndex() );

						oldGroup.remove( node );
						insertPreferredIndex( newGroup, friend, node );

						model.reload( oldGroup );
						model.reload( newGroup );
					}

					model.reload(node);
					refreshGroupNode();
				}
			});
		}

		public void instantMessageReceived( SwitchboardSession ss, MsnFriend friend,
			MimeMessage msg )
		{
			ChatDialog chat = (ChatDialog)sessionMap.get(ss.getSessionId());

			if( chat!=null ) // Existing session
			{
				chat.appendMessage( friend, msg );
			}
			else             // New session
			{
				createNewSession(ss, friend, msg);
			}
		}

		/**
		 *
		 */
		public void userOnline( final MsnFriend friend )
		{
			final String loginName = friend.getLoginName();
			final String formatStatus = UserStatusBox.getFormattedUserStatus(friend.getStatus());
			final String formatName = friend.getFormattedFriendlyName();

			SwingUtilities.invokeLater( new Runnable() {
			public void run() {
			DefaultMutableTreeNode node = findTreeNode(friend);

			BuddyList list = msnm.getBuddyGroup().getForwardList();
			MsnFriend old = list.get( loginName );

			// 扁粮俊 乐菌绊, 惑怕父 函版窍看阑 版快(捞傈惑怕啊 OFFLINE捞 酒囱版快)
			if( node!=null && !UserStatus.OFFLINE.equals(old.getOldStatus()) )
			{
				main.addEvent( formatStatus + " " + formatName + 
					" (" + loginName + ")", friend );
				old.setFriendlyName( friend.getFriendlyName() );
				old.setStatus( friend.getStatus() );
				node.setUserObject( old );

				node.removeFromParent();
				DefaultMutableTreeNode group = findGroupNode( old.getGroupIndex() );
				insertPreferredIndex( group, old, node );

				model.reload( group );
			}
			// 扁粮俊 绝菌芭唱, 乐菌绰单 坷橇扼牢捞看阑 版快
			else
			{
				if( node==null )
				{
					friend.setGroupIndex( old.getGroupIndex() );
					node = new DefaultMutableTreeNode(friend);

					DefaultMutableTreeNode group = findGroupNode(friend.getGroupIndex());
					insertPreferredIndex( group, friend, node );
					model.reload( group );
				}
				else
				{
					node.removeFromParent();
				    node.setUserObject( friend );

					DefaultMutableTreeNode group = findGroupNode(friend.getGroupIndex());
					insertPreferredIndex( group, friend, node );
					model.reload( group );
				}
				refreshGroupNode();

				main.addEvent( Msg.get("event.login", loginName, formatName), friend );
				MusicBox.play( MusicBox.SOUND_LOGIN );
			}
			}});
		}

		/**
		 * Tree俊辑 秦寸 荤侩磊甫 茫酒辑 惑怕甫 OFFLINE栏肺 函版茄 饶,
		 * Model俊辑 reload茄促.
		 */
		public void userOffline( final String loginName )
		{
			SwingUtilities.invokeLater( new Runnable() {
			public void run() {
			DefaultMutableTreeNode node = findTreeNode(new MsnFriend(loginName,""));
			if( node!=null )
			{
				MsnFriend friend = (MsnFriend)node.getUserObject();
				friend.setStatus( UserStatus.OFFLINE );
				if( offView )
				{
					node.removeFromParent();
				    DefaultMutableTreeNode group = findGroupNode( friend.getGroupIndex() );
					insertPreferredIndex( group, friend, node );
					model.reload( group );
				}
				else
				{
					DefaultMutableTreeNode parent =
						(DefaultMutableTreeNode)node.getParent();

⌨️ 快捷键说明

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