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

📄 tempclusterinfowizardpage.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.cluster;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import edu.tsinghua.lumaqq.Colors;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.tool.AroundBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.UITool;
import edu.tsinghua.swt.models.ShutterModel;

/**
 * 临时群信息填写页
 * 
 * @author luma
 */
public class TempClusterInfoWizardPage extends WizardPage {
    private int tempType;
    private Text textName;
    private Label lblParent;
    private CCombo comboParent;
    private ClusterWizard wizard;
    private List clusters;
    
    /**
     * @param pageName
     */
    protected TempClusterInfoWizardPage(String pageName) {
        super(pageName);
        setTitle(LumaQQ.getString("temp.title"));
        setMessage(LumaQQ.getString("temp.message"));
    }

    /* (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());
        GridLayout layout = new GridLayout(2, false);
        layout.marginHeight = layout.marginWidth = 15;
        layout.verticalSpacing = 8;
        control.setLayout(layout);
        control.addPaintListener(new AroundBorderPaintListener(new Class[] { Text.class, CCombo.class }));

        UITool.setDefaultBackground(control.getBackground());
        
        // 群名称
        UITool.createLabel(control, LumaQQ.getString("temp.name"));
        // 群名称文本框
        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        gd.heightHint = 18;
        gd.widthHint = 200;
        textName = UITool.createSingleText(control, gd);
        textName.setBackground(Colors.WHITE);
        textName.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                setPageComplete(validatePage());
            }
        });
        // 父群
        lblParent = UITool.createLabel(control, LumaQQ.getString("temp.parent.cluster"));
        // 父群选择框
        gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        comboParent = UITool.createCCombo(control, gd);
        comboParent.setBackground(Colors.WHITE);        
        initParentCluster();
        refreshControlStatus();
        
        setControl(control);
    }
    
    /**
     * 刷新控件状态
     */
    private void refreshControlStatus() {
        boolean visible = tempType == CreateWhatWizardPage.DISCUSSION_GROUP;
        lblParent.setVisible(visible);
        comboParent.setVisible(visible);
    }

    /**
     * 把现有的群添加到下拉框中
     */
    private void initParentCluster() {
        clusters = new ArrayList();
        if(tempType == CreateWhatWizardPage.MULTI_TALK)
            return;
        
        MainShell main = wizard.getMainShell();
        int[] groups = main.getMVCHelper().listClusterGroup();
        ShutterModel model = main.getModel();
        if(clusters != null && groups.length > 0) {
            for(int i = 0; i < groups.length; i++) {                
	            int clusterCount = model.getItemCount(groups[i]);
	            for(int j = 0; j < clusterCount; j++) {
	                ClusterModel c = (ClusterModel)model.getItem(groups[i], j);
	                if(c.isPermanent()) {
	                    comboParent.add(c.getName());
	                    clusters.add(c);
	                }
	            }
            }
        }
        comboParent.select(0);
        comboParent.setVisibleItemCount(10);
    }
    
    /**
     * 发送创建临时群请求
     */
    public void doCreate() {
        wizard.getMainShell().getClient().createTemporaryCluster(
                getClusterName(),
                (getTempType() == CreateWhatWizardPage.MULTI_TALK) ? QQ.QQ_TEMP_CLUSTER_TYPE_MULTI_TALK : QQ.QQ_TEMP_CLUSTER_TYPE_DISCUSSION_GROUP,
                getParentClusterId(),
                wizard.getMemberQQArray());
    }

    /**
     * @return Returns the tempType.
     */
    public int getTempType() {
        return tempType;
    }
    
    /**
     * @param tempType The tempType to set.
     */
    public void setTempType(int tempType) {
        this.tempType = tempType;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.wizard.WizardPage#setWizard(org.eclipse.jface.wizard.IWizard)
     */
    public void setWizard(IWizard newWizard) {
        super.setWizard(newWizard);
        this.wizard = (ClusterWizard)newWizard;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
     */
    public void setVisible(boolean visible) {
        if(visible)
            refreshControlStatus();
        super.setVisible(visible);        
    }
    
    /**
     * @return
     * 	 	父群的ClusterModel对象
     */
    public ClusterModel getParentClusterModel() {
        if(comboParent.getItemCount() == 0)
            return null;
        else
            return (ClusterModel)clusters.get(comboParent.getSelectionIndex());
    }
    
    /**
     * @return
     * 		父群内部ID,如果没有父群,返回0
     */
    public int getParentClusterId() {
        ClusterModel c = getParentClusterModel();
        if(c == null)
            return 0;
        else
            return c.getClusterId();
    }
    
    /**
     * @return
     * 		群名称
     */
    public String getClusterName() {
        return textName.getText().trim();
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
     */
    public boolean isPageComplete() {
        return validatePage();
    }

    /**
     * @return
     * 		true表示输入有效
     */
    private boolean validatePage() {
        if("".equals(textName.getText().trim())) {
            setErrorMessage(LumaQQ.getString("error.empty.name"));
            return false;
        }
        
        if(tempType == CreateWhatWizardPage.DISCUSSION_GROUP) {
            if(comboParent.getSelectionIndex() == -1) {
                setErrorMessage(LumaQQ.getString("error.parent.empty"));
                return false;
            }
        }
        
        setErrorMessage(null);
        return true;
    }
}

⌨️ 快捷键说明

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