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

📄 skinbutton.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   SkinButton.java

package org.gudy.azureus2.ui.swt.components.widgets;

import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.mainwindow.Cursors;

// Referenced classes of package org.gudy.azureus2.ui.swt.components.widgets:
//			Inset

public abstract class SkinButton extends Canvas
{

	protected static String imagePath = "com/aelitis/azureus/ui/images/";
	public static final int WIDGET_STATE_NORMAL = 0;
	public static final int WIDGET_STATE_NOT_VISIBLE = 1;
	public static final int WIDGET_STATE_DISABLED = 2;
	public static final int WIDGET_STATE_HOVER = 3;
	private int currentState;
	private Image buttonImage;
	private String buttonText;
	private int alpha;
	private Inset inset;
	private Color foregroundHover;
	private Color foregroundDisabled;
	private boolean enabled;

	public SkinButton(Composite parent)
	{
		this(parent, null, null);
	}

	public SkinButton(Composite parent, String buttonText)
	{
		this(parent, buttonText, null);
	}

	public SkinButton(Composite parent, String buttonText, Image buttonImage)
	{
		super(parent, 0x20000001);
		currentState = 0;
		this.buttonImage = null;
		this.buttonText = null;
		alpha = 255;
		inset = new Inset(0, 0, 0, 0);
		foregroundHover = null;
		foregroundDisabled = null;
		enabled = true;
		this.buttonImage = buttonImage;
		this.buttonText = buttonText;
		init();
	}

	private void init()
	{
		setCursor(Cursors.handCursor);
		addPaintListener(new PaintListener() {

			final SkinButton this$0;

			public void paintControl(PaintEvent e)
			{
				try
				{
					e.gc.setAntialias(1);
					e.gc.setTextAntialias(1);
					e.gc.setAlpha(alpha);
					e.gc.setInterpolation(2);
				}
				catch (Exception ex) { }
				Image images[] = getCurrentBackgroundImages();
				if (null != images)
					if (images.length != 3)
					{
						if (null != images[0] && !images[0].isDisposed())
						{
							ImageData iData = images[0].getImageData();
							e.gc.drawImage(images[0], 0, 0, iData.width, iData.height, 0, 0, iData.width, iData.height);
						}
					} else
					{
						int leftOffset = 0;
						int rightOffset = 0;
						if (null != images[0] && !images[0].isDisposed())
						{
							ImageData iData = images[0].getImageData();
							e.gc.drawImage(images[0], 0, 0, iData.width, iData.height, 0, 0, iData.width, iData.height);
							leftOffset = iData.width;
						}
						if (null != images[2] && !images[2].isDisposed())
						{
							ImageData iData = images[2].getImageData();
							rightOffset = getSize().x - iData.width;
							e.gc.drawImage(images[2], 0, 0, iData.width, iData.height, rightOffset, 0, iData.width, iData.height);
						}
						if (null != images[1] && !images[1].isDisposed())
						{
							ImageData iData = images[1].getImageData();
							int iterations = (rightOffset - leftOffset) / iData.width;
							int roundingOverflow = rightOffset - leftOffset - iterations * iData.width;
							for (int i = 0; i < iterations; i++)
								e.gc.drawImage(images[1], 0, 0, iData.width, iData.height, leftOffset + i * iData.width, 0, iData.width, iData.height);

							if (roundingOverflow > 0)
								e.gc.drawImage(images[1], 0, 0, roundingOverflow, iData.height, leftOffset + iterations * iData.width, 0, roundingOverflow, iData.height);
						}
					}
				int imageOffset = 0;
				if (null != getImage() && !getImage().isDisposed())
				{
					ImageData iData = getImage().getImageData();
					e.gc.drawImage(getImage(), 0, 0, iData.width, iData.height, inset.left, inset.top, iData.width, iData.height);
					imageOffset = inset.left + iData.width;
				}
				if (null != getText())
				{
					if (currentState == 2)
					{
						if (null != getForegroundColors()[2])
							e.gc.setForeground(getForegroundColors()[2]);
					} else
					if (currentState == 3)
					{
						if (null != getForegroundColors()[1])
							e.gc.setForeground(getForegroundColors()[1]);
					} else
					if (null != getForegroundColors()[0])
						e.gc.setForeground(getForegroundColors()[0]);
					else
						e.gc.setForeground(getForeground());
					if (imageOffset != 0)
					{
						imageOffset += 6;
						Point extent = e.gc.textExtent(getText());
						e.gc.drawText(getText(), imageOffset, getSize().y / 2 - extent.y / 2, 9);
					} else
					{
						Point extent = e.gc.textExtent(getText());
						e.gc.drawText(getText(), getSize().x / 2 - extent.x / 2, getSize().y / 2 - extent.y / 2, 9);
					}
				}
			}

			
			{
				this$0 = SkinButton.this;
				super();
			}
		});
		addMouseTrackListener(new MouseTrackAdapter() {

			final SkinButton this$0;

			public void mouseEnter(MouseEvent e)
			{
				if (currentState != 2 && currentState != 3)
				{
					currentState = 3;
					refreshVisuals();
				}
			}

			public void mouseExit(MouseEvent e)
			{
				if (currentState != 2 && currentState != 0)
				{
					currentState = 0;
					refreshVisuals();
				}
			}

			
			{
				this$0 = SkinButton.this;
				super();
			}
		});
	}

	public Point computeSize(int hint, int hint2, boolean changed)
	{
		Point backgroundExtent = new Point(0, 0);
		Point imageExtent = new Point(0, 0);
		Point textExtent = new Point(0, 0);
		if (null != getImage())
		{
			imageExtent.x = getImage().getImageData().width;
			imageExtent.y = getImage().getImageData().height;
		}
		if (null != getText())
		{
			GC gc = new GC(getDisplay());
			textExtent = gc.textExtent(getText());
			gc.dispose();
		}
		Image bgImages[] = getBackgroundImages();
		if (null != bgImages)
		{
			if (null != bgImages[0])
			{
				backgroundExtent.x = bgImages[0].getImageData().width;
				backgroundExtent.y = bgImages[0].getImageData().height;
			}
			if (null != bgImages[1])
			{
				backgroundExtent.x += bgImages[1].getImageData().width;
				backgroundExtent.y = bgImages[1].getImageData().height;
			}
			if (null != bgImages[2])
			{
				backgroundExtent.x += bgImages[2].getImageData().width;
				backgroundExtent.y = bgImages[2].getImageData().height;
			}
		}
		int maxHeight = Math.max(backgroundExtent.y, imageExtent.y + inset.top + inset.bottom);
		maxHeight = Math.max(maxHeight, textExtent.y + inset.top + inset.bottom);
		int maxWidth = Math.max(backgroundExtent.x, imageExtent.x + 6 + textExtent.x + inset.left + inset.right);
		maxWidth = Math.max(maxWidth, imageExtent.x + inset.left + inset.right);
		maxWidth = Math.max(maxWidth, textExtent.x + inset.left + inset.right);
		return new Point(maxWidth, maxHeight);
	}

	private Image[] getCurrentBackgroundImages()
	{
		Image images[];
		if (currentState == 2)
		{
			images = getBackgroundImages_disabled();
			if (null != images && images.length > 0)
				return images;
		} else
		if (currentState == 3)
		{
			images = getBackgroundImages_hover();
			if (null != images && images.length > 0)
				return images;
		}
		images = getBackgroundImages();
		if (null != images && images.length > 0)
			return images;
		else
			return null;
	}

	public Image getImage()
	{
		return buttonImage;
	}

	public void setImage(Image buttonImage)
	{
		if (this.buttonImage != buttonImage)
		{
			this.buttonImage = buttonImage;
			refreshVisuals();
		}
	}

	public String getText()
	{
		return buttonText;
	}

	public void setText(String buttonText)
	{
		if (this.buttonText != buttonText)
		{
			this.buttonText = buttonText;
			refreshVisuals();
		}
	}

	public abstract Image[] getBackgroundImages();

	public abstract Image[] getBackgroundImages_disabled();

	public abstract Image[] getBackgroundImages_hover();

	public abstract Color[] getForegroundColors();

	public void setEnabled(boolean enabled)
	{
		if (this.enabled != enabled)
		{
			this.enabled = enabled;
			super.setEnabled(enabled);
			if (!enabled)
			{
				currentState = 2;
				alpha = 128;
			} else
			{
				currentState = 0;
				alpha = 255;
			}
			refreshVisuals();
			update();
		}
	}

	public boolean isEnabled()
	{
		return enabled;
	}

	public Inset getInset()
	{
		return inset;
	}

	public void setInset(Inset inset)
	{
		if (this.inset != inset)
		{
			this.inset = inset;
			refreshVisuals();
		}
	}

	public void refreshVisuals()
	{
		Utils.execSWTThread(new AERunnable() {

			final SkinButton this$0;

			public void runSupport()
			{
				if (!isDisposed())
					redraw();
			}

			
			{
				this$0 = SkinButton.this;
				super();
			}
		}, false);
	}

	public Color getForegroundHover()
	{
		return foregroundHover;
	}

	public void setForegroundHover(Color foregroundHover)
	{
		this.foregroundHover = foregroundHover;
	}

	public Color getForegroundDisabled()
	{
		return foregroundDisabled;
	}

	public void setForegroundDisabled(Color foregroundDisabled)
	{
		this.foregroundDisabled = foregroundDisabled;
	}






}

⌨️ 快捷键说明

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