FileDocCategorySizeDatePackage
FakeTableCell.javaAPI DocAzureus 3.0.3.415323Sat Sep 08 19:47:18 BST 2007com.aelitis.azureus.ui.swt.views.skin

FakeTableCell

public class FakeTableCell extends Object implements TableCell
author
TuxPaper
created
Aug 29, 2007

Fields Summary
private org.gudy.azureus2.core3.util.AEMonitor
this_mon
private ArrayList
refreshListeners
private ArrayList
disposeListeners
private ArrayList
tooltipListeners
private ArrayList
cellMouseListeners
private ArrayList
cellMouseMoveListeners
private ArrayList
cellVisibilityListeners
private Image
image
private Rectangle
imageBounds
private int
marginHeight
private int
orientation
private int
marginWidth
private Comparable
sortValue
private Object
ds
private org.eclipse.swt.widgets.Control
composite
private final TableColumn
tableColumn
Constructors Summary
public FakeTableCell(TableColumn column)

param
columnRateUpDown


	  	 
	   
		this.tableColumn = column;
		setOrientationViaColumn();
	
Methods Summary
private boolean_setSortValue(java.lang.Comparable valueToSort)

		if (sortValue == valueToSort)
			return false;

		if ((valueToSort instanceof String) && (sortValue instanceof String)
				&& sortValue.equals(valueToSort)) {
			return false;
		}

		if ((valueToSort instanceof Number) && (sortValue instanceof Number)
				&& sortValue.equals(valueToSort)) {
			return false;
		}

		sortValue = valueToSort;

		return true;
	
public voidaddDisposeListener(TableCellDisposeListener listener)

		try {
			this_mon.enter();

			if (disposeListeners == null) {
				disposeListeners = new ArrayList(1);
			}
			disposeListeners.add(listener);
		} finally {

			this_mon.exit();
		}
	
public voidaddListeners(java.lang.Object listenerObject)

		if (listenerObject instanceof TableCellDisposeListener)
			addDisposeListener((TableCellDisposeListener) listenerObject);

		if (listenerObject instanceof TableCellRefreshListener)
			addRefreshListener((TableCellRefreshListener) listenerObject);

		if (listenerObject instanceof TableCellToolTipListener)
			addToolTipListener((TableCellToolTipListener) listenerObject);

		if (listenerObject instanceof TableCellMouseMoveListener) {
			addMouseMoveListener((TableCellMouseMoveListener) listenerObject);
		}

		if (listenerObject instanceof TableCellMouseListener) {
			addMouseListener((TableCellMouseListener) listenerObject);
		}

		if (listenerObject instanceof TableCellVisibilityListener)
			addVisibilityListener((TableCellVisibilityListener) listenerObject);
	
public voidaddMouseListener(TableCellMouseListener listener)

		try {
			this_mon.enter();

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

			cellMouseListeners.add(listener);

		} finally {
			this_mon.exit();
		}
	
public voidaddMouseMoveListener(TableCellMouseMoveListener listener)

		try {
			this_mon.enter();

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

			cellMouseMoveListeners.add(listener);

		} finally {
			this_mon.exit();
		}
	
public voidaddRefreshListener(TableCellRefreshListener listener)

		try {
			this_mon.enter();

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

			refreshListeners.add(listener);

		} finally {
			this_mon.exit();
		}
	
public voidaddToolTipListener(TableCellToolTipListener listener)

		try {
			this_mon.enter();

			if (tooltipListeners == null) {
				tooltipListeners = new ArrayList(1);
			}
			tooltipListeners.add(listener);

		} finally {
			this_mon.exit();
		}
	
public voidaddVisibilityListener(TableCellVisibilityListener listener)

		try {
			this_mon.enter();

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

			cellVisibilityListeners.add(listener);

		} finally {
			this_mon.exit();
		}
	
protected TableCellMouseEventbuildMouseEvent(MouseEvent e, int eventType)

param
e
return
since
3.0.2.1

		TableCellMouseEvent event = new TableCellMouseEvent();
		event.cell = this;
		event.button = e.button;
		event.keyboardState = e.stateMask;
		event.eventType = eventType;

		Rectangle r = composite.getBounds();
//		int align = tableColumn.getAlignment();
//		if (align == TableColumn.ALIGN_CENTER) {
//			r.x = marginWidth;
//			r.x += (r.width - (marginWidth * 2) - imageBounds.width) / 2;
//		}

		event.x = e.x - r.x;
		event.y = e.y - r.y;

		return event;
	
public voiddoPaint(GC gc, Rectangle bounds)

		// TODO: Cleanup and stop calling me so often!

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

		if (image != null && !image.isDisposed()) {
			Point size = new Point(bounds.width, bounds.height);

			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 java.lang.ObjectgetDataSource()

		return ds;
	
public int[]getForeground()

		// TODO Auto-generated method stub
		return null;
	
public org.gudy.azureus2.plugins.ui.GraphicgetGraphic()

		// TODO Auto-generated method stub
		return null;
	
public intgetHeight()

		if (composite != null) {
			return composite.getSize().y;
		}
		return 0;
	
public intgetMaxLines()

		// TODO Auto-generated method stub
		return 0;
	
public java.lang.ComparablegetSortValue()

		return sortValue;
	
public TableColumngetTableColumn()

		// TODO Auto-generated method stub
		return null;
	
public java.lang.StringgetTableID()

		// TODO Auto-generated method stub
		return null;
	
public TableRowgetTableRow()

		// TODO Auto-generated method stub
		return null;
	
public java.lang.StringgetText()

		// TODO Auto-generated method stub
		return null;
	
public java.lang.ObjectgetToolTip()

		// TODO Auto-generated method stub
		return null;
	
public intgetWidth()

		if (composite != null) {
			return composite.getSize().x;
		}
		return 0;
	
public voidinvalidate()

	
public voidinvokeMouseListeners(TableCellMouseEvent event)

		ArrayList listeners = event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE
				? cellMouseMoveListeners : cellMouseListeners;
		if (listeners == null)
			return;

		if (event.cell != null && event.row == null) {
			event.row = event.cell.getTableRow();
		}

		for (int i = 0; i < listeners.size(); i++) {
			try {
				TableCellMouseListener l = (TableCellMouseListener) (listeners.get(i));

				l.cellMouseTrigger(event);

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

		// TODO Auto-generated method stub
		return false;
	
public booleanisShown()

		return true;
	
public booleanisValid()

		// TODO Auto-generated method stub
		return false;
	
public voidrefresh()

		//System.out.println("refresh");
		if (refreshListeners != null) {
			for (int i = 0; i < refreshListeners.size(); i++) {
				((TableCellRefreshListener) (refreshListeners.get(i))).refresh(this);
			}
		}
	
public voidremoveDisposeListener(TableCellDisposeListener listener)

		try {
			this_mon.enter();

			if (disposeListeners == null)
				return;

			disposeListeners.remove(listener);

		} finally {

			this_mon.exit();
		}
	
public voidremoveMouseListener(TableCellMouseListener listener)

		try {
			this_mon.enter();

			if (cellMouseListeners == null)
				return;

			cellMouseListeners.remove(listener);

		} finally {
			this_mon.exit();
		}
	
public voidremoveMouseMoveListener(TableCellMouseMoveListener listener)

		try {
			this_mon.enter();

			if (cellMouseMoveListeners == null)
				return;

			cellMouseMoveListeners.remove(listener);

		} finally {
			this_mon.exit();
		}
	
public voidremoveRefreshListener(TableCellRefreshListener listener)

		try {
			this_mon.enter();

			if (refreshListeners == null)
				return;

			refreshListeners.remove(listener);
		} finally {

			this_mon.exit();
		}
	
public voidremoveToolTipListener(TableCellToolTipListener listener)

		try {
			this_mon.enter();

			if (tooltipListeners == null)
				return;

			tooltipListeners.remove(listener);
		} finally {

			this_mon.exit();
		}
	
public voidremoveVisibilityListener(TableCellVisibilityListener listener)

		try {
			this_mon.enter();

			if (cellVisibilityListeners == null)
				return;

			cellVisibilityListeners.remove(listener);

		} finally {
			this_mon.exit();
		}
	
public voidsetControl(org.eclipse.swt.widgets.Composite composite)

		this.composite = composite;

		composite.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				doPaint(e.gc, composite.getClientArea());
			}
		});

		composite.addMouseListener(new MouseListener() {

			public void mouseUp(MouseEvent e) {
				invokeMouseListeners(buildMouseEvent(e,
						TableCellMouseEvent.EVENT_MOUSEUP));
			}

			public void mouseDown(MouseEvent e) {
				invokeMouseListeners(buildMouseEvent(e,
						TableCellMouseEvent.EVENT_MOUSEDOWN));
			}

			public void mouseDoubleClick(MouseEvent e) {
			}

		});

		composite.addMouseMoveListener(new MouseMoveListener() {
			public void mouseMove(MouseEvent e) {
				invokeMouseListeners(buildMouseEvent(e,
						TableCellMouseEvent.EVENT_MOUSEMOVE));
			}
		});
		
		composite.addMouseTrackListener(new MouseTrackListener() {
		
			public void mouseHover(MouseEvent e) {
				// TODO Auto-generated method stub
		
			}
		
			public void mouseExit(MouseEvent e) {
				invokeMouseListeners(buildMouseEvent(e,
						TableCellMouseEvent.EVENT_MOUSEEXIT));
			}
		
			public void mouseEnter(MouseEvent e) {
				invokeMouseListeners(buildMouseEvent(e,
						TableCellMouseEvent.EVENT_MOUSEENTER));
			}
		
		});
	
public voidsetDataSource(java.lang.Object datasource)

		ds = datasource;
	
public voidsetFillCell(boolean fillCell)

		// TODO Auto-generated method stub

	
public booleansetForeground(int red, int green, int blue)

		// TODO Auto-generated method stub
		return false;
	
public booleansetGraphic(org.gudy.azureus2.plugins.ui.Graphic img)

		Image imgSWT = null;
		if (img instanceof UISWTGraphic) {
			imgSWT = ((UISWTGraphic) img).getImage();
		}

		if (imgSWT != null && imgSWT.isDisposed()) {
			return false;
		}

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

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

		if (composite != null) {
			Utils.execSWTThread(new AERunnable() {
				public void runSupport() {
					composite.redraw();
				}
			});
		}

		return true;
	
public voidsetMarginHeight(int height)

		// TODO Auto-generated method stub

	
public voidsetMarginWidth(int width)

		// TODO Auto-generated method stub

	
private voidsetOrientationViaColumn()

		int align = tableColumn.getAlignment();
		if (align == TableColumn.ALIGN_CENTER)
			orientation = SWT.CENTER;
		else if (align == TableColumn.ALIGN_LEAD)
			orientation = SWT.LEFT;
		else if (align == TableColumn.ALIGN_TRAIL)
			orientation = SWT.RIGHT;
	
public booleansetSortValue(java.lang.Comparable valueToSort)

		// TODO Auto-generated method stub
		return false;
	
public booleansetSortValue(float valueToSort)

		// TODO Auto-generated method stub
		return false;
	
public booleansetSortValue(long valueToSort)

		if ((sortValue instanceof Long)
				&& ((Long) sortValue).longValue() == valueToSort)
			return false;

		return _setSortValue(new Long(valueToSort));
	
public booleansetText(java.lang.String text)

		// TODO Auto-generated method stub
		return false;
	
public voidsetToolTip(java.lang.Object tooltip)

		// TODO Auto-generated method stub