Search in sources :

Example 16 with TableCellSWT

use of com.biglybt.ui.swt.views.table.TableCellSWT 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 17 with TableCellSWT

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

the class ColumnActivityActions method cellMouseTrigger.

// @see com.biglybt.pif.ui.tables.TableCellMouseListener#cellMouseTrigger(com.biglybt.pif.ui.tables.TableCellMouseEvent)
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    ActivitiesEntry entry = (ActivitiesEntry) event.cell.getDataSource();
    String tooltip = null;
    boolean invalidateAndRefresh = false;
    Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
    String text = (String) event.cell.getTableRow().getData("text");
    if (text == null) {
        return;
    }
    GCStringPrinter sp = null;
    GC gc = new GC(Display.getDefault());
    try {
        if (font != null) {
            gc.setFont(font);
        }
        Rectangle drawBounds = getDrawBounds((TableCellSWT) event.cell);
        sp = new GCStringPrinter(gc, text, drawBounds, true, true, SWT.WRAP | SWT.CENTER);
        sp.calculateMetrics();
    } catch (Exception e) {
        Debug.out(e);
    } finally {
        gc.dispose();
    }
    if (sp != null) {
        URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
        int newCursor;
        if (hitUrl != null) {
            if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
                if (hitUrl.url.equals("download")) {
                    String referal = null;
                    Object ds = event.cell.getDataSource();
                    if (ds instanceof ActivitiesEntry) {
                        referal = DLReferals.DL_REFERAL_DASHACTIVITY + "-" + ((ActivitiesEntry) ds).getTypeID();
                    }
                    TorrentListViewsUtils.downloadDataSource(ds, false, referal);
                } else if (hitUrl.url.equals("play")) {
                    String referal = null;
                    Object ds = event.cell.getDataSource();
                    if (ds instanceof ActivitiesEntry) {
                        referal = DLReferals.DL_REFERAL_PLAYDASHACTIVITY + "-" + ((ActivitiesEntry) ds).getTypeID();
                    }
                    TorrentListViewsUtils.playOrStreamDataSource(ds, referal, false, true);
                } else if (hitUrl.url.equals("launch")) {
                    // run via play or stream so we get the security warning
                    Object ds = event.cell.getDataSource();
                    TorrentListViewsUtils.playOrStreamDataSource(ds, DLReferals.DL_REFERAL_LAUNCH, false, true);
                } else if (hitUrl.url.startsWith("action:")) {
                    entry.invokeCallback(hitUrl.url.substring(7));
                } else if (!UrlFilter.getInstance().urlCanRPC(hitUrl.url)) {
                    Utils.launch(hitUrl.url);
                } else {
                    UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
                    if (uif != null) {
                        String target = hitUrl.target;
                        if (target == null) {
                            target = SkinConstants.VIEWID_BROWSER_BROWSE;
                        }
                        uif.viewURL(hitUrl.url, target, "column.activity.action");
                        return;
                    }
                }
            }
            Object ds = event.cell.getDataSource();
            newCursor = SWT.CURSOR_HAND;
            if (UrlFilter.getInstance().urlCanRPC(hitUrl.url)) {
                tooltip = hitUrl.title;
            } else {
                tooltip = hitUrl.url;
            }
        } else {
            newCursor = SWT.CURSOR_ARROW;
        }
        int oldCursor = ((TableCellSWT) event.cell).getCursorID();
        if (oldCursor != newCursor) {
            invalidateAndRefresh = true;
            ((TableCellSWT) event.cell).setCursorID(newCursor);
        }
    }
    Object o = event.cell.getToolTip();
    if ((o == null) || (o instanceof String)) {
        String oldTooltip = (String) o;
        if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
            invalidateAndRefresh = true;
            event.cell.setToolTip(tooltip);
        }
    }
    if (invalidateAndRefresh) {
        event.cell.invalidate();
        ((TableCellSWT) event.cell).redraw();
    }
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo)

Example 18 with TableCellSWT

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

the class ColumnActivityText method cellMouseTrigger.

// @see com.biglybt.pif.ui.tables.TableCellMouseListener#cellMouseTrigger(com.biglybt.pif.ui.tables.TableCellMouseEvent)
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    String tooltip = null;
    boolean invalidateAndRefresh = false;
    ActivitiesEntry entry = (ActivitiesEntry) event.cell.getDataSource();
    // Rectangle bounds = getDrawBounds((TableCellSWT) event.cell);
    Rectangle bounds = ((TableCellSWT) event.cell).getBounds();
    String text = entry.getText();
    GC gc = new GC(Display.getDefault());
    GCStringPrinter sp = null;
    try {
        sp = setupStringPrinter(gc, (TableCellSWT) event.cell);
    } catch (Exception e) {
        Debug.out(e);
    } finally {
        gc.dispose();
    }
    if (sp != null) {
        URLInfo hitUrl = sp.getHitUrl(event.x + bounds.x, event.y + bounds.y);
        int newCursor;
        if (hitUrl != null) {
            String url = hitUrl.url;
            boolean ourUrl = UrlFilter.getInstance().urlCanRPC(url) || url.startsWith("/") || url.startsWith("#");
            if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN && event.button == 1) {
                if (!ourUrl) {
                    if (UrlUtils.isInternalProtocol(url)) {
                        try {
                            UIFunctionsManagerSWT.getUIFunctionsSWT().doSearch(url);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    } else {
                        Utils.launch(url);
                    }
                } else {
                    UIFunctionsSWT uif = UIFunctionsManagerSWT.getUIFunctionsSWT();
                    if (uif != null) {
                        String target = hitUrl.target;
                        if (target == null) {
                            target = SkinConstants.VIEWID_BROWSER_BROWSE;
                        }
                        uif.viewURL(hitUrl.url, target, "column.activity.text");
                        return;
                    }
                }
            }
            newCursor = SWT.CURSOR_HAND;
            if (ourUrl) {
                try {
                    tooltip = hitUrl.title == null ? null : URLDecoder.decode(hitUrl.title, "utf-8");
                } catch (UnsupportedEncodingException e) {
                }
            } else {
                tooltip = hitUrl.url;
            }
        } else {
            newCursor = SWT.CURSOR_ARROW;
        }
        int oldCursor = ((TableCellSWT) event.cell).getCursorID();
        if (oldCursor != newCursor) {
            invalidateAndRefresh = true;
            ((TableCellSWT) event.cell).setCursorID(newCursor);
        }
    }
    Object o = event.cell.getToolTip();
    if ((o == null) || (o instanceof String)) {
        String oldTooltip = (String) o;
        if (!StringCompareUtils.equals(oldTooltip, tooltip)) {
            invalidateAndRefresh = true;
            event.cell.setToolTip(tooltip);
        }
    }
    if (invalidateAndRefresh) {
        event.cell.invalidate();
        ((TableCellSWT) event.cell).redraw();
    }
}
Also used : GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) URLInfo(com.biglybt.ui.swt.shells.GCStringPrinter.URLInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry)

Example 19 with TableCellSWT

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

the class SizeItem method refresh.

@Override
public void refresh(TableCell cell, boolean sortOnlyRefresh) {
    DownloadStubFile fileInfo = (DownloadStubFile) cell.getDataSource();
    long size;
    if (fileInfo == null) {
        size = 0;
    } else {
        size = fileInfo.getLength();
    }
    if (!cell.setSortValue(size) && cell.isValid()) {
        return;
    }
    if (size < 0) {
        // skipped
        cell.setText("(" + DisplayFormatters.formatByteCountToKiBEtc(-size) + ")");
    } else {
        cell.setText(DisplayFormatters.formatByteCountToKiBEtc(size));
    }
    if (Utils.getUserMode() > 0 && (cell instanceof TableCellSWT)) {
        if (size >= 0x40000000l) {
            ((TableCellSWT) cell).setTextAlpha(200 | 0x100);
        } else if (size < 0x100000) {
            ((TableCellSWT) cell).setTextAlpha(180);
        } else {
            ((TableCellSWT) cell).setTextAlpha(255);
        }
    }
}
Also used : DownloadStubFile(com.biglybt.pif.download.DownloadStub.DownloadStubFile) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT)

Example 20 with TableCellSWT

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

the class ColumnTorrentSpeed method refresh.

@Override
public void refresh(TableCell cell) {
    Object ds = cell.getDataSource();
    if (!(ds instanceof Download)) {
        return;
    }
    Download dm = (Download) ds;
    long value;
    long sortValue;
    String prefix = "";
    int iState;
    iState = dm.getState();
    if (iState == Download.ST_DOWNLOADING) {
        value = dm.getStats().getDownloadAverage();
        ((TableCellSWT) cell).setIcon(imgDown);
    } else if (iState == Download.ST_SEEDING) {
        value = dm.getStats().getUploadAverage();
        ((TableCellSWT) cell).setIcon(imgUp);
    } else {
        ((TableCellSWT) cell).setIcon(null);
        value = 0;
    }
    sortValue = (value << 4) | iState;
    if (cell.setSortValue(sortValue) || !cell.isValid()) {
        cell.setText(value > 0 ? prefix + DisplayFormatters.formatByteCountToKiBEtcPerSec(value) : "");
    }
}
Also used : TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Download(com.biglybt.pif.download.Download)

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