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

📄 systemmessagelistdialog.java

📁 类似于MSN
💻 JAVA
字号:
/*
* 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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
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.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;

import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.MessageEntry;
import edu.tsinghua.lumaqq.qq.Utils;
import edu.tsinghua.lumaqq.widgets.RecordViewer;
import edu.tsinghua.lumaqq.widgets.SystemMessageExporter;
import edu.tsinghua.lumaqq.widgets.SystemMessageFormatter;

/**
 * 列出收到的所有系统消息的对话框
 * 系统消息的内容有些不太一样,分成三个域
 * 第一个是消息类型,第二个是QQ号,第三个是消息,中间用|相隔,这
 * 只是权宜之计
 * 
 * @author 马若劼
 */
public class SystemMessageListDialog extends Dialog implements ShellListener {
	// Log对象
    protected static Log log = LogFactory.getLog(SystemMessageListDialog.class);
    // 主shell
    private MainShell main;
    // 本窗口shell
	private Shell dialog;
	// display
	private Display display;
	// 界面控件
	private RecordViewer viewer;
	
	/**
	 * @param parent
	 */
	public SystemMessageListDialog(MainShell main) {
		super(main.getShell());
		this.main = main;
	}
	
	/**
	 * 打开对话框
	 */
	public void open()	{
	    // create dialog
	    Shell parent = getParent();
	    Display display = parent.getDisplay();
		dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.MODELESS | SWT.MIN);
		dialog.setSize(400, 250);
		// init child controls
		initLayout();
		// 初始化控件的值
		initValue();
		// set listener
		dialog.addShellListener(this);
		// set title and image
		dialog.setImage(main.icons.getResource(IconHolder.icoQQ));
		dialog.setText(LumaQQ.getResourceString("sys.msg.list.title"));
		// set dialog to center of screen
		Rectangle dialogRect = dialog.getBounds();
		Rectangle displayRect = display.getBounds();
		dialog.setLocation((displayRect.width-dialogRect.width)/2, (displayRect.height-dialogRect.height)/2);
		// event loop
		dialog.open();
		dialog.layout();		
		while(!dialog.isDisposed()) 
			if(!display.readAndDispatch()) 
			    display.sleep();
	}

	/**
	 * 初始化窗口布局
	 */
	private void initLayout() {
		dialog.setLayout(new FormLayout());
		// 聊天记录查看控件
		viewer = new RecordViewer(dialog, SWT.NONE);
		FormData fd = new FormData();
		fd.left = fd.top = new FormAttachment(0, 5);
		fd.right = fd.bottom = new FormAttachment(100, -5);
		viewer.setLayoutData(fd);
		// 设置viewer变量
		viewer.setMessageManager(main.mm);
		viewer.setFormatter(new SystemMessageFormatter());
		viewer.setExporter(new SystemMessageExporter());
		viewer.setQQ(10000);
		// 添加表头
		viewer.setTableColumn(new String[] { LumaQQ.getResourceString("sys.msg.list.table.header.from"), LumaQQ.getResourceString("sys.msg.list.table.header.time"), LumaQQ.getResourceString("sys.msg.list.table.header.message") });
		viewer.setTableColumnWidth(new int[] { 80, 120, 400 });
		// tableitem双击事件监听器
		viewer.addSelectionListener(
			new SelectionAdapter() {
				public void widgetDefaultSelected(SelectionEvent e) {
					MessageEntry me = viewer.getSelectedMessageEntry();
					TableItem ti = viewer.getSelectedItem();
					if(me == null || ti == null) return;
					String msg = me.getMessage();
					int delimit = msg.indexOf('|');
					if(delimit != -1) {
						char type = Utils.getChar(msg.substring(0, delimit), 0);
						if(type == 0) return;
						ReceiveSystemMessageShell rsms = new ReceiveSystemMessageShell(main);
						rsms.setSystemMessage(type, me.getSource(), me.getSender(), ti.getText(2), (byte)0, false);
						rsms.open();
					}
				}
			}
		);
	}

	/**
	 * 初始化一些值
	 */
	private void initValue() {
		// 得到记录,显示在table中
		viewer.refreshRecord(false);
		// 显示最后一条记录
		viewer.showLast();
		// layout
		dialog.layout();
	}

	/**
	 * @param b
	 */
	public void setMinimized(boolean b) {
		dialog.setMinimized(b);
	}

	/**
	 * 激活窗口
	 */
	public void setActive() {
		dialog.setActive();
	}

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

	/* (non-Javadoc)
	 * @see org.eclipse.swt.events.ShellListener#shellClosed(org.eclipse.swt.events.ShellEvent)
	 */
	public void shellClosed(ShellEvent e) {
		main.systemMessageListDialog = null;
	}

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

	/* (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) {
	    // 没什么要做的
	}
}

⌨️ 快捷键说明

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