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

📄 receivesmsshell.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.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.qq.packets.in.ReceiveIMPacket;
import edu.tsinghua.lumaqq.utils.DateUtil;
import edu.tsinghua.swt.widgets.CoolButton;
import edu.tsinghua.swt.widgets.MySWT;

/**
 * <pre>
 * 接收到短消息的窗口
 * </pre>
 * 
 * @author 马若劼
 */
public class ReceiveSMSShell extends ShellAdapter {
	// Log对象
    protected static Log log = LogFactory.getLog(ReceiveSMSShell.class);
    private MainShell main;
	private Shell shell;
	private Display display;
	
	private Text textSMS;
	private CoolButton btnClose, btnNext, btnReply, btnFace;
	private Label lblQQ, lblNick, lblTime; 
	
	private ReceiveIMPacket packet;
	private IconHolder icons = IconHolder.getInstance();
	
	/**
	 * 构造函数
	 * @param main MainShell对象
	 */
	public ReceiveSMSShell(MainShell main) {
	    this.main = main;
		display = main.getDisplay();
		shell = new Shell(display, SWT.SHELL_TRIM);
		shell.setSize(350, 200);
		shell.setImage(icons.getImage(IconHolder.icoMobile));
		shell.setText(LumaQQ.getString("receive.sms.title"));
		// 添加监听器
		shell.addShellListener(this);
		// 初始化界面
		initLayout();
	}

    /**
     * 初始化界面
     */
    private void initLayout() {
        GridLayout layout = new GridLayout();
        shell.setLayout(layout);
        
        Composite comp = new Composite(shell, SWT.NONE);
        comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        layout = new GridLayout();
        layout.numColumns = 3;
        comp.setLayout(layout);
        
		// QQ号标签
		lblQQ = new Label(comp, SWT.LEFT);
		GridData gd = new GridData();
		gd.widthHint = 80;
		lblQQ.setLayoutData(gd);		
		// 昵称标签
		lblNick = new Label(comp, SWT.LEFT);
		gd = new GridData();
		gd.widthHint = 80;
		lblNick.setLayoutData(gd);
		// 时间标签
		lblTime = new Label(comp, SWT.CENTER);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		lblTime.setLayoutData(gd);		
		
		// 消息框
		textSMS = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.READ_ONLY);		
		textSMS.setLayoutData(new GridData(GridData.FILL_BOTH));
		textSMS.addKeyListener(new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
                if(e.stateMask == SWT.ALT) {
        		    if(e.character == 'r' || e.character == 'R')
        		        reply();
        		    else if(e.character == 'c' || e.character == 'C')
        		        shell.close();
        		    else if(e.character == 'n' || e.character == 'N')
        		        next();
        		}
            }
        });
		
		// 按钮区
		comp = new Composite(shell, SWT.NONE);
		comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		layout = new GridLayout();
		layout.numColumns = 3;		
		comp.setLayout(layout);
		
		btnReply = new CoolButton(comp, SWT.RIGHT | MySWT.HOVER, LumaQQ.getString("receive.sms.button.reply"), icons.getImage(IconHolder.icoMobile));
		gd = new GridData();
		gd.widthHint = 100;
		btnReply.setLayoutData(gd);
		btnReply.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                reply();
            }
		});
		
		btnClose = new CoolButton(comp, SWT.CENTER | MySWT.HOVER, LumaQQ.getString("receive.sms.button.close"), null);
		gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
		gd.grabExcessHorizontalSpace = true;
		gd.widthHint = 80;
		btnClose.setLayoutData(gd);
		btnClose.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                shell.close();
            }
		});
		
		btnNext = new CoolButton(comp, SWT.CENTER | MySWT.HOVER, LumaQQ.getString("receive.sms.button.next"), null);
		gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
		gd.widthHint = 80;
		btnNext.setLayoutData(gd);
		btnNext.setEnabled(false);
		btnNext.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                next();
            }
		});
    }
    
	/**
     * 查看下一条手机短信
     */
    protected void next() {
        main.getShellLauncher().openReceiveSMSShell();
    }

    /**
     * 回复短信
     */
    protected void reply() {
        shell.close();
        main.getShellLauncher().openSMSShell(packet.sms.sender);
    }

    /**
	 * 打开shell
	 */
	public void open()	{
		// 设置窗口位置
	    Rectangle rect = display.getClientArea();
	    Point size = shell.getSize();
	    shell.setLocation((rect.width - size.x) / 2, (rect.height - size.y) / 2);
		// 打开shell
		shell.layout();
		shell.open();
		textSMS.setFocus();
	}
	
	/**
	 * 使next按钮使能或禁止
	 * @param b true表示使能
	 */
	public void setNextButtonEnabled(boolean b) {
	    btnNext.setEnabled(b);
	}
	
	/**
	 * 设置短信内容到文本框
	 * 
	 * @param sms
	 * 			短信内容
	 */
	public void setSMS(ReceiveIMPacket packet) {
	    this.packet = packet;
	    textSMS.setText(packet.sms.message);
	    lblNick.setText(LumaQQ.getString("receive.sms.label.nick", new Object[] { packet.sms.senderName }));
	    lblQQ.setText(LumaQQ.getString("receive.sms.label.qq", new Object[] { String.valueOf(packet.sms.sender) }));
	    lblTime.setText(LumaQQ.getString("receive.sms.label.time", new Object[] { DateUtil.getCurrentDateTimeString() }));
	}
	
    /**
	 * 是当前窗口激活
	 */
	public void setActive() {
		shell.setActive();
	}	
	
	/**
	 * 代理方法,设置窗口的最小化状态
	 * @param b
	 */
	public void setMinimized(boolean b) {
		shell.setMinimized(b);
	}
	
	/**
	 * 使chatbox获得焦点
	 */
	public void setFocus() {
		textSMS.setFocus();
	}
	
	/* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
     */
    public void shellClosed(ShellEvent e) {
        main.getShellRegistry().deregisterReceiveSMSShell();
    }
}

⌨️ 快捷键说明

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