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

📄 addfriendclusterwizardpage.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.wizard.search;

import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

import edu.tsinghua.lumaqq.Colors;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.ui.tool.UITool;

/**
 * 添加好友或者群的页面
 * 
 * @author luma
 */
public class AddFriendClusterWizardPage extends WizardPage {
    private CLabel lblHint;
    private Text textAuth;
    private Button btnSend;
    private SearchWizard wizard;
    
    protected static final int INIT = -1;
    protected static final int ADDING = 0;
    protected static final int AUTH_INPUTING = 1;
    protected static final int AUTH_SENDING = 2;
    protected static final int ADD_TIMEOUT = 3;
    protected static final int ADD_FINISHED = 4;
    protected static final int AUTH_SENT = 5;
    protected static final int ADD_DENY = 6;
    protected static final int JOIN_TIMEOUT = 7;
    protected static final int JOIN_DENY = 8;
    protected static final int AUTH_TIMEOUT = 9;
    protected static final int JOINING = 10;
    protected static final int JOIN_FINISHED = 11;
    private int status;
    
    /**
     * @param pageName
     */
    protected AddFriendClusterWizardPage(String pageName) {
        super(pageName);
        setTitle(LumaQQ.getString("add.title"));
        setMessage(LumaQQ.getString("add.message"));
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.wizard.WizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
     */
    public void setWizard(IWizard newWizard) {
        super.setWizard(newWizard);
        wizard = (SearchWizard)newWizard;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
     */
    public void createControl(Composite parent) {
        Composite control = new Composite(parent, SWT.NONE);
        control.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        GridLayout layout = new GridLayout();
        layout.verticalSpacing = 20;
        control.setLayout(layout);
        
        UITool.setDefaultBackground(control.getBackground());
        
        // 提示标签
        lblHint = new CLabel(control, SWT.CENTER | SWT.WRAP);
        lblHint.setLayoutData(new GridData(GridData.FILL_BOTH));
        
        layout = new GridLayout(2, false);
        Composite c = UITool.createContainer(control, new GridData(GridData.HORIZONTAL_ALIGN_CENTER), layout);
        // 认证框
        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
        gd.heightHint = 60;
        gd.widthHint = 300;
        textAuth = UITool.createMultiText(c, gd, SWT.MULTI | SWT.WRAP | SWT.BORDER);
        textAuth.setBackground(Colors.WHITE);
        // 发送按钮
        btnSend = UITool.createButton(c, LumaQQ.getString("add.send"), new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL), SWT.PUSH);
        btnSend.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                wizard.doAuth(textAuth.getText());
            }
        });
        
        setAuthControlVisible(false);
        setStatus(INIT);
        
        setControl(control);
    }
    
    /**
     * 设置认证控件的可见状态
     * 
     * @param b
     */
    public void setAuthControlVisible(boolean b) {
        textAuth.setVisible(b);
        btnSend.setVisible(b);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
     */
    public void setVisible(boolean visible) {
        super.setVisible(visible);
        if(visible) {
            wizard.setEnterResultPage(false);
            wizard.doAdd();
        } else {
            setStatus(INIT);
        }
    }
    
    /**
     * 设置状态,刷新各个控件状态
     * @param status
     */
    public void setStatus(int status) {
        this.status = status;
        switch(status) {
            case INIT:
                setHint("");
                setAuthControlVisible(false);
                break;
            case ADDING:
            case JOINING:
                setHint(LumaQQ.getString("hint.processing"));
                setAuthControlVisible(false);
                break;
            case AUTH_INPUTING:
                setHint(LumaQQ.getString("hint.need.auth"));
                setAuthControlVisible(true);
                setSendButtonEnable(true);
                break;
            case AUTH_SENDING:
                setHint(LumaQQ.getString("hint.processing"));
                setAuthControlVisible(true);
                setSendButtonEnable(false);
                break;
            case ADD_FINISHED:            
                setHint(LumaQQ.getString("hint.added"));
                setAuthControlVisible(false);
                break;
            case ADD_TIMEOUT:
            case JOIN_TIMEOUT:
                setHint(LumaQQ.getString("error.timeout"));
                setAuthControlVisible(false);
                break;
            case ADD_DENY:
                setHint(LumaQQ.getString("hint.add.deny"));
                setAuthControlVisible(false);
                break;
            case AUTH_SENT:
                setHint(LumaQQ.getString("hint.auth.sent"));
                setAuthControlVisible(false);
                break;
            case AUTH_TIMEOUT:
                setHint(LumaQQ.getString("hint.auth.timeout"));
                setAuthControlVisible(true);
                setSendButtonEnable(true);
                break;
            case JOIN_DENY:
                setHint(LumaQQ.getString("hint.join.deny"));
                setAuthControlVisible(false);
                break;
            case JOIN_FINISHED:
                setHint(LumaQQ.getString("hint.joined"));
                setAuthControlVisible(false);
                break;
        }
        
        setPageComplete(isPageComplete());
    }
    
    /**
     * 设置发送按钮的使能状态
     * 
     * @param b
     */
    private void setSendButtonEnable(boolean b) {
        btnSend.setEnabled(b);
    }
    
    /**
     * 设置提示信息
     * 
     * @param hint
     */
    private void setHint(String hint) {
        lblHint.setText(hint);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
     */
    public boolean isPageComplete() {
        return status != INIT &&
        	status != ADDING &&
        	status != JOINING &&
        	status != AUTH_SENDING;
    }
}

⌨️ 快捷键说明

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