FileDocCategorySizeDatePackage
ListCellGraphic.javaAPI DocAzureus 3.0.3.43806Wed Mar 07 17:19:14 GMT 2007com.aelitis.azureus.ui.swt.views.list

ListCellGraphic

public class ListCellGraphic extends ListCell implements org.gudy.azureus2.ui.swt.components.BufferedGraphicTableItem
author
TuxPaper
created
Jul 2, 2006

Fields Summary
private int
marginHeight
private int
marginWidth
private int
orientation
private Image
image
private Rectangle
imageBounds
Constructors Summary
public ListCellGraphic(ListRow row, int position, int alignment, Rectangle bounds)


	      
			  
		super(row, position, alignment, bounds);
	
Methods Summary
public voiddoPaint(GC gc)

		if (getPosition() < 0) {
			return;
		}

		gc.setBackground(getBackground());
		if (DEBUG_COLORCELL) {
			gc.setBackground(Display.getDefault().getSystemColor(
					(int) (Math.random() * 16)));
		}
		Rectangle bounds = getBounds();
		if (bounds == null) {
			return;
		}
		gc.fillRectangle(bounds);

		// TODO: Orientation: fill
		if (image != null && !image.isDisposed()) {
			Point size = getSize();
			//System.out.println(bounds);

			int x;

			int y = marginHeight;
			y += (size.y - imageBounds.height) / 2;

			if (orientation == SWT.CENTER) {
				x = marginWidth;
				x += (size.x - (marginWidth * 2) - imageBounds.width) / 2;
			} else if (orientation == SWT.RIGHT) {
				x = bounds.height - marginWidth - imageBounds.width;
			} else {
				x = marginWidth;
			}

			int width = Math.min(bounds.width - x - marginWidth, imageBounds.width);
			int height = Math.min(bounds.height - y - marginHeight,
					imageBounds.height);

			if (width >= 0 && height >= 0) {
				gc.drawImage(image, 0, 0, width, height, bounds.x + x, bounds.y + y,
						width, height);
			}
		}
	
public ImagegetGraphic()

		return image;
	
public intgetMarginHeight()

		return marginHeight;
	
public intgetMarginWidth()

		return marginWidth;
	
public intgetOrientation()

		return orientation;
	
public PointgetSize()

		Rectangle bounds = getBounds();
		if (bounds == null) {
			return new Point(0, 0);
		}
		return new Point(bounds.width - (marginWidth * 2), bounds.height
				- (marginHeight * 2));
	
public booleansetGraphic(Image img)

		//System.out.println(img.getBounds());
		if (img != null && img.isDisposed()) {
			return false;
		}

		if (image == img) {
			return false;
		}

		image = img;
		if (image != null) {
			imageBounds = image.getBounds();
		}

		((ListView) row.getView()).cellRefresh(this, true, true);

		return true;
	
public voidsetMargin(int width, int height)

		if (width >= 0) {
			marginWidth = width;
		}

		if (height >= 0) {
			marginHeight = height;
		}
	
public voidsetOrientation(int orientation)

		this.orientation = orientation;