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

📄 systemmessagelistshell.java

📁 java写的qq代码实现qq的部分功能
💻 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.ui;

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.Util;
import edu.tsinghua.lumaqq.widgets.RecordViewer;
import edu.tsinghua.lumaqq.widgets.SystemMessageExporter;
import edu.tsinghua.lumaqq.widgets.SystemMessageFormatter;

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

	/**
	 * 初始化窗口布局
	 */
	private void initLayout() {
		shell.setLayout(new FormLayout());
		// 聊天记录查看控件
		viewer = new RecordViewer(shell, 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.getMessageManager());
		viewer.setFormatter(new SystemMessageFormatter());
		viewer.setExporter(new SystemMessageExporter());
		viewer.setQQ(10000);
		// 添加表头
		viewer.setTableColumn(new String[] { LumaQQ.getString("sys.msg.list.table.header.from"), LumaQQ.getString("sys.msg.list.table.header.time"), LumaQQ.getString("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 = Util.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);
		// layout
		shell.layout();
	}

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

	/**
	 * 激活窗口
	 */
	public void setActive() {
		shell.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.getShellRegistry().deregisterSystemMessageListShell();
	}

	/* (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 + -