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

📄 simpleliststrategy.java

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