Search in sources :

Example 1 with TableCellSWTBase

use of com.biglybt.ui.swt.views.table.impl.TableCellSWTBase in project BiglyBT by BiglySoftware.

the class TableRowPainted method swt_paintGC.

/**
 * @param gc GC to draw to
 * @param drawBounds Area that needs redrawing
 * @param rowStartX where in the GC this row's x-axis starts
 * @param rowStartY where in the GC this row's y-axis starts
 * @param pos
 */
public void swt_paintGC(GC gc, Rectangle drawBounds, int rowStartX, int rowStartY, int pos, boolean isTableSelected, boolean isTableEnabled) {
    if (isRowDisposed() || gc == null || gc.isDisposed() || drawBounds == null || isHidden) {
        return;
    }
    // done by caller
    // if (!drawBounds.intersects(rowStartX, rowStartY, 9999, getHeight())) {
    // return;
    // }
    TableColumnCore[] visibleColumns = getView().getVisibleColumns();
    if (visibleColumns == null || visibleColumns.length == 0) {
        return;
    }
    boolean isSelected = isSelected();
    boolean isSelectedNotFocused = isSelected && !isTableSelected;
    Color origBG = gc.getBackground();
    Color origFG = gc.getForeground();
    Color fg = getForeground();
    Color shadowColor = null;
    Color altColor;
    Color bg;
    if (isTableEnabled) {
        altColor = Colors.alternatingColors[pos >= 0 ? pos % 2 : 0];
        if (altColor == null) {
            altColor = gc.getDevice().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
        }
        if (isSelected) {
            Color color;
            color = gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION);
            gc.setBackground(color);
        } else {
            gc.setBackground(altColor);
        }
        bg = getBackground();
        if (bg == null) {
            bg = gc.getBackground();
        } else {
            gc.setBackground(bg);
        }
        if (isSelected) {
            shadowColor = fg;
            fg = gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
        } else {
            if (fg == null) {
                fg = gc.getDevice().getSystemColor(SWT.COLOR_LIST_FOREGROUND);
            }
        }
    } else {
        Device device = gc.getDevice();
        altColor = Colors.getSystemColor(device, SWT.COLOR_WIDGET_BACKGROUND);
        if (isSelected) {
            bg = Colors.getSystemColor(device, SWT.COLOR_WIDGET_LIGHT_SHADOW);
        } else {
            bg = altColor;
        }
        gc.setBackground(bg);
        fg = Colors.getSystemColor(device, SWT.COLOR_WIDGET_NORMAL_SHADOW);
    }
    gc.setForeground(fg);
    int rowAlpha = getAlpha();
    Font font = gc.getFont();
    Rectangle clipping = gc.getClipping();
    int x = rowStartX;
    // boolean paintedRow = false;
    synchronized (lock) {
        if (mTableCells == null) {
            // not sure if this is wise, but visibleRows seems to keep up to date.. so, it must be ok!
            setShown(true, true);
        }
        if (mTableCells != null) {
            for (TableColumn tc : visibleColumns) {
                TableCellCore cell = mTableCells.get(tc.getName());
                int w = tc.getWidth();
                Rectangle r = new Rectangle(x, rowStartY, w, getHeight());
                TableCellPainted cellSWT = null;
                if (cell instanceof TableCellPainted && !cell.isDisposed()) {
                    cellSWT = (TableCellPainted) cell;
                    cellSWT.setBoundsRaw(r);
                }
                if (drawBounds.intersects(r)) {
                    // paintedRow = true;
                    gc.setAlpha(255);
                    if (isSelectedNotFocused) {
                        gc.setBackground(altColor);
                        gc.fillRectangle(r);
                        gc.setAlpha(100);
                        gc.setBackground(bg);
                        gc.fillRectangle(r);
                    } else {
                        gc.setBackground(bg);
                        gc.fillRectangle(r);
                        if (isSelected) {
                            gc.setAlpha(80);
                            gc.setForeground(altColor);
                            gc.fillGradientRectangle(r.x, r.y, r.width, r.height, true);
                            gc.setForeground(fg);
                        }
                    }
                    gc.setAlpha(rowAlpha);
                    if (cellSWT == null) {
                        x += w;
                        continue;
                    }
                    if (swt_paintCell(gc, cellSWT.getBounds(), cellSWT, shadowColor)) {
                        // row color may have changed; this would update the color
                        // for all new cells.  However, setting color triggers a
                        // row redraw that will fix up the UI
                        // Color fgNew = getForeground();
                        // if (fgNew != null && fgNew != fg) {
                        // fg = fgNew;
                        // }
                        gc.setBackground(bg);
                        gc.setForeground(fg);
                        gc.setFont(font);
                        Utils.setClipping(gc, clipping);
                    }
                    if (DEBUG_ROW_PAINT) {
                        ((TableCellSWTBase) cell).debug("painted " + (cell.getVisuallyChangedSinceRefresh() ? "VC" : "!P") + " @ " + r);
                    }
                } else {
                    if (DEBUG_ROW_PAINT) {
                        ((TableCellSWTBase) cell).debug("Skip paintItem; no intersects; r=" + r + ";dB=" + drawBounds + " from " + Debug.getCompressedStackTrace(4));
                    }
                }
                x += w;
            }
        }
        int w = drawBounds.width - x;
        if (w > 0) {
            Rectangle r = new Rectangle(x, rowStartY, w, getHeight());
            if (clipping.intersects(r)) {
                gc.setAlpha(255);
                if (isSelectedNotFocused) {
                    gc.setBackground(altColor);
                    gc.fillRectangle(r);
                    gc.setAlpha(100);
                    gc.setBackground(bg);
                    gc.fillRectangle(r);
                } else {
                    gc.fillRectangle(r);
                    if (isSelected) {
                        gc.setAlpha(80);
                        gc.setForeground(altColor);
                        gc.fillGradientRectangle(r.x, r.y, r.width, r.height, true);
                        gc.setForeground(fg);
                    }
                }
                gc.setAlpha(rowAlpha);
            }
        }
    }
    if (isFocused()) {
        gc.setAlpha(40);
        gc.setForeground(origFG);
        gc.setLineDash(new int[] { 1, 2 });
        gc.drawRectangle(rowStartX, rowStartY, getViewPainted().getClientArea().width - 1, getHeight() - 1);
        gc.setLineStyle(SWT.LINE_SOLID);
    }
    gc.setAlpha(255);
    gc.setBackground(origBG);
    gc.setForeground(origFG);
}
Also used : TableCellSWTBase(com.biglybt.ui.swt.views.table.impl.TableCellSWTBase) TableCellCore(com.biglybt.ui.common.table.TableCellCore) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableColumn(com.biglybt.pif.ui.tables.TableColumn)

Aggregations

TableColumn (com.biglybt.pif.ui.tables.TableColumn)1 TableCellCore (com.biglybt.ui.common.table.TableCellCore)1 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)1 TableCellSWTBase (com.biglybt.ui.swt.views.table.impl.TableCellSWTBase)1