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

📄 operationshell.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.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;

/**
 * 操作提示窗口,当有需要比较长时间的操作在进行时,显示这个窗口
 * 
 * @author 马若劼
 */
public class OperationShell extends ShellAdapter {
	private IconHolder icons = IconHolder.getInstance();
	private Label lblHint;
	private Shell shell;
	private MainShell main;
	private Display display;
	// 操作是成功还是失败
	private boolean success;
	// 成功的字符串
	private String successString;
	// 失败的字符串
	private String failString;
	
	/**
	 * @param parent
	 * @param style
	 */
	public OperationShell(MainShell main) {		
		this.main = main;
		this.display = main.display;
	    // create dialog
		shell = new Shell(main.getShell(), SWT.BORDER | SWT.MODELESS);
		// set title and image
		shell.setImage(icons.getResource(IconHolder.icoQQ));
		// init child controls
		initLayout();
		// add listener
		shell.addShellListener(this);
	}
	
	/**
	 * 打开对话框
	 */
	public void open() {
		// layout
		shell.layout();
		shell.pack();
		// set dialog to center of screen
		Rectangle dialogRect = shell.getBounds();
		Rectangle displayRect = display.getBounds();
		shell.setLocation((displayRect.width-dialogRect.width)/2, (displayRect.height-dialogRect.height)/2);
		// open
		shell.open();
	}

	/**
	 * @param dialog
	 */
	private void initLayout() {
		shell.setLayout(new GridLayout());
		lblHint = new Label(shell, SWT.NONE);
		lblHint.setLayoutData(new GridData(GridData.FILL_BOTH));
	}
	
	/**
	 * 设置窗口标题
	 * @param title
	 */
	public void setTitle(String title) {
	    shell.setText(title);
	}
	
	/**
	 * 设置提示消息
	 * @param hint
	 */
	public void setHint(String hint) {
	    lblHint.setText(hint);
	}
	
	/**
	 * 关闭窗口
	 */
	public void close(boolean success) {
	    this.success = success;
		shell.close();
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.swt.events.ShellListener#shellClosed(org.eclipse.swt.events.ShellEvent)
	 */
	public void shellClosed(ShellEvent e) {
	    main.opDialog = null;
		/* 根据操作结果和操作方式显示不同的消息框 */
		MessageBox box = null;
		if(success) {
			box = new MessageBox(main.getShell(), SWT.ICON_INFORMATION | SWT.OK);
			box.setText(LumaQQ.getResourceString("message.box.common.success.title"));
			box.setMessage(successString);			
		} else {
			box = new MessageBox(main.getShell(), SWT.ICON_ERROR | SWT.OK);
			box.setText(LumaQQ.getResourceString("message.box.common.fail.title"));
			box.setMessage(failString);		
		}
		box.open();
	}

	/**
	 * @return true 如果对话框已经被释放
	 */
	public boolean isDisposed() {
		return (shell == null || shell.isDisposed());
	}
	
    /**
     * @return Returns the failString.
     */
    public String getFailString() {
        return failString;
    }
    
    /**
     * @param failString The failString to set.
     */
    public void setFailString(String failString) {
        this.failString = failString;
    }
    
    /**
     * @return Returns the successString.
     */
    public String getSuccessString() {
        return successString;
    }
    
    /**
     * @param successString The successString to set.
     */
    public void setSuccessString(String successString) {
        this.successString = successString;
    }
}

⌨️ 快捷键说明

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