📄 personalpage.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.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
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.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
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.events.IFaceSelectionListener;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.IQQNode;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.qq.beans.ContactInfo;
import edu.tsinghua.lumaqq.qq.packets.BasicOutPacket;
import edu.tsinghua.lumaqq.qq.packets.out.ModifyInfoPacket;
import edu.tsinghua.lumaqq.ui.config.AbstractPage;
import edu.tsinghua.lumaqq.ui.config.IPacketFiller;
import edu.tsinghua.lumaqq.ui.tool.AroundBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.CenterBorderPaintListener;
import edu.tsinghua.lumaqq.ui.tool.HeadFactory;
import edu.tsinghua.lumaqq.ui.tool.UITool;
import edu.tsinghua.lumaqq.widgets.HeadImageProvider;
import edu.tsinghua.lumaqq.widgets.IImageProvider;
import edu.tsinghua.lumaqq.widgets.ImageSelector;
/**
* 个人资料配置页
*
* @author luma
*/
public class PersonalPage extends AbstractPage implements IPacketFiller, IFaceSelectionListener {
private FriendModel model;
private PaintListener centerBorderPaintListener, aroundBorderPaintListener;
private int headId;
private Text textQQ, textNick, textRealName, textCollege, textHomePage, textAge, textIntro;
private CCombo comboGender, comboOccupation, comboZodiac, comboHoroscope, comboBlood;
private CLabel btnFace;
private Cursor handCursor;
/**
* @param parent
*/
public PersonalPage(Composite parent, FriendModel model, int style) {
super(parent, style);
this.model = model;
}
/* (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.shells.AbstractPage#initialVariable()
*/
protected void initialVariable() {
centerBorderPaintListener = new CenterBorderPaintListener(new Class[] { Text.class, CCombo.class }, 20, Colors.PAGE_CONTROL_BORDER);
aroundBorderPaintListener = new AroundBorderPaintListener(new Class[] { CLabel.class }, Colors.PAGE_CONTROL_BORDER);
handCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND);
headId = 0;
}
/* (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, -20);
fd.right = new FormAttachment(100, -50);
container.setLayoutData(fd);
GridLayout layout = new GridLayout(4, false);
layout.marginHeight = layout.horizontalSpacing = 8;
layout.verticalSpacing = 14;
layout.marginWidth = 15;
container.setLayout(layout);
container.setBackground(Colors.PAGE_BACKGROUND);
container.addPaintListener(centerBorderPaintListener);
container.addPaintListener(aroundBorderPaintListener);
// 设置使用缺省背景色
UITool.setDefaultBackground(null);
// 用户号码
UITool.createLabel(container, LumaQQ.getString("user.info.basic.qq"));
GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 155;
textQQ = UITool.createSingleText(container, gd, SWT.SINGLE | SWT.READ_ONLY);
textQQ.setBackground(Colors.PAGE_READONLY_CONTROL_BACKGROUND);
// 头像按钮
btnFace = new CLabel(container, SWT.CENTER);
gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_BEGINNING);
gd.heightHint = gd.widthHint = 48;
gd.horizontalSpan = 2;
gd.verticalSpan = 3;
gd.horizontalIndent = 30;
btnFace.setLayoutData(gd);
btnFace.setCursor(handCursor);
btnFace.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if(style == UserInfoWindow.EDITABLE) {
Rectangle bound = btnFace.getBounds();
bound.height++;
openImageSelectionShell(btnFace.getParent().toDisplay(bound.x, bound.y + bound.height));
}
}
});
// 用户昵称
UITool.createLabel(container, LumaQQ.getString("user.info.basic.nick"));
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 155;
textNick = UITool.createSingleText(container, gd);
// 性别
UITool.createLabel(container, LumaQQ.getString("user.info.basic.gender"));
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 155;
comboGender = UITool.createCCombo(container, gd, SWT.FLAT);
comboGender.setTextLimit(6);
comboGender.add(LumaQQ.getString("user.info.basic.gender.male"));
comboGender.add(LumaQQ.getString("user.info.basic.gender.female"));
comboGender.add(LumaQQ.getString("user.info.basic.gender.both"));
comboGender.add(LumaQQ.getString("user.info.basic.gender.null"));
comboGender.setVisibleItemCount(4);
// 真实姓名
UITool.createLabel(container, LumaQQ.getString("user.info.basic.name"));
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 155;
textRealName = UITool.createSingleText(container, gd);
// 年龄
gd = new GridData();
gd.horizontalIndent = 30;
UITool.createLabel(container, LumaQQ.getString("user.info.basic.age"), gd);
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 70;
textAge = UITool.createSingleText(container, gd);
textAge.setTextLimit(3);
// 毕业院校
UITool.createLabel(container, LumaQQ.getString("user.info.basic.college"));
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 155;
textCollege = UITool.createSingleText(container, gd);
// 生肖
gd = new GridData();
gd.horizontalIndent = 30;
UITool.createLabel(container, LumaQQ.getString("user.info.basic.zodiac"), gd);
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 70;
comboZodiac = UITool.createCCombo(container, gd);
for(int i = 0; i <= 12; i++)
comboZodiac.add(LumaQQ.getString("user.info.basic.zodiac." + i));
comboZodiac.setVisibleItemCount(13);
// 职业
UITool.createLabel(container, LumaQQ.getString("user.info.basic.occupation"));
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 155;
comboOccupation = UITool.createCCombo(container, gd, SWT.FLAT);
int n = Util.getInt(LumaQQ.getString("user.info.basic.occupation.number"), 0);
for(int i = 1; i <= n; i++)
comboOccupation.add(LumaQQ.getString("user.info.basic.occupation." + i));
comboOccupation.setVisibleItemCount(n);
// 星座
gd = new GridData();
gd.horizontalIndent = 30;
UITool.createLabel(container, LumaQQ.getString("user.info.basic.horoscope"), gd);
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 50;
comboHoroscope = UITool.createCCombo(container, gd);
for(int i = 0; i <= 12; i++)
comboHoroscope.add(LumaQQ.getString("user.info.basic.horoscope." + i));
comboHoroscope.setVisibleItemCount(13);
// 个人主页
UITool.createLabel(container, LumaQQ.getString("user.info.basic.homepage"));
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 155;
textHomePage = UITool.createSingleText(container, gd);
// 血型
gd = new GridData();
gd.horizontalIndent = 30;
UITool.createLabel(container, LumaQQ.getString("user.info.basic.blood"), gd);
gd = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
gd.widthHint = 70;
comboBlood = UITool.createCCombo(container, gd);
for(int i = 0; i <= 5; i++)
comboBlood.add(LumaQQ.getString("user.info.basic.blood." + i));
comboBlood.setVisibleItemCount(6);
// 个人说明
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
UITool.createLabel(container, LumaQQ.getString("user.info.basic.intro"), gd);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 3;
textIntro = UITool.createMultiText(container, gd, SWT.MULTI | SWT.WRAP);
textIntro.setTextLimit(131);
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() {
// 昵称和头像和QQ号
textNick.setText(model.getNick());
textQQ.setText(String.valueOf(model.getQQ()));
btnFace.setImage(HeadFactory.getOnlineHead(model));
headId = model.getHeadId();
// 开始设置其他联系信息
ContactInfo info = (ContactInfo)model.getProperty(IQQNode.CONTACT);
if(info == null) return;
// 年龄
textAge.setText(info.infos[info.age]);
// 性别
comboGender.setText(info.infos[info.gender]);
// 真实姓名
textRealName.setText(info.infos[info.name]);
// 毕业学校
textCollege.setText(info.infos[info.college]);
// 职业
comboOccupation.setText(info.infos[info.occupation]);
// 生肖
int i = Util.getInt(info.infos[info.zodiac], 0);
if(i <= 12 && i >=0)
comboZodiac.setText(comboZodiac.getItem(i));
// 血型
i = Util.getInt(info.infos[info.blood], 0);
if(i <= 5 && i >= 0)
comboBlood.setText(comboBlood.getItem(i));
// 星座
i = Util.getInt(info.infos[info.horoscope], 0);
if(i <= 12 && i >= 0 )
comboHoroscope.setText(comboHoroscope.getItem(i));
// 主页
textHomePage.setText(info.infos[info.homepage]);
// 个人说明
textIntro.setText(info.infos[info.intro]);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractPage#getImage()
*/
protected Image getImage() {
if(style == UserInfoWindow.EDITABLE)
return IconHolder.getInstance().getImage(IconHolder.icoModifyPersonInfo24);
else
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.basic");
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.IPacketFiller#fill(edu.tsinghua.lumaqq.qq.packets.OutPacket)
*/
public void fill(BasicOutPacket packet) {
if(packet instanceof ModifyInfoPacket) {
ContactInfo info = ((ModifyInfoPacket)packet).getContactInfo();
info.infos[info.face] = String.valueOf(headId);
info.infos[info.qqStr] = textQQ.getText();
info.infos[info.nick] = textNick.getText();
info.infos[info.gender] = comboGender.getText();
info.infos[info.name] = textRealName.getText();
info.infos[info.college] = textCollege.getText();
info.infos[info.occupation] = comboOccupation.getText();
info.infos[info.homepage] = textHomePage.getText();
info.infos[info.age] = textAge.getText();
info.infos[info.zodiac] = String.valueOf(comboZodiac.indexOf(comboZodiac.getText()));
info.infos[info.blood] = String.valueOf(comboBlood.indexOf(comboBlood.getText()));
info.infos[info.horoscope] = String.valueOf(comboHoroscope.indexOf(comboHoroscope.getText()));
info.infos[info.intro] = textIntro.getText();
}
}
/**
* 打开图片选择窗口
*/
private void openImageSelectionShell(Point loc) {
ImageSelector fss = new ImageSelector(parentShell, new HeadImageProvider());
fss.setListener(this);
fss.setLocation(loc);
fss.open();
}
/**
* @return Returns the faceId.
*/
protected int getHeadId() {
return headId;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.events.IFaceSelectionListener#faceSelected(edu.tsinghua.lumaqq.ui.IImageProvider, int, int)
*/
public void faceSelected(IImageProvider provider, int group, int sequence) {
int code = provider.getImageCode(group, sequence);
if(code != -1) {
headId = code;
btnFace.setImage(provider.getImage(group, sequence));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -