FileDocCategorySizeDatePackage
ListCell.javaAPI DocAzureus 3.0.3.48135Wed Aug 22 17:59:02 BST 2007com.aelitis.azureus.ui.swt.views.list

ListCell

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

Fields Summary
protected static final boolean
DEBUG_COLORCELL
private final int
position
private String
sText
protected Color
colorFG
protected Color
colorBG
protected Rectangle
bounds
protected final ListRow
row
private final int
alignment
private boolean
bLastIsShown
private com.aelitis.azureus.ui.common.table.TableCellCore
cell
protected org.gudy.azureus2.plugins.ui.tables.TableColumn
column
private Image
imgIcon
private ListView
view
private int
fontHeight
private int
maxLines
Constructors Summary
public ListCell(ListRow row, int position, int alignment, Rectangle bounds)


	         
		this.row = row;
		this.position = position;
		this.alignment = alignment;
		this.bounds = bounds;
		this.view = (ListView) row.getView();

		Utils.execSWTThreadWithObject("getCellFontHeight",
				new AERunnableObject() {
					public Object runSupport() {
						Control control = view.getControl();
						if (control != null) {
							GC gc = new GC(control);
							try {
								fontHeight = gc.textExtent("(/|,jI~`gy").y;
							} finally {
								gc.dispose();
							}
						}
						return null;
					}
				});
	
Methods Summary
public voiddispose()

		// TODO Auto-generated method stub

	
public voiddoPaint(GC gc)

		// TODO: Orientation

		if (!isShowable()) {
			return;
		}

		if (sText == null) {
			return;
		}

		gc.setForeground(getForeground());
		gc.setBackground(getBackground());

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

		if (((TableCellImpl) cell).bDebug) {
			((TableCellImpl) cell).debug("drawText " + bounds);
		}

		Point size = gc.textExtent(sText);

		boolean hasIcon = (imgIcon != null && !imgIcon.isDisposed());
		if (hasIcon) {
			int w = imgIcon.getBounds().width + 2;
			size.x += w;
			gc.drawImage(imgIcon, bounds.x, bounds.y);
			bounds.x += w;
		}

		size.x += ListView.COLUMN_PADDING_WIDTH;

		if (column.isMaxWidthAuto() && column.getMaxWidth() < size.x) {
			column.setMaxWidth(size.x);
		}
		if (column.isMinWidthAuto() && column.getMinWidth() < size.x) {
			column.setMinWidth(size.x);
		}
		if (column.isPreferredWidthAuto() && column.getPreferredWidth() < size.x) {
			column.setPreferredWidth(size.x);
		}
		//gc.drawText(sText, bounds.x, bounds.y);
		GCStringPrinter.printString(gc, sText, bounds, true, true, alignment
				| SWT.WRAP);
	
public ColorgetBackground()

		if (colorBG == null) {
			return row.getBackground();
		}

		return colorBG;
	
public ImagegetBackgroundImage()

		return null;
	
public RectanglegetBounds()

		TableColumnMetrics columnMetrics = view.getColumnMetrics(column);
		if (columnMetrics == null) {
			return null;
		}

		bounds.x = columnMetrics.x;
		bounds.width = columnMetrics.width;
		try {
			bounds.y = row.getVisibleYOffset() + ListView.ROW_MARGIN_HEIGHT;
			bounds.height = ListRow.ROW_HEIGHT - (ListView.ROW_MARGIN_HEIGHT * 2);
		} catch (Exception e) {
			//System.err.println(cell.getTableColumn().getName() + " " + bounds + ";" + row + ";");
		}
		return bounds;
	
public ColorgetForeground()

		if (colorFG == null) {
			return row.getForeground();
		}

		return colorFG;
	
public ImagegetIcon()

		return imgIcon;
	
public intgetMaxLines()

		if (maxLines <= 0) {
  		if (fontHeight <= 0) {
  			maxLines = 1;
  		} else {
  			maxLines = (int) Math.ceil((double)getBounds().height / fontHeight);
  		}
		}
		return maxLines;
	
public intgetPosition()

		return position;
	
public ListRowgetRow()

		return row;
	
public java.lang.StringgetText()

		return sText;
	
public voidinvalidate()

	
private booleanisSameColor(Color c1, Color c2)

		if (c1 == null && c2 == null) {
			return true;
		}
		if (c1 == null || c2 == null) {
			return false;
		}
		return c1.getRGB().equals(c2.getRGB());
	
private booleanisShowable()
Whether the column is set to be showable

return

		return position >= 0 && bounds != null && bounds.height > 0;
	
public booleanisShown()

		boolean bIsShown = isShowable() && row.isVisible();
		if (bIsShown != bLastIsShown) {
			bLastIsShown = bIsShown;
			if (cell != null) {
				int mode = bIsShown ? TableCellVisibilityListener.VISIBILITY_SHOWN
						: TableCellVisibilityListener.VISIBILITY_HIDDEN;
				((TableColumnCore) cell.getTableColumn()).invokeCellVisibilityListeners(
						cell, mode);
				cell.invokeVisibilityListeners(mode);
			}
		}
		return bIsShown;
	
public voidlocationChanged()

		// TODO Auto-generated method stub

	
public booleanneedsPainting()

		return isShown();
	
public voidredraw()

		// XXX Complete.  We don't have a redraw for cells, so redraw the row
		if (!isShown()) {
			return;
		}
		row.redraw();
		// invalidating the area
		//	Utils.execSWTThread(new AERunnable() {
		//	public void runSupport() {
		//		if (!isShown()) {
		//			return;
		//		}
		//  	Rectangle r = getBounds();
		//  	if (r == null) {
		//  		return;
		//  	}
		//  	((TableViewSWT) row.getView()).getTableComposite().redraw(r.x, r.y,
		//				r.width, r.height, true);
		//	}
		//});
	
public voidrefresh()

		redraw();
	
public voidsetBounds(Rectangle bounds)

param
bounds the bounds to set

		if (((TableCellImpl) cell).bDebug) {
			((TableCellImpl) cell).debug("setBounds " + bounds);
		}

		//System.out.println(cell.getTableID() + "]" + cell.getTableColumn().getName() + ": " + bounds);
		this.bounds = bounds;
	
public booleansetForeground(Color color)

		if (isSameColor(colorFG, color)) {
			return false;
		}
		colorFG = color;
		return true;
	
public booleansetForeground(int red, int green, int blue)

		// TODO Auto-generated method stub
		return false;
	
public voidsetIcon(Image img)

		imgIcon = img;
	
public voidsetRowForeground(Color color)

		// TODO Auto-generated method stub

	
public voidsetTableCell(com.aelitis.azureus.ui.common.table.TableCellCore cell)

param
cell

		this.cell = cell;
		this.column = cell.getTableColumn();
	
public booleansetText(java.lang.String text)

		if (sText == null && text == null) {
			return false;
		}
		if (sText != null && text != null && (sText == text || sText.equals(text))) {
			return false;
		}

		sText = text;

		view.cellRefresh(this, true, true);

		return true;