📄 remarkpage.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.config.user;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
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.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import edu.tsinghua.lumaqq.Colors;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.IQQNode;
import edu.tsinghua.lumaqq.qq.beans.FriendRemark;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.config.AbstractPage;
import edu.tsinghua.lumaqq.ui.tool.CenterBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.UITool;
import edu.tsinghua.lumaqq.utils.OptionUtil;
import edu.tsinghua.lumaqq.utils.RemarkUtil;
import edu.tsinghua.lumaqq.xml.remarks.Remark;
import edu.tsinghua.lumaqq.xml.remarks.RemarkImpl;
import edu.tsinghua.swt.models.INode;
/**
* 备注配置页
*
* @author luma
*/
public class RemarkPage extends AbstractPage {
private FriendModel model;
private PaintListener paintListener;
private MainShell main;
private Button btnDownload, btnUpload;
private Text textRemarkName, textRemarkZipcode, textRemarkTelephone, textRemarkMobile, textRemarkEmail, textRemarkAddress, textRemarkNote;
private Button chkAutoUpload;
/**
* @param parent
*/
public RemarkPage(Composite parent, MainShell main, FriendModel model) {
super(parent);
this.main = main;
this.model = model;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractPage#initialVariable()
*/
protected void initialVariable() {
paintListener = new CenterBorderPaintListener(new Class[] { Text.class }, 20, Colors.PAGE_CONTROL_BORDER);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractPage#setModel(java.lang.Object)
*/
public void setModel(Object model) {
if(model instanceof FriendModel)
this.model = (FriendModel)model;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.ui.config.AbstractPage#createContent(org.eclipse.swt.widgets.Composite)
*/
protected Control createContent(Composite parent) {
Composite content = new Composite(parent, SWT.NONE);
content.setBackground(Colors.PAGE_BACKGROUND);
content.setLayout(new FormLayout());
Composite container = new Composite(content, SWT.NONE);
FormData fd = new FormData();
fd.top = fd.left = new FormAttachment(0, 0);
fd.bottom = new FormAttachment(100, -50);
fd.right = new FormAttachment(100, -70);
container.setLayoutData(fd);
GridLayout layout = new GridLayout(4, false);
layout.marginHeight = 14;
layout.horizontalSpacing = 8;
layout.verticalSpacing = 14;
layout.marginWidth = 15;
container.setLayout(layout);
container.setBackground(Colors.PAGE_BACKGROUND);
container.addPaintListener(paintListener);
// 设置使用缺省背景色
UITool.setDefaultBackground(null);
// 用户名称:
UITool.createLabel(container, LumaQQ.getString("user.info.remark.name"));
textRemarkName = UITool.createSingleText(container, new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
// 邮政编码:
UITool.createLabel(container, LumaQQ.getString("user.info.remark.zipcode"));
textRemarkZipcode = UITool.createSingleText(container, new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
// 常用电话:
UITool.createLabel(container, LumaQQ.getString("user.info.remark.telephone"));
textRemarkTelephone = UITool.createSingleText(container, new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
// 手机号码:
UITool.createLabel(container, LumaQQ.getString("user.info.remark.mobile"));
textRemarkMobile = UITool.createSingleText(container, new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
// 电子邮箱:
UITool.createLabel(container, LumaQQ.getString("user.info.remark.email"));
GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.horizontalSpan = 3;
textRemarkEmail = UITool.createSingleText(container, gd);
// 联系地址:
UITool.createLabel(container, LumaQQ.getString("user.info.remark.address"));
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.horizontalSpan = 3;
textRemarkAddress = UITool.createSingleText(container, gd);
// 备注说明:
UITool.createLabel(container, LumaQQ.getString("user.info.remark.note"), new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
textRemarkNote = UITool.createSingleText(container, gd);
// 上传下载组
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 4;
layout = new GridLayout(3, false);
layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = 8;
Group updownGroup = UITool.createGroup(container, LumaQQ.getString("user.info.group.up.down"), gd, layout);
// 上传备注
btnUpload = UITool.createButton(updownGroup, LumaQQ.getString("user.info.remark.button.upload"));
btnUpload.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
uploadFriendRemark();
}
});
// 下载备注
btnDownload = UITool.createButton(updownGroup, LumaQQ.getString("user.info.remark.button.download"));
btnDownload.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
btnDownload.setEnabled(false);
main.getClient().downloadFriendRemark(model.getQQ());
}
});
// 自动上传备注
chkAutoUpload = UITool.createCheckbox(updownGroup, LumaQQ.getString("user.info.remark.auto.upload"));
chkAutoUpload.setSelection(true);
return content;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractPage#saveDirtyProperty(int)
*/
protected void saveDirtyProperty(int propertyId) {
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractPage#initializeValues()
*/
protected void initializeValues() {
RemarkUtil ru = RemarkUtil.getInstance();
Remark remark = ru.getRemark(model.getQQ());
if(remark != null) {
setRemarkInfo(remark);
}
}
/**
* 设置各文本框的内容,remark不能为null,也不做检查
* @param remark
*/
protected void setRemarkInfo(Remark remark) {
textRemarkName.setText(remark.getName());
textRemarkZipcode.setText(remark.getZipcode());
textRemarkTelephone.setText(remark.getTelephone());
textRemarkMobile.setText(remark.getMobile());
textRemarkEmail.setText(remark.getEmail());
textRemarkAddress.setText(remark.getAddress());
textRemarkNote.setText(remark.getNote());
}
/**
* 设置下载备注按钮的使能状态
*
* @param b
*/
protected void setDownloadRemarkEnable(boolean b) {
btnDownload.setEnabled(b);
}
/**
* 设置上传备注按钮的使能状态
*
* @param b
*/
protected void setUploadRemarkEnable(boolean b) {
btnUpload.setEnabled(b);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractPage#getImage()
*/
protected Image getImage() {
return IconHolder.getInstance().getImage(IconHolder.icoViewPersonInfo24);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractPage#getTitle()
*/
protected String getTitle(int page) {
return LumaQQ.getString("user.info.page.remark");
}
/**
* 上传好友备注信息,上传的同时会保存到xml中
*/
protected void uploadFriendRemark() {
setUploadRemarkEnable(false);
Remark remark = createRemarkElement();
FriendRemark fr = createFriendRemarkObject(remark);
// 保存到xml
saveToXML(remark);
// 上传
main.getClient().uploadFriendRemark(model.getQQ(), fr);
}
/**
* 创建FriendRemark对象
*
* @param remark
* Remark元素对象
* @return
* FriendRemark对象
*/
protected FriendRemark createFriendRemarkObject(Remark remark) {
FriendRemark fr = new FriendRemark();
fr.name = remark.getName();
fr.zipcode = remark.getZipcode();
fr.telephone = remark.getTelephone();
fr.mobile = remark.getMobile();
fr.email = remark.getEmail();
fr.address = remark.getAddress();
fr.note = remark.getNote();
return fr;
}
/**
* 创建Remark元素对象
*/
protected Remark createRemarkElement() {
// 创建Remark元素对象
Remark remark = new RemarkImpl();
remark.setName(textRemarkName.getText());
remark.setZipcode(textRemarkZipcode.getText());
remark.setTelephone(textRemarkTelephone.getText());
remark.setMobile(textRemarkMobile.getText());
remark.setEmail(textRemarkEmail.getText());
remark.setAddress(textRemarkAddress.getText());
remark.setNote(textRemarkNote.getText());
remark.setQqNum(String.valueOf(model.getQQ()));
return remark;
}
/**
* 保存备注
*/
public void doSave() {
// 保存到xml
Remark remark = createRemarkElement();
saveToXML(remark);
// 上传
if(chkAutoUpload.getSelection()) {
setUploadRemarkEnable(false);
FriendRemark fr = createFriendRemarkObject(remark);
main.getClient().uploadFriendRemark(model.getQQ(), fr);
}
}
/**
* 保存备注信息到xml文件
*
* @param remark2
* Remark
*/
protected void saveToXML(final Remark remark) {
// 保存备注
RemarkUtil ru = RemarkUtil.getInstance();
ru.addRemark(remark);
ru.save();
// 修改model的realName属性,如果现在好友列表正处于显示备注名称模式,则还要修改name属性
main.getDisplay().syncExec(new Runnable() {
public void run() {
main.setFriendProperty(model, IQQNode.REAL_NAME, remark.getName());
if(!OptionUtil.getInstance().isShowNick())
main.setFriendProperty(model, INode.NAME, remark.getName());
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -