小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

閑著沒事寫了兩個(gè)可以設(shè)置背景圖片的面板類,感興趣的下(2)

 ShangShujie 2008-05-28
for SWT

Java code
package craky; import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.widgets.Composite; /** * 可設(shè)置背景圖片的Composite * Composite本身是可以設(shè)置背景圖片的,但是只提供了平鋪的顯示方式,該類實(shí)現(xiàn)了居中、平鋪和拉伸三種顯示方式。 * * @author 003 */ public class ImageComposite extends Composite implements PaintListener { /** * 居中 */ public static final String CENTRE = "Centre"; /** * 平鋪 */ public static final String TILED = "Tiled"; /** * 拉伸 */ public static final String SCALED = "Scaled"; /** * 背景圖片 */ private Image backgroundImage; /** * 背景圖片顯示模式 */ private String imageDisplayMode; /** * 背景圖片顯示模式索引(引入此屬性有助于必要時(shí)擴(kuò)展) */ private int modeIndex; /** * 構(gòu)造一個(gè)沒有背景圖片的ImageComposite * @param parent 父組件 * @param style 風(fēng)格 */ public ImageComposite(Composite parent, int style) { this(parent, style, null, CENTRE); } /** * 構(gòu)造一個(gè)具有指定背景圖片和指定顯示模式的ImageComposite * @param parent 父組件 * @param style 風(fēng)格 * @param image 背景圖片 * @param modeName 背景圖片顯示模式 */ public ImageComposite(Composite parent, int style, Image image, String modeName) { super(parent, style); addPaintListener(this); setBackgroundImage(image); setImageDisplayMode(modeName); } /** * 獲取背景圖片 * @return 背景圖片 * @see org.eclipse.swt.widgets.Control#getBackgroundImage(Image) */ @Override public Image getBackgroundImage() { return backgroundImage; } /** * 設(shè)置背景圖片 * @param 背景圖片 * @see org.eclipse.swt.widgets.Control#setBackgroundImage(Image) */ @Override public void setBackgroundImage(Image backgroundImage) { this.backgroundImage = backgroundImage; this.redraw(); } /** * 獲取背景圖片顯示模式 * @return 顯示模式 */ public String getImageDisplayMode() { return imageDisplayMode; } /** * 設(shè)置背景圖片顯示模式 * @param modeName 模式名稱,取值僅限于ImagePane.TILED ImagePane.SCALED ImagePane.CENTRE */ public void setImageDisplayMode(String modeName) { if(modeName != null) { modeName = modeName.trim(); //居中 if(modeName.equalsIgnoreCase(CENTRE)) { this.imageDisplayMode = CENTRE; modeIndex = 0; } //平鋪 else if(modeName.equalsIgnoreCase(TILED)) { this.imageDisplayMode = TILED; modeIndex = 1; } //拉伸 else if(modeName.equalsIgnoreCase(SCALED)) { this.imageDisplayMode = SCALED; modeIndex = 2; } this.redraw(); } } /** * 繪圖事件 */ public void paintControl(PaintEvent e) { //如果設(shè)置了背景圖片則顯示 if(backgroundImage != null) { int width = this.getSize().x; int height = this.getSize().y; int imageWidth = backgroundImage.getImageData().width; int imageHeight = backgroundImage.getImageData().height; switch(modeIndex) { //居中 case 0: { int x = (width - imageWidth) / 2; int y = (height - imageHeight) / 2; e.gc.drawImage(backgroundImage, x, y); break; } //平鋪 case 1: { for(int ix = 0; ix < width; ix += imageWidth) { for(int iy = 0; iy < height; iy += imageHeight) { e.gc.drawImage(backgroundImage, ix, iy); } } break; } //拉伸 case 2: { ImageData data = backgroundImage.getImageData().scaledTo(width, height); e.gc.drawImage(new Image(e.display, data), 0, 0); break; } } } } }

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多