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

📄 sendimwindow.java

📁 java写的qq代码实现qq的部分功能
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
					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());
	            }
	        });            
        }
        // 表情
        ti = new ToolItem(tb, SWT.NONE);
        ti.setImage(icons.getImage(IconHolder.icoSmiley));
        ti.setToolTipText(LumaQQ.getString("tooltip.button.smiley"));
        ti.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				ToolBar tb = ((ToolItem)e.widget).getParent();
				Rectangle bound = tb.getBounds();
				openImageSelectionShell(tb.getParent().toDisplay(bound.x, bound.y + bound.height));					
			}
		});
        // 动画状态
        ti = new ToolItem(tb, SWT.CHECK);
        ti.setImage(icons.getImage(IconHolder.icoStop));
        ti.setToolTipText(LumaQQ.getString("tooltip.button.forbid.animation"));
        ti.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() ? LumaQQ.getString("tooltip.button.animation") : LumaQQ.getString("tooltip.button.forbid.animation"));
            }
        });
        inputForm.setTopLeft(tb);
        Composite comp = new Composite(inputForm, SWT.NONE);
        comp.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
        layout = new GridLayout(3, false);
        layout.marginHeight = 3;
        comp.setLayout(layout);
        lblStatus = new Label(comp, SWT.RIGHT);
        lblStatus.setVisible(false);
        lblStatus.setBackground(comp.getBackground());
        gd = new GridData();
        gd.widthHint = 40;
        gd.heightHint = 14;
        lblStatus.setLayoutData(gd);
        lblPercent = new Label(comp, SWT.RIGHT);
        lblPercent.setVisible(false);
        lblPercent.setBackground(comp.getBackground());
        gd = new GridData();
        gd.widthHint = 25;
        gd.heightHint = 14;
        lblPercent.setLayoutData(gd);
		bar = new ProgressBar(comp, SWT.HORIZONTAL | SWT.SMOOTH);
		bar.setVisible(false);
		bar.setMinimum(0);
		bar.setBackground(comp.getBackground());
		bar.setForeground(Colors.DARK_GREEN);
        gd = new GridData(GridData.VERTICAL_ALIGN_CENTER);
        gd.widthHint = 100;
        gd.heightHint = 14;
        bar.setLayoutData(gd);        
        inputForm.setTopCenter(comp);    
        inputForm.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
        inputBox = new RichBox(inputForm);
        inputBox.setBackground(Colors.WHITE);
        inputForm.setContent(inputBox);

        // 按钮区
        Composite buttonContainer = new Composite(container, SWT.NONE);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        buttonContainer.setLayoutData(gd);
        layout = new GridLayout(5, false);
        layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
        buttonContainer.setLayout(layout);
        buttonContainer.setBackground(container.getBackground());
        
        QButton btnRecord = new QButton(buttonContainer);
        btnRecord.setText(LumaQQ.getString("im.button.record"));
        btnRecord.setLayoutData(new GridData());
        btnRecord.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                showRecord();
            }
        });
        
        btnMode = new QButton(buttonContainer);
        btnMode.setText(LumaQQ.getString("im.button.mode.message"));
        gd = new GridData();
        gd.horizontalIndent = 3;
        btnMode.setLayoutData(gd);
        btnMode.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
				if(talkMode) {
				    // 检查是否在传送文件,如果是,不能切换到消息模式
				    if(hasFileOperating()) {
				        MessageDialog.openWarning(getShell(), LumaQQ.getString("message.box.common.warning.title"), LumaQQ.getString("message.box.cannot.switch.to.message.mode"));
				        return;
				    }
					setTalkMode(false);
				} else {
					setTalkMode(true);
				}
            }
        });
        
        QButton btnClose = new QButton(buttonContainer);
        btnClose.setText(LumaQQ.getString("im.button.close"));
        gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
        gd.grabExcessHorizontalSpace = true;
        btnClose.setLayoutData(gd);
		btnClose.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				getShell().close();
			}
		});
        
        final QButton btnSend = new QButton(buttonContainer);
        btnSend.setText(LumaQQ.getString("im.button.send"));
        gd = new GridData();
        gd.horizontalIndent = 3;
        btnSend.setLayoutData(gd);
		btnSend.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				sendMessage(inputBox.getText());
			}
		});
        
        QButton btnDropDown = new QButton(buttonContainer, SWT.ARROW_DOWN);
        btnDropDown.setMarginWidth(0);
        gd = new GridData();
        gd.horizontalIndent = 1;
        btnDropDown.setLayoutData(gd);
        btnDropDown.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
				// 设置菜单位置
				Rectangle bound = btnSend.getBounds();
				enterMenu.setLocation(btnSend.getParent().toDisplay(bound.x, bound.y + bound.height));
				// 显示菜单
				enterMenu.setVisible(true);
            }
		});
        
		// 聊天记录面板
		viewer = new RecordViewer(container, SWT.NONE);
		viewer.setVisible(false);
		viewer.setBackground(container.getBackground());
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
		gd.horizontalSpan = 2;
		gd.heightHint = 0;
		viewer.setLayoutData(gd);
        
		// 设置消息管理器、字符串格式化器,导出器
		viewer.setMessageManager(main.getMessageManager());
		viewer.setQQ(model.getQQ());
		viewer.setExporter(new FriendMessageExporter(main.getMyModel(), model));
		viewer.setFormatter(new FriendMessageFormatter(main.getMyModel(), model));
		// 添加表头
		viewer.setTableColumn(new String[] { LumaQQ.getString("im.table.header.nick"), LumaQQ.getString("im.table.header.time"), LumaQQ.getString("im.table.header.message") });
		viewer.setTableColumnWidth(new String[] { "80", "120", "*" });
		// tableitem双击事件监听器
		viewer.addSelectionListener(
			new SelectionAdapter() {
				public void widgetDefaultSelected(SelectionEvent e) {
					TableItem ti = viewer.getSelectedItem();
					inputBox.setText(ti.getText(2));
				}
			}
		);
		
		// 初始化菜单
		initEnterMenu();
		initFileMenu();
		
		// 初始化快捷键设置
		initKeyAction();
		
		setTalkMode(model.isTalkMode());
		
        return container;
    }
    
    /**
     * 初始化快捷键设置
     */
    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('T' | SWT.MOD3, modeAction);
        
        // 发送消息的快捷键
        reinstallSendKey(talkMode ? OptionUtil.getInstance().isUseEnterInTalkMode() : OptionUtil.getInstance().isUseEnterInMessageMode());      
    }
    
    /**
     * 刷新发送快捷键设置
     * 
     * @param useEnter
     */
    private void reinstallSendKey(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);
        }  
    }

    /**
     * 刷新群名称标签
     */
    private void setFriendNameLabel() {
        lblName.setImage(HeadFactory.getSmallHeadByStatus(model));
        lblName.setText(model.getName() + " (" + model.getQQ() + ')');
    }

    /**
     * 设置列表提示文本
     * 
     * @param total
     * 		群内人数
     * @param online
     * 		群内在线数
     */
    private void setListLabel(int total, int online) {
        lblList.setText(LumaQQ.getString("cluster.im.list.label", new Object[] { 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()
     */
    protected int getShellStyle() {
        return SWT.SHELL_TRIM;
    }
    
    /**
     * 设置窗口激活
     */
    public void setActive() {
        getShell().setActive();
    }
    
    /**
     * 设置最小化状态
     * 
     * @param b
     */
    public void setMinimized(boolean b) {
        getShell().setMinimized(b);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#open()
     */
    public int open() {
        int ret = super.open();
		// 设置输入框获得焦点,设置输入框的字体和颜色
		inputBox.setFocus();
		if(main.getDefaultStyle() != null)
			inputBox.setDefaultStyle(main.getDefaultStyle());
		// 添加自己为QQ listener
        main.getClient().addQQListener(this);
        return ret;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#constrainShellSize()
     */
    protected void constrainShellSize() {
        if(model.isTalkMode())
            getShell().setSize(470, 430);
        else
            getShell().setSize(440, 340);
        
		Point loc = new Point(50, 50);
		int x = model.getLocationX();
		int y = model.getLocationY();
		if(x > 0) loc.x = x;
		if(y > 0) loc.y = y;
		getShell().setLocation(loc);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
     */
    protected Point getInitialLocation(Point initialSize) {
		Point loc = new Point(50, 50);
		int x = model.getLocationX();
		int y = model.getLocationY();
		if(x > 0) loc.x = x;
		if(y > 0) loc.y = y;
		return loc;
	}

    /**
     * @param c
     * 		群model
     * @param im
     * 		群消息结构
     * @param header
     * @param me
     * 		true表示是我自己
     */
    public void appendMessage(FriendModel f, NormalIM im, NormalIMHeader header) {
        date.setTime(header.sendTime);
		outputBox.appendText('(' + f.getName() + ")  " + df.format(date), otherStyle);
		LineStyle style = getLineStyle(im);
		outputBox.appendText(im.message, style);
    }
    
	/**
	 * 设置已经发送的消息,这个方法只用在聊天模式时
	 * @param name 发送消息的人的昵称
	 * @param msg 消息内容
	 * @param date 消息发送时间
     * 		true表示是我自己
	 */
	private void appendMessage(String name, String msg, Date date) {
		outputBox.appendText('(' + name + ")  " + df.format(date), myStyle);		
		outputBox.appendText(msg, getLineStyle(main.getDefaultStyle()));
	}
	
	/**
	 * 在输出框中添加提示信息
	 * 
	 * @param hint
	 * @param style
	 */
	private void appendHint(String hint, LineStyle style) {
	    outputBox.appendText(hint, style);
	}

    /**
     * @return
     * 		true表示当前窗口是活动窗口
     */
    public boolean isActive() {
        return active;

⌨️ 快捷键说明

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