Search in sources :

Example 21 with TableCellSWT

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

the class SubscriptionWizard method initColumns.

private static void initColumns() {
    if (columnsAdded) {
        return;
    }
    columnsAdded = true;
    UIManager uiManager = PluginInitializer.getDefaultInterface().getUIManager();
    TableManager tableManager = uiManager.getTableManager();
    tableManager.registerColumn(Subscription.class, "SubWizName", new TableColumnCreationListener() {

        private Image rssIcon;

        @Override
        public void tableColumnCreated(com.biglybt.pif.ui.tables.TableColumn column) {
            // this'll get triggered for the Subscriptions Overview table too - easiest fix is to default to hidden there
            column.setVisible(column.getTableID().equals("SubscriptionWizard"));
            ImageLoader imageLoader = ImageLoader.getInstance();
            rssIcon = imageLoader.getImage("icon_rss");
            column.addCellAddedListener(new TableCellAddedListener() {

                @Override
                public void cellAdded(TableCell cell) {
                    Subscription sub = (Subscription) cell.getDataSource();
                    if (sub.isSubscribed()) {
                        cell.setForeground(0xa0, 0xa0, 0xa0);
                    }
                    cell.setText(sub.getName());
                    ((TableCellSWT) cell).setIcon(rssIcon);
                    cell.setToolTip(sub.getNameEx());
                }
            });
        }
    });
    tableManager.registerColumn(Subscription.class, "SubWizRank", new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(com.biglybt.pif.ui.tables.TableColumn column) {
            column.setWidthLimits(RANK_COLUMN_WIDTH, RANK_COLUMN_WIDTH);
            // as above
            column.setVisible(column.getTableID().equals("SubscriptionWizard"));
            column.addCellRefreshListener(new TableCellRefreshListener() {

                @Override
                public void refresh(TableCell cell) {
                    Subscription sub = (Subscription) cell.getDataSource();
                    cell.setSortValue(sub.getCachedPopularity());
                }
            });
            if (column instanceof TableColumnCore) {
                TableColumnCore columnCore = (TableColumnCore) column;
                columnCore.setSortAscending(false);
                columnCore.addCellOtherListener("SWTPaint", new TableCellSWTPaintListener() {

                    @Override
                    public void cellPaint(GC gc, TableCellSWT cell) {
                        Subscription sub = (Subscription) cell.getDataSource();
                        Rectangle bounds = cell.getBounds();
                        bounds.width -= 5;
                        bounds.height -= 7;
                        bounds.x += 2;
                        bounds.y += 3;
                        gc.setBackground(ColorCache.getColor(gc.getDevice(), 255, 255, 255));
                        gc.fillRectangle(bounds);
                        gc.setForeground(ColorCache.getColor(gc.getDevice(), 200, 200, 200));
                        gc.drawRectangle(bounds);
                        bounds.width -= 2;
                        bounds.height -= 2;
                        bounds.x += 1;
                        bounds.y += 1;
                        long popularity = sub.getCachedPopularity();
                        // Rank in pixels between 0 and 80
                        // 0 -> no subscriber
                        // 80 -> 1000 subscribers
                        int rank = 80 * (int) popularity / 1000;
                        if (rank > 80)
                            rank = 80;
                        if (rank < 5)
                            rank = 5;
                        Rectangle clipping = gc.getClipping();
                        bounds.width = rank;
                        bounds.height -= 1;
                        bounds.x += 1;
                        bounds.y += 1;
                        Utils.setClipping(gc, bounds);
                        ImageLoader imageLoader = ImageLoader.getInstance();
                        Image rankingBars = imageLoader.getImage("ranking_bars");
                        gc.drawImage(rankingBars, bounds.x, bounds.y);
                        imageLoader.releaseImage("ranking_bars");
                        Utils.setClipping(gc, clipping);
                    }
                });
            }
        }
    });
    TableColumnManager tcm = TableColumnManager.getInstance();
    tcm.setDefaultColumnNames(TABLE_SUB_WIZ, new String[] { "SubWizName", "SubWizRank" });
}
Also used : TableCellSWTPaintListener(com.biglybt.ui.swt.views.table.TableCellSWTPaintListener) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Rectangle(org.eclipse.swt.graphics.Rectangle) UIManager(com.biglybt.pif.ui.UIManager) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) Image(org.eclipse.swt.graphics.Image) TableCellAddedListener(com.biglybt.pif.ui.tables.TableCellAddedListener) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCell(com.biglybt.pif.ui.tables.TableCell) TableManager(com.biglybt.pif.ui.tables.TableManager) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Subscription(com.biglybt.core.subs.Subscription) GC(org.eclipse.swt.graphics.GC)

Aggregations

TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)21 Image (org.eclipse.swt.graphics.Image)9 DownloadManager (com.biglybt.core.download.DownloadManager)7 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 Download (com.biglybt.pif.download.Download)4 GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)4 GC (org.eclipse.swt.graphics.GC)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 Graphic (com.biglybt.pif.ui.Graphic)3 UISWTGraphic (com.biglybt.ui.swt.pif.UISWTGraphic)3 UISWTGraphicImpl (com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl)3 URLInfo (com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)3 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)2 AERunnable (com.biglybt.core.util.AERunnable)2 TableCell (com.biglybt.pif.ui.tables.TableCell)2 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)2 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)2 TableManager (com.biglybt.pif.ui.tables.TableManager)2 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2