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

📄 receivemessageshell.java

📁 类似于MSN
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.shells;

import java.text.DateFormat;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.events.AcceleratorListener;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.utils.ReplyUtils;
import edu.tsinghua.lumaqq.widgets.ChatBox;
import edu.tsinghua.swt.widgets.MySWT;
import edu.tsinghua.swt.widgets.ShutterLabel;

/**
 * 接收消息窗口,用来查看收到的消息
 * 
 * @author 马若劼
 */
public class ReceiveMessageShell extends ShellAdapter implements DisposeListener, ControlListener, AcceleratorListener {
	// Log对象
    protected static Log log = LogFactory.getLog(ReceiveMessageShell.class);
    private MainShell main;
	private Shell shell;
	private Display display;
	private Label lblQQ, lblNick, lblTime, lblPlace, lblIp;
	private ChatBox chatBox;
	private ShutterLabel btnFriend, btnNext, btnQuickReply;
	private IconHolder icons = IconHolder.getInstance();
	// 发来消息的好友的qq号,昵称和头像号
	private int qq, face;
	private String nick;
	// 按钮的背景色
	private Color buttonColor;
	private String msg;
	private Menu quickReplyMenu;
	// 字体和颜色
	private Font font;
	private Color fontColor;
	// 好友的model
	private FriendModel f;
	// 回复信息工具类实例
	private ReplyUtils replies = ReplyUtils.getInstance();
	
	/**
	 * 构造函数
	 * @param main MainShell对象
	 */
	public ReceiveMessageShell(MainShell m) {
	    main = m;
		display = m.display;
		buttonColor = new Color(display, 0xEF, 0xEF, 0xF7);
		shell = new Shell(display, SWT.TITLE | SWT.CLOSE | SWT.MIN);
		shell.setSize(400, 280);
		shell.setImage(icons.getResource(IconHolder.icoMessage));
		// 设置layout
		shell.setLayout(new FormLayout());
		// 添加事件监听器
		shell.addDisposeListener(this);
		shell.addShellListener(this);
		shell.addControlListener(this);
		
		initLayout();
		initQuickReplyMenu();
	}

	// 打开回复消息窗口
	private SendMessageShell openSendMessageShell() {
		SendMessageShell sms = main.getSMS(f);
		if(sms == null) {
			sms = new SendMessageShell(main);
			main.putSMS(f, sms);
			sms.setFriendModel(f);
			// 设置ip信息
			sms.setIp(lblIp.getText());
			sms.setPlace(lblPlace.getText());
			sms.open();
		} else {
			sms.setMinimized(false);
			sms.setActive();
			sms.setFocus();
		}
		return sms;
	}

	// 初始化控件布局
	private void initLayout() {
		// 好友按钮,就是那个头像,一按就出来好友信息那个
		btnFriend = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, null);
		btnFriend.setShowSmallImage(false);
		FormData fd = new FormData();
		fd.left = fd.top = new FormAttachment(0, 5);
		btnFriend.setLayoutData(fd);
		btnFriend.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					main.openUserInfoShell(main.getFriendViewPart(qq), false);
				}
			}
		);
		// QQ号标签
		lblQQ = new Label(shell, SWT.NONE);
		fd = new FormData();
		fd.left = new FormAttachment(btnFriend, 10, SWT.RIGHT);
		fd.top = new FormAttachment(0, 5);
		lblQQ.setLayoutData(fd);
		// 昵称标签
		lblNick = new Label(shell, SWT.NONE);
		fd = new FormData();
		fd.left = new FormAttachment(btnFriend, 10, SWT.RIGHT);
		fd.top = new FormAttachment(lblQQ, 5, SWT.BOTTOM);
		lblNick.setLayoutData(fd);
		// 发送时间标签
		lblTime = new Label(shell, SWT.NONE);
		fd = new FormData();
		fd.left = new FormAttachment(btnFriend, 10, SWT.RIGHT);
		fd.top = new FormAttachment(lblNick, 5, SWT.BOTTOM);
		lblTime.setLayoutData(fd);
		// 好友所在地区标签
		lblPlace = new Label(shell, SWT.CENTER);
		fd = new FormData();
		fd.left = new FormAttachment(40, 0);
		fd.right = new FormAttachment(100, 0);
		fd.top = new FormAttachment(0, 5);
		lblPlace.setLayoutData(fd);
		// ip地址标签
		lblIp = new Label(shell, SWT.CENTER);
		fd = new FormData();
		fd.left = new FormAttachment(40, 0);
		fd.right = new FormAttachment(100, 0);
		fd.top = new FormAttachment(lblPlace, 5, SWT.BOTTOM);
		lblIp.setLayoutData(fd);
		// 查看消息框
		chatBox = new ChatBox(shell, SWT.NONE);
		chatBox.setEnabled(false);
		fd = new FormData();
		fd.left = new FormAttachment(0, 5);
		fd.top = new FormAttachment(lblTime, 5, SWT.BOTTOM);
		fd.right = new FormAttachment(100, -5);
		fd.bottom = new FormAttachment(100, -36);
		chatBox.setLayoutData(fd);
		chatBox.addAcceleratorListener(this);
		// 回复消息按钮
		ShutterLabel btnReply = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("receive.message.button.reply"), null);
		btnReply.setFocus();
		btnReply.setBackground(buttonColor);
		fd = new FormData();
		fd.left = new FormAttachment(0, 8);
		fd.top = new FormAttachment(chatBox, 8, SWT.BOTTOM);
		btnReply.setLayoutData(fd);
		btnReply.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					openSendMessageShell();
					shell.close();
				}
			}
		);
		// 快捷回复按钮
		btnQuickReply = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("receive.message.button.quickreply"), null);
		btnQuickReply.setBackground(buttonColor);
		fd = new FormData();
		fd.left = new FormAttachment(btnReply, 5, SWT.RIGHT);
		fd.top = new FormAttachment(chatBox, 8, SWT.BOTTOM);
		btnQuickReply.setLayoutData(fd);
		btnQuickReply.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					quickReply();
				}
			}
		);
		// 快捷回复旁边的下拉箭头按钮
		Button btnArrow = new Button(shell, SWT.ARROW | SWT.DOWN);
		btnArrow.setBackground(buttonColor);
		fd = new FormData();
		fd.left = new FormAttachment(btnQuickReply, 0, SWT.RIGHT);
		fd.right = new FormAttachment(btnQuickReply, 10, SWT.RIGHT);
		fd.top = new FormAttachment(btnQuickReply, 0, SWT.TOP);
		fd.bottom = new FormAttachment(btnQuickReply, 0, SWT.BOTTOM);
		btnArrow.setLayoutData(fd);
		btnArrow.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					// 设置菜单位置
					Rectangle bound = btnQuickReply.getBounds();
					quickReplyMenu.setLocation(shell.toDisplay(bound.x, bound.y + bound.height));	
					// 显示菜单
					quickReplyMenu.setVisible(true);
				}
			}
		);
		// 下一条消息按钮
		btnNext = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("receive.message.button.next"), null);
		btnNext.setBackground(buttonColor);
		btnNext.setEnabled(false);
		fd = new FormData();
		fd.right = new FormAttachment(100, -8);
		fd.left = new FormAttachment(100, -78);
		fd.top = new FormAttachment(chatBox, 8, SWT.BOTTOM);

⌨️ 快捷键说明

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