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

📄 clusterimcontainer.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    item.setToolTipText(tooltip_button_hide);
				}
				
                sideContainer.getParent().layout();
            }
        });
        
        // 垂直sash
        vSash = new Sash(this, SWT.VERTICAL);
        gd = new GridData(GridData.FILL_VERTICAL);
        gd.verticalSpan = 2;
		vSash.setLayoutData(gd);
		vSash.setBackground(Colors.MAINSHELL_BACKGROUND);
		vSash.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                GridData d = (GridData)sideContainer.getLayoutData();   
                GridLayout l = (GridLayout)sideContainer.getParent().getLayout();
                d.widthHint = sideContainer.getParent().getClientArea().width - e.x - (l.marginWidth << 1);
                sideContainer.getParent().layout();
            }
        });
        
        // 成员列表区
        sideContainer = new Composite(this, SWT.NONE);
        gd = new GridData(GridData.FILL_VERTICAL);
        gd.verticalSpan = 2;
        gd.widthHint = 140;
        sideContainer.setLayoutData(gd);
        layout = new GridLayout();
        layout.marginHeight = layout.marginWidth = 1;
        layout.horizontalSpacing = layout.verticalSpacing = 0;
        sideContainer.setLayout(layout);
        sideContainer.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                Composite c = (Composite)e.getSource();
                Rectangle rect = c.getClientArea();
                rect.width--;
                rect.height--;
                if(rect.width > 0 && rect.height > 0) {
	                e.gc.setForeground(Colors.WIDGET_BORDER);
	                e.gc.drawRectangle(rect);                    
                }
            }
        });
        
        // 群栏目
        MouseTrackListener mtl = new MouseTrackAdapter() {
        	@Override
        	public void mouseEnter(MouseEvent e) {
        		if(!infoBar.isVisible())
        			infoBar.setVisible(true);
        	}
        	@Override
        	public void mouseExit(MouseEvent e) {
        		Control control = main.getDisplay().getCursorControl();
        		if(control == null)
        			infoBar.setVisible(false);
        		else if(control == infoBar ||
        				control == noticeContainer ||
        				control.getParent() == noticeContainer)
        			return;
        		else
        			infoBar.setVisible(false);
        	}
        };        

    	infoForm = new ViewForm(sideContainer, SWT.FLAT);
    	gd = new GridData(GridData.FILL_HORIZONTAL);
    	gd.heightHint = 140; 
    	infoForm.setLayoutData(gd);
    	final CLabel lblExpand = new CLabel(infoForm, SWT.LEFT);
    	lblExpand.setImage(res.getImage(Resources.icoFlatCollapse));
    	lblExpand.setText(cluster_im_list_info);
    	lblExpand.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
    	lblExpand.setForeground(Colors.VIEWFORM_BANNER_TEXT);
    	infoForm.setTopLeft(lblExpand);
    	lblExpand.addMouseListener(new MouseAdapter() {
    		@Override
    		public void mouseUp(MouseEvent e) {
    			infoFormExpanded = !infoFormExpanded;
    			if(infoFormExpanded) {
    				lblExpand.setImage(res.getImage(Resources.icoFlatCollapse));
    				GridData gd = (GridData)infoForm.getLayoutData();
    				gd.heightHint = 140;
    				sideContainer.layout();
    			} else {
    				lblExpand.setImage(res.getImage(Resources.icoFlatExpand));
    				GridData gd = (GridData)infoForm.getLayoutData();
    				gd.heightHint = infoForm.getTopLeft().getSize().y;
    				sideContainer.layout();
    			}
    		}
    	});
    	Composite content = new Composite(infoForm, SWT.NONE);
    	content.setLayout(new FormLayout());
    	FormData fd = new FormData();
    	fd.left = fd.top = new FormAttachment(0, 0);
    	fd.bottom = fd.right = new FormAttachment(100, 0);
    	noticeContainer = new Composite(content, SWT.NONE);
    	noticeContainer.setBackground(Colors.TOOLTIP_BACKGROUND);
    	noticeContainer.setLayout(new GridLayout());
    	noticeContainer.setLayoutData(fd);
    	CLabel lblNotice = new CLabel(noticeContainer, SWT.LEFT);
    	lblNotice.setImage(res.getImage(Resources.icoSysMsg));
    	lblNotice.setText(cluster_im_label_notice);
    	lblNotice.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
    	lblNotice.setBackground(noticeContainer.getBackground());
    	lblNotice.addMouseTrackListener(mtl);
    	textNotice = new Text(noticeContainer, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY);
    	textNotice.setBackground(noticeContainer.getBackground());
    	textNotice.setLayoutData(new GridData(GridData.FILL_BOTH));
    	textNotice.addMouseTrackListener(mtl);
    	infoBar = new ToolBar(content, SWT.FLAT);
    	infoBar.setBackground(Colors.WHITE);
    	ToolItem tiInfo = new ToolItem(infoBar, SWT.PUSH);
    	tiInfo.setImage(res.getImage(Resources.icoClusterInfo));
    	tiInfo.setToolTipText(cluster_im_button_info);
    	tiInfo.addSelectionListener(new SelectionAdapter() {
    		@Override
    		public void widgetSelected(SelectionEvent e) {
				main.getShellLauncher().openClusterInfoWindow(cluster);
    		}
    	});
    	ToolItem tiCard = new ToolItem(infoBar, SWT.PUSH);
    	tiCard.setImage(res.getImage(Resources.icoClusterCard));
    	tiCard.setToolTipText(cluster_im_button_card);
    	tiCard.addSelectionListener(new SelectionAdapter() {
    		@Override
    		public void widgetSelected(SelectionEvent e) {
				User u = cluster.getMember(main.getMyModel().qq);
				if(u == null)
					return;
				u.info = main.getMyModel().info;
				UserInfoWindow uiw = main.getShellLauncher().openUserInfoWindow(u, UserInfoWindow.EDITABLE);
				uiw.setCurrentPage(UserInfoWindow.CARD);
    		}
    	});
    	ToolItem tiUpdate = new ToolItem(infoBar, SWT.PUSH);
    	tiUpdate.setImage(res.getImage(Resources.icoRefresh));
    	tiUpdate.setToolTipText(cluster_im_button_update);
    	tiUpdate.addSelectionListener(new SelectionAdapter() {
    		@Override
    		public void widgetSelected(SelectionEvent e) {
    			main.getClient().getClusterInfo(cluster.clusterId);
    			cluster.cardUpdated = false;
				main.getClient().getCardBatch(cluster.clusterId, 0);
    		}
    	});
    	fd = new FormData();
    	fd.right = fd.bottom = new FormAttachment(100, 0);
    	infoBar.setLayoutData(fd);
    	infoBar.moveAbove(noticeContainer);
    	infoBar.setVisible(false);
    	infoBar.addMouseTrackListener(mtl);
    	infoBar.addPaintListener(new PaintListener() {
    		public void paintControl(PaintEvent e) {
    			Rectangle rect = infoBar.getClientArea();
    			e.gc.setForeground(Colors.PAGE_CONTROL_BORDER);
    			rect.height--;
    			rect.width--;
    			e.gc.drawRectangle(rect);
    		}
    	});
    	noticeContainer.addMouseTrackListener(mtl);
    	infoForm.setContent(content);    	
        
        // 群成员列表
        ViewForm listForm = new ViewForm(sideContainer, SWT.FLAT);
        listForm.setLayoutData(new GridData(GridData.FILL_BOTH));
        lblList = new CLabel(listForm, SWT.LEFT);
        lblList.setImage(res.getSmallClusterHead(6));
        lblList.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        lblList.setForeground(Colors.VIEWFORM_BANNER_TEXT);
        listForm.setTopLeft(lblList);
        listViewer = new TableViewer(listForm, SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION);
        listViewer.setLabelProvider(new ClusterMemberLabelProvider());
        listViewer.setSorter(new ModelSorter());
        Table t = listViewer.getTable();
        new TableColumn(t, SWT.LEFT);
        new TableColumn(t, SWT.LEFT);
        t.addControlListener(new ControlAdapter() {
            public void controlResized(ControlEvent e) {
                Table table = (Table)e.getSource();
                table.getColumn(0).setWidth(20);
                table.getColumn(1).setWidth(table.getClientArea().width - 20);
            }
        });
        t.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                if(e.button == 3) {        
                    Table table = (Table)e.getSource();
                    memberMenu.setLocation(table.toDisplay(e.x, e.y));
                    memberMenu.setVisible(true);
                }
            }
        });
        t.addSelectionListener(new SelectionAdapter() {
            public void widgetDefaultSelected(SelectionEvent e) {
			    IStructuredSelection selection = (IStructuredSelection)listViewer.getSelection();	    
				if(!selection.isEmpty()) {
					User f = (User)selection.getFirstElement();
					main.getShellLauncher().openUserInfoWindow(f, UserInfoWindow.READ_ONLY);
					main.getClient().getUserInfo(f.qq);
				}
            }
        });
        t.setHeaderVisible(false);
        t.setLinesVisible(false);        
        listForm.setContent(t);           

		
		// 初始化菜单
		initMemberMenu();
		
        addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
                int size = styleCache.size();
                for(int i = 0; i < size; i++) {
                    LineStyle style = (LineStyle)styleCache.get(i);
                    if(style.foreground != null)
                        style.foreground.dispose();
                    if(style.background != null)
                        style.background.dispose();
                }
                workflow.dispose();
            }
        });
	}
	
    /**
     * 初始化快捷键设置
     */
    private void initKeyAction() {
        // mod3 -> alt
        inputBox.setUserKeyAction('C' | SWT.MOD3, closeAction);
        inputBox.setUserKeyAction('S' | SWT.MOD3, sendAction);
        inputBox.setUserKeyAction('H' | SWT.MOD3, showRecordAction);
        inputBox.setUserKeyAction('Q' | SWT.MOD3, nextUnreadTabAction);
        inputBox.setUserKeyAction(SWT.MOD3 | SWT.ARROW_RIGHT, nextTabAction);
        inputBox.setUserKeyAction(SWT.MOD3 | SWT.ARROW_LEFT, prevTabAction);
        
        // 发送消息的快捷键
        if(main.getOptionHelper().isUseEnterInTalkMode()) {
		    inputBox.removeUserKeyAction(SWT.MOD1 | SWT.CR);
		    inputBox.setUserKeyAction(SWT.CR, sendAction);
		    inputBox.setKeyBinding(SWT.MOD1 | SWT.CR, RichBox.NEW_LINE);
        } else {
		    inputBox.removeUserKeyAction(SWT.CR);
		    inputBox.setUserKeyAction(SWT.MOD1 | SWT.CR, sendAction);
		    inputBox.setKeyBinding(SWT.CR, RichBox.NEW_LINE);
        }           
    }

	/**
     * 打开表情选择窗口
     */
    private void openImageSelectionShell(Point loc) {
    	ImageSelector fss = new ImageSelector(getShell(), new FaceImageAdvisor(main));
    	fss.setListener(this);
		fss.setLocation(loc);
		fss.open();	
    }

	public void setKeyHandler(IContainerKeyHandler ka) {
		keyHandler = ka;
	}

	public Image getHead() {
		if(cluster.isPermanent())
			return res.getSmallClusterHead(cluster.headId);
		else
			return res.getImage(Resources.icoDialog);
	}

	public int getUnreadCount() {
		return unread;
	}

	public void setActive(boolean active) {
		this.active = active;
		if(active)
			unread = 0;
	}

	public String getDisplayedName() {
		return cluster.name;
	}

	public int getId() {
		return cluster.clusterId;
	}

	public Model getModel() {
		return cluster;
	}

	public void setModel(Model model) {
		this.cluster = (Cluster)model;
		GridData gd = (GridData)infoForm.getLayoutData();
		gd.exclude = !cluster.isPermanent();
		infoForm.getParent().layout();
		if(!gd.exclude)
	    	setNotice(cluster.notice);    
		
        setListLabel(cluster.members.size(), 0);
        setClusterNameLabel();
        listViewer.setContentProvider(new MapValueContentProvider(cluster.members));
        listViewer.setInput(this);
	}
	
    /**
     * 刷新群名称标签
     */
    private void setClusterNameLabel() {
    	if(cluster.clusterType == ClusterType.NORMAL)
    		lblName.setImage(res.getSmallClusterHead(cluster.headId));
    	else
    		lblName.setImage(res.getImage(Resources.icoDialog));
    	
        if(cluster.isPermanent())
            lblName.setText(cluster.name + " (" + cluster.externalId + ')');
        else 
            lblName.setText(cluster.name);
    }

	public void setMainShell(MainShell main) {
		this.main = main;
		workflow = new ClusterIMDelegate(main.getClient());
		workflow.setSender(this);
		// 初始化快捷键设置
		initKeyAction();
	}

	public void send() {
		String s = inputBox.getText();
	    // 检查消息是否为空
	    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);
		}
	}

	public void putMessage(ReceiveIMPacket packet) {
		appendMessage(cluster, packet.clusterIM, false);
		if(!active)
			unread++;
	}

	public void setUseEnter(boolean useEnter) {
		if(useEnter) {
		    inputBox.removeUserKeyAction(SWT.MOD1 | SWT.CR);
		    inputBox.setUserKeyAction(SWT.CR, sendAction);
		    inputBox.setKeyBinding(SWT.MOD1 | SWT.CR, RichBox.NEW_LINE);
		} else {
		    inputBox.removeUserKeyAction(SWT.CR);
		    inputBox.setUserKeyAction(SWT.MOD1 | SWT.CR, sendAction);
		    inputBox.setKeyBinding(SWT.CR, RichBox.NEW_LINE);
		}
	}

	public Composite getComposite() {
		return this;
	}

	public void setText(String text) {
		inputBox.setText(text);
	}

	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();

⌨️ 快捷键说明

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