Search in sources :

Example 11 with TableCellCore

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

the class TorrentMenuFancy method buildTorrentCustomMenu_Content.

protected void buildTorrentCustomMenu_Content(final Composite detailArea, final DownloadManager[] dms) {
    // Run Data File
    if (hasSelection) {
        createRow(detailArea, "MyTorrentsView.menu.open", "run", new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.runDataSources(dms);
            }
        });
    }
    // Explore (or open containing folder)
    if (hasSelection) {
        final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
        createRow(detailArea, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"), null, new ListenerDMTask(dms, false) {

            @Override
            public void run(DownloadManager dm) {
                ManagerUtils.open(dm, use_open_containing_folder);
            }
        });
    }
    if (hasSelection) {
        createMenuRow(detailArea, "MyTorrentsView.menu.browse", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menuBrowse) {
                final MenuItem itemBrowsePublic = new MenuItem(menuBrowse, SWT.PUSH);
                itemBrowsePublic.setText(MessageText.getString("label.public") + "...");
                itemBrowsePublic.addListener(SWT.Selection, new ListenerDMTask(dms, false) {

                    @Override
                    public void run(DownloadManager dm) {
                        ManagerUtils.browse(dm, false, true);
                    }
                });
                final MenuItem itemBrowseAnon = new MenuItem(menuBrowse, SWT.PUSH);
                itemBrowseAnon.setText(MessageText.getString("label.anon") + "...");
                itemBrowseAnon.addListener(SWT.Selection, new ListenerDMTask(dms, false) {

                    @Override
                    public void run(DownloadManager dm) {
                        ManagerUtils.browse(dm, true, true);
                    }
                });
                new MenuItem(menuBrowse, SWT.SEPARATOR);
                final MenuItem itemBrowseURL = new MenuItem(menuBrowse, SWT.PUSH);
                Messages.setLanguageText(itemBrowseURL, "label.copy.url.to.clip");
                itemBrowseURL.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        Utils.getOffOfSWTThread(new AERunnable() {

                            @Override
                            public void runSupport() {
                                String url = ManagerUtils.browse(dms[0], true, false);
                                if (url != null) {
                                    ClipboardCopy.copyToClipBoard(url);
                                }
                            }
                        });
                    }
                });
                itemBrowseURL.setEnabled(dms.length == 1);
                new MenuItem(menuBrowse, SWT.SEPARATOR);
                final MenuItem itemBrowseDir = new MenuItem(menuBrowse, SWT.CHECK);
                Messages.setLanguageText(itemBrowseDir, "library.launch.web.in.browser.dir.list");
                itemBrowseDir.setSelection(COConfigurationManager.getBooleanParameter("Library.LaunchWebsiteInBrowserDirList"));
                itemBrowseDir.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        COConfigurationManager.setParameter("Library.LaunchWebsiteInBrowserDirList", itemBrowseDir.getSelection());
                    }
                });
            }
        });
    }
    // set thumbnail
    createRow(detailArea, "MyTorrentsView.menu.torrent.set.thumb", null, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            FileDialog fDialog = new FileDialog(parentShell, SWT.OPEN | SWT.MULTI);
            fDialog.setText(MessageText.getString("MainWindow.dialog.choose.thumb"));
            String path = fDialog.open();
            if (path == null)
                return;
            File file = new File(path);
            try {
                byte[] thumbnail = FileUtil.readFileAsByteArray(file);
                String name = file.getName();
                int pos = name.lastIndexOf(".");
                String ext;
                if (pos != -1) {
                    ext = name.substring(pos + 1);
                } else {
                    ext = "";
                }
                String type = HTTPUtils.guessContentTypeFromFileType(ext);
                for (DownloadManager dm : dms) {
                    try {
                        TOTorrent torrent = dm.getTorrent();
                        PlatformTorrentUtils.setContentThumbnail(torrent, thumbnail, type);
                    } catch (Throwable e) {
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    });
    boolean fileMove = true;
    boolean locateFiles = false;
    boolean exportFiles = true;
    boolean canSetMOC = dms.length > 0;
    boolean canClearMOC = false;
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = dms[i];
        if (!dm.canMoveDataFiles()) {
            fileMove = false;
        }
        if (!dm.canExportDownload()) {
            exportFiles = false;
        }
        if (!dm.isDownloadComplete(false)) {
            locateFiles = true;
        }
        boolean incomplete = !dm.isDownloadComplete(true);
        DownloadManagerState dm_state = dm.getDownloadState();
        String moc_dir = dm_state.getAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR);
        canSetMOC &= incomplete;
        canClearMOC |= (moc_dir != null && moc_dir.length() > 0);
    }
    if (fileMove) {
        createRow(detailArea, "MyTorrentsView.menu.movedata", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.moveDataFiles(parentShell, dms);
            }
        });
    }
    if (canSetMOC || canClearMOC) {
        boolean f_canSetMOC = canSetMOC;
        boolean f_canClearMOC = canClearMOC;
        createMenuRow(detailArea, "label.move.on.comp", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu moc_menu) {
                MenuItem clear_item = new MenuItem(moc_menu, SWT.PUSH);
                Messages.setLanguageText(clear_item, "Button.clear");
                clear_item.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager[] dms) {
                        TorrentUtil.clearMOC(dms);
                    }
                });
                clear_item.setEnabled(f_canClearMOC);
                MenuItem set_item = new MenuItem(moc_menu, SWT.PUSH);
                Messages.setLanguageText(set_item, "label.set");
                set_item.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager[] dms) {
                        TorrentUtil.setMOC(parentShell, dms);
                    }
                });
                set_item.setEnabled(f_canSetMOC);
            }
        });
    }
    if (exportFiles) {
        createRow(detailArea, "MyTorrentsView.menu.exportdownload", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.exportDownloads(parentShell, dms);
            }
        });
    }
    createRow(detailArea, "MyTorrentsView.menu.checkfilesexist", null, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            dm.filesExist(true);
        }
    });
    if (locateFiles) {
        createRow(detailArea, "MyTorrentsView.menu.locatefiles", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                ManagerUtils.locateFiles(dms, parentShell);
            }
        });
    }
    if (dms.length == 1 && ManagerUtils.canFindMoreLikeThis()) {
        createRow(detailArea, "MyTorrentsView.menu.findmorelikethis", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                ManagerUtils.findMoreLikeThis(dms[0], parentShell);
            }
        });
    }
    createRow(detailArea, "MyTorrentsView.menu.thisColumn.toClipboard", null, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String sToClipboard = "";
            if (column == null) {
                return;
            }
            String columnName = column.getName();
            if (columnName == null) {
                return;
            }
            TableRowCore[] rows = tv.getSelectedRows();
            for (TableRowCore row : rows) {
                if (row != rows[0]) {
                    sToClipboard += "\n";
                }
                TableCellCore cell = row.getTableCellCore(columnName);
                if (cell != null) {
                    sToClipboard += cell.getClipboardText();
                }
            }
            if (sToClipboard.length() == 0) {
                return;
            }
            new Clipboard(Display.getDefault()).setContents(new Object[] { sToClipboard }, new Transfer[] { TextTransfer.getInstance() });
        }
    });
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) Point(org.eclipse.swt.graphics.Point) TableRowCore(com.biglybt.ui.common.table.TableRowCore) TOTorrent(com.biglybt.core.torrent.TOTorrent) TableCellCore(com.biglybt.ui.common.table.TableCellCore) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) File(java.io.File)

Example 12 with TableCellCore

use of com.biglybt.ui.common.table.TableCellCore 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 13 with TableCellCore

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

the class TorrentInfoView method delete.

private void delete() {
    if (headerFont != null) {
        headerFont.dispose();
    }
    if (cells != null) {
        for (int i = 0; i < cells.length; i++) {
            TableCellCore cell = cells[i];
            cell.dispose();
        }
    }
}
Also used : TableCellCore(com.biglybt.ui.common.table.TableCellCore)

Example 14 with TableCellCore

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

the class ColumnStream method noIconForYou.

private boolean noIconForYou(Object ds, TableCell cell) {
    if (ds instanceof FilesView.FilesViewTreeNode) {
        if (!((FilesView.FilesViewTreeNode) ds).isLeaf()) {
            return (true);
        }
    }
    if (!(ds instanceof DownloadManager)) {
        return false;
    }
    if (!(cell instanceof TableCellCore)) {
        return false;
    }
    DownloadManager dm = (DownloadManager) ds;
    TableRowCore rowCore = ((TableCellCore) cell).getTableRowCore();
    return rowCore != null && (dm.getNumFileInfos() > 1 && rowCore.isExpanded());
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) FilesView(com.biglybt.ui.swt.views.FilesView) TableCellCore(com.biglybt.ui.common.table.TableCellCore) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 15 with TableCellCore

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

the class ColumnThumbAndName method cellMouseTrigger.

@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
    if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE || event.eventType == TableRowMouseEvent.EVENT_MOUSEDOWN) {
        TableRow row = event.cell.getTableRow();
        if (row == null) {
            return;
        }
        Object data = row.getData(ID_EXPANDOHITAREA);
        if (data instanceof Rectangle) {
            Rectangle hitArea = (Rectangle) data;
            boolean inExpando = hitArea.contains(event.x, event.y);
            if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE) {
                ((TableCellCore) event.cell).setCursorID(inExpando ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW);
            } else if (inExpando) {
                // mousedown
                if (row instanceof TableRowCore) {
                    TableRowCore rowCore = (TableRowCore) row;
                    rowCore.setExpanded(!rowCore.isExpanded());
                }
            }
        }
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) Rectangle(org.eclipse.swt.graphics.Rectangle) TableCellCore(com.biglybt.ui.common.table.TableCellCore)

Aggregations

TableCellCore (com.biglybt.ui.common.table.TableCellCore)18 TableRowCore (com.biglybt.ui.common.table.TableRowCore)6 Rectangle (org.eclipse.swt.graphics.Rectangle)4 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)3 Point (org.eclipse.swt.graphics.Point)3 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)2 DownloadManager (com.biglybt.core.download.DownloadManager)2 TableColumn (com.biglybt.pif.ui.tables.TableColumn)2 FilesView (com.biglybt.ui.swt.views.FilesView)2 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 TableCell (com.biglybt.pif.ui.tables.TableCell)1 TableSelectedRowsListener (com.biglybt.ui.swt.views.table.TableSelectedRowsListener)1 TableCellSWTBase (com.biglybt.ui.swt.views.table.impl.TableCellSWTBase)1 File (java.io.File)1 CLabel (org.eclipse.swt.custom.CLabel)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1 Transfer (org.eclipse.swt.dnd.Transfer)1