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

📄 sendclusterimwindow.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    	else
    		lblName.setImage(res.getImage(Resources.icoDialog));
    	
        if(model.isPermanent())
            lblName.setText(model.name + " (" + model.externalId + ')');
        else 
            lblName.setText(model.name);
    }

    /**
     * 设置列表提示文本
     * 
     * @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)));
    }
    
    /**
     * 停止闪烁图标
     */
    protected void stopBlinkImage() {
        blinkRunnable.setStop(true);
    }
    
    /**
     * 开始闪烁图标
     */
    public void startBlinkImage() {
        if(!blinkRunnable.isStop()) return;
        blinkRunnable.setStop(false);
        main.getDisplay().timerExec(0, blinkRunnable);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getShellStyle()
     */
	@Override
    protected int getShellStyle() {
		int onTop = main.getOptionHelper().isIMOnTop() ? SWT.ON_TOP : SWT.NONE;
		if(LumaQQ.IS_GTK)
			return SWT.NO_TRIM | SWT.NO_BACKGROUND | onTop;
		else
			return SWT.SHELL_TRIM | onTop;
    }
    
    /**
     * 设置窗口激活
     */
    public void setActive() {
        getShell().setActive();
    }
    
    /**
     * 设置最小化状态
     * 
     * @param b
     */
    public void setMinimized(boolean b) {
        getShell().setMinimized(b);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#open()
     */
	@Override
    public int open() {
        int ret = super.open();
		// 设置输入框获得焦点,设置输入框的字体和颜色
		inputBox.setFocus();
		if(main.getDefaultStyle() != null)
			inputBox.setDefaultStyle(main.getDefaultStyle());
		// 添加自己为QQ listener
        main.getClient().addQQListener(this);
		// 得到在线成员
		if(model.isPermanent())
		    main.getClient().getClusterOnlineMember(model.clusterId);
		
        return ret;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getInitialSize()
     */
	@Override
    protected Point getInitialSize() {
        return new Point(470, 430);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
     */
    protected Point getInitialLocation(Point initialSize) {
		// 缺省实现是把窗口居中
		Rectangle displayRect = main.getDisplay().getClientArea();
		return new Point((displayRect.width - initialSize.x) / 2, (displayRect.height - initialSize.y) / 2);
    }

    /**
     * @param c
     * 		群model
     * @param im
     * 		群消息结构
     * @param me
     * 		true表示是我自己
     * @param timestamp
     * 		时间
     */
    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.fontStyle);
		outputBox.appendText(im.message, 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 image
     */
    public void refreshClusterInfo() {
        setClusterNameLabel();
        listViewer.refresh();
        setListLabel(model.members.size(), model.getOnlineMemberCount());
        setNotice(model.notice);
    }

    /**
     * 设置群公告
     * 
     * @param notice
     */
    private void setNotice(String notice) {
    	if(notice != null && infoForm != null)
    		textNotice.setText(notice);
	}

	/**
     * @return
     * 		true表示当前窗口是活动窗口
     */
    public boolean isActive() {
        return active;
    }
    
    /**
	 * 打开与某个成员的聊天窗口
	 * 
	 * @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);
		}
	}
	
	/**
	 * 发送群消息
	 * @param string
	 */
	protected void sendMessage(String s) {
	    // 检查消息是否为空
	    if(s.length() == 0) {
	        MessageDialog.openWarning(getShell(), message_box_common_warning_title, message_box_cannot_send_empty_message);
	        return;
	    }
	    // 判断用户是否登录
		if(main.getClient().getUser().isLoggedIn()) {
		    workflow.setOriginalMessage(s);
		    workflow.start();
		} else {
		    MessageDialog.openWarning(getShell(), message_box_common_warning_title, message_box_please_login_first);
		}
	}
    
    /**
     * 显示记录控件
     */
    private void showRecord() {
        GridData gd = (GridData)viewer.getLayoutData();
        Shell shell = getShell();
		if(gd.exclude) {
			gd.exclude = false;
			viewer.refreshRecord();
		} else {
			gd.exclude = true;
		}
        if(!shell.getMaximized()) {
			Point p = shell.getSize();
			shell.setSize(p.x, p.y + (gd.exclude ? -205 : 205));						    
		}  
		viewer.setVisible(!gd.exclude);
        viewer.getParent().layout();
        shell.layout();
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.qq.events.IQQListener#qqEvent(edu.tsinghua.lumaqq.qq.events.QQEvent)
     */
    public void qqEvent(QQEvent e) {
		switch(e.type) {
			case QQEvent.QQ_GET_CLUSTER_INFO_FAIL:
			case QQEvent.QQ_GET_MEMBER_INFO_FAIL:
			case QQEvent.QQ_GET_ONLINE_MEMBER_FAIL:
			case QQEvent.QQ_GET_TEMP_CLUSTER_INFO_FAIL:
				processClusterCommandFail(e);
				break;
			default:
		        workflow.delegateQQEvent(e);
				break;
		}
    }

	/**
	 * <pre>
	 * 处理群命令失败事件:失败时,弹出一个对话框提示,如果错误类型表示自己已经不是这个群的
	 * 成员,则移除这个群
	 * </pre>
	 * @param e
	 */
	private void processClusterCommandFail(QQEvent e) {
		final ClusterCommandReplyPacket packet = (ClusterCommandReplyPacket)e.getSource();
		if(packet.clusterId == model.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);
        }
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.IIMSender#send(java.lang.String)
     */
    public void send(String msg) {
	    // 发送	    
	    LineStyle style = main.getDefaultStyle();
		if(model.isPermanent())
		    main.getClient().sendClusterIM(
		            model.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(
		            model.clusterType.toQQConstant(),
		            model.clusterId, 
		            model.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 = model.clusterId;
	    key.sender = main.getMyModel().qq;
	    key.senderParent = model.clusterId;
	    key.receiver = model.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 model.clusterId;
    }

	/**
	 * 关闭窗口
	 */
	public void closeWindow() {
		getShell().close();
	}
}

⌨️ 快捷键说明

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