📄 twistetogglestrategy.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 appears as a triangle pointing to the right when
* collapsed and pointing downwards when expanded.
*
* @author chris
*/
public class TwisteToggleStrategy 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();
if (!hovering){
gcPlus.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
} else {
gcPlus.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION));
}
gcPlus.setBackground(gc.getForeground());
if (expanded){
gcPlus.drawPolygon( new int[]{1,3,4,6,5,6,8,3} );
gcPlus.fillPolygon( new int[]{1,3,4,6,5,6,8,3} );
} else {
gcPlus.drawPolygon( new int[]{3,1,6,4,6,5,3,8} );
gcPlus.fillPolygon( new int[]{3,1,6,4,6,5,3,8} );
}
if (hasFocus){
gcPlus.setBackground(back);
gcPlus.setForeground(fore);
gcPlus.drawFocus(-1,-1,12,12);
}
}
/*
* Returns the toggle's size (10,10).
* @see com.swtplus.widgets.toggle.IToggleStrategy#getSize()
*/
public Point getSize() {
return new Point(10,10);
}
/* (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 + -