📄 howtosearchclusterwizardpage.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.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.qq.Util;
import edu.tsinghua.lumaqq.ui.tool.AroundBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.UITool;
/**
* 查找群的方式页
*
* @author luma
*/
public class HowToSearchClusterWizardPage extends WizardPage {
public static final int DEMO_CLUSTER = 0;
public static final int BY_ID = 1;
private Button rdoDemo, rdoById;
private Text textId;
private SearchWizard wizard;
/**
* @param pageName
*/
public HowToSearchClusterWizardPage(String pageName) {
super(pageName);
setTitle(LumaQQ.getString("how.to.search.cluster.title"));
setMessage(LumaQQ.getString("how.to.search.cluster.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.marginHeight = layout.marginWidth = 15;
layout.verticalSpacing = 8;
control.setLayout(layout);
control.addPaintListener(new AroundBorderPaintListener(new Class[] { Text.class }));
UITool.setDefaultBackground(control.getBackground());
SelectionListener sl = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
wizard.setSearchMode(rdoDemo.getSelection() ? SearchWizard.DEMO_CLUSTER : SearchWizard.BY_CLUSTER_ID);
refreshControlStatus();
setPageComplete(validatePage());
}
};
// 查找示范群
rdoDemo = UITool.createRadio(control, LumaQQ.getString("how.to.search.demo.cluster"));
rdoDemo.setSelection(true);
rdoDemo.addSelectionListener(sl);
// 通过群ID
rdoById = UITool.createRadio(control, LumaQQ.getString("how.to.search.cluster.by.id"));
rdoById.addSelectionListener(sl);
// 群ID输入框
GridData gd = new GridData();
gd.widthHint = 100;
gd.heightHint = 18;
gd.horizontalIndent = 20;
textId = UITool.createSingleText(control, gd);
textId.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
setPageComplete(validatePage());
}
});
setControl(control);
refreshControlStatus();
}
/**
* 刷新控件状态
*/
private void refreshControlStatus() {
if(rdoDemo.getSelection()) {
textId.setEnabled(false);
textId.setBackground(getControl().getBackground());
} else {
textId.setEnabled(true);
textId.setBackground(Colors.WHITE);
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
*/
public boolean isPageComplete() {
return validatePage();
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
if(visible) {
wizard.setEnterResultPage(true);
wizard.setSearchMode(rdoDemo.getSelection() ? SearchWizard.DEMO_CLUSTER : SearchWizard.BY_CLUSTER_ID);
}
}
/**
* @return
* true表示输入有效
*/
private boolean validatePage() {
if(rdoById.getSelection()) {
if(!Util.isInt(textId.getText().trim())) {
setErrorMessage(LumaQQ.getString("error.invalid.cluster.id"));
return false;
}
}
setErrorMessage(null);
return true;
}
/**
* @return
* 搜索方式ID
*/
public int getSearchMethod() {
return rdoDemo.getSelection() ? DEMO_CLUSTER : BY_ID;
}
/**
* @return
* 得到群ID
*/
public int getClusterId() {
return Util.getInt(textId.getText().trim(), 0);
}
/**
* @return
* 包序号
*/
public char doSearch() {
if(rdoDemo.getSelection())
return wizard.getMainShell().getClient().searchDemoCluster();
else
return wizard.getMainShell().getClient().searchClusterById(Util.getInt(textId.getText().trim(), 0));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -