FileDocCategorySizeDatePackage
ListRow.javaAPI DocAzureus 3.0.3.420348Wed Aug 15 10:04:48 BST 2007com.aelitis.azureus.ui.swt.views.list

ListRow

public class ListRow extends Object implements org.gudy.azureus2.ui.swt.views.table.TableRowSWT
author
TuxPaper
created
Jun 12, 2006

Fields Summary
public static int
ROW_HEIGHT
private com.aelitis.azureus.ui.swt.skin.SWTSkinProperties
skinProperties
private Object
coreDataSource
private Object
pluginDataSource
private Map
mapTableCells
private boolean
bDisposed
private boolean
bSelected
private ListView
view
private final org.eclipse.swt.widgets.Composite
parent
private Color
fg
private Color
bg
private boolean
bRowVisuallyChangedSinceRefresh
private ArrayList
mouseListeners
private org.gudy.azureus2.core3.util.AEMonitor
this_mon
Constructors Summary
public ListRow(ListView view, org.eclipse.swt.widgets.Composite parent, Object datasource)

param
position


	    	 
	        
		this.parent = parent;
		coreDataSource = datasource;
		this.view = view;

		pluginDataSource = null;
		bDisposed = false;
		bSelected = false;
		mapTableCells = new LinkedHashMap();

		skinProperties = view.getSkinProperties();

		TableColumnCore[] columns = view.getAllColumns();
		// XXX Need invisible "sort by" column
		int iStartPos = ListView.COLUMN_MARGIN_WIDTH;
		// this is -1 :(
		//int height = rowComposite.getSize().y;
		for (int i = 0; i < columns.length; i++) {
			TableColumnCore column = columns[i];

			boolean bVisible = column.getPosition() >= 0;
			Rectangle bounds = bVisible ? new Rectangle(iStartPos,
					ListView.ROW_MARGIN_HEIGHT, column.getWidth(), ROW_HEIGHT
							- (ListView.ROW_MARGIN_HEIGHT * 2)) : null;

			ListCell listCell;
			int iColumnPos = column.getPosition();
			int iSWTAlign = CoreTableColumn.getSWTAlign(column.getAlignment());
			if (column.getType() == TableColumn.TYPE_GRAPHIC) {
				listCell = new ListCellGraphic(this, iColumnPos, iSWTAlign, bounds);
			} else {
				listCell = new ListCell(this, iColumnPos, iSWTAlign, bounds);
			}

			if (bVisible) {
				iStartPos += bounds.width + (ListView.COLUMN_MARGIN_WIDTH * 2);
			}

			TableCellSWT cell = new TableCellImpl(this, column, i, listCell);
			listCell.setTableCell(cell);
			cell.setUpToDate(false);

			mapTableCells.put(column.getName(), cell);
			//cell.refresh();
		}
	
Methods Summary
protected java.util.List_refresh(boolean bDoGraphics, boolean bVisible)

		// If this were called from a plugin, we'd have to refresh the sorted column
		// even if we weren't visible

		if (!bVisible) {
			setUpToDate(false);
			return new ArrayList();
		}

		ArrayList list = new ArrayList();

		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT cell = (TableCellSWT) iter.next();
			Rectangle bounds = cell.getBounds();
			TableColumn column = cell.getTableColumn();
			if (bounds != null && column.isVisible()) {
				boolean thisChanged = cell.refresh(bDoGraphics, bVisible);
				if (thisChanged) {
					list.add(cell);
				}
			}
		}
		if (bRowVisuallyChangedSinceRefresh) {
			list.add(0, this);
		}
		bRowVisuallyChangedSinceRefresh = false;
		return list;
	
public voidaddMouseListener(TableRowMouseListener listener)

		try {
			this_mon.enter();

			if (mouseListeners == null)
				mouseListeners = new ArrayList(1);

			mouseListeners.add(listener);

		} finally {
			this_mon.exit();
		}
	
private voidcheckCellForSetting()

		if (bDisposed) {
			throw new UIRuntimeException("ListRow is disposed.");
		}
	
private booleancolorsEqual(Color color1, Color color2)

		if (color1 == color2) {
			return true;
		}
		if (color1 == null || color2 == null) {
			return false;
		}
		return color1.equals(color2);
	
public voiddelete()

		bDisposed = true;

		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT item = (TableCellSWT) iter.next();
			try {
				item.dispose();
			} catch (Exception e) {
				Debug.out("Disposing ListRow Column", e);
			}
		}
	
public voiddoPaint(GC gc)

		if (bDisposed) {
			return;
		}
		doPaint(gc, isVisible());
	
public voiddoPaint(GC gc, boolean bVisible)

		doPaint(gc, bVisible, false);
	
public voiddoPaint(GC gc, boolean bVisible, boolean bListCellPaint)

		// XXX Copied from TableRowImpl
		if (bDisposed || !bVisible) {
			return;
		}

		TableColumnCore[] visibleColumns = view.getVisibleColumns();

		long lTimeStart = System.currentTimeMillis();
		Rectangle oldClipping = gc.getClipping();
		try {
			gc.setForeground(getForeground());
			gc.setBackground(getBackground());
			//gc.setBackground(Display.getDefault().getSystemColor((int)(Math.random() * 16)));

			Rectangle clientArea = view.getClientArea();
			gc.fillRectangle(0, view.rowGetVisibleYOffset(this), clientArea.width,
					ROW_HEIGHT);
			if (isFocused()) {
				gc.setLineStyle(SWT.LINE_DOT);
				gc.drawRectangle(0, view.rowGetVisibleYOffset(this),
						clientArea.width - 1, ROW_HEIGHT - 1);
			}

			for (int i = 0; i < visibleColumns.length; i++) {
				TableColumnCore column = visibleColumns[i];
				TableCellSWT cell = (TableCellSWT) mapTableCells.get(column.getName());
				if (cell == null) {
					continue;
				}

				try {
					if (cell.needsPainting()) {
						Rectangle bounds = cell.getBounds();
						if (bounds != null) {
							Rectangle clipping = bounds.intersection(oldClipping);
							gc.setClipping(clipping);

							if (bListCellPaint) {
								ListCell listcell = (ListCell) cell.getBufferedTableItem();
								listcell.doPaint(gc);
							} else {
								cell.doPaint(gc);
							}
						}
					}
				} catch (Exception e) {
					//Debug.out(e);
					System.err.println("column " + column.getName() + ";" + cell);
				}
			}
		} finally {
			gc.setClipping(oldClipping);
		}
		long diff = System.currentTimeMillis() - lTimeStart;
		if (diff > 60) {
			view.log("doPaint took " + diff + "ms. " + this.toString());
		}
	
public booleanfixupPosition()
Fixes up row's layout. Does not check if rows next to it are correct, even if some layout information changed

return

		int iRowPos = getIndex();

		setBackgroundColor(iRowPos);

		if (parent == null || parent.isDisposed()) {
			return false;
		}

		return true;
	
private ColorgetAlternatingColor()

		boolean bOdd = ((getIndex() + 1) % 2) == 0;
		if (skinProperties != null) {
			String sColorID = (bOdd) ? "color.row.odd.bg" : "color.row.even.bg";
			Color color = skinProperties.getColor(sColorID);
			if (color != null) {
				return color;
			}
		}
		return parent.getBackground();
	
public ColorgetBackground()

		if (bg == null) {
			setBackgroundColor(getIndex());
		}
		return bg;
	
public java.lang.ObjectgetDataSource()

		return getDataSource(false);
	
public java.lang.ObjectgetDataSource(boolean bCoreObject)

		if (bCoreObject) {
			return coreDataSource;
		}

		if (pluginDataSource != null) {
			return pluginDataSource;
		}

		if (coreDataSource instanceof DownloadManager) {
			DownloadManager dm = (DownloadManager) coreDataSource;
			if (dm != null) {
				try {
					pluginDataSource = DownloadManagerImpl.getDownloadStatic(dm);
				} catch (DownloadException e) { /* Ignore */
				}
			}
		}
		if (coreDataSource instanceof PEPeer) {
			PEPeer peer = (PEPeer) coreDataSource;
			if (peer != null) {
				pluginDataSource = PeerManagerImpl.getPeerForPEPeer(peer);
			}
		}

		if (coreDataSource instanceof PEPiece) {
			// XXX There is no Piece object for plugins yet
			PEPiece piece = (PEPiece) coreDataSource;
			if (piece != null) {
				pluginDataSource = null;
			}
		}

		if (coreDataSource instanceof DiskManagerFileInfo) {
			DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) coreDataSource;
			if (fileInfo != null) {
				try {
					pluginDataSource = new DiskManagerFileInfoImpl(
							DownloadManagerImpl.getDownloadStatic(fileInfo.getDownloadManager()),
							fileInfo);
				} catch (DownloadException e) { /* Ignore */
				}
			}
		}

		if (coreDataSource instanceof TRHostTorrent) {
			TRHostTorrent item = (TRHostTorrent) coreDataSource;
			if (item != null) {
				pluginDataSource = new TrackerTorrentImpl(item);
			}
		}

		return pluginDataSource;
	
public ColorgetForeground()

		if (fg == null) {
			setBackgroundColor(getIndex());
		}
		return fg;
	
public intgetIndex()

		return view.indexOf(this);
	
public TableCellgetTableCell(java.lang.String sColumnName)

		if (bDisposed) {
			return null;
		}

		return (TableCell) mapTableCells.get(sColumnName);
	
public com.aelitis.azureus.ui.common.table.TableCellCoregetTableCellCore(java.lang.String field)

		if (bDisposed) {
			return null;
		}

		return (TableCellCore) mapTableCells.get(field);
	
public org.gudy.azureus2.ui.swt.views.table.TableCellSWTgetTableCellSWT(java.lang.String sColumnName)

		if (bDisposed) {
			return null;
		}

		return (TableCellSWT) mapTableCells.get(sColumnName);
	
public org.gudy.azureus2.ui.swt.views.table.TableCellSWTgetTableCellSWT(int x, int y)

param
x
param
y
return

		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT cell = (TableCellSWT) iter.next();
			if (cell.isShown()) {
				Rectangle bounds = cell.getBounds();
				if (bounds != null && bounds.contains(x, bounds.y)) {
					return cell;
				}
			}
		}
		return null;
	
public java.lang.StringgetTableID()

		return view.getTableID();
	
public com.aelitis.azureus.ui.common.table.TableViewgetView()

		return view;
	
public intgetVisibleYOffset()

		return view.rowGetVisibleYOffset(this);
	
public booleangetVisuallyChangedSinceLastRefresh()

		if (bDisposed) {
			return true;
		}

		if (bRowVisuallyChangedSinceRefresh) {
			return true;
		}

		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT cell = (TableCellSWT) iter.next();
			if (cell != null) {
				if (cell.getVisuallyChangedSinceRefresh()) {
					return true;
				}
			}
		}
		return false;
	
public voidinvalidate()

		if (bDisposed) {
			return;
		}

		long lTimeStart = System.currentTimeMillis();
		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT cell = (TableCellSWT) iter.next();
			if (cell != null) {
				cell.invalidate(true);
			}
		}
		long diff = System.currentTimeMillis() - lTimeStart;
		if (diff >= 10) {
			System.out.println("invalidate: " + diff + "ms");
		}
	
public voidinvalidateGraphic()

		if (bDisposed) {
			return;
		}

		long lTimeStart = System.currentTimeMillis();
		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT cell = (TableCellSWT) iter.next();
			if (cell.getTableColumn().getType() == TableColumn.TYPE_GRAPHIC) {
				cell.invalidate(true);
			}
		}
		long diff = System.currentTimeMillis() - lTimeStart;
		if (diff >= 10) {
			System.out.println("invalidate: " + diff + "ms");
		}
	
public voidinvokeMouseListeners(TableRowMouseEvent event)

		ArrayList listeners = mouseListeners;
		if (listeners == null)
			return;
		
		for (int i = 0; i < listeners.size(); i++) {
			try {
				TableRowMouseListener l = (TableRowMouseListener) (listeners.get(i));

				l.rowMouseTrigger(event);

			} catch (Throwable e) {
				Debug.printStackTrace(e);
			}
		}
	
public booleanisFocused()

		return this.equals(view.getRowFocused());
	
public booleanisRowDisposed()

		return bDisposed;
	
public booleanisSelected()

		return bSelected;
	
public booleanisValid()

		if (bDisposed) {
			return true;
		}

		boolean valid = true;
		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT cell = (TableCellSWT) iter.next();
			if (cell != null) {
				valid &= cell.isValid();
			}
		}
		return valid;
	
public booleanisVisible()

		return view.isRowVisible(this);
	
public voidlocationChanged(int iStartColumn)

		// TODO Auto-generated method stub

	
public voidredraw()

		view.rowRefreshAsync(this, true, true);
	
public java.util.Listrefresh(boolean bDoGraphics)

		if (bDisposed) {
			return new ArrayList();
		}

		boolean bVisible = isVisible();

		return refresh(bDoGraphics, bVisible);
	
public java.util.Listrefresh(boolean bDoGraphics, boolean bVisible)

		if (bDisposed) {
			return new ArrayList();
		}
		return view.rowRefresh(this, bDoGraphics, bVisible);
	
public voidremoveMouseListener(TableRowMouseListener listener)

		try {
			this_mon.enter();

			if (mouseListeners == null)
				return;

			mouseListeners.remove(listener);

		} finally {
			this_mon.exit();
		}
	
public voidsetAlternatingBGColor(boolean bEvenIfNotVisible)

		setBackgroundColor(getIndex());
	
private voidsetBackgroundColor(int iPosition)

		checkCellForSetting();

		boolean bOdd = ((iPosition + 1) % 2) == 0;
		if (bSelected) {
			if (skinProperties == null) {
				bg = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
				fg = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
			} else {
				String sColorID = (bOdd) ? "color.row.odd.selected.bg"
						: "color.row.even.selected.bg";
				Color color = skinProperties == null ? null
						: skinProperties.getColor(sColorID);
				if (color != null) {
					bg = color;
				} else {
					bg = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
				}

				sColorID = (bOdd) ? "color.row.odd.selected.fg"
						: "color.row.even.selected.fg";
				Color cText = skinProperties == null ? null
						: skinProperties.getColor(sColorID);
				if (cText == null) {
					sColorID = (bOdd) ? "color.row.odd.fg" : "color.row.even.fg";
					cText = skinProperties == null ? null
							: skinProperties.getColor(sColorID);

					if (cText == null) {
						cText = parent.getDisplay().getSystemColor(
								SWT.COLOR_LIST_SELECTION_TEXT);
					}
				}

				fg = cText;
			}
			bRowVisuallyChangedSinceRefresh = true;

			invalidateGraphic();
			if (isVisible()) {
				redraw();
			}
		} else {
			boolean bChanged = false;
			if (skinProperties != null) {
				String sColorID = (bOdd) ? "color.row.odd.bg" : "color.row.even.bg";
				Color color = skinProperties.getColor(sColorID);
				if (color != null && !colorsEqual(color, bg)) {
					bChanged = true;
					bg = color;
				}
			} else {
				Color oldColor = bg;
				bg = bOdd ? bg = parent.getDisplay().getSystemColor(
						SWT.COLOR_LIST_BACKGROUND) : Colors.colorAltRow;
				if (!colorsEqual(oldColor, bg)) {
					bChanged = true;
				}
			}

			String sColorID = (bOdd) ? "color.row.odd.fg" : "color.row.even.fg";
			Color cText = skinProperties == null ? null
					: skinProperties.getColor(sColorID);

			if (cText == null) {
				cText = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
			}
			if (!colorsEqual(cText, fg)) {
				bChanged = true;
				fg = cText;
			}

			if (bChanged) {
				bRowVisuallyChangedSinceRefresh = true;
				invalidateGraphic();
				if (isVisible()) {
					redraw();
				}
			}
		}
		// 1160681379555: r54c4r.v?N;Invalidate Cell;true from ListRow::setBackgroundColor::316,ListRow::setIndex::468,ListView::notifyIndexChanges::385,ListView$3::run::344,Utils::execSWTThread::590,Utils::execSWTThread::618,ListView::addDataSources::313,ListView::processDataSourceQueue::242,ListView::updateUI::660,UIUpdaterImpl::update::139,UIUpdaterImpl::access$0::126,UIUpdaterImpl$1::runSupport::72,AERunnable::run::38,RunnableLock::run::35,Synchronizer::runAsyncMessages::123,Display::runAsyncMessages::3325,Display::readAndDispatch::2971,SWTThread::<init>::130,SWTThread::createInstance::64,Initializer::<init>::169,Initializer::main::147
	
public voidsetFocused(boolean b)

param
b

		ListRow oldRow = view.getRowFocused();
		if (b) {
			view.rowSetFocused(this);
		} else if (isFocused()) {
			view.rowSetFocused(null);
		}
		if (oldRow != null) {
			oldRow.redraw();
		}
		redraw();
	
public voidsetForeground(Color c)

		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT item = (TableCellSWT) iter.next();
			item.setForeground(c);
		}
	
public booleansetHeight(int iHeight)

		// TODO Auto-generated method stub
		bRowVisuallyChangedSinceRefresh = true;
		return false;
	
public booleansetIconSize(Point pt)

		// TODO Auto-generated method stub
		bRowVisuallyChangedSinceRefresh = true;
		return false;
	
public voidsetSelected(boolean bSelected)

		if (this.bSelected == bSelected) {
			return;
		}

		this.bSelected = bSelected;
		setBackgroundColor(getIndex());
		view.rowSetSelected(this, bSelected);
	
public booleansetTableItem(int iRowPos)
Fixes up layout, and if something changed, it makes sure items near it are fixed up

		if (!fixupPosition()) {
			return false;
		}

		ListRow row = view.getRow(iRowPos + 1);
		if (row != null) {
			row.fixupPosition();
		}

		bRowVisuallyChangedSinceRefresh = true;
		return true;
	
public voidsetUpToDate(boolean upToDate)

		if (bDisposed) {
			return;
		}

		long lTimeStart = System.currentTimeMillis();
		Iterator iter = mapTableCells.values().iterator();
		while (iter.hasNext()) {
			TableCellSWT cell = (TableCellSWT) iter.next();
			if (cell != null) {
				boolean bOldUpToDate = cell.isUpToDate();
				if (bOldUpToDate != upToDate) {
					cell.setUpToDate(upToDate);

					// hack.. a call to ListCell.isShown will trigger Visibility Listener
					ListCell listcell = (ListCell) cell.getBufferedTableItem();
					listcell.isShown();
				}
			}
		}
		long diff = System.currentTimeMillis() - lTimeStart;
		if (diff >= 50) {
			System.out.println("sutd: " + upToDate + " for " + getIndex() + "; "
					+ diff + "ms");
		}
	
public java.lang.StringtoString()

		return "ListRow {" + getIndex() + (bDisposed ? ", Disposed" : "") + ","
				+ view.getTableID() + "}";