?? simpleliststrategy.java
字號:
package com.swtplus.widgets.list;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import com.swtplus.internal.PGC;
import com.swtplus.widgets.PListItem;
import com.swtplus.widgets.PList;
/**
* SimpleListStrategy is a simple list that includes an image as well
* as text.
*/
public class SimpleListStrategy implements IListStrategy {
private PList parent;
private int margin = 2;
private int hSpacing = 4;
/**
* Creates a SimpleListStrategy with the given style.
*
* @param style style
*/
public SimpleListStrategy(int style){
}
/* (non-Javadoc)
* @see com.swtplus.widgets.IListPlusStrategy#computeHeight(com.swtplus.widgets.ListItem, int)
*/
public Point computeSize(PListItem item,PGC gc, int wHint, int hHint) {
int imageHeight = 0;
if (item.getImage() != null)
imageHeight = item.getImage().getBounds().height;
int fontHeight = gc.getFontMetrics().getHeight();
return new Point(0,Math.max(imageHeight + (2*margin),fontHeight + (2*margin)));
}
/* (non-Javadoc)
* @see com.swtplus.widgets.IListPlusStrategy#paintItem(com.swtplus.widgets.ListItem, com.swtplus.GCPlus, boolean, boolean, boolean)
*/
public void paintItem(PListItem item, PGC gc, boolean selected,
boolean focused, boolean hovering, Point size) {
int x = 0,y = 0;
Color back = gc.getBackground();
if (selected){
gc.setBackground(parent.getSelectionColor());
}
gc.fillRectangle(0,0,size.x,size.y);
if (selected)
gc.setBackground(back);
if (focused){
gc.drawFocus(0,0,size.x,size.y);
}
x = margin;
if (item.getImage() != null){
Image img = item.getImage();
y = ((size.y - img.getBounds().height)/2);
gc.drawImage(img,x,y);
x += img.getBounds().width + hSpacing;
}
y = ((size.y - gc.getFontMetrics().getHeight())/2);
if (selected)
gc.setForeground(parent.getSelectionTextColor());
String text = gc.getShortString(item.getText(),parent.getSize().x - x);
gc.drawString(text,x,y,true);
}
/* (non-Javadoc)
* @see com.swtplus.widgets.IListPlusStrategy#checkItem(com.swtplus.widgets.ListItem)
*/
public void checkItem(PListItem item) {
}
/* (non-Javadoc)
* @see com.swtplus.widgets.list.IListStrategy#initialize(com.swtplus.widgets.list.PList)
*/
public void initialize(PList pList) {
parent = pList;
}
/* (non-Javadoc)
* @see com.swtplus.widgets.IListPlusStrategy#isHoverReady()
*/
public boolean isHoverOnUnselected() {
return false;
}
/* (non-Javadoc)
* @see com.swtplus.widgets.listplus.IListPlusStrategy#dispose()
*/
public void dispose() {
}
/* (non-Javadoc)
* @see com.swtplus.widgets.list.IListStrategy#fontChanged()
*/
public void fontChanged() {
}
/* (non-Javadoc)
* @see com.swtplus.widgets.list.IListStrategy#colorChanged()
*/
public void colorChanged() {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -