📄 treenodetogglestrategy.java
字号:
package com.swtplus.widgets.toggle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Widget;
import com.swtplus.internal.PGC;
/**
* This toggle strategy mimics a Windows tree node. That is, it shows a plus
* (surrounded by a box) when collapsed and a minus when expanded.
*
* @author chris
*/
public class TreeNodeToggleStrategy implements IToggleStrategy {
private Point location;
/* (non-Javadoc)
* @see com.swtplus.widgets.toggle.IToggleStrategy#paint(org.eclipse.swt.events.PaintEvent, boolean, boolean, boolean)
*/
public void paint(Widget parent,GC gc, boolean expanded, boolean hasFocus, boolean hovering) {
PGC gcPlus = new PGC(gc,location.x,location.y);
Color back = gcPlus.getBackground();
Color fore = gcPlus.getForeground();
gcPlus.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
gcPlus.fillRectangle(0,0,8,8);
gcPlus.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
gcPlus.drawLine(2,4,6,4);
if (!expanded){
gcPlus.drawLine(4,2,4,6);
}
gcPlus.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
gcPlus.drawRectangle(0,0,8,8);
if (hasFocus){
gcPlus.setBackground(back);
gcPlus.setForeground(fore);
gcPlus.drawFocus(-1,-1,11,11);
}
}
/*
* Returns the toggle's size (9,9).
* @see com.swtplus.widgets.toggle.IToggleStrategy#getSize()
*/
public Point getSize() {
return new Point(9,9);
}
/* (non-Javadoc)
* @see com.swtplus.widgets.toggle.IToggleStrategy#setLocation(org.eclipse.swt.graphics.Point)
*/
public void setLocation(Point p) {
location = p;
}
/**
* @return Returns the location.
*/
public Point getLocation() {
return location;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -