📄 onlinehinter.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.experimental;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.MouseTrackListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
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.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.config.sys.SystemOptionWindow;
import edu.tsinghua.swt.widgets.AbstractHinter;
import edu.tsinghua.swt.widgets.BottomShow;
/**
* <pre>
* 上线提示窗口
* </pre>
*
* @author 马若劼
*/
public class OnlineHinter extends AbstractHinter {
private Label lblFace;
private Label lblSetup, lblUserInfo, lblClose;
private Color background;
private Cursor handCursor;
private IconHolder icons;
// 好友是否有QQShow保存在本地
private boolean hasQQShow;
// 头像或者QQ秀
private Image faceOrQQShow;
// display
private Display display;
// 主窗口
private MainShell main;
// 鼠标移动到标签上时的事件处理器
private MouseTrackListener mtl = new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(display.getSystemColor(SWT.COLOR_YELLOW));
}
public void mouseExit(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
}
};
/**
* @param parent
* @param w
* @param h
*/
public OnlineHinter(MainShell main, int w, int h) {
super(main.getShell(), w, h);
this.main = main;
icons = IconHolder.getInstance();
setBackgroundImage(icons.getImage(IconHolder.bmpOnlineTipBackground));
setShowStyle(new BottomShow());
addDisposeListener(new DisposeListener() {
/* (non-Javadoc)
* @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
*/
public void widgetDisposed(DisposeEvent e) {
background.dispose();
handCursor.dispose();
}
});
}
/* (non-Javadoc)
* @see edu.tsinghua.swt.widgets.AbstractHinter#createContent(org.eclipse.swt.widgets.Shell)
*/
protected Composite createContent(final Shell shell) {
shell.setSize(167, 87);
shell.setLayout(new FormLayout());
// 头像显示,显示小头像
lblFace = new Label(shell, SWT.NONE);
lblFace.setBackground(background);
FormData fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.right = new FormAttachment(0, 58);
fd.top = new FormAttachment(0, 13);
fd.bottom = new FormAttachment(100, -3);
lblFace.setLayoutData(fd);
lblFace.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Rectangle ca = lblFace.getBounds();
if (faceOrQQShow != null) {
// 得到图像大小
Rectangle bound = faceOrQQShow.getBounds();
// 如果是QQ秀需要画边框,没有是画头像,不要边框
if(hasQQShow) {
int x = (bound.width - ca.width) / 2;
e.gc.drawImage(faceOrQQShow, x, 38, ca.width, ca.height, 0, 0, ca.width, ca.height);
e.gc.drawRectangle(0, 0, ca.width - 1, ca.height - 1);
} else {
int x = (bound.width - ca.width) / 2;
int y = (bound.height - ca.height) / 2;
if (x >= 0 && y >= 0)
e.gc.drawImage(faceOrQQShow, x, y, ca.width, ca.height, 0, 0,
ca.width, ca.height);
else if (x >= 0 && y < 0)
e.gc.drawImage(faceOrQQShow, x, 0, ca.width, bound.height, 0,
-y, ca.width, bound.height);
else if (x < 0 && y >= 0)
e.gc.drawImage(faceOrQQShow, 0, y, bound.width, ca.height, -x,
0, bound.width, ca.height);
else
e.gc.drawImage(faceOrQQShow, 0, 0, bound.width, bound.height,
-x, -y, bound.width, bound.height);
}
}
}
});
// QQ号标签
lblUserInfo = new Label(shell, SWT.WRAP);
lblUserInfo.setBackground(background);
lblUserInfo.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
lblUserInfo.setCursor(handCursor);
fd = new FormData();
fd.left = new FormAttachment(lblFace, 5, SWT.RIGHT);
fd.right = new FormAttachment(100, -5);
fd.top = new FormAttachment(0, 30);
fd.bottom = new FormAttachment(100, -20);
lblUserInfo.setLayoutData(fd);
lblUserInfo.addMouseTrackListener(mtl);
lblUserInfo.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
dispose();
main.getShellLauncher().openNormalIMWindow((FriendModel)shell.getData());
}
});
// 关闭标签
lblClose = new Label(shell, SWT.NONE);
lblClose.setBackground(background);
lblClose.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
fd = new FormData();
fd.right = new FormAttachment(100, -5);
fd.left = new FormAttachment(100, -12);
fd.top = new FormAttachment(0, 13);
fd.bottom = new FormAttachment(0, 20);
lblClose.setLayoutData(fd);
lblClose.setCursor(handCursor);
lblClose.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseEnter(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(display.getSystemColor(SWT.COLOR_YELLOW));
c.redraw();
}
public void mouseExit(MouseEvent e) {
Control c = (Control)e.getSource();
c.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
c.redraw();
}
});
lblClose.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
dispose();
}
});
lblClose.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Rectangle rect = lblClose.getBounds();
e.gc.drawLine(0, 0, rect.width - 1, rect.height - 1);
e.gc.drawLine(1, 0, rect.width - 1, rect.height - 2);
e.gc.drawLine(0, 1, rect.width - 2, rect.height - 1);
e.gc.drawLine(rect.width - 1, 0, 0, rect.height - 1);
e.gc.drawLine(rect.width - 2, 0, 0, rect.height - 2);
e.gc.drawLine(rect.width - 1, 1, 1, rect.height - 1);
}
});
// 设置标签
lblSetup = new Label(shell, SWT.NONE);
lblSetup.setText(LumaQQ.getString("onlinetip.shell.label.qq.setup"));
lblSetup.setBackground(background);
lblSetup.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
lblSetup.setCursor(handCursor);
lblSetup.addMouseTrackListener(mtl);
lblSetup.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
dispose();
main.getShellLauncher().openSystemOptionWindow().setCurrentPage(SystemOptionWindow.GUI);
}
});
fd = new FormData();
fd.right = new FormAttachment(100, -5);
fd.bottom = new FormAttachment(100, -5);
lblSetup.setLayoutData(fd);
// 专用伺候linux的代码
shell.layout();
return null;
}
/* (non-Javadoc)
* @see edu.tsinghua.swt.widgets.AbstractHinter#setHint(java.lang.Object)
*/
public void setHint(Object model) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see edu.tsinghua.swt.widgets.AbstractHinter#setHint(java.lang.Object[])
*/
public void setHint(Object[] models) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see edu.tsinghua.swt.widgets.AbstractHinter#initVaribles()
*/
protected void initVaribles() {
background = new Color(display, 0x73, 0x8A, 0xEF);
handCursor = new Cursor(display, SWT.CURSOR_HAND);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -