⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chevronstogglestrategy.java

📁 利用它可以做出非常漂亮的swt界面,包含的组件有PShelf Plist
💻 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;


/**
 * A dual chevron toggle strategy that shows two chevrons facing upwards when
 * expanded (thus clueing the user to click the chevrons to collapse) and two
 * chevrons facing downwards when collapsed.  When hovered the chevrons are 
 * encircled by a rounded rectangle.
 *
 * @author chris
 */
public class ChevronsToggleStrategy 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){
            Color old = gc.getForeground();
            gcPlus.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
            gcPlus.drawRoundRectangle(0,0,16,15,5,5);
            gcPlus.setForeground(old);
        }
        
        if (expanded){
            gcPlus.drawPolygon( new int[]{5,6,8,3,11,6,10,6,8,4,6,6} );
            
            gcPlus.drawPolygon( new int[]{5,10,8,7,11,10,10,10,8,8,6,10} );
        } else {
            gcPlus.drawPolygon( new int[]{5,4,8,7,11,4,10,4,8,6,6,4} );
            
            gcPlus.drawPolygon( new int[]{5,8,8,11,11,8,10,8,8,10,6,8} );
        }
		
		if (hasFocus){
			gcPlus.setBackground(back);
			gcPlus.setForeground(fore);
			gcPlus.drawFocus(2,2,13,12);
		}
		
	}

	/* (non-Javadoc)
	 * @see com.swtplus.widgets.toggle.IToggleStrategy#setLocation(org.eclipse.swt.graphics.Point)
	 */
	public void setLocation(Point p) {
		location = p;		
	}	
	
	/* 
	 * Returns the toggle's size (17,16).
	 * @see com.swtplus.widgets.toggle.IToggleStrategy#getSize()
	 */
	public Point getSize() {
		return new Point(17,16);
	}

	/**
	 * @return Returns the location.
	 */
	public Point getLocation() {
		return location;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -