📄 userinfoshell.java
字号:
/**
* 从FriendRemark中创建Remark对象
* @param fr
* @return
*/
private Remark createRemarkElement(FriendRemark fr) {
Remark remark = new RemarkImpl();
remark.setName(fr.name);
remark.setZipcode(fr.zipcode);
remark.setTelephone(fr.telephone);
remark.setMobile(fr.mobile);
remark.setEmail(fr.email);
remark.setAddress(fr.address);
remark.setNote(fr.note);
remark.setQqNum(String.valueOf(qqNum));
return remark;
}
/**
* 保存备注信息到xml文件
* @param remark2
*/
private void saveToXML(final Remark remark) {
RemarkUtils ru = RemarkUtils.getInstance();
ru.addRemark(remark);
ru.save();
// 修改model的realName属性,如果现在好友列表正处于显示备注名称模式,则还要修改name属性
main.display.syncExec(new Runnable() {
public void run() {
f.addProperty("realName", remark.getName());
if(!OptionUtils.getInstance().isShowNick())
f.addProperty("name", remark.getName());
}
});
}
// 初始化网络安全面板
private void initSecurityPanel() {
Composite security = createPanel();
security.setVisible(false);
composites[SECURITY] = security;
// banner
securityBanner = new Label(security, SWT.NONE);
securityBanner.setBackground(bannerBackground);
securityBanner.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
FormData fd = new FormData();
fd.left = fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(0, 24);
securityBanner.setLayoutData(fd);
securityBanner.addPaintListener(new BannerPaintListener(LumaQQ.getResourceString("user.info.banner.security")));
// 修改密码check box
chkChangePassword = new Button(security, SWT.CHECK);
chkChangePassword.setBackground(panelBackground);
chkChangePassword.setText(LumaQQ.getResourceString("user.info.security.changepassword"));
fd = new FormData();
fd.left = new FormAttachment(0, 5);
fd.top = new FormAttachment(securityBanner, 5, SWT.BOTTOM);
chkChangePassword.setLayoutData(fd);
Label lblSeparator = new Label(security, SWT.SEPARATOR | SWT.HORIZONTAL);
lblSeparator.setBackground(panelBackground);
fd = new FormData();
fd.left = new FormAttachment(chkChangePassword, 0, SWT.RIGHT);
fd.right = new FormAttachment(100, -5);
fd.top = new FormAttachment(chkChangePassword, 0, SWT.TOP);
fd.bottom = new FormAttachment(chkChangePassword, 0, SWT.BOTTOM);
lblSeparator.setLayoutData(fd);
// 旧密码标签
Label lblOldPassword = new Label(security, SWT.NONE);
lblOldPassword.setBackground(panelBackground);
lblOldPassword.setText(LumaQQ.getResourceString("user.info.security.oldpassword"));
fd = new FormData();
fd.left = new FormAttachment(chkChangePassword, 10, SWT.LEFT);
fd.right = new FormAttachment(30, 0);
fd.top = new FormAttachment(securityBanner, 25, SWT.BOTTOM);
lblOldPassword.setLayoutData(fd);
// 旧密码文本框
textOldPassword = new Text(security, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
textOldPassword.setBackground(controlBackground);
textOldPassword.setTextLimit(16);
fd = new FormData();
fd.left = new FormAttachment(lblOldPassword, 3, SWT.RIGHT);
fd.right = new FormAttachment(70, 0);
fd.top = new FormAttachment(securityBanner, 25, SWT.BOTTOM);
textOldPassword.setLayoutData(fd);
// 输入密码的提示,长度在16位以内
Label lblHint = new Label(security, SWT.NONE);
lblHint.setBackground(panelBackground);
lblHint.setText(LumaQQ.getResourceString("user.info.security.changepassword.hint"));
fd = new FormData();
fd.left = new FormAttachment(70, 5);
fd.top = new FormAttachment(securityBanner, 25, SWT.BOTTOM);
lblHint.setLayoutData(fd);
// 新密码标签
Label lblNewPassword = new Label(security, SWT.NONE);
lblNewPassword.setBackground(panelBackground);
lblNewPassword.setText(LumaQQ.getResourceString("user.info.security.newpassword"));
fd = new FormData();
fd.left = new FormAttachment(chkChangePassword, 10, SWT.LEFT);
fd.right = new FormAttachment(30, 0);
fd.top = new FormAttachment(securityBanner, 50, SWT.BOTTOM);
lblNewPassword.setLayoutData(fd);
// 新密码文本框
textNewPassword = new Text(security, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
textNewPassword.setBackground(controlBackground);
textNewPassword.setTextLimit(16);
fd = new FormData();
fd.left = new FormAttachment(lblNewPassword, 3, SWT.RIGHT);
fd.right = new FormAttachment(70, 0);
fd.top = new FormAttachment(securityBanner, 50, SWT.BOTTOM);
textNewPassword.setLayoutData(fd);
// 输入密码的提示,长度在16位以内
lblHint = new Label(security, SWT.NONE);
lblHint.setBackground(panelBackground);
lblHint.setText(LumaQQ.getResourceString("user.info.security.changepassword.hint"));
fd = new FormData();
fd.left = new FormAttachment(70, 5);
fd.top = new FormAttachment(securityBanner, 50, SWT.BOTTOM);
lblHint.setLayoutData(fd);
// 确认密码标签
Label lblConfirmPassword = new Label(security, SWT.NONE);
lblConfirmPassword.setBackground(panelBackground);
lblConfirmPassword.setText(LumaQQ.getResourceString("user.info.security.confirmpassword"));
fd = new FormData();
fd.left = new FormAttachment(chkChangePassword, 10, SWT.LEFT);
fd.right = new FormAttachment(30, 0);
fd.top = new FormAttachment(securityBanner, 75, SWT.BOTTOM);
lblConfirmPassword.setLayoutData(fd);
// 确认密码文本框
textConfirmPassword = new Text(security, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
textConfirmPassword.setBackground(controlBackground);
textConfirmPassword.setTextLimit(16);
fd = new FormData();
fd.left = new FormAttachment(lblConfirmPassword, 3, SWT.RIGHT);
fd.right = new FormAttachment(70, 0);
fd.top = new FormAttachment(securityBanner, 75, SWT.BOTTOM);
textConfirmPassword.setLayoutData(fd);
// open hp标签
Label lblOpenHp = new Label(security, SWT.NONE);
lblOpenHp.setBackground(panelBackground);
lblOpenHp.setText(LumaQQ.getResourceString("user.info.security.openhp"));
fd = new FormData();
fd.left = new FormAttachment(0, 5);
fd.top = new FormAttachment(securityBanner, 110, SWT.BOTTOM);
lblOpenHp.setLayoutData(fd);
lblSeparator = new Label(security, SWT.SEPARATOR | SWT.HORIZONTAL);
lblSeparator.setBackground(panelBackground);
fd = new FormData();
fd.left = new FormAttachment(lblOpenHp, 0, SWT.RIGHT);
fd.right = new FormAttachment(100, -5);
fd.top = new FormAttachment(lblOpenHp, 0, SWT.TOP);
fd.bottom = new FormAttachment(lblOpenHp, 0, SWT.BOTTOM);
lblSeparator.setLayoutData(fd);
// 允许任何人加我为好友
radioAnyOne = new Button(security, SWT.RADIO);
radioAnyOne.setText(LumaQQ.getResourceString("user.info.security.openhp.anyone"));
radioAnyOne.setBackground(panelBackground);
fd = new FormData();
fd.left = new FormAttachment(lblOpenHp, 10, SWT.LEFT);
fd.top = new FormAttachment(lblOpenHp, 5, SWT.BOTTOM);
radioAnyOne.setLayoutData(fd);
// 需要验证才能加我为好友
radioAuth = new Button(security, SWT.RADIO);
radioAuth.setText(LumaQQ.getResourceString("user.info.security.openhp.auth"));
radioAuth.setBackground(panelBackground);
fd = new FormData();
fd.left = new FormAttachment(lblOpenHp, 10, SWT.LEFT);
fd.top = new FormAttachment(radioAnyOne, 5, SWT.BOTTOM);
radioAuth.setLayoutData(fd);
// 不允许任何人加我为好友
radioNever = new Button(security, SWT.RADIO);
radioNever.setText(LumaQQ.getResourceString("user.info.security.openhp.never"));
radioNever.setBackground(panelBackground);
fd = new FormData();
fd.left = new FormAttachment(lblOpenHp, 10, SWT.LEFT);
fd.top = new FormAttachment(radioAuth, 5, SWT.BOTTOM);
radioNever.setLayoutData(fd);
}
// 打开shell
public void open() {
// 打开shell
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);
shell.open();
// 把自己加为QQ事件监听器
main.client.addQQListener(this);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.qq.events.QQListener#qqEvent(edu.tsinghua.lumaqq.qq.events.QQEvent)
*/
public void qqEvent(QQEvent e) {
switch(e.type) {
case QQEvent.QQ_UPLOAD_FRIEND_REMARK_SUCCESS:
processUploadFriendRemarkSuccess(e);
break;
case QQEvent.QQ_DOWNLOAD_FRIEND_REMARK_SUCCESS:
processDownloadFriendRemarkSuccess(e);
break;
case QQEvent.QQ_OPERATION_TIMEOUT:
if(e.operation == QQ.QQ_CMD_FRIEND_REMARK_OP)
processFriendRemarkOpTimeout(e);
break;
}
}
// 处理备注操作超时事件
private void processFriendRemarkOpTimeout(QQEvent e) {
final FriendRemarkOpPacket packet = (FriendRemarkOpPacket)e.getSource();
if(packet.getQqNum() == qqNum) {
main.display.asyncExec(
new Runnable() {
public void run() {
if(packet.getType() == QQ.QQ_DOWNLOAD_FRIEND_REMARK)
btnDownloadRemark.setEnabled(true);
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
box.setText(LumaQQ.getResourceString("message.box.common.fail.title"));
box.setMessage(LumaQQ.getResourceString("message.box.common.timeout"));
box.open();
}
}
);
}
}
// 处理上传好友备注信息成功事件
private void processUploadFriendRemarkSuccess(QQEvent e) {
FriendRemarkOpPacket packet = (FriendRemarkOpPacket)e.getSource();
if(packet.getQqNum() == qqNum) {
main.display.syncExec(
new Runnable() {
public void run() {
MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
box.setText(LumaQQ.getResourceString("message.box.common.success.title"));
box.setMessage(LumaQQ.getResourceString("message.box.upload.remark.success"));
box.open();
}
}
);
}
}
// 处理下载好友备注信息成功事件
private void processDownloadFriendRemarkSuccess(QQEvent e) {
FriendRemarkOpReplyPacket packet = (FriendRemarkOpReplyPacket)e.getSource();
if(packet.hasRemark) {
if(packet.qqNum == qqNum) {
// 把下载到的信息保存到xml
final Remark remark = createRemarkElement(packet.remark);
saveToXML(remark);
// 设置下载按钮为enable
main.display.syncExec(
new Runnable() {
public void run() {
btnDownloadRemark.setEnabled(true);
// 设置各文本框内容
setRemarkInfo(remark);
}
}
);
}
} else {
// 好友没有备注,把按钮使能
main.display.syncExec(new Runnable() {
public void run() {
btnDownloadRemark.setEnabled(true);
}
});
}
}
/**
* 激活该窗口
*/
public void setActive() {
shell.setActive();
}
/**
* 设置资料是否能被修改
* @param can
*/
public void setCanModified(boolean can) {
this.canModified = can;
if(can) {
shell.setText(LumaQQ.getResourceString("user.info.title.modify"));
buttons[SECURITY].setVisible(true);
buttons[REMARK].setVisible(false);
btnUpdate.setVisible(false);
btnModify.setVisible(true);
} else {
shell.setText(LumaQQ.getResourceString("user.info.title.view"));
buttons[SECURITY].setVisible(false);
buttons[REMARK].setVisible(true);
btnUpdate.setVisible(true);
btnModify.setVisible(false);
}
}
/**
* @param model The fModel to set.
*/
public void setFriendModel(FriendModel model) {
f = model;
qqNum = f.getQQ();
faceId = f.getFaceId();
freshValue();
initRemarkInfo();
}
// 如果是查看好友信息,则设置好友的备注信息
private void initRemarkInfo() {
RemarkUtils ru = RemarkUtils.getInstance();
Remark remark = ru.getRemark(qqNum);
if(remark != null) {
setRemarkInfo(remark);
}
}
/**
* 设置各文本框的内容,remark不能为null,也不做检查
* @param remark
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -