Search in sources :

Example 1 with ICellRenderer

use of de.jaret.util.ui.table.renderer.ICellRenderer in project translationstudio8 by heartsome.

the class JaretTable method getCellRendererFromMap.

/**
     * Retrieve a cell renderer for a given class. Checks all interfaces and all superclasses.
     * 
     * @param clazz class in queston
     * @return renderer or null
     */
private ICellRenderer getCellRendererFromMap(Class<?> clazz) {
    ICellRenderer result = null;
    result = _colClassRendererMap.get(clazz);
    if (result != null) {
        return result;
    }
    Class<?>[] interfaces = clazz.getInterfaces();
    for (Class<?> c : interfaces) {
        result = _colClassRendererMap.get(c);
        if (result != null) {
            return result;
        }
    }
    Class<?> sc = clazz.getSuperclass();
    while (sc != null) {
        result = _colClassRendererMap.get(sc);
        if (result != null) {
            return result;
        }
        // interfaces of the superclass
        Class<?>[] scinterfaces = sc.getInterfaces();
        for (Class<?> c : scinterfaces) {
            result = _colClassRendererMap.get(c);
            if (result != null) {
                return result;
            }
        }
        sc = sc.getSuperclass();
    }
    return result;
}
Also used : ICellRenderer(de.jaret.util.ui.table.renderer.ICellRenderer)

Example 2 with ICellRenderer

use of de.jaret.util.ui.table.renderer.ICellRenderer in project translationstudio8 by heartsome.

the class JaretTablePrinter method drawCell.

/**
     * TODO creation and disposal of the cell renderers for printing is ... well should be changed!
     * 
     * @param gc
     * @param area
     * @param row
     * @param col
     */
private void drawCell(GC gc, Rectangle area, IRow row, IColumn col) {
    ICellStyle bc = _table.getTableViewState().getCellStyle(row, col);
    ICellRenderer cellRenderer = _table.getCellRenderer(row, col).createPrintRenderer(_printer);
    if (cellRenderer != null) {
        cellRenderer.draw(gc, _table, bc, area, row, col, false, false, true);
    }
    cellRenderer.dispose();
}
Also used : ICellStyle(de.jaret.util.ui.table.renderer.ICellStyle) ICellRenderer(de.jaret.util.ui.table.renderer.ICellRenderer)

Example 3 with ICellRenderer

use of de.jaret.util.ui.table.renderer.ICellRenderer in project translationstudio8 by heartsome.

the class JaretTable method getCellRenderer.

/**
     * Retrieve the cell renderer for a cell.
     * 
     * @param row row row of the cell
     * @param column column column of the cell
     * @return cell renderer
     */
protected ICellRenderer getCellRenderer(IRow row, IColumn column) {
    // first check column specific renderers
    ICellRenderer renderer = null;
    renderer = _colCellRendererMap.get(column);
    if (renderer == null) {
        // try class map
        Object value = column.getValue(row);
        if (value != null) {
            renderer = getCellRendererFromMap(value.getClass());
        }
        if (renderer == null) {
            // nothing? -> default
            renderer = _colClassRendererMap.get(void.class);
        }
    }
    return renderer;
}
Also used : ICellRenderer(de.jaret.util.ui.table.renderer.ICellRenderer)

Example 4 with ICellRenderer

use of de.jaret.util.ui.table.renderer.ICellRenderer in project translationstudio8 by heartsome.

the class JaretTable method getToolTipText.

/**
     * Supply tooltip text for a position in the table.
     * 
     * @param x x coordinate
     * @param y y coordinate
     * @return tooltip text or <code>null</code>
     */
private String getToolTipText(int x, int y) {
    IJaretTableCell cell = getCell(x, y);
    if (cell != null) {
        Rectangle bounds = getCellBounds(cell);
        ICellRenderer renderer = getCellRenderer(cell.getRow(), cell.getColumn());
        if (renderer != null) {
            String tt = renderer.getTooltip(this, bounds, cell.getRow(), cell.getColumn(), x, y);
            if (tt != null) {
                return tt;
            }
        }
    }
    return null;
}
Also used : ICellRenderer(de.jaret.util.ui.table.renderer.ICellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell)

Example 5 with ICellRenderer

use of de.jaret.util.ui.table.renderer.ICellRenderer in project translationstudio8 by heartsome.

the class JaretTable method getPreferredRowHeight.

/**
     * Calculate the preferred height of a row. Only visibl columns are taken into account.
     * 
     * @param gc Graphics context
     * @param row row to calculate the height for
     * @return preferred height or -1 if no preferred height can be determined
     */
private int getPreferredRowHeight(GC gc, IRow row) {
    int result = -1;
    for (IColumn column : _cols) {
        if (_tvs.getColumnVisible(column)) {
            ICellRenderer renderer = getCellRenderer(row, column);
            ICellStyle cellStyle = _tvs.getCellStyle(row, column);
            int ph = renderer.getPreferredHeight(gc, cellStyle, _tvs.getColumnWidth(column), row, column);
            if (ph > result) {
                result = ph;
            }
        }
    }
    return result;
}
Also used : ICellStyle(de.jaret.util.ui.table.renderer.ICellStyle) IColumn(de.jaret.util.ui.table.model.IColumn) ICellRenderer(de.jaret.util.ui.table.renderer.ICellRenderer) Point(org.eclipse.swt.graphics.Point)

Aggregations

ICellRenderer (de.jaret.util.ui.table.renderer.ICellRenderer)7 ICellStyle (de.jaret.util.ui.table.renderer.ICellStyle)3 IColumn (de.jaret.util.ui.table.model.IColumn)1 IJaretTableCell (de.jaret.util.ui.table.model.IJaretTableCell)1 BooleanCellRenderer (de.jaret.util.ui.table.renderer.BooleanCellRenderer)1 DateCellRenderer (de.jaret.util.ui.table.renderer.DateCellRenderer)1 DoubleCellRenderer (de.jaret.util.ui.table.renderer.DoubleCellRenderer)1 ImageCellRenderer (de.jaret.util.ui.table.renderer.ImageCellRenderer)1 TextCellRenderer (de.jaret.util.ui.table.renderer.TextCellRenderer)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1