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

📄 sendimwindow.java

📁 java写的qq代码实现qq的部分功能
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @param style
     * @return
     */
    private LineStyle getLineStyle(LineStyle ls) {
        int size = styleCache.size();
        for(int i = 0; i < size; i++) {
            LineStyle style = (LineStyle)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 = (LineStyle)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;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getParentShell()
     */
    protected Shell getParentShell() {
        return null;
    }
    
	/**
	 * 初始化使用Enter键的菜单
	 */
	private void initEnterMenu() {
		enterMenu = new Menu(getShell(), SWT.POP_UP);
		// 使用Enter键菜单
		MenuItem mi = new MenuItem(enterMenu, SWT.RADIO);
		mi.setText(LumaQQ.getString("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);
			    if(talkMode)
			        OptionUtil.getInstance().setUseEnterInTalkMode(true);
			    else
			        OptionUtil.getInstance().setUseEnterInMessageMode(true);
			}
		});
		// 使用Ctrl + Enter键菜单
		mi = new MenuItem(enterMenu, SWT.RADIO);
		mi.setText(LumaQQ.getString("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);
			    if(talkMode)
			        OptionUtil.getInstance().setUseEnterInTalkMode(false);
			    else
			        OptionUtil.getInstance().setUseEnterInMessageMode(false);
			}
		});
		// 添加菜单显示事件监听器
		enterMenu.addMenuListener(new MenuAdapter() {
			public void menuShown(MenuEvent e) {
			    refreshEnterMenu();
			}
		});
	}
	
	/**
	 * 根据当前选项设置菜单项状态
	 */
	private void refreshEnterMenu() {
		boolean b = talkMode ? OptionUtil.getInstance().isUseEnterInTalkMode() : OptionUtil.getInstance().isUseEnterInMessageMode();
		enterMenu.getItem(0).setSelection(b);
		enterMenu.getItem(1).setSelection(!b);
	}
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
    protected void configureShell(Shell newShell) {
        newShell.setText(LumaQQ.getString("im.title", new Object[] { model.getName() }));
        newShell.setImage(icons.getImage(IconHolder.icoMessage));
        newShell.addControlListener(new ControlAdapter() {
            public void controlMoved(ControlEvent e) {
        		// 保存自己的位置,以便下次打开窗口时在同样的位置
        		Point loc = ((Shell)e.getSource()).getLocation();
        		model.addProperty(IQQNode.LOCATION_X, new Integer(loc.x));
        		model.addProperty(IQQNode.LOCATION_Y, new Integer(loc.y));
            }
        });
        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();
                }
            }
        });
        main.getShell().addShellListener(new ShellAdapter() {
            public void shellClosed(ShellEvent e) {
                inputBox.dispose();
                outputBox.dispose();
            }
        });
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getShellListener()
     */
    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().removeSendIMWindow(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)
     */
    protected Control createContents(Composite parent) {
        parent.setLayout(new FillLayout());
        Composite container = (Composite)super.createContents(parent);
        GridLayout layout = new GridLayout();
        layout.horizontalSpacing = 0;
        container.setLayout(layout);
        container.setBackground(Colors.DIALOG_BACKGOUND);
        
        // 上方的工具条
        Composite topContainer = new Composite(container, SWT.NONE);
        topContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        layout = new GridLayout(2, false);
        layout.marginHeight = layout.marginWidth = layout.verticalSpacing = 0;
        topContainer.setLayout(layout);
        topContainer.setBackground(Colors.DIALOG_BACKGOUND);
        
        ToolBar topBar = new ToolBar(topContainer, SWT.FLAT);
        GridData gd = new GridData();
        gd.verticalSpan = 2;
        topBar.setLayoutData(gd);
        
		// 发送文件按钮
		ToolItem ti = new ToolItem(topBar, SWT.DROP_DOWN);
		ti.setImage(icons.getImage(IconHolder.icoSendFile32));
		ti.setToolTipText(LumaQQ.getString("tooltip.button.sendfile"));
		ti.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			    if(e.detail == SWT.ARROW) {
			        ToolItem ti = (ToolItem)e.widget;
			        Rectangle bound = ti.getBounds();
			        fileMenu.setLocation(ti.getParent().toDisplay(bound.x, bound.y + bound.height));
			        fileMenu.setVisible(true);				        
			    } else
			        requestSendFile();
			}
		});
		// 发送短消息按钮
		ti = new ToolItem(topBar, SWT.PUSH);
		ti.setImage(icons.getImage(IconHolder.icoMobile32));
		ti.setToolTipText(LumaQQ.getString("tooltip.button.sms"));
		ti.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                main.getShellLauncher().openSMSShell(model);
            }
		});
		// 同意接收文件按钮
		tiYes = new ToolItem(topBar, SWT.PUSH);
		tiYes.setEnabled(false);
		tiYes.setImage(icons.getImage(IconHolder.icoYes));
		tiYes.setToolTipText(LumaQQ.getString("tooltip.button.accept.sendfile"));
		tiYes.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			    acceptSendFile();
			}
		});
		// 拒绝接收文件按钮
		tiNo = new ToolItem(topBar, SWT.PUSH);
		tiNo.setEnabled(false);
		tiNo.setImage(icons.getImage(IconHolder.icoNo));
		tiNo.setToolTipText(LumaQQ.getString("tooltip.button.reject.sendfile"));
		tiNo.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
			    cancelFileOperation();
			}
		});
		
		// ip标签
		lblIp = new Label(topContainer, SWT.CENTER);
		lblIp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		lblIp.setText(ip);
		lblIp.setBackground(lblIp.getParent().getBackground());
		// 地址
		lblPlace = new Label(topContainer, SWT.CENTER);
		lblPlace.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		lblPlace.setText(place);
		lblPlace.setBackground(lblIp.getParent().getBackground());
        
        // 聊天区
        Composite 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);
            }
        });
        
        outputForm = new ViewForm(chatContainer, SWT.FLAT);
        outputForm.setLayoutData(new GridData(GridData.FILL_BOTH));
        lblName = new CLabel(outputForm, SWT.LEFT);
        lblName.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
        setFriendNameLabel();
        lblName.setCursor(handCursor);
        lblName.setForeground(Colors.WHITE);
        lblName.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                main.getShellLauncher().openUserInfoWindow(model, UserInfoWindow.READ_ONLY);
            }
        });
        lblName.addMouseTrackListener(new MouseTrackAdapter() {
            public void mouseEnter(MouseEvent e) {
                lblName.setForeground(Colors.YELLOW);
            }
            
            public void mouseExit(MouseEvent e) {
                lblName.setForeground(Colors.WHITE);
            }
        });
        outputForm.setTopLeft(lblName);        
        outputBox = new RichBox(outputForm);
        outputBox.setReadonly(true);
        outputBox.setBackground(Colors.WHITE);
        outputForm.setContent(outputBox);      
        
        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);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.heightHint = 100;
        inputForm.setLayoutData(gd);
        ToolBar tb = new ToolBar(inputForm, SWT.FLAT);
        tb.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
        // 字体
        ti = new ToolItem(tb, SWT.NONE);        
        ti.setImage(icons.getImage(IconHolder.icoFont));
        ti.setToolTipText(LumaQQ.getString("tooltip.button.font"));
        ti.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(icons.getImage(IconHolder.icoColor));
	        tiColor.setToolTipText(LumaQQ.getString("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());

⌨️ 快捷键说明

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