Search in sources :

Example 1 with TableCell

use of com.biglybt.pif.ui.tables.TableCell in project BiglyBT by BiglySoftware.

the class ColumnCheckBox method cellMouseTrigger.

@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
        TableCell cell = event.cell;
        int event_x = event.x;
        int event_y = event.y;
        int cell_width = cell.getWidth();
        int cell_height = cell.getHeight();
        Rectangle icon_bounds = tick_icon.getImage().getBounds();
        int x_pad = (cell_width - icon_bounds.width) / 2;
        int y_pad = (cell_height - icon_bounds.height) / 2;
        if (event_x >= x_pad && event_x <= cell_width - x_pad && event_y >= y_pad && event_y <= cell_height - y_pad) {
            Object datasource = cell.getDataSource();
            Boolean state = getCheckBoxState(datasource);
            if (state != null) {
                setCheckBoxState(datasource, !state);
                cell.invalidate();
                if (cell instanceof TableCellCore) {
                    ((TableCellCore) cell).refresh(true);
                }
            }
        }
    }
}
Also used : TableCell(com.biglybt.pif.ui.tables.TableCell) Rectangle(org.eclipse.swt.graphics.Rectangle) TableCellCore(com.biglybt.ui.common.table.TableCellCore)

Example 2 with TableCell

use of com.biglybt.pif.ui.tables.TableCell in project BiglyBT by BiglySoftware.

the class LocProvUtils method addColumns.

private void addColumns() {
    synchronized (this) {
        if (cl_installed || active_provider == null) {
            return;
        }
        TableManager tm = core.getPluginManager().getDefaultPluginInterface().getUIManager().getTableManager();
        String[] peer_tables = new String[] { TableManager.TABLE_TORRENT_PEERS, TableManager.TABLE_ALL_PEERS };
        for (int i = 0; i < peer_tables.length; i++) {
            TableColumn iso3166Column = tm.createColumn(peer_tables[i], "CountryCode");
            iso3166Column.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_LAST, 30, TableColumn.INTERVAL_INVALID_ONLY);
            iso3166Column.addCellRefreshListener(new TableCellRefreshListener() {

                @Override
                public void refresh(TableCell cell) {
                    Peer peer = (Peer) cell.getDataSource();
                    String s = getCountryCode(peer);
                    if (!cell.setSortValue(s) && cell.isValid()) {
                        return;
                    }
                    cell.setText(s);
                }
            });
            tm.addColumn(iso3166Column);
            columns.add(iso3166Column);
            // Country Name
            TableColumn countryColumn = tm.createColumn(peer_tables[i], "Country");
            countryColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_INVISIBLE, 80, TableColumn.INTERVAL_INVALID_ONLY);
            countryColumn.addCellRefreshListener(new TableCellRefreshListener() {

                @Override
                public void refresh(TableCell cell) {
                    Peer peer = (Peer) cell.getDataSource();
                    String s = getCountryName(peer);
                    if (!cell.setSortValue(s) && cell.isValid()) {
                        return;
                    }
                    cell.setText(s);
                }
            });
            tm.addColumn(countryColumn);
            columns.add(countryColumn);
            // Small Flags
            TableColumn flagsColumn = tm.createColumn(peer_tables[i], "CountryFlagSmall");
            flagsColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_INVISIBLE, 25, TableColumn.INTERVAL_INVALID_ONLY);
            flagsColumn.setType(TableColumn.TYPE_GRAPHIC);
            FlagListener flagListener = new FlagListener(true);
            flagsColumn.addCellRefreshListener(flagListener);
            flagsColumn.addCellToolTipListener(flagListener);
            tm.addColumn(flagsColumn);
            columns.add(flagsColumn);
            // Normal Flags
            flagsColumn = tm.createColumn(peer_tables[i], "CountryFlag");
            flagsColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_LAST, 25, TableColumn.INTERVAL_INVALID_ONLY);
            flagsColumn.setType(TableColumn.TYPE_GRAPHIC);
            flagListener = new FlagListener(false);
            flagsColumn.addCellRefreshListener(flagListener);
            flagsColumn.addCellToolTipListener(flagListener);
            tm.addColumn(flagsColumn);
            columns.add(flagsColumn);
        }
    }
}
Also used : TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableCell(com.biglybt.pif.ui.tables.TableCell) Peer(com.biglybt.pif.peers.Peer) TableManager(com.biglybt.pif.ui.tables.TableManager) TableColumn(com.biglybt.pif.ui.tables.TableColumn)

Example 3 with TableCell

use of com.biglybt.pif.ui.tables.TableCell in project BiglyBT by BiglySoftware.

the class BuddyPluginView method addBetaSubviews.

private void addBetaSubviews(boolean enable) {
    String[] views = { TableManager.TABLE_MYTORRENTS_ALL_BIG, TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, "TagsView" };
    if (enable) {
        taggableLifecycleAdapter = new TaggableLifecycleAdapter() {

            @Override
            public void taggableTagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }

            @Override
            public void taggableUntagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }
        };
        TagManagerFactory.getTagManager().addTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
        UISWTViewEventListener listener = new UISWTViewEventListener() {

            @Override
            public boolean eventOccurred(UISWTViewEvent event) {
                UISWTView currentView = event.getView();
                switch(event.getType()) {
                    case UISWTViewEvent.TYPE_CREATE:
                        {
                            beta_subviews.put(currentView, new BetaSubViewHolder());
                            currentView.setDestroyOnDeactivate(false);
                            break;
                        }
                    case UISWTViewEvent.TYPE_INITIALIZE:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.initialise(event.getView(), (Composite) event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.setDataSource(event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSGAINED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.gotFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSLOST:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.lostFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DESTROY:
                        {
                            BetaSubViewHolder subview = beta_subviews.remove(currentView);
                            if (subview != null) {
                                subview.destroy();
                            }
                            break;
                        }
                }
                return true;
            }
        };
        for (String table_id : views) {
            ui_instance.addView(table_id, "azbuddy.ui.menu.chat", listener);
        }
        TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
        TableCellRefreshListener msg_refresh_listener = new TableCellRefreshListener() {

            @Override
            public void refresh(TableCell _cell) {
                TableCellSWT cell = (TableCellSWT) _cell;
                Download dl = (Download) cell.getDataSource();
                if (dl == null) {
                    return;
                }
                List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                boolean is_pending = false;
                for (ChatInstance instance : instances) {
                    if (instance.getMessageOutstanding()) {
                        is_pending = true;
                    }
                }
                Image graphic;
                String tooltip;
                int sort_order;
                if (is_pending) {
                    graphic = bs_chat_gray_text;
                    tooltip = MessageText.getString("TableColumn.header.chat.msg.out");
                    sort_order = 1;
                } else {
                    graphic = null;
                    tooltip = MessageText.getString("label.no.messages");
                    sort_order = 0;
                }
                cell.setMarginHeight(0);
                cell.setGraphic(graphic);
                cell.setToolTip(tooltip);
                cell.setSortValue(sort_order);
                cell.setCursorID(graphic == null ? SWT.CURSOR_ARROW : SWT.CURSOR_HAND);
            }
        };
        TableCellMouseListener msg_mouse_listener = new TableCellMouseListener() {

            @Override
            public void cellMouseTrigger(TableCellMouseEvent event) {
                if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
                    TableCell cell = event.cell;
                    Download dl = (Download) cell.getDataSource();
                    if (dl != null) {
                        List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                        for (ChatInstance instance : instances) {
                            if (instance.getMessageOutstanding()) {
                                try {
                                    BuddyPluginUtils.getBetaPlugin().showChat(instance);
                                } catch (Throwable e) {
                                    Debug.out(e);
                                }
                            }
                        }
                    }
                }
            }
        };
        columnMessagePending = new TableColumnCreationListener() {

            @Override
            public void tableColumnCreated(TableColumn result) {
                result.setAlignment(TableColumn.ALIGN_CENTER);
                result.setPosition(TableColumn.POSITION_LAST);
                result.setWidth(32);
                result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
                result.setType(TableColumn.TYPE_GRAPHIC);
                result.addCellRefreshListener(msg_refresh_listener);
                result.addCellMouseListener(msg_mouse_listener);
                result.setIconReference("dchat_gray", true);
                synchronized (columns) {
                    columns.add(result);
                }
            }
        };
        table_manager.registerColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
    } else {
        for (String table_id : views) {
            ui_instance.removeViews(table_id, "azbuddy.ui.menu.chat");
        }
        for (UISWTView entry : new ArrayList<>(beta_subviews.keySet())) {
            entry.closeView();
        }
        if (taggableLifecycleAdapter != null) {
            TagManagerFactory.getTagManager().removeTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
            taggableLifecycleAdapter = null;
        }
        beta_subviews.clear();
        if (columnMessagePending != null) {
            TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
            table_manager.unregisterColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
            columnMessagePending = null;
            synchronized (columns) {
                columns.clear();
            }
        }
    }
}
Also used : ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TaggableLifecycleAdapter(com.biglybt.core.tag.TaggableLifecycleAdapter) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) TableCellMouseListener(com.biglybt.pif.ui.tables.TableCellMouseListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCell(com.biglybt.pif.ui.tables.TableCell) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) TableManager(com.biglybt.pif.ui.tables.TableManager) Download(com.biglybt.pif.download.Download) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) TableColumn(com.biglybt.pif.ui.tables.TableColumn) Point(org.eclipse.swt.graphics.Point) TagType(com.biglybt.core.tag.TagType) UISWTView(com.biglybt.ui.swt.pif.UISWTView) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableCellMouseEvent(com.biglybt.pif.ui.tables.TableCellMouseEvent) Tag(com.biglybt.core.tag.Tag) Taggable(com.biglybt.core.tag.Taggable)

Example 4 with TableCell

use of com.biglybt.pif.ui.tables.TableCell 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

TableCell (com.biglybt.pif.ui.tables.TableCell)4 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)3 TableManager (com.biglybt.pif.ui.tables.TableManager)3 TableColumn (com.biglybt.pif.ui.tables.TableColumn)2 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)2 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)2 Image (org.eclipse.swt.graphics.Image)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 DownloadManager (com.biglybt.core.download.DownloadManager)1 Subscription (com.biglybt.core.subs.Subscription)1 Tag (com.biglybt.core.tag.Tag)1 TagType (com.biglybt.core.tag.TagType)1 Taggable (com.biglybt.core.tag.Taggable)1 TaggableLifecycleAdapter (com.biglybt.core.tag.TaggableLifecycleAdapter)1 Download (com.biglybt.pif.download.Download)1 Peer (com.biglybt.pif.peers.Peer)1 UIManager (com.biglybt.pif.ui.UIManager)1 TableCellAddedListener (com.biglybt.pif.ui.tables.TableCellAddedListener)1 TableCellMouseEvent (com.biglybt.pif.ui.tables.TableCellMouseEvent)1 TableCellMouseListener (com.biglybt.pif.ui.tables.TableCellMouseListener)1