📄 batchdetecthiddenshell.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 java.util.Hashtable;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableTree;
import org.eclipse.swt.custom.TableTreeItem;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.Button;
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.TableColumn;
import edu.tsinghua.lumaqq.IPSeeker;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.GroupModel;
import edu.tsinghua.lumaqq.models.IQQNode;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.events.IQQListener;
import edu.tsinghua.lumaqq.qq.packets.in.ReceiveIMPacket;
import edu.tsinghua.lumaqq.qq.packets.out.SendIMPacket;
import edu.tsinghua.lumaqq.ui.tool.BusyFlag;
/**
* <pre>
* 批量探测好友是否隐身的窗口,如来神掌,万无一失
* </pre>
*
* @author 马若劼
*/
public class BatchDetectHiddenShell extends ShellAdapter implements IQQListener {
/**
* 隔一定时间发送一个探测包,免得太快堵塞
*
* @author luma
*/
private class DetectTask extends TimerTask {
public void run() {
getNext();
if(f == null) {
timer.cancel();
timer = null;
display.syncExec(new Runnable() {
public void run() {
btnCast.setEnabled(true);
}
});
} else
main.getClient().detectHidden(f.getQQ());
}
}
private IconHolder icons = IconHolder.getInstance();
private Label lblHint;
private Shell shell;
private MainShell main;
private Button btnCast;
private Display display;
private TableTree tt;
private Timer timer;
private Hashtable hash;
private FriendModel f;
private List hiddens;
// 当前探测到的组索引和好友索引
private int currentG, currentF;
// 探测间隔
private static final int INTERVAL = 1500;
/**
* 创建一个如来神掌乱舞窗口
*
* @param parent
* main shell
*/
public BatchDetectHiddenShell(MainShell main) {
this.main = main;
this.display = main.getDisplay();
// create shell
shell = new Shell(display, SWT.SHELL_TRIM);
shell.setText(LumaQQ.getString("rlsz.lw.title"));
shell.setSize(700, 600);
// set title and image
shell.setImage(icons.getImage(IconHolder.icoPalms));
shell.addShellListener(this);
hash = new Hashtable();
// init child controls
initLayout();
}
/**
* 得到下一个探测的好友,如果都探测完了,返回null
*/
private void getNext() {
display.syncExec(new Runnable() {
public void run() {
TableTreeItem[] root = tt.getItems();
while(currentG < root.length) {
if(currentF >= root[currentG].getItemCount()) {
currentF = 0;
currentG++;
} else {
TableTreeItem tti = root[currentG].getItems()[currentF];
f = (FriendModel)tti.getData();
if(!f.isOffline() && !f.isHidden()) {
tti.setText(1, LumaQQ.getString("rlsz.lw.online"));
currentF++;
} else if(tti.getChecked()) {
tti.setText(1, LumaQQ.getString("rlsz.lw.detecting"));
currentF++;
return;
} else {
tti.setText(1, LumaQQ.getString("rlsz.lw.skip"));
currentF++;
}
}
}
if(currentG >= root.length)
f = null;
}
});
}
/**
* 打开对话框
*/
public void open() {
// layout
shell.layout();
// 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();
// 加为QQ listener
main.getClient().addQQListener(this);
}
/**
* @param dialog
*/
private void initLayout() {
shell.setLayout(new GridLayout());
// 提示标签
lblHint = new Label(shell, SWT.LEFT);
lblHint.setText(LumaQQ.getString("rlsz.lw.label.hint"));
lblHint.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// table tree
tt = new TableTree(shell, SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
tt.setLayoutData(new GridData(GridData.FILL_BOTH));
TableColumn tc = new TableColumn(tt.getTable(), SWT.LEFT);
tc.setWidth(180);
tc = new TableColumn(tt.getTable(), SWT.LEFT);
tc.setText(LumaQQ.getString("rlsz.lw.table.header.status"));
tc.setWidth(100);
tc = new TableColumn(tt.getTable(), SWT.LEFT);
tc.setText(LumaQQ.getString("rlsz.lw.table.header.internet.ip"));
tc.setWidth(100);
tc = new TableColumn(tt.getTable(), SWT.LEFT);
tc.setText(LumaQQ.getString("rlsz.lw.table.header.location"));
tc.setWidth(200);
tc = new TableColumn(tt.getTable(), SWT.LEFT);
tc.setText(LumaQQ.getString("rlsz.lw.table.header.local.ip"));
tc.setWidth(100);
tt.getTable().setHeaderVisible(true);
tt.getTable().setLinesVisible(true);
tt.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if(e.detail == SWT.CHECK) {
TableTreeItem tti = (TableTreeItem)e.item;
TableTreeItem[] children = tti.getItems();
for(int i = 0; i < children.length; i++)
children[i].setChecked(tti.getChecked());
}
}
public void widgetDefaultSelected(SelectionEvent e) {
TableTreeItem tti = (TableTreeItem)e.item;
if(tti.getItemCount() == 0) {
FriendModel f = (FriendModel)tti.getData();
main.getShellLauncher().openNormalIMWindow(f);
}
}
});
// 按钮行
Composite btnComp = new Composite(shell, SWT.NONE);
btnComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -