Search in sources :

Example 31 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class TableColumnCreatorV3 method upgradeColumns.

private static void upgradeColumns(String[] oldOrder, String[] newOrder, Map<String, TableColumnCore> mapTCs) {
    List<String> listCurrentOrder = new ArrayList<>();
    for (TableColumnCore tc : mapTCs.values()) {
        if (tc.isVisible()) {
            listCurrentOrder.add(tc.getName());
        }
    }
    if (oldOrder.length == listCurrentOrder.size()) {
        List<String> listOldOrder = Arrays.asList(oldOrder);
        if (listOldOrder.containsAll(listCurrentOrder)) {
            // exactly the same items (perhaps in different order) -- upgrade to new list
            System.out.println("upgradeColumns: SAME -> UPGRADING!");
            setVisibility(mapTCs, newOrder, true);
        }
    } else if (listCurrentOrder.size() > oldOrder.length) {
        List<String> listNewOrder = Arrays.asList(newOrder);
        if (listCurrentOrder.containsAll(listNewOrder)) {
            System.out.println("upgradeColumns: has all old plus -> UPGRADING!");
            // make all new columns visible (keep old ones visible too)
            for (String id : newOrder) {
                TableColumnCore tc = mapTCs.get(id);
                if (tc != null) {
                    tc.setVisible(true);
                }
            }
        }
    }
}
Also used : TableColumnCore(com.biglybt.ui.common.table.TableColumnCore)

Example 32 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class TableColumnCreatorV3 method createAllDM.

/**
 * @since 4.0.0.1
 */
public static TableColumnCore[] createAllDM(String tableID, boolean big) {
    final String[] oldVisibleOrder = { ColumnUnopened.COLUMN_ID, ColumnThumbAndName.COLUMN_ID, ColumnStream.COLUMN_ID, SizeItem.COLUMN_ID, ColumnProgressETA.COLUMN_ID, "azsubs.ui.column.subs", "azbuddy.ui.column.msgpending", StatusItem.COLUMN_ID, ColumnTorrentSpeed.COLUMN_ID, SeedsItem.COLUMN_ID, PeersItem.COLUMN_ID, ShareRatioItem.COLUMN_ID };
    final String[] defaultVisibleOrder = { RankItem.COLUMN_ID, ColumnThumbAndName.COLUMN_ID, ColumnStream.COLUMN_ID, ColumnProgressETA.COLUMN_ID, SizeItem.COLUMN_ID, ColumnTorrentSpeed.COLUMN_ID, ETAItem.COLUMN_ID, // DateCompletedItem.COLUMN_ID,
    "RatingColumn", "azsubs.ui.column.subs", "azbuddy.ui.column.msgpending", DateAddedItem.COLUMN_ID };
    TableColumnManager tcManager = TableColumnManager.getInstance();
    Map<String, TableColumnCore> mapTCs = tcManager.getTableColumnsAsMap(Download.class, tableID);
    tcManager.setDefaultColumnNames(tableID, defaultVisibleOrder);
    if (!tcManager.loadTableColumnSettings(Download.class, tableID) || areNoneVisible(mapTCs)) {
        setVisibility(mapTCs, defaultVisibleOrder, true);
        RankItem tc = (RankItem) mapTCs.get(RankItem.COLUMN_ID);
        if (tc != null) {
            tcManager.setDefaultSortColumnName(tableID, RankItem.COLUMN_ID);
            tc.setSortAscending(true);
        }
    } else {
        upgradeColumns(oldVisibleOrder, defaultVisibleOrder, mapTCs);
    }
    // special changes
    StatusItem tcStatusItem = (StatusItem) mapTCs.get(StatusItem.COLUMN_ID);
    if (tcStatusItem != null) {
        tcStatusItem.setChangeRowFG(false);
        if (big) {
            tcStatusItem.setChangeCellFG(false);
            tcStatusItem.setShowTrackerErrors(true);
        }
    }
    if (big) {
        ShareRatioItem tcShareRatioItem = (ShareRatioItem) mapTCs.get(ShareRatioItem.COLUMN_ID);
        if (tcShareRatioItem != null) {
            tcShareRatioItem.setChangeFG(false);
            tcShareRatioItem.setWidth(80);
        }
    }
    return mapTCs.values().toArray(new TableColumnCore[0]);
}
Also used : TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager)

Example 33 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class TableColumnCreatorV3 method createCompleteDM.

public static TableColumnCore[] createCompleteDM(String tableID, boolean big) {
    final String[] oldVisibleOrder = { ColumnUnopened.COLUMN_ID, ColumnThumbAndName.COLUMN_ID, "RatingColumn", "azsubs.ui.column.subs", "azbuddy.ui.column.msgpending", SizeItem.COLUMN_ID, StatusItem.COLUMN_ID, ShareRatioItem.COLUMN_ID, DateCompletedItem.COLUMN_ID };
    final String[] defaultVisibleOrder = { RankItem.COLUMN_ID, ColumnThumbAndName.COLUMN_ID, ColumnStream.COLUMN_ID, StatusItem.COLUMN_ID, SizeItem.COLUMN_ID, ColumnTorrentSpeed.COLUMN_ID, "RatingColumn", "azsubs.ui.column.subs", "azbuddy.ui.column.msgpending", DateCompletedItem.COLUMN_ID };
    TableColumnManager tcManager = TableColumnManager.getInstance();
    Map<String, TableColumnCore> mapTCs = tcManager.getTableColumnsAsMap(DownloadTypeComplete.class, tableID);
    tcManager.setDefaultColumnNames(tableID, defaultVisibleOrder);
    if (!tcManager.loadTableColumnSettings(DownloadTypeComplete.class, tableID) || areNoneVisible(mapTCs)) {
        setVisibility(mapTCs, defaultVisibleOrder, true);
        DateCompletedItem tc = (DateCompletedItem) mapTCs.get(DateCompletedItem.COLUMN_ID);
        if (tc != null) {
            tcManager.setDefaultSortColumnName(tableID, DateCompletedItem.COLUMN_ID);
            tc.setSortAscending(false);
        }
    } else {
        upgradeColumns(oldVisibleOrder, defaultVisibleOrder, mapTCs);
    }
    // special changes
    StatusItem tcStatusItem = (StatusItem) mapTCs.get(StatusItem.COLUMN_ID);
    if (tcStatusItem != null) {
        tcStatusItem.setChangeRowFG(false);
        if (big) {
            tcStatusItem.setChangeCellFG(false);
        }
    }
    if (big) {
        ShareRatioItem tcShareRatioItem = (ShareRatioItem) mapTCs.get(ShareRatioItem.COLUMN_ID);
        if (tcShareRatioItem != null) {
            tcShareRatioItem.setChangeFG(false);
            tcShareRatioItem.setWidth(80);
        }
    }
    return mapTCs.values().toArray(new TableColumnCore[0]);
}
Also used : TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager)

Example 34 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class TableColumnCreatorV3 method createUnopenedDM.

public static TableColumnCore[] createUnopenedDM(String tableID, boolean big) {
    final String[] oldVisibleOrder = { ColumnUnopened.COLUMN_ID, ColumnThumbAndName.COLUMN_ID, "azsubs.ui.column.subs", "azbuddy.ui.column.msgpending", SizeItem.COLUMN_ID, ColumnProgressETA.COLUMN_ID, StatusItem.COLUMN_ID, DateCompletedItem.COLUMN_ID };
    final String[] defaultVisibleOrder = { ColumnUnopened.COLUMN_ID, ColumnThumbAndName.COLUMN_ID, ColumnStream.COLUMN_ID, SizeItem.COLUMN_ID, "RatingColumn", "azsubs.ui.column.subs", "azbuddy.ui.column.msgpending", DateCompletedItem.COLUMN_ID };
    TableColumnManager tcManager = TableColumnManager.getInstance();
    Map<String, TableColumnCore> mapTCs = tcManager.getTableColumnsAsMap(DownloadTypeComplete.class, tableID);
    tcManager.setDefaultColumnNames(tableID, defaultVisibleOrder);
    if (!tcManager.loadTableColumnSettings(DownloadTypeComplete.class, tableID) || areNoneVisible(mapTCs)) {
        setVisibility(mapTCs, defaultVisibleOrder, true);
        DateCompletedItem tc = (DateCompletedItem) mapTCs.get(DateCompletedItem.COLUMN_ID);
        if (tc != null) {
            tcManager.setDefaultSortColumnName(tableID, DateCompletedItem.COLUMN_ID);
            tc.setSortAscending(false);
        }
    } else {
        upgradeColumns(oldVisibleOrder, defaultVisibleOrder, mapTCs);
    }
    // special changes
    StatusItem tcStatusItem = (StatusItem) mapTCs.get(StatusItem.COLUMN_ID);
    if (tcStatusItem != null) {
        tcStatusItem.setChangeRowFG(false);
        if (big) {
            tcStatusItem.setChangeCellFG(false);
        }
    }
    if (big) {
        ShareRatioItem tcShareRatioItem = (ShareRatioItem) mapTCs.get(ShareRatioItem.COLUMN_ID);
        if (tcShareRatioItem != null) {
            tcShareRatioItem.setChangeFG(false);
            tcShareRatioItem.setWidth(80);
        }
    }
    return mapTCs.values().toArray(new TableColumnCore[0]);
}
Also used : TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager)

Example 35 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class TableRowPainted method swt_paintCell.

private boolean swt_paintCell(GC gc, Rectangle cellBounds, TableCellSWTBase cell, Color shadowColor) {
    // Only called from swt_PaintGC, so we can assume GC, cell are valid
    if (cellBounds == null) {
        return false;
    }
    boolean gcChanged = false;
    try {
        gc.setTextAntialias(SWT.DEFAULT);
        TableViewSWT<?> view = (TableViewSWT<?>) getView();
        TableColumnCore column = (TableColumnCore) cell.getTableColumn();
        view.invokePaintListeners(gc, this, column, cellBounds);
        int fontStyle = getFontStyle();
        Font oldFont = null;
        if (fontStyle == SWT.BOLD) {
            oldFont = gc.getFont();
            gc.setFont(FontUtils.getAnyFontBold(gc));
            gcChanged = true;
        } else if (fontStyle == SWT.ITALIC) {
            oldFont = gc.getFont();
            gc.setFont(FontUtils.getAnyFontItalic(gc));
            gcChanged = true;
        }
        if (!cell.isUpToDate()) {
            // System.out.println("R " + rowIndex + ":" + iColumnNo);
            cell.refresh(true, true);
        // return;
        }
        String text = cell.getText();
        Color fg = cell.getForegroundSWT();
        if (fg != null) {
            gcChanged = true;
            if (isSelected()) {
                shadowColor = fg;
            } else {
                gc.setForeground(fg);
            }
        }
        Color bg = cell.getBackgroundSWT();
        if (bg != null) {
            gcChanged = true;
            gc.setBackground(bg);
        }
        // }
        if (cell.needsPainting()) {
            Image graphicSWT = cell.getGraphicSWT();
            if (graphicSWT != null && !graphicSWT.isDisposed()) {
                Rectangle imageBounds = graphicSWT.getBounds();
                Rectangle graphicBounds = new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
                if (cell.getFillCell()) {
                    if (!graphicBounds.isEmpty()) {
                        gc.setAdvanced(true);
                        // System.out.println(imageBounds + ";" + graphicBounds);
                        gc.drawImage(graphicSWT, 0, 0, imageBounds.width, imageBounds.height, graphicBounds.x, graphicBounds.y, graphicBounds.width, graphicBounds.height);
                    }
                } else {
                    if (imageBounds.width < graphicBounds.width) {
                        int alignment = column.getAlignment();
                        if ((alignment & TableColumn.ALIGN_CENTER) > 0) {
                            graphicBounds.x += (graphicBounds.width - imageBounds.width) / 2;
                        } else if ((alignment & TableColumn.ALIGN_TRAIL) > 0) {
                            graphicBounds.x = (graphicBounds.x + graphicBounds.width) - imageBounds.width;
                        }
                    }
                    if (imageBounds.height < graphicBounds.height) {
                        graphicBounds.y += (graphicBounds.height - imageBounds.height) / 2;
                    }
                    gc.drawImage(graphicSWT, graphicBounds.x, graphicBounds.y);
                }
            }
            cell.doPaint(gc);
            gcChanged = true;
        }
        if (text.length() > 0) {
            int ofsx = 0;
            Image image = cell.getIcon();
            Rectangle imageBounds = null;
            if (image != null && !image.isDisposed()) {
                imageBounds = image.getBounds();
                int ofs = imageBounds.width;
                ofsx += ofs;
                cellBounds.x += ofs;
                cellBounds.width -= ofs;
            }
            // System.out.println("PS " + getIndex() + ";" + cellBounds + ";" + cell.getText());
            int style = TableColumnSWTUtils.convertColumnAlignmentToSWT(column.getAlignment());
            if (cellBounds.height > 20) {
                style |= SWT.WRAP;
            }
            int textOpacity = cell.getTextAlpha();
            // textOpacity = 130;
            if (textOpacity < 255) {
                // gc.setTextAntialias(SWT.ON);
                gc.setAlpha(textOpacity);
                gcChanged = true;
            } else if (textOpacity > 255) {
                boolean is_italic = (gc.getFont().getFontData()[0].getStyle() & SWT.ITALIC) != 0;
                if (is_italic) {
                    gc.setFont(FontUtils.getAnyFontBoldItalic(gc));
                } else {
                    gc.setFont(FontUtils.getAnyFontBold(gc));
                }
                // gc.setTextAntialias(SWT.ON);
                // gc.setAlpha(textOpacity & 255);
                gcChanged = true;
            }
            // put some padding on text
            ofsx += 6;
            cellBounds.x += 3;
            cellBounds.width -= 6;
            cellBounds.y += 2;
            cellBounds.height -= 4;
            if (!cellBounds.isEmpty()) {
                GCStringPrinter sp = new GCStringPrinter(gc, text, cellBounds, true, cellBounds.height > 20, style);
                boolean fit;
                if (shadowColor != null) {
                    Color oldFG = gc.getForeground();
                    gc.setForeground(shadowColor);
                    cellBounds.x += 1;
                    cellBounds.y += 1;
                    int alpha = gc.getAlpha();
                    gc.setAlpha(0x40);
                    sp.printString(gc, cellBounds, style);
                    gc.setAlpha(alpha);
                    gc.setForeground(oldFG);
                    cellBounds.x -= 1;
                    cellBounds.y -= 1;
                    fit = sp.printString2(gc, cellBounds, style);
                } else {
                    fit = sp.printString();
                }
                if (fit) {
                    cell.setDefaultToolTip(null);
                } else {
                    cell.setDefaultToolTip(text);
                }
                Point psize = sp.getCalculatedPreferredSize();
                psize.x += ofsx;
                TableColumn tableColumn = cell.getTableColumn();
                if (tableColumn != null && tableColumn.getPreferredWidth() < psize.x) {
                    tableColumn.setPreferredWidth(psize.x);
                }
                if (imageBounds != null) {
                    int drawToY = cellBounds.y + (cellBounds.height / 2) - (imageBounds.height / 2);
                    boolean hack_adv = Constants.isWindows8OrHigher && gc.getAdvanced();
                    if (hack_adv) {
                        // problem with icon transparency on win8
                        gc.setAdvanced(false);
                    }
                    if ((style & SWT.RIGHT) != 0) {
                        Point size = sp.getCalculatedSize();
                        size.x += ofsx;
                        int drawToX = cellBounds.x + cellBounds.width - size.x;
                        gc.drawImage(image, drawToX, drawToY);
                    } else {
                        if (imageBounds.height > cellBounds.height) {
                            float pct = cellBounds.height / (float) imageBounds.height;
                            gc.drawImage(image, 0, 0, imageBounds.width, imageBounds.height, cellBounds.x - imageBounds.width - 3, cellBounds.y, (int) (imageBounds.width * pct), (int) (imageBounds.height * pct));
                        } else {
                            gc.drawImage(image, cellBounds.x - imageBounds.width - 3, drawToY);
                        }
                    }
                    if (hack_adv) {
                        gc.setAdvanced(true);
                    }
                }
            } else {
                cell.setDefaultToolTip(null);
            }
        }
        cell.clearVisuallyChangedSinceRefresh();
        if (oldFont != null) {
            gc.setFont(oldFont);
        }
    } catch (Exception e) {
        Debug.out(cell.getTableID() + ":" + cell.getTableColumn().getName(), e);
    }
    return gcChanged;
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableViewSWT(com.biglybt.ui.swt.views.table.TableViewSWT) TableColumn(com.biglybt.pif.ui.tables.TableColumn)

Aggregations

TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)41 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)16 TableColumn (com.biglybt.pif.ui.tables.TableColumn)5 LightHashMap (com.biglybt.core.util.LightHashMap)4 TableRowCore (com.biglybt.ui.common.table.TableRowCore)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 TableCellCore (com.biglybt.ui.common.table.TableCellCore)3 TableColumnCoreCreationListener (com.biglybt.ui.common.table.TableColumnCoreCreationListener)3 Composite (org.eclipse.swt.widgets.Composite)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 Subscription (com.biglybt.core.subs.Subscription)2 TableCellAddedListener (com.biglybt.pif.ui.tables.TableCellAddedListener)2 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)2 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)2 GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 TableCellSWTPaintListener (com.biglybt.ui.swt.views.table.TableCellSWTPaintListener)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2