📄 mainshell.java
字号:
} else if(item.getData() instanceof Directory) {
boolean accept = diskManager.isChildCreatable((Directory)item.getData());
event.detail = accept ? event.operations : DND.DROP_NONE;
if(accept)
event.feedback |= DND.FEEDBACK_EXPAND;
} else
event.detail = DND.DROP_NONE;
}
public void drop(DropTargetEvent event) {
Object moved = DragHelper.getObject();
boolean moveFile = moved instanceof File;
Object obj = event.item.getData();
if(obj instanceof Integer) {
if(moveFile)
diskJobQueue.addJob(new MoveJob((File)moved, 0));
else
diskJobQueue.addJob(new MoveJob((Directory)moved, 0));
} else if(obj instanceof Directory) {
if(moveFile)
diskJobQueue.addJob(new MoveJob((File)moved, ((Directory)obj).id));
else
diskJobQueue.addJob(new MoveJob((Directory)moved, ((Directory)obj).id));
}
}
public void dropAccept(DropTargetEvent event) {
}
});
// 密码面板
passwordPanel = new Composite(diskCenter, SWT.NONE);
passwordPanel.setBackground(Colors.WHITE);
layout = new GridLayout();
layout.verticalSpacing = 15;
layout.marginWidth = layout.marginHeight = 15;
passwordPanel.setLayout(layout);
passwordPanel.addPaintListener(new CenterBorderPaintListener(new Class[] { Text.class }, 20, Colors.PAGE_CONTROL_BORDER));
UITool.setDefaultBackground(passwordPanel.getBackground());
// 提示
UITool.createLabel(passwordPanel, disk_hint_input_password);
// 密码输入框
final Text textPassword = UITool.createSingleText(passwordPanel, new GridData(GridData.FILL_HORIZONTAL), SWT.SINGLE | SWT.PASSWORD);
textPassword.setTextLimit(16);
// 确定按钮
Slat btnOK = UITool.createSlat(passwordPanel, button_ok, new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
btnOK.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
diskManager.setPassword(textPassword.getText());
switchToDiskViewer();
}
});
// hint bar
Composite hintContainer = new Composite(comp, SWT.NONE);
hintContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
layout = new GridLayout(2, false);
layout.marginWidth = layout.marginHeight = layout.horizontalSpacing = layout.verticalSpacing = 0;
hintContainer.setLayout(layout);
lblDiskHint = new CLabel(hintContainer, SWT.LEFT);
lblDiskHint.setBackground(Colors.LIGHT_BLUE_2);
lblDiskHint.setLayoutData(new GridData(GridData.FILL_BOTH));
lblDiskHint.setText(NLS.bind(disk_hint_capacity, FileTool.getSizeString(diskManager.getUnused()), FileTool.getSizeString(diskManager.getCapacity())));
// 取消单个文件按钮
ToolBar cBar = new ToolBar(hintContainer, SWT.FLAT);
cBar.setBackground(Colors.LIGHT_BLUE_2);
cBar.setLayoutData(new GridData(GridData.FILL_VERTICAL));
tiAbort = new ToolItem(cBar, SWT.PUSH);
tiAbort.setImage(res.getImage(Resources.icoAbort));
tiAbort.setToolTipText(disk_hint_abort);
tiAbort.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ICancelableJob job = (ICancelableJob)tiAbort.getData();
if(job == null)
return;
job.cancel(ICancelableJob.ABORT);
}
});
tiAbortAll = new ToolItem(cBar, SWT.PUSH);
tiAbortAll.setImage(res.getImage(Resources.icoAbortAll));
tiAbortAll.setToolTipText(disk_hint_abort_all);
tiAbortAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ICancelableJob job = (ICancelableJob)tiAbortAll.getData();
if(job == null)
return;
job.cancel(ICancelableJob.ABORT_ALL);
}
});
switchToDiskViewer();
onDiskViewerSelection(null);
setFileAbortButtonStatus(false);
views[VIEW_DISK] = comp;
}
/**
* 上传时调用
*
* @param selection
*/
protected void onDiskUpload(IStructuredSelection selection) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
String path = dialog.open();
if(path == null)
return;
Object obj = selection.getFirstElement();
String name = FileTool.getFilename(path);
if(obj instanceof Integer) {
File f = diskManager.getMyFile(name, 0);
if(f == null)
diskJobQueue.addJob(new CreateFileJob(0, path));
else
diskJobQueue.addJob(new CreateFileJob(0, path, f));
} else if(obj instanceof Directory) {
Directory d = (Directory)obj;
File f = diskManager.getMyFile(name, d.id);
if(f == null)
diskJobQueue.addJob(new CreateFileJob(d.id, path));
else
diskJobQueue.addJob(new CreateFileJob(d.id, path, f));
}
}
/**
* 把一个可以取消的任务添加到取消按钮的data中
*
* @param job
*/
public void hookCancelableJob(ICancelableJob job) {
tiAbort.setData(job);
tiAbortAll.setData(job);
}
/**
* 设置按钮状态
*
* @param enable
*/
public void setFileAbortButtonStatus(boolean enable) {
tiAbort.setEnabled(enable);
tiAbortAll.setEnabled(enable);
}
/**
* 点击下载时
*
* @param e
*/
public void onDiskDownload(IStructuredSelection s) {
if(s.isEmpty())
return;
Object obj = s.getFirstElement();
if(obj instanceof File) {
File f = (File)obj;
DirectoryDialog dialog = new DirectoryDialog(getShell());
String dir = dialog.open();
if(dir != null) {
// 询问用户是否断点续传
if(!dir.endsWith(java.io.File.separator))
dir += java.io.File.separatorChar;
java.io.File diskfile = new java.io.File(dir + f.name);
boolean resume = false;
if(diskfile.exists()) {
MessageDialog msg = new MessageDialog(getShell(),
message_box_common_question_title,
null,
NLS.bind(message_box_resume_file, diskfile.getAbsolutePath()),
MessageDialog.QUESTION,
new String[] { button_resume, button_overwrite, button_cancel },
0);
switch(msg.open()) {
case 0:
resume = true;
break;
case 1:
resume = false;
break;
default:
return;
}
}
// 开始任务
if(f.owner == 0)
return;
diskJobQueue.addJob(new DownloadFileJob(f, dir, resume));
}
}
}
/**
* 切换到网络硬盘密码输入面板
*/
public void switchToDiskPasswordPanel() {
StackLayout layout = (StackLayout)diskCenter.getLayout();
if(layout.topControl != passwordPanel) {
layout.topControl = passwordPanel;
diskCenter.layout();
}
}
/**
* 切换到网络硬盘树型图面板
*/
public void switchToDiskViewer() {
StackLayout layout = (StackLayout)diskCenter.getLayout();
if(layout.topControl != diskTreePanel) {
layout.topControl = diskTreePanel;
diskCenter.layout();
}
}
/**
* 点击网络硬盘密码设置时
*/
protected void onDiskPassword() {
DiskPasswordDialog dialog = new DiskPasswordDialog(this);
if(dialog.open() == IDialogConstants.OK_ID) {
if(dialog.isSetPassword())
diskJobQueue.addJob(new SetDiskPasswordJob(dialog.getOldPassword(), dialog.getNewPassword()));
else
diskJobQueue.addJob(new CancelDiskPasswordJob(dialog.getOldPassword()));
}
}
/**
* 初始化好友视图
*/
private void initFriendView() {
// 好友视图
blind = new Blind(viewContainer, SWT.BORDER);
views[VIEW_FRIEND] = blind;
}
/**
* 初始化shell和边框,等等
*/
private Composite initShell() {
int shellStyle = SWT.NO_TRIM | SWT.NO_BACKGROUND;
if(optionHelper.isOnTop())
shellStyle |= SWT.ON_TOP;
shell = new Shell(display, shellStyle);
shell.setImage(res.getImage(Resources.icoLumaQQ));
// 添加事件监听器
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if(font != null)
font.dispose();
if(defaultStyle != null)
if(defaultStyle.foreground != null)
defaultStyle.foreground.dispose();
if(groupColor != null)
groupColor.dispose();
Colors.dispose();
}
});
shell.addShellListener(new ShellAdapter() {
public void shellIconified(ShellEvent e) {
if(item != null && !item.getVisible()) {
initTray();
uiHelper.setTrayIconByStatus();
}
menuHelper.hideAllMenu();
}
public void shellClosed(ShellEvent e) {
// 上传分组
checkGroupDirty();
// 关闭Client
if(processor != null && client != null)
client.removeQQListener(processor);
// 注销
if(client != null) {
client.logout();
client.release();
}
// 关闭定时器
timerHelper.dispose();
// 保存用户信息文件
configHelper.saveSelf();
// 保存好友分组信息
blindHelper.saveModel();
// 释放Tray Icon
if(item != null)
item.dispose();
// 停止声音线程
if(sounder != null)
sounder.setStop(true);
// 保存当前设置
if(optionHelper.getOptionsModel() != null) {
// 保存窗口位置大小
if(isOff()) {
Rectangle bound = shell.getBounds();
optionHelper.setLocationX(bound.x);
optionHelper.setLocationY(bound.y);
optionHelper.setWidth(bound.width);
optionHelper.setHeight(bound.height);
}
// 保存字体信息
if(defaultStyle != null) {
optionHelper.setFontName(defaultStyle.fontName);
optionHelper.setFontSize(defaultStyle.fontSize);
optionHelper.setBold((defaultStyle.fontStyle & SWT.BOLD) != 0);
optionHelper.setItalic((defaultStyle.fontStyle & SWT.ITALIC) != 0);
}
// 保存字体颜色
if(defaultStyle.foreground != null) {
RGB rgb = defaultStyle.foreground.getRGB();
optionHelper.setFontColor(rgb);
}
optionHelper.save();
}
// 保存表情文件
FaceRegistry.getInstance().save();
// 关闭消息队列
if(rm != null)
rm.dispose();
// 关闭群分类文件
if(ccu != null)
ccu.dispose();
}
});
shell.addControlListener(new ControlAdapter() {
public void controlMoved(ControlEvent e) {
shellLocation = shell.getLocation();
}
});
BorderStyler styler = new BorderStyler(this);
styler.setCheckMinimizeWhenClose(true);
if(!optionHelper.isOnTop())
styler.setHideWhenMinimize(optionHelper.isHideWhenMinimize());
styler.setMaximizeWhenDoubleClick(false);
styler.setShowPlusButton(true);
styler.setPlusMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
if(menuHelper.isPlusMenuVisible())
menuHelper.setPlusMenuVisible(false);
else {
Control c = (Control)e.getSource();
Rectangle bound = c.getBounds();
menuHelper.setPlusMenuLocation(c.getParent().toDisplay(bound.x, bound.y + bound.height));
menuHelper.setPlusMenuVisible(true);
}
}
});
styler.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
menuHelper.hideAllMenu();
}
});
return styler.decorateShell(shell);
}
/**
* 画背景
*
* @param e
* @param clientWidth
*/
protected void paintBackground(PaintEvent e, int clientWidth, Image tile) {
int backWidth = tile.getBounds().width;
int x = 0;
while(x < clientWidth) {
e.gc.drawImage(tile, x, 0);
x += backWidth;
}
}
/**
* @return Returns the configHelper.
*/
public ConfigHelper getConfigHelper() {
return configHelper;
}
public MessageHelper getMessageHelper() {
return messageHelper;
}
public User getMyModel() {
return myModel;
}
public List<User> getCurrentOnlines() {
return currentOnlines;
}
public TipHelper getTipHelper() {
return tipHelper;
}
public UIHelper getUIHelper() {
return uiHelper;
}
/**
* 设置QQ在线人数
*
* @param currentOnlineNumber
* 当前QQ在线人数
*/
public void setCurrentOnlineNumber(String currentOnlineNumber) {
this.currentOnlineNumber = currentOnlineNumber;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -