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

📄 sendclusterimwindow.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getParentShell()
     */
    protected Shell getParentShell() {
        return null;
    }
    
	/**
	 * 初始化成员菜单
	 */
	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);
				}
			}
		});
	}
	
	/**
	 * 初始化使用Enter键的菜单
	 */
	private void initEnterMenu() {
		enterMenu = new Menu(getShell(), SWT.POP_UP);
		// 使用Enter键菜单
		MenuItem mi = new MenuItem(enterMenu, SWT.RADIO);
		mi.setText(cluster_im_menu_use_enter);
		mi.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
				    inputBox.removeUserKeyAction(SWT.MOD1 | SWT.CR);
				    inputBox.setUserKeyAction(SWT.CR, sendAction);
				    inputBox.setKeyBinding(SWT.MOD1 | SWT.CR, RichBox.NEW_LINE);
				    main.getOptionHelper().setUseEnterInTalkMode(true);
				}
			}
		);
		// 使用Ctrl + Enter键菜单
		mi = new MenuItem(enterMenu, SWT.RADIO);
		mi.setText(cluster_im_menu_use_ctrl_enter);
		mi.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
				    inputBox.removeUserKeyAction(SWT.CR);
				    inputBox.setUserKeyAction(SWT.MOD1 | SWT.CR, sendAction);
				    inputBox.setKeyBinding(SWT.CR, RichBox.NEW_LINE);
				    main.getOptionHelper().setUseEnterInTalkMode(false);
				}
			}
		);
		// 添加菜单显示事件监听器
		enterMenu.addMenuListener(
			new MenuAdapter() {
				public void menuShown(MenuEvent e) {
					// 根据当前选项设置菜单项状态
					boolean b = main.getOptionHelper().isUseEnterInTalkMode();
					enterMenu.getItem(0).setSelection(b);
					enterMenu.getItem(1).setSelection(!b);
				}
			}
		);
	}
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
	@Override
    protected void configureShell(Shell newShell) {
        newShell.setText(NLS.bind(cluster_im_title, model.name));
        if(model.clusterType == ClusterType.NORMAL)
        	newShell.setImage(res.getSmallClusterHead(model.headId));
        else
        	newShell.setImage(res.getImage(Resources.icoDialog));
        newShell.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();
            }
        });
        main.getShell().addShellListener(new ShellAdapter() {
            public void shellClosed(ShellEvent e) {
                inputBox.dispose();
                outputBox.dispose();
            }
        });
        
        if(LumaQQ.IS_GTK) {
        	BorderStyler styler = new BorderStyler(main);
        	styler.setShowMaxButton(true);
        	styler.setHideWhenMinimize(false);
        	styler.decorateShell(newShell);        	
        }
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getShellListener()
     */
	@Override
    protected ShellListener getShellListener() {
        return this;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellActivated(org.eclipse.swt.events.ShellEvent)
     */
    public void shellActivated(ShellEvent e) {
        stopBlinkImage();
        active = true;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent)
     */
    public void shellDeactivated(ShellEvent e) {
        active = false;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
     */
    public void shellClosed(ShellEvent e) {
		main.getClient().removeQQListener(this);
		main.getShellRegistry().removeSendClusterIMWindow(model);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellDeiconified(org.eclipse.swt.events.ShellEvent)
     */
    public void shellDeiconified(ShellEvent e) {
    }

    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellIconified(org.eclipse.swt.events.ShellEvent)
     */
    public void shellIconified(ShellEvent e) {
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
     */
	@Override
    protected Control createContents(Composite parent) {
		Composite container = null;
		if(LumaQQ.IS_GTK) {
			container = ((BorderStyler)getShell().getData(BorderStyler.STYLER)).getCenter();
		} else {
			parent.setLayout(new FillLayout());
			container = (Composite)super.createContents(parent);			
		}
        GridLayout layout = new GridLayout(3, false);
        layout.horizontalSpacing = 0;
        container.setLayout(layout);
        container.setBackground(Colors.MAINSHELL_BACKGROUND);
        
        // 聊天区
        chatContainer = new Composite(container, SWT.NONE);
        chatContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
        layout = new GridLayout();        
        layout.marginHeight = layout.marginWidth = 1;
        layout.horizontalSpacing = layout.verticalSpacing = 0;
        chatContainer.setLayout(layout);
        chatContainer.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                Composite c = (Composite)e.getSource();
                Rectangle rect = c.getClientArea();
                rect.width--;
                rect.height--;
                e.gc.setForeground(Colors.WIDGET_BORDER);
                e.gc.drawRectangle(rect);
            }
        });
        
        ViewForm outputForm = new ViewForm(chatContainer, SWT.FLAT);
        outputForm.setLayoutData(new GridData(GridData.FILL_BOTH));
        lblName = new CLabel(outputForm, SWT.LEFT);
        lblName.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        setClusterNameLabel();
        lblName.setCursor(handCursor);
        lblName.setForeground(Colors.VIEWFORM_BANNER_TEXT);
        lblName.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
            	ShellLauncher shellLauncher = main.getShellLauncher();
				if(model.isPermanent())
					shellLauncher.openClusterInfoWindow(model);
				else
					shellLauncher.openMemberEditShell(MemberEditShell.TEMP_CLUSTER, model.getParentCluster(), null, model);
            }
        });
        lblName.addMouseTrackListener(new MouseTrackAdapter() {
            public void mouseEnter(MouseEvent e) {
                lblName.setForeground(Colors.VIEWFORM_BANNER_TEXT_HOVER);
            }
            
            public void mouseExit(MouseEvent e) {
                lblName.setForeground(Colors.VIEWFORM_BANNER_TEXT);
            }
        });
        outputForm.setTopLeft(lblName);        
        outputBox = new RichBox(outputForm);
        outputBox.setReadonly(true);
        outputBox.setBackground(Colors.WHITE);
        outputForm.setContent(outputBox);      
        
        Sash sash = new Sash(chatContainer, SWT.HORIZONTAL);
        sash.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        sash.setBackground(Colors.READONLY_BACKGROUND);
        sash.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                GridData gd = (GridData)inputForm.getLayoutData();
                gd.heightHint = inputForm.getParent().getClientArea().height - e.y;
                inputForm.getParent().layout();
            }
        });
        
        inputForm = new ViewForm(chatContainer, SWT.FLAT);
        inputForm.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.heightHint = 100;
        inputForm.setLayoutData(gd);
        final ToolBar tb = new ToolBar(inputForm, SWT.FLAT);
        tb.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        // 字体
        ToolItem tiFont = new ToolItem(tb, SWT.NONE);        
        tiFont.setImage(res.getImage(Resources.icoFont));
        tiFont.setToolTipText(tooltip_button_font);
        tiFont.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				FontDialog dialog = new FontDialog(getShell());
				if(main.getDefaultStyle() != null) 
					dialog.setFontList(main.getDefaultStyle().createFontData());
				if(main.getFontColor() != null)
					dialog.setRGB(main.getFontColor().getRGB());
				dialog.open();
				FontData[] fontList = dialog.getFontList();
				if(fontList == null) return;
				RGB rgb = dialog.getRGB();
				if(main.getFontColor() != null) main.getFontColor().dispose();
				main.getDefaultStyle().fontName = fontList[0].getName();
				main.getDefaultStyle().fontSize = fontList[0].getHeight();
				main.getDefaultStyle().fontStyle = fontList[0].getStyle();
				if(rgb != null) {
					main.setFontColor(new Color(main.getDisplay(), rgb));
					main.getDefaultStyle().foreground = main.getFontColor();
				}
				inputBox.setDefaultStyle(main.getDefaultStyle());
			}
		});
        // 颜色,在有些平台下需要
        if(IS_GTK || IS_MOTIF) {
	        ToolItem tiColor = new ToolItem(tb, SWT.NONE);
	        tiColor.setImage(res.getImage(Resources.icoColor));
	        tiColor.setToolTipText(tooltip_button_color);
	        tiColor.addSelectionListener(new SelectionAdapter() {
	            public void widgetSelected(SelectionEvent e) {
	                ColorDialog dialog = new ColorDialog(getShell());
					if(main.getFontColor() != null)
						dialog.setRGB(main.getFontColor().getRGB());
					dialog.open();
					RGB rgb = dialog.getRGB();
					if(rgb != null) {
						if(main.getFontColor() != null) 
						    main.getFontColor().dispose();
						if(rgb != null) {
							main.setFontColor(new Color(main.getDisplay(), rgb));
							main.getDefaultStyle().foreground = main.getFontColor();
						}
					}
					inputBox.setDefaultStyle(main.getDefaultStyle());
	            }
	        });            
        }
        // 表情
        ToolItem tiFace = new ToolItem(tb, SWT.NONE);
        tiFace.setImage(res.getImage(Resources.icoSmiley));
        tiFace.setToolTipText(tooltip_button_face);
        tiFace.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Rectangle bound = tb.getBounds();
			    openImageSelectionShell(tb.getParent().toDisplay(bound.x, bound.y + bound.height));
			}
		});
        // 动画状态
        ToolItem tiAnimation = new ToolItem(tb, SWT.CHECK);
        tiAnimation.setImage(res.getImage(Resources.icoStop));
        tiAnimation.setToolTipText(tooltip_button_disable_animation);
        tiAnimation.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                ToolItem ti = (ToolItem)e.widget;
                outputBox.setForbiddenAnimation(ti.getSelection());
                inputBox.setForbiddenAnimation(ti.getSelection());                
                ti.setToolTipText(ti.getSelection() ? tooltip_button_animation : tooltip_button_disable_animation);

⌨️ 快捷键说明

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