Search in sources :

Example 26 with TableRowCore

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

the class NameItem method cellPaint.

@Override
public void cellPaint(GC gc, final TableCellSWT cell) {
    final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
    Rectangle cellBounds = cell.getBounds();
    int originalBoundxsX = cellBounds.x;
    int textX = originalBoundxsX;
    TableRowCore rowCore = cell.getTableRowCore();
    boolean showIcon = bShowIcon;
    if (rowCore != null) {
        int depth;
        boolean is_leaf;
        int is_skipped = -1;
        if (fileInfo instanceof FilesView.FilesViewTreeNode) {
            FilesView.FilesViewTreeNode node = (FilesView.FilesViewTreeNode) fileInfo;
            depth = node.getDepth();
            is_leaf = node.isLeaf();
            if (!is_leaf) {
                showIcon = false;
                is_skipped = node.getSkippedState();
            }
        } else {
            depth = 0;
            is_leaf = true;
        }
        int numSubItems = rowCore.getSubItemCount();
        int paddingX = 3;
        int width = 7;
        paddingX += depth * width;
        boolean show_twisty;
        if (NEVER_SHOW_TWISTY) {
            show_twisty = false;
        } else if (numSubItems > 1 || !is_leaf) {
            show_twisty = true;
        } else {
            show_twisty = false;
        }
        if (!NEVER_SHOW_TWISTY) {
            cellBounds.x += paddingX;
            cellBounds.width -= paddingX;
        }
        if (show_twisty) {
            int middleY = cellBounds.y + (cellBounds.height / 2) - 1;
            int startX = cellBounds.x + paddingX;
            int halfHeight = 2;
            Color bg = gc.getBackground();
            gc.setBackground(gc.getForeground());
            gc.setAntialias(SWT.ON);
            gc.setAdvanced(true);
            if (rowCore.isExpanded()) {
                gc.fillPolygon(new int[] { startX, middleY - halfHeight, startX + width, middleY - halfHeight, startX + (width / 2), middleY + (halfHeight * 2) + 1 });
            } else {
                gc.fillPolygon(new int[] { startX, middleY - halfHeight, startX + width, middleY + halfHeight, startX, middleY + (halfHeight * 2) + 1 });
            }
            gc.setBackground(bg);
            Rectangle hitArea = new Rectangle(paddingX * 2, middleY - halfHeight - cellBounds.y, width, (halfHeight * 4) + 1);
            rowCore.setData(ID_EXPANDOHITAREA, hitArea);
        }
        if (!NEVER_SHOW_TWISTY) {
            cellBounds.x += paddingX + width;
            cellBounds.width -= paddingX + width;
        }
        ImageLoader im = ImageLoader.getInstance();
        String check_key;
        boolean is_ro = false;
        if (is_leaf) {
            if (fileInfo.isSkipped()) {
                check_key = "check_no";
            } else {
                if (fileInfo.getLength() == fileInfo.getDownloaded()) {
                    check_key = "check_ro_yes";
                    is_ro = true;
                } else {
                    check_key = "check_yes";
                }
            }
        } else {
            if (is_skipped == 0) {
                check_key = "check_no";
            } else if (is_skipped == 1) {
                if (fileInfo.getLength() == fileInfo.getDownloaded()) {
                    check_key = "check_ro_yes";
                    is_ro = true;
                } else {
                    check_key = "check_yes";
                }
            } else {
                check_key = "check_maybe";
            }
        }
        Image check = im.getImage(check_key);
        Rectangle checkSize = check.getBounds();
        int checkYOffset = (cellBounds.height - checkSize.height) / 2 + 1;
        gc.drawImage(check, cellBounds.x + 2, cellBounds.y + checkYOffset);
        im.releaseImage(check_key);
        if (!is_ro) {
            Rectangle hitArea = new Rectangle(cellBounds.x + 2 - originalBoundxsX, checkYOffset, checkSize.width, checkSize.height);
            rowCore.setData(ID_CHECKHITAREA, hitArea);
        }
        cellBounds.x += checkSize.width + 4;
        cellBounds.width -= checkSize.width + 4;
    }
    if (!showIcon) {
        cellBounds.x += 2;
        cellBounds.width -= 4;
        cellPaintName(cell, gc, cellBounds, cellBounds.x, originalBoundxsX);
        return;
    }
    Image[] imgThumbnail = new Image[] { fileInfo == null ? null : ImageRepository.getPathIcon(fileInfo.getFile(true).getPath(), cell.getHeight() > 32, false) };
    if (imgThumbnail != null && ImageLoader.isRealImage(imgThumbnail[0])) {
        try {
            if (cellBounds.height > 30) {
                cellBounds.y += 1;
                cellBounds.height -= 3;
            }
            Rectangle imgBounds = imgThumbnail[0].getBounds();
            int dstWidth;
            int dstHeight;
            if (imgBounds.height > cellBounds.height) {
                dstHeight = cellBounds.height;
                dstWidth = imgBounds.width * cellBounds.height / imgBounds.height;
            } else if (imgBounds.width > cellBounds.width) {
                dstWidth = cellBounds.width - 4;
                dstHeight = imgBounds.height * cellBounds.width / imgBounds.width;
            } else {
                dstWidth = imgBounds.width;
                dstHeight = imgBounds.height;
            }
            if (cellBounds.height <= 18) {
                dstWidth = Math.min(dstWidth, cellBounds.height);
                dstHeight = Math.min(dstHeight, cellBounds.height);
                if (imgBounds.width > 16) {
                    cellBounds.y++;
                    dstHeight -= 2;
                }
            }
            try {
                gc.setAdvanced(true);
                gc.setInterpolation(SWT.HIGH);
            } catch (Exception e) {
            }
            int x = cellBounds.x;
            textX = x + dstWidth + 3;
            int minWidth = dstHeight * 7 / 4;
            int imgPad = 0;
            if (dstHeight > 25) {
                if (dstWidth < minWidth) {
                    imgPad = ((minWidth - dstWidth + 1) / 2);
                    x = cellBounds.x + imgPad;
                    textX = cellBounds.x + minWidth + 3;
                }
            }
            if (cellBounds.width - dstWidth - (imgPad * 2) < 100 && dstHeight > 18) {
                dstWidth = Math.min(32, dstHeight);
                x = cellBounds.x + ((32 - dstWidth + 1) / 2);
                dstHeight = imgBounds.height * dstWidth / imgBounds.width;
                textX = cellBounds.x + dstWidth + 3;
            }
            int y = cellBounds.y + ((cellBounds.height - dstHeight + 1) / 2);
            if (dstWidth > 0 && dstHeight > 0 && !imgBounds.isEmpty()) {
                // Rectangle dst = new Rectangle(x, y, dstWidth, dstHeight);
                Rectangle lastClipping = gc.getClipping();
                try {
                    Utils.setClipping(gc, cellBounds);
                    boolean hack_adv = Constants.isWindows8OrHigher && gc.getAdvanced();
                    if (hack_adv) {
                        // problem with icon transparency on win8
                        gc.setAdvanced(false);
                    }
                    for (int i = 0; i < imgThumbnail.length; i++) {
                        Image image = imgThumbnail[i];
                        if (image == null || image.isDisposed()) {
                            continue;
                        }
                        Rectangle srcBounds = image.getBounds();
                        if (i == 0) {
                            int w = dstWidth;
                            int h = dstHeight;
                            if (imgThumbnail.length > 1) {
                                w = w * 9 / 10;
                                h = h * 9 / 10;
                            }
                            gc.drawImage(image, srcBounds.x, srcBounds.y, srcBounds.width, srcBounds.height, x, y, w, h);
                        } else {
                            int w = dstWidth * 3 / 8;
                            int h = dstHeight * 3 / 8;
                            gc.drawImage(image, srcBounds.x, srcBounds.y, srcBounds.width, srcBounds.height, x + dstWidth - w, y + dstHeight - h, w, h);
                        }
                    }
                    if (hack_adv) {
                        gc.setAdvanced(true);
                    }
                } catch (Exception e) {
                    Debug.out(e);
                } finally {
                    Utils.setClipping(gc, lastClipping);
                }
            }
        } catch (Throwable t) {
            Debug.out(t);
        }
    }
    cellPaintName(cell, gc, cellBounds, textX, originalBoundxsX);
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) IOException(java.io.IOException) TableRowCore(com.biglybt.ui.common.table.TableRowCore) FilesView(com.biglybt.ui.swt.views.FilesView) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 27 with TableRowCore

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

the class TorrentMenuFancy method addPluginItem.

private void addPluginItem(Composite detailArea, final com.biglybt.pif.ui.menus.MenuItem item) {
    // menuWillBeShown listeners might change the visibility, so run before check
    MenuItemImpl menuImpl = ((MenuItemImpl) item);
    menuImpl.invokeMenuWillBeShownListeners(getTarget(item));
    if (!item.isVisible()) {
        if (DEBUG_MENU) {
            System.out.println("Menu Not Visible: " + item.getText() + ": " + item.getMenuID());
        }
        return;
    }
    Graphic graphic = item.getGraphic();
    FancyRowInfo row;
    if (DEBUG_MENU) {
        System.out.println("Menu " + item.getText() + ": " + item.getMenuID());
    }
    if (item.getStyle() == com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU) {
        row = createMenuRow(detailArea, item.getResourceKey(), null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                if (dms.length != 0) {
                    MenuBuilder submenuBuilder = ((MenuItemImpl) item).getSubmenuBuilder();
                    if (submenuBuilder != null) {
                        try {
                            item.removeAllChildItems();
                            submenuBuilder.buildSubmenu(item, getTarget(item));
                        } catch (Throwable t) {
                            Debug.out(t);
                        }
                    }
                    MenuBuildUtils.addPluginMenuItems(item.getItems(), menu, false, true, new MenuBuildUtils.PluginMenuController() {

                        @Override
                        public Listener makeSelectionListener(final com.biglybt.pif.ui.menus.MenuItem plugin_menu_item) {
                            return new TableSelectedRowsListener(tv, false) {

                                @Override
                                public boolean run(TableRowCore[] rows) {
                                    if (rows.length != 0) {
                                        ((MenuItemImpl) plugin_menu_item).invokeListenersMulti(getTarget(item));
                                    }
                                    return true;
                                }
                            };
                        }

                        @Override
                        public void notifyFillListeners(com.biglybt.pif.ui.menus.MenuItem menu_item) {
                            ((MenuItemImpl) menu_item).invokeMenuWillBeShownListeners(getTarget(item));
                        }

                        // @see com.biglybt.ui.swt.MenuBuildUtils.PluginMenuController#buildSubmenu(com.biglybt.pif.ui.menus.MenuItem)
                        @Override
                        public void buildSubmenu(com.biglybt.pif.ui.menus.MenuItem parent) {
                            com.biglybt.pif.ui.menus.MenuBuilder submenuBuilder = ((MenuItemImpl) parent).getSubmenuBuilder();
                            if (submenuBuilder != null) {
                                try {
                                    parent.removeAllChildItems();
                                    submenuBuilder.buildSubmenu(parent, getTarget(item));
                                } catch (Throwable t) {
                                    Debug.out(t);
                                }
                            }
                        }
                    });
                }
            }
        });
    } else {
        row = createRow(detailArea, item.getResourceKey(), null, new TableSelectedRowsListener(tv, false) {

            @Override
            public boolean run(TableRowCore[] rows) {
                if (rows.length != 0) {
                    ((MenuItemImpl) item).invokeListenersMulti(getTarget(item));
                }
                return true;
            }
        });
    }
    row.setEnabled(item.isEnabled());
    if (graphic instanceof UISWTGraphic) {
        row.getIconLabel().setImage(((UISWTGraphic) graphic).getImage());
    } else if (graphic instanceof GraphicURI) {
        ImageLoader.getInstance().setLabelImage(row.getIconLabel(), ((GraphicURI) graphic).getURI().toString());
    }
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuBuilder(com.biglybt.pif.ui.menus.MenuBuilder) MenuItemImpl(com.biglybt.pifimpl.local.ui.menus.MenuItemImpl) TableRowCore(com.biglybt.ui.common.table.TableRowCore) GraphicURI(com.biglybt.pif.ui.GraphicURI) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic)

Example 28 with TableRowCore

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

the class SubscriptionWizard method createAvailableSubscriptionComposite.

private Composite createAvailableSubscriptionComposite(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    Label hsep1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label hsep2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label vsep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
    Label subtitle1 = new Label(composite, SWT.NONE);
    Label subtitle2 = new Label(composite, SWT.NONE);
    subtitle1.setFont(subTitleFont);
    subtitle2.setFont(subTitleFont);
    subtitle1.setText(MessageText.getString("Wizard.Subscription.subscribe.library"));
    subtitle2.setText(MessageText.getString("Wizard.Subscription.subscribe.subscriptions"));
    libraryTable = new Table(composite, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
    final TableColumn torrentColumn = new TableColumn(libraryTable, SWT.NONE);
    torrentColumn.setWidth(Utils.adjustPXForDPI(50));
    final Composite compEmpty = new Composite(composite, SWT.NONE);
    compEmpty.setBackground(Colors.getSystemColor(display, SWT.COLOR_WHITE));
    compEmpty.setBackgroundMode(SWT.INHERIT_DEFAULT);
    FillLayout fl = new FillLayout();
    fl.marginHeight = 15;
    fl.marginWidth = 15;
    compEmpty.setLayout(fl);
    compEmpty.setVisible(false);
    final Link labelEmpty = new Link(compEmpty, SWT.WRAP);
    labelEmpty.setText(MessageText.getString("Wizard.Subscription.subscribe.library.empty"));
    labelEmpty.setFont(subTitleFont);
    labelEmpty.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
    labelEmpty.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
                Utils.launch(event.text);
            }
        }
    });
    initColumns();
    final Composite cTV = new Composite(composite, SWT.NONE);
    cTV.setLayoutData(Utils.getFilledFormData());
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
    cTV.setLayout(layout);
    tvSubscriptions = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_SUB_WIZ, TABLE_SUB_WIZ, new TableColumnCore[0], "SubWizRank", SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
    tvSubscriptions.setMenuEnabled(false);
    tvSubscriptions.setHeaderVisible(false);
    tvSubscriptions.setRowDefaultHeightEM(1.4f);
    tvSubscriptions.initialize(cTV);
    tvSubscriptions.getComposite().addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            com.biglybt.pif.ui.tables.TableColumn tcName = tvSubscriptions.getTableColumn("SubWizName");
            com.biglybt.pif.ui.tables.TableColumn tcRank = tvSubscriptions.getTableColumn("SubWizRank");
            Rectangle clientArea = ((Composite) event.widget).getClientArea();
            tcName.setWidthPX(clientArea.width - tcRank.getWidth() - 1);
        }
    });
    tvSubscriptions.addSelectionListener(new TableSelectionListener() {

        @Override
        public void selected(TableRowCore[] row) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (tvSubscriptions.getSelectedRowsSize() == 0) {
                        addButton.setEnabled(false);
                    } else {
                        addButton.setEnabled(true);
                        TableRowCore[] rows = tvSubscriptions.getSelectedRows();
                        Subscription subscription = (Subscription) rows[0].getDataSource();
                        if (subscription.isSubscribed()) {
                            addButton.setEnabled(false);
                        } else {
                            addButton.setEnabled(true);
                        }
                        addButton.setData("subscription", subscription);
                    }
                }
            });
        }

        @Override
        public void mouseExit(TableRowCore row) {
        }

        @Override
        public void mouseEnter(TableRowCore row) {
        }

        @Override
        public void focusChanged(TableRowCore focus) {
        }

        @Override
        public void deselected(TableRowCore[] rows) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (tvSubscriptions.getSelectedRowsSize() == 0) {
                        addButton.setEnabled(false);
                    }
                }
            });
        }

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
        }
    }, false);
    UIUpdaterSWT.getInstance().addUpdater(new UIUpdatable() {

        @Override
        public void updateUI() {
            if (tvSubscriptions != null) {
                tvSubscriptions.refreshTable(false);
            }
        }

        @Override
        public String getUpdateUIName() {
            return "SubWiz";
        }
    });
    Listener resizeListener = new Listener() {

        int last_width;

        @Override
        public void handleEvent(Event event) {
            Table table = (Table) event.widget;
            Rectangle rect = table.getClientArea();
            int width = rect.width - 3;
            if (width == last_width) {
                return;
            }
            last_width = width;
            int nbColumns = table.getColumnCount();
            if (nbColumns == 1) {
                table.getColumns()[0].setWidth(width);
            }
            ((Table) event.widget).update();
        }
    };
    // subscriptionTable.addListener(SWT.Resize , resizeListener);
    libraryTable.addListener(SWT.Resize, resizeListener);
    final Listener selectionListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            subscriptions = (Subscription[]) item.getData("subscriptions");
            tvSubscriptions.removeDataSources(tvSubscriptions.getDataSources().toArray(new Subscription[0]));
            if (subscriptions != null) {
                tvSubscriptions.addDataSources(subscriptions);
            }
            tvSubscriptions.processDataSourceQueueSync();
            addButton.setEnabled(false);
            addButton.setData("subscription", null);
            tvSubscriptions.setSelectedRows(new TableRowCore[0]);
            if (subscriptions != null && subscriptions.length > 0) {
                TableRowCore row = tvSubscriptions.getRow(subscriptions[0]);
                if (row != null) {
                    row.setSelected(true);
                }
            }
        }
    };
    libraryTable.addListener(SWT.Selection, selectionListener);
    if (availableSubscriptions != null) {
        libraryTable.addListener(SWT.SetData, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = libraryTable.indexOf(item);
                SubscriptionDownloadDetails subInfo = availableSubscriptions[index];
                item.setText(subInfo.getDownload().getDisplayName());
                item.setData("subscriptions", subInfo.getSubscriptions());
                boolean isSubscribed = false;
                Subscription[] subs = subInfo.getSubscriptions();
                for (int i = 0; i < subs.length; i++) {
                    if (subs[i].isSubscribed())
                        isSubscribed = true;
                }
                if (isSubscribed) {
                    item.setForeground(Colors.getSystemColor(display, SWT.COLOR_GRAY));
                }
                if (subInfo.getDownload() == download) {
                    libraryTable.setSelection(item);
                    selectionListener.handleEvent(event);
                }
                if (index == 0 && download == null) {
                    libraryTable.setSelection(item);
                    selectionListener.handleEvent(event);
                }
                if (libraryTable.getSelectionIndex() == index) {
                    // If the item was already selected and we got the SetData afterwards, then let's populate the
                    // subscriptionsTable
                    selectionListener.handleEvent(event);
                }
            }
        });
        libraryTable.setItemCount(availableSubscriptions.length);
        if (availableSubscriptions.length == 0) {
            libraryTable.setVisible(false);
            compEmpty.setVisible(true);
        }
    } else {
        // Test code
        libraryTable.addListener(SWT.SetData, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = libraryTable.indexOf(item);
                item.setText("test " + index);
            }
        });
        libraryTable.setItemCount(20);
    }
    addButton.setEnabled(false);
    addButton.setData("subscription", null);
    // final Image rssIcon = imageLoader.getImage("icon_rss");
    libraryTable.addListener(SWT.MeasureItem, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.height = 20;
        }
    });
    FormLayout formLayout = new FormLayout();
    composite.setLayout(formLayout);
    FormData data;
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(40, 0);
    data.bottom = new FormAttachment(100, 0);
    vsep.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 5);
    subtitle1.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(vsep, 5);
    data.right = new FormAttachment(100, 0);
    subtitle2.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(subtitle1, 5);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 0);
    hsep1.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(subtitle2, 5);
    data.left = new FormAttachment(vsep, -1);
    data.right = new FormAttachment(100, 0);
    hsep2.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(hsep1, 0);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    if (availableSubscriptions != null && availableSubscriptions.length > 0) {
        libraryTable.setLayoutData(data);
    } else {
        // hack: dispose libraryTable as it's not needed and draws over controls
        // (makes a white box covering text).  Would be smarter to not
        // create the libraryTable at all..
        libraryTable.dispose();
        cancelButton.setFocus();
        shell.setDefaultButton(cancelButton);
        compEmpty.setLayoutData(data);
    }
    data = new FormData();
    data.top = new FormAttachment(hsep2, 0);
    data.left = new FormAttachment(vsep, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    cTV.setLayoutData(data);
    return composite;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) TableCellAddedListener(com.biglybt.pif.ui.tables.TableCellAddedListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableCellSWTPaintListener(com.biglybt.ui.swt.views.table.TableCellSWTPaintListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) Listener(org.eclipse.swt.widgets.Listener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableRowCore(com.biglybt.ui.common.table.TableRowCore) GridLayout(org.eclipse.swt.layout.GridLayout) Subscription(com.biglybt.core.subs.Subscription) FormAttachment(org.eclipse.swt.layout.FormAttachment) UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableColumn(org.eclipse.swt.widgets.TableColumn) SubscriptionDownloadDetails(com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails) Event(org.eclipse.swt.widgets.Event) Link(org.eclipse.swt.widgets.Link)

Example 29 with TableRowCore

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

the class SBC_LibraryTableView method initShow.

public void initShow(Core core) {
    Object data = soParent.getControl().getData("TorrentFilterMode");
    if (data instanceof Long) {
        torrentFilterMode = (int) ((Long) data).longValue();
    }
    data = soParent.getControl().getData("DataSource");
    boolean useBigTable = useBigTable();
    SWTSkinObjectTextbox soFilter = (SWTSkinObjectTextbox) skin.getSkinObject("library-filter", soParent.getParent());
    Text txtFilter = soFilter == null ? null : soFilter.getTextControl();
    SWTSkinObjectContainer soCats = (SWTSkinObjectContainer) skin.getSkinObject("library-categories", soParent.getParent());
    Composite cCats = soCats == null ? null : soCats.getComposite();
    // columns not needed for small mode, all torrents
    TableColumnCore[] columns = useBigTable || torrentFilterMode != SBC_LibraryView.TORRENTS_ALL ? getColumns() : null;
    if (null != columns) {
        TableColumnManager tcManager = TableColumnManager.getInstance();
        tcManager.addColumns(columns);
    }
    if (useBigTable) {
        if (torrentFilterMode == SBC_LibraryView.TORRENTS_COMPLETE || torrentFilterMode == SBC_LibraryView.TORRENTS_INCOMPLETE || torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
            swtViewListener = torrentView = new MyTorrentsView_Big(core, torrentFilterMode, columns, txtFilter, cCats);
        } else {
            swtViewListener = torrentView = new MyTorrentsView_Big(core, torrentFilterMode, columns, txtFilter, cCats);
        }
    } else {
        String tableID = SB_Transfers.getTableIdFromFilterMode(torrentFilterMode, false);
        if (torrentFilterMode == SBC_LibraryView.TORRENTS_COMPLETE) {
            swtViewListener = torrentView = new MyTorrentsView(core, tableID, true, columns, txtFilter, cCats, true);
        } else if (torrentFilterMode == SBC_LibraryView.TORRENTS_INCOMPLETE) {
            swtViewListener = torrentView = new MyTorrentsView(core, tableID, false, columns, txtFilter, cCats, true);
        } else if (torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
            swtViewListener = torrentView = new MyTorrentsView(core, tableID, true, columns, txtFilter, cCats, true) {

                @Override
                public boolean isOurDownloadManager(DownloadManager dm) {
                    if (PlatformTorrentUtils.getHasBeenOpened(dm)) {
                        return false;
                    }
                    return super.isOurDownloadManager(dm);
                }
            };
        } else {
            swtViewListener = new MyTorrentsSuperView(txtFilter, cCats) {

                @Override
                public void initializeDone() {
                    MyTorrentsView seedingview = getSeedingview();
                    if (seedingview != null) {
                        seedingview.overrideDefaultSelected(new TableSelectionAdapter() {

                            @Override
                            public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
                                doDefaultClick(rows, stateMask, false, origin);
                            }
                        });
                        MyTorrentsView torrentview = getTorrentview();
                        if (torrentview != null) {
                            torrentview.overrideDefaultSelected(new TableSelectionAdapter() {

                                @Override
                                public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
                                    doDefaultClick(rows, stateMask, false, origin);
                                }
                            });
                        }
                    }
                }
            };
        }
        if (torrentView != null) {
            torrentView.overrideDefaultSelected(new TableSelectionAdapter() {

                @Override
                public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
                    doDefaultClick(rows, stateMask, false, origin);
                }
            });
        }
    }
    if (torrentView != null) {
        tv = torrentView.getTableView();
        if (torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
            torrentView.setRebuildListOnFocusGain(true);
        }
    }
    try {
        view = new UISWTViewImpl(ID + torrentFilterMode, UISWTInstance.VIEW_MAIN, false);
        view.setDatasource(data);
        view.setEventListener(swtViewListener, true);
    } catch (Exception e) {
        Debug.out(e);
    }
    SWTSkinObjectContainer soContents = new SWTSkinObjectContainer(skin, skin.getSkinProperties(), getUpdateUIName(), "", soMain);
    skin.layout();
    viewComposite = soContents.getComposite();
    viewComposite.setLayoutData(Utils.getFilledFormData());
    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = gridLayout.marginHeight = gridLayout.marginWidth = 0;
    viewComposite.setLayout(gridLayout);
    view.initialize(viewComposite);
    SWTSkinObject soSizeSlider = skin.getSkinObject("table-size-slider", soParent.getParent());
    if (soSizeSlider instanceof SWTSkinObjectContainer) {
        SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
        if (tv != null && !tv.enableSizeSlider(so.getComposite(), 16, 100)) {
            so.setVisible(false);
        }
    }
    if (torrentFilterMode == SBC_LibraryView.TORRENTS_ALL && tv != null) {
        tv.addRefreshListener(new TableRowRefreshListener() {

            @Override
            public void rowRefresh(TableRow row) {
                TableRowSWT rowCore = (TableRowSWT) row;
                Object ds = rowCore.getDataSource(true);
                if (!(ds instanceof DownloadManager)) {
                    return;
                }
                DownloadManager dm = (DownloadManager) ds;
                boolean changed = false;
                boolean assumedComplete = dm.getAssumedComplete();
                if (!assumedComplete) {
                    changed |= rowCore.setAlpha(160);
                } else if (!PlatformTorrentUtils.getHasBeenOpened(dm)) {
                    changed |= rowCore.setAlpha(255);
                } else {
                    changed |= rowCore.setAlpha(255);
                }
            }
        });
    }
    viewComposite.getParent().layout(true);
}
Also used : TableSelectionAdapter(com.biglybt.ui.common.table.TableSelectionAdapter) TableRowSWT(com.biglybt.ui.swt.views.table.TableRowSWT) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) DownloadManager(com.biglybt.core.download.DownloadManager) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) TableRowCore(com.biglybt.ui.common.table.TableRowCore) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) GridLayout(org.eclipse.swt.layout.GridLayout) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SWTSkinObjectTextbox(com.biglybt.ui.swt.skin.SWTSkinObjectTextbox) MyTorrentsSuperView(com.biglybt.ui.swt.views.MyTorrentsSuperView) Composite(org.eclipse.swt.widgets.Composite) TableRowRefreshListener(com.biglybt.pif.ui.tables.TableRowRefreshListener) Text(org.eclipse.swt.widgets.Text) MyTorrentsView(com.biglybt.ui.swt.views.MyTorrentsView) UISWTViewImpl(com.biglybt.ui.swt.pifimpl.UISWTViewImpl) TableRow(com.biglybt.pif.ui.tables.TableRow) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Aggregations

TableRowCore (com.biglybt.ui.common.table.TableRowCore)29 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)7 DownloadManager (com.biglybt.core.download.DownloadManager)6 TableCellCore (com.biglybt.ui.common.table.TableCellCore)6 Point (org.eclipse.swt.graphics.Point)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)4 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)3 FilesView (com.biglybt.ui.swt.views.FilesView)3 List (java.util.List)3 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 PEPeerTransport (com.biglybt.core.peer.impl.PEPeerTransport)2 PeerItem (com.biglybt.core.peermanager.peerdb.PeerItem)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 TableColumn (com.biglybt.pif.ui.tables.TableColumn)2 TableSelectionListener (com.biglybt.ui.common.table.TableSelectionListener)2 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2