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

📄 clusterimcontainer.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		if(packet.clusterId == cluster.clusterId) {
			main.getDisplay().asyncExec(new Runnable() {
				public void run() {
				    MessageDialog.openError(main.getShell(), message_box_common_fail_title, packet.errorMessage);
				}				
			});			
		}
	}
	
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.events.IFaceSelectionListener#faceSelected(edu.tsinghua.lumaqq.ui.IImageProvider, int, int)
     */
    public void faceSelected(IImageSelectorAdvisor provider, int group, int sequence) {
        if(group == 0) {
            int index = res.getFaceCode(sequence);
            if(index != -1)
                inputBox.insertImage(IRichContent.DEFAULT_FACE_TAG, index);
        } else {
            FaceRegistry util = FaceRegistry.getInstance();
            Face face = util.getFace(group - 1, sequence);
            if(face == null)
                return;
            int id = face.getId();
            inputBox.insertImage(IRichContent.CUSTOM_FACE_TAG, id);
        }
    }
    
    /**
     * 设置群公告
     * 
     * @param notice
     */
    private void setNotice(String notice) {
    	if(notice != null && infoForm != null)
    		textNotice.setText(notice);
	}
    
    /**
     * 设置列表提示文本
     * 
     * @param total
     * 		群内人数
     * @param online
     * 		群内在线数
     */
    private void setListLabel(int total, int online) {
        lblList.setText(NLS.bind(cluster_im_list_label, String.valueOf(online), String.valueOf(total)));
    }
    
	/**
	 * 初始化成员菜单
	 */
	private void initMemberMenu() {
		memberMenu = new Menu(getShell());
		// 收发消息
		final MenuItem miSend = new MenuItem(memberMenu, SWT.PUSH);
		miSend.setText(cluster_im_menu_member_send);
		miSend.setImage(res.getImage(Resources.icoSendReceiveMessage));
		miSend.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				openMemberMessageShell();
			}
		});
		// 临时会话
		MenuItem mi = new MenuItem(memberMenu, SWT.PUSH);
		mi.setImage(res.getImage(Resources.icoTempSessionIM));
		mi.setText(menu_friend_temp_session);
		mi.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			    IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();
				if(!selection.isEmpty()) {
					User u = (User)selection.getFirstElement();
					main.getShellLauncher().openTempSessionIMWindow(u.qq);					
				}
			}
		});
		new MenuItem(memberMenu, SWT.SEPARATOR);
		// 加为好友
		final MenuItem miAdd = new MenuItem(memberMenu, SWT.PUSH);
		miAdd.setText(cluster_im_menu_member_add);
		miAdd.setImage(res.getImage(Resources.icoAddFriend));
		miAdd.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			    IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();	    
				if(!selection.isEmpty()) {
					User f = (User)selection.getFirstElement();
					main.getShellLauncher().openAddReceiveSystemMessageShell(f);
					main.getClient().addFriend(f.qq);																	
				}
			}
		});		
		// 查看资料
		mi = new MenuItem(memberMenu, SWT.PUSH);
		mi.setText(cluster_im_menu_member_viewinfo);
		mi.setImage(res.getImage(Resources.icoPersonInfo));
		mi.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			    IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();	    
				if(!selection.isEmpty()) {
					User f = (User)selection.getFirstElement();
					main.getShellLauncher().openUserInfoWindow(f, UserInfoWindow.READ_ONLY);
				}
			}
		});
		// separator
		mi = new MenuItem(memberMenu, SWT.SEPARATOR);
		// 消息管理菜单
		mi = new MenuItem(memberMenu, SWT.CASCADE);
		mi.setText(cluster_im_menu_member_message);
		mi.setImage(res.getImage(Resources.icoMessageManage));
		Menu msgMenu = new Menu(mi);
		mi.setMenu(msgMenu);
		// 导出聊天记录菜单
		mi = new MenuItem(msgMenu, SWT.PUSH);
		mi.setText(cluster_im_menu_member_export);
		mi.setImage(res.getImage(Resources.icoTxtFile));
		mi.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			    IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();	    
				if(!selection.isEmpty()) {
					User f = (User)selection.getFirstElement();
					// 导出
					main.getExportHelper().exportMessage(f);
				}
			}
		});
		// 添加菜单显示事件监听器
		memberMenu.addMenuListener(new MenuAdapter() {
			public void menuShown(MenuEvent e) {
			    IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();	    
				if(selection.isEmpty())
					memberMenu.setVisible(false);
				else {
					User f = (User)selection.getFirstElement();
					// 设置菜单的使能状态,对于好友,可以发消息,不是好友不能发
					boolean b = f.isFriend();
					miSend.setEnabled(b);
					miAdd.setEnabled(!b);
				}
			}
		});
	}
	
    /**
	 * 打开与某个成员的聊天窗口
	 * 
	 * @return 
	 * 		打开的窗口对象,可能为ReceiveMessageShell, 也可能为SendMessageShell
	 */
	protected void openMemberMessageShell() {
	    IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();	    
		if(!selection.isEmpty()) {
			User f = (User)selection.getFirstElement();
			// 在现在的好友中查找这个model
			User f2 = ModelRegistry.getUser(f.qq);
			// 如果找到model为null,说明这个人不是我的好友了,为了界面上的一致
			// 性,把这个人添加到陌生人再打开窗口。否则,这个人肯定已经在model中
			// ,直接打开窗口
			if(f2 == null) {
				/* 否则这个人还不是我的好友 */
				f2 = f;
				main.getBlindHelper().addUser(f2, GroupType.STRANGER_GROUP);
				main.getBlindHelper().refreshGroup(f2.group);
			}
			main.getShellLauncher().openNormalIMWindow(f2);
		}
	}

	public void send(String msg) {
	    // 发送	    
	    LineStyle style = main.getDefaultStyle();
		if(cluster.isPermanent())
		    main.getClient().sendClusterIM(
		    		cluster.clusterId,
		            msg,
		            workflow.getMessageId(), 
		            workflow.getTotalFragments(), 
		            workflow.getCurrentFragment(),
		            style.fontName,
		            (style.fontStyle & SWT.BOLD) != 0,
		            (style.fontStyle & SWT.ITALIC) != 0,
		            false,
		            style.fontSize,
		            style.foreground.getRed(),
		            style.foreground.getGreen(),
		            style.foreground.getBlue());
		else
		    main.getClient().sendTempClusterIM(
		    		cluster.clusterType.toQQConstant(),
		    		cluster.clusterId, 
		    		cluster.parentClusterId, 
		            msg, 
		            workflow.getMessageId(), 
		            workflow.getTotalFragments(), 
		            workflow.getCurrentFragment(),
		            style.fontName,
		            (style.fontStyle & SWT.BOLD) != 0,
		            (style.fontStyle & SWT.ITALIC) != 0,
		            false,
		            style.fontSize,
		            style.foreground.getRed(),
		            style.foreground.getGreen(),
		            style.foreground.getBlue());
	}

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.IIMSender#notifyOver()
     */
    public void notifyOver() {
        main.getDisplay().syncExec(enableRunnable);
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.IIMSender#notifyStart(java.lang.String)
     */
    public void notifyStart(String toBeSent) {
	    // 设置输入框暂时不可写
	    inputBox.setReadonly(true);
	    inputBox.setBackground(Colors.READONLY_BACKGROUND);	    
		// 保存到聊天记录中
	    RecordEntry key = new RecordEntry();
	    key.owner = cluster.clusterId;
	    key.sender = main.getMyModel().qq;
	    key.senderParent = cluster.clusterId;
	    key.receiver = cluster.clusterId;
	    key.time = System.currentTimeMillis();
	    key.type = IKeyConstants.CLUSTER;
	    key.message = toBeSent;
		main.getRecordManager().addRecord(key);
		// 清空发送框
		inputBox.clear();
		// 把发送的消息显示到输出框中
		appendMessage(key);
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.IIMSender#notifyFail(java.lang.String)
     */
    public void notifyFail(String msg) {
	    main.getDisplay().syncExec(enableRunnable);
		appendRunnable.hint = msg;
	    main.getDisplay().syncExec(appendRunnable);
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.IIMSender#notifyTimeout(java.lang.String)
     */
    public void notifyTimeout(String failToSent) {
	    main.getDisplay().syncExec(enableRunnable);
		appendRunnable.hint = NLS.bind(cluster_im_hint_timemout, failToSent);
	    main.getDisplay().syncExec(appendRunnable);
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.IIMSender#getSenderId()
     */
    public int getSenderId() {
        return cluster.clusterId;
    }
    
	/**
	 * 在输出框中添加提示信息
	 * 
	 * @param hint
	 * @param style
	 */
	private void appendHint(String hint, LineStyle style) {
	    outputBox.appendText(hint, style);
	}
	
    /**
     * 往输出框追加消息
     * 
     * @param entry
     * 		RecordEntry
     */
    private void appendMessage(RecordEntry entry) {
		outputBox.appendText('(' + DefaultFace.escapeFaces(main.getMyModel().displayName) + ")  " + DateTool.format(entry.time), myStyle);		
		outputBox.appendText(entry.message, getLineStyle(main.getDefaultStyle()));
    }
	
    /**
     * @param c
     * 		群model
     * @param im
     * 		群消息结构
     * @param me
     * 		true表示是我自己
     */
    public void appendMessage(Cluster c, ClusterIM im, boolean me) {
        User f = c.getMember(im.sender);
        String name = (f == null) ? String.valueOf(im.sender) : DefaultFace.escapeFaces(f.displayName);
		outputBox.appendText('(' + name + ")  " + DateTool.format(im.sendTime), me ? myStyle : otherStyle);
		LineStyle style = getLineStyle(im);
		outputBox.appendText(im.message, style);
    }
	
    /**
     * 得到行样式
     * 
     * @param im
     * @return
     */
    private LineStyle getLineStyle(ClusterIM im) {
        int fontStyle = 0;
        if(im.fontStyle.isBold())
            fontStyle |= SWT.BOLD;
        if(im.fontStyle.isItalic())
            fontStyle |= SWT.ITALIC;
        if(fontStyle == 0)
            fontStyle = SWT.NORMAL;
        
        return getLineStyle(im.fontStyle.getFontName(), 
        		fontStyle, 
        		im.fontStyle.getFontSize(), 
        		im.fontStyle.getRed(), 
        		im.fontStyle.getGreen(), 
        		im.fontStyle.getBlue());
    }
    
    /**
     * 根据一个现有的style,在cache里面查找一个相同的style,没有则新建一个
     * 
     * @param style
     * @return
     */
    private LineStyle getLineStyle(LineStyle ls) {
        int size = styleCache.size();
        for(int i = 0; i < size; i++) {
            LineStyle style = styleCache.get(i);
            if(style.equals(ls))
                return style;
        }
        
        LineStyle style = (LineStyle)ls.clone();
        styleCache.add(style);
        return style;
    }
    
    /**
     * 根据具体的样式信息查找style
     * 
     * @param fontName
     * @param fontStyle
     * @param fontSize
     * @param red
     * @param green
     * @param blue
     * @return
     */
    private LineStyle getLineStyle(String fontName, int fontStyle, int fontSize, int red, int green, int blue) {        
        int size = styleCache.size();
        for(int i = 0; i < size; i++) {
            LineStyle style = styleCache.get(i);
            if(!style.fontName.equals(fontName))
                continue;
            if(style.fontSize != fontSize)
                continue;            
            if(style.fontStyle != fontStyle)
                continue;
            // TODO add underline here
            if(style.foreground.getRed() != red)
                continue;
            if(style.foreground.getGreen() != green)
                continue;
            if(style.foreground.getBlue() != blue)
                continue;
            return style;
        }
        
        LineStyle style = new LineStyle(new Color(main.getDisplay(), red, green, blue), null, fontName, fontStyle, fontSize);
        styleCache.add(style);
        return style;
    }

	public void release() {
		dispose();
	}

	public void setKeyboardFocus() {
		inputBox.setFocus();
	}

	public void init() {
		inputBox.setDefaultStyle(main.getDefaultStyle());
		main.getClient().getClusterInfo(cluster.clusterId);
	}

	public boolean isActiveContainer() {
		return true;
	}

	public void appendText(String text) {
		inputBox.appendText(text, main.getDefaultStyle());
	}
}

⌨️ 快捷键说明

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