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

📄 receivemessageshell.java

📁 类似于MSN
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		btnNext.setLayoutData(fd);
		btnNext.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					main.openNormalMessageShell(main.getFriendViewPart(qq));
				}
			}
		);
		// 关闭按钮
		ShutterLabel btnClose = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("receive.message.button.close"), null);
		btnClose.setBackground(buttonColor);
		fd = new FormData();
		fd.right = new FormAttachment(btnNext, -3, SWT.LEFT);
		fd.left = new FormAttachment(btnNext, -73, SWT.LEFT);
		fd.top = new FormAttachment(chatBox, 8, SWT.BOTTOM);
		btnClose.setLayoutData(fd);
		btnClose.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					shell.close();
				}
			}
		);
	}	
	
	// 快速回复
	protected void quickReply() {
		SendMessageShell sms = openSendMessageShell();
		shell.close();
		sms.sendMessage(replies.getCurrentQuickReplyString());
	}

	// 初始化快捷回复菜单
	private void initQuickReplyMenu() {
		quickReplyMenu = new Menu(shell, SWT.POP_UP);
		// 循环初始化菜单项,有多少条快捷回复消息就创建多少菜单项,最后加上一个自定义项
		for(int i = 0; i < replies.getQuickReplySize(); i++) {
			final int j = i;
			final MenuItem mi = new MenuItem(quickReplyMenu, SWT.RADIO);
			mi.setText(replies.getQuickReply(i));
			mi.addSelectionListener(
				new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						if(mi.getSelection()) {
							replies.setCurrentQuickReply(j);
							quickReply();							
						}
					}
				}
			);			
		}
		MenuItem separator = new MenuItem(quickReplyMenu, SWT.SEPARATOR);
		// 自定义
		MenuItem mi = new MenuItem(quickReplyMenu, SWT.PUSH);
		mi.setImage(icons.getResource(IconHolder.icoReply));
		mi.setText(LumaQQ.getResourceString("menu.quick.reply.addnew"));
		mi.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					main.openSystemOptionShell().showPanel(SystemOptionShell.REPLY);
				}
			}
		);
		// 设置菜单项的选择状态
		quickReplyMenu.getItem(replies.getCurrentQuickReply()).setSelection(true);
	}
	
	/**
	 * @return Returns the qq.
	 */
	public int getQQ() {
		return qq;
	}
	
	/**
	 * 设置好友位置信息
	 * @param loc
	 */
	public void setPlace(String loc) {
		lblPlace.setText(loc);
	}
	
	/**
	 * 设置好友ip信息
	 * @param ip
	 */
	public void setIp(String ip) {
		lblIp.setText(ip);
	}
	
	/**
	 * 设置发送时间
	 * @param time
	 */
	public void setTime(long time) {
		Date date = new Date(time);
		lblTime.setText(LumaQQ.getResourceString("receive.message.label.time", new Object[] { DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(date) }));
	}	
    
	// 打开shell
	public void open()	{
		setShellLocation();
		// 打开shell
		shell.layout();
		shell.open();
		if(font != null) chatBox.setFont(font);
		if(fontColor != null) chatBox.setForeground(fontColor);
		chatBox.setFocus();
		if(msg != null)
			chatBox.setMessage(msg);
	}
	
	// 设置窗口位置
	private void setShellLocation() {
		Point loc = new Point(0, 0);
		if(f.hasProperty("locationX"))
			loc.x = ((Integer)f.getProperty("locationX")).intValue();
		if(f.hasProperty("locationY"))
			loc.y = ((Integer)f.getProperty("locationY")).intValue();
		shell.setLocation(loc);
	}
	
	/**
	 * 设置消息内容
	 * @param msg
	 */
	public void setMessage(String msg) {
		if(chatBox != null)
			chatBox.setMessage(msg);
		else
			this.msg = msg;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
	 */
	public void widgetDisposed(DisposeEvent e) {
		buttonColor.dispose();
		if(font != null) font.dispose();
		if(fontColor != null) fontColor.dispose();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.swt.events.ShellListener#shellClosed(org.eclipse.swt.events.ShellEvent)
	 */
	public void shellClosed(ShellEvent e) {
		main.removeMeFromRMSMap(f);
	}
	
	/**
	 * 设置“下一条”消息按钮的enable状态
	 * @param enabled true如果有下一条消息可用
	 */
	public void setNextButtonEnabled(boolean enabled) {
		btnNext.setEnabled(enabled);
	}	
	
	/**
	 * 代理方法,设置窗口的最小化状态
	 * @param b
	 */
	public void setMinimized(boolean b) {
		shell.setMinimized(b);
	}
	
	/**
	 * 是当前窗口激活
	 */
	public void setActive() {
		shell.setActive();
	}	
	
	/**
	 * @return Returns the face.
	 */
	public int getFace() {
		return face;
	}
	
	/**
	 * 设置消息框字体
	 * @param font
	 */
	public void setFont(Font font)  {
		this.font = font;
	}
	
	/**
	 * 设置消息框字体颜色
	 * @param fontColor
	 */
	public void setFontColor(Color fontColor) {
		this.fontColor = fontColor;
	}
	
	/**
	 * @param f The f to set.
	 */
	public void setFriendModel(FriendModel f) {
		this.f = f;
		this.nick = (String)f.getProperty("name");
		this.qq = f.getQQ();
		btnFriend.setImage(main.getFriendFace(f));
		lblQQ.setText(LumaQQ.getResourceString("receive.message.label.qq", new Object[] { String.valueOf(qq) }));
		lblNick.setText(LumaQQ.getResourceString("receive.message.label.nick", new Object[] { nick }));
		shell.setText(LumaQQ.getResourceString("receive.message.title", new Object[] { nick }));
	}

    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent)
     */
    public void controlMoved(ControlEvent e) {
		// 保存自己的位置,以便下次打开窗口时在同样的位置
		Point loc = shell.getLocation();
		f.addProperty("locationX", new Integer(loc.x));
		f.addProperty("locationY", new Integer(loc.y));
    }

    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent)
     */
    public void controlResized(ControlEvent e) {
        // 没什么要做的
    }

	/* (non-Javadoc)
	 * @see edu.tsinghua.lumaqq.events.AcceleratorListener#acceleratorPressed(org.eclipse.swt.events.KeyEvent)
	 */
	public void acceleratorPressed(KeyEvent e) {
		if(e.keyCode == SWT.CR) {
			openSendMessageShell();
			shell.close();
		} else if(e.stateMask == SWT.ALT) {
		    if(e.character == 'r' || e.character == 'R') {
			    openSendMessageShell();
			    shell.close();					        
		    } else if(e.character == 'c' || e.character == 'C')
		        shell.close();
		    else if(e.character == 's' || e.character == 'S')
		        quickReply();
		    else if(e.character == 'n' || e.character == 'N')
		        main.openNormalMessageShell(main.getFriendViewPart(qq));
		}
	}
}

⌨️ 快捷键说明

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