Search in sources :

Example 81 with DiskManagerFileInfo

use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class ColumnThumbAndName method cellPaintName.

private void cellPaintName(TableCell cell, GC gc, Rectangle cellBounds, int textX, int originalBoundxsX) {
    String name = null;
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        return;
    }
    DownloadManager dm = (DownloadManager) ds;
    if (dm != null)
        name = dm.getDisplayName();
    if (name == null)
        name = "";
    GCStringPrinter sp = new GCStringPrinter(gc, name, new Rectangle(textX, cellBounds.y, cellBounds.x + cellBounds.width - textX, cellBounds.height), true, true, getTableID().endsWith(".big") ? SWT.WRAP : SWT.NULL);
    boolean fit = sp.printString();
    Point p = sp.getCalculatedPreferredSize();
    int pref = (textX - originalBoundxsX) + p.x + 10;
    TableColumn tableColumn = cell.getTableColumn();
    if (tableColumn != null && tableColumn.getPreferredWidth() < pref) {
        tableColumn.setPreferredWidth(pref);
    }
    String tooltip = fit ? "" : name;
    if (dm != null) {
        try {
            String desc = PlatformTorrentUtils.getContentDescription(dm.getTorrent());
            if (desc != null && desc.length() > 0) {
                tooltip += (tooltip.length() == 0 ? "" : "\r\n") + desc;
            }
        } catch (Throwable e) {
        }
    }
    cell.setToolTip(tooltip.length() == 0 ? null : tooltip);
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) GCStringPrinter(com.biglybt.ui.swt.shells.GCStringPrinter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) DownloadManager(com.biglybt.core.download.DownloadManager) Point(org.eclipse.swt.graphics.Point)

Example 82 with DiskManagerFileInfo

use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class ColumnThumbAndName method cellPaint.

@Override
public void cellPaint(GC gc, final TableCellSWT cell) {
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        cellPaintFileInfo(gc, cell, (DiskManagerFileInfo) ds);
        return;
    }
    Rectangle cellBounds = cell.getBounds();
    int originalBoundxsX = cellBounds.x;
    int textX = originalBoundxsX;
    TableRowCore rowCore = cell.getTableRowCore();
    if (rowCore != null) {
        int numSubItems = rowCore.getSubItemCount();
        int paddingX = 3;
        int width = 7;
        boolean show_twisty;
        if (NEVER_SHOW_TWISTY) {
            show_twisty = false;
        } else if (numSubItems > 1) {
            show_twisty = true;
        } else {
            Boolean show = (Boolean) rowCore.getData(ID_EXPANDOHITAREASHOW);
            if (show == null) {
                DownloadManager dm = (DownloadManager) ds;
                TOTorrent torrent = dm.getTorrent();
                show_twisty = torrent != null && !dm.getTorrent().isSimpleTorrent();
                rowCore.setData(ID_EXPANDOHITAREASHOW, Boolean.valueOf(show_twisty));
            } else {
                show_twisty = show;
            }
        }
        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, middleY - halfHeight - cellBounds.y, width, (halfHeight * 4) + 1);
            rowCore.setData(ID_EXPANDOHITAREA, hitArea);
        }
        if (!NEVER_SHOW_TWISTY) {
            cellBounds.x += paddingX * 2 + width;
            cellBounds.width -= paddingX * 2 + width;
        }
    }
    if (!showIcon) {
        cellBounds.x += 2;
        cellBounds.width -= 4;
        cellPaintName(cell, gc, cellBounds, cellBounds.x, originalBoundxsX);
        return;
    }
    Image[] imgThumbnail = TorrentUIUtilsV3.getContentImage(ds, cellBounds.height >= 20, new ContentImageLoadedListener() {

        @Override
        public void contentImageLoaded(Image image, boolean wasReturned) {
            if (!wasReturned) {
                // this may be triggered many times, so only invalidate and don't
                // force a refresh()
                cell.invalidate();
            }
        }
    });
    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);
                }
            }
            TorrentUIUtilsV3.releaseContentImage(ds);
        } 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) ContentImageLoadedListener(com.biglybt.ui.swt.utils.TorrentUIUtilsV3.ContentImageLoadedListener) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) Point(org.eclipse.swt.graphics.Point) TableRowCore(com.biglybt.ui.common.table.TableRowCore) TOTorrent(com.biglybt.core.torrent.TOTorrent)

Example 83 with DiskManagerFileInfo

use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class ColumnThumbAndName method getClipboardText.

@Override
public String getClipboardText(TableCell cell) {
    String name = null;
    Object ds = cell.getDataSource();
    if (ds instanceof DiskManagerFileInfo) {
        return null;
    }
    DownloadManager dm = (DownloadManager) ds;
    if (dm != null)
        name = dm.getDisplayName();
    if (name == null)
        name = "";
    return name;
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 84 with DiskManagerFileInfo

use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class ColumnTorrentFileProgress method fileInfoMouseTrigger.

public void fileInfoMouseTrigger(TableCellMouseEvent event) {
    if (event.eventType != TableRowMouseEvent.EVENT_MOUSEDOWN) {
        return;
    }
    final Object dataSource = ((TableRowCore) event.row).getDataSource(true);
    if (dataSource instanceof DiskManagerFileInfo) {
        final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) dataSource;
        Rectangle hilowBounds = (Rectangle) event.row.getData("hilowBounds");
        if (event.button == 1 && hilowBounds != null && hilowBounds.contains(event.x, event.y)) {
            if (fileInfo.getPriority() > 0) {
                fileInfo.setPriority(0);
            } else {
                fileInfo.setPriority(1);
            }
            ((TableRowCore) event.row).redraw();
        }
        Rectangle buttonBounds = (Rectangle) event.row.getData("buttonBounds");
        if (buttonBounds != null && buttonBounds.contains(event.x, event.y)) {
            Menu menu = new Menu(Display.getDefault().getActiveShell(), SWT.POP_UP);
            MenuItem itemHigh = new MenuItem(menu, SWT.RADIO);
            Messages.setLanguageText(itemHigh, "priority.high");
            itemHigh.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_HIGH, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemHigh.setSelection(fileInfo.getPriority() != 0);
            MenuItem itemNormal = new MenuItem(menu, SWT.RADIO);
            Messages.setLanguageText(itemNormal, "priority.normal");
            itemNormal.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_NORMAL, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemNormal.setSelection(fileInfo.getPriority() == 0);
            new MenuItem(menu, SWT.SEPARATOR);
            boolean canStart = fileInfo.isSkipped() || fileInfo.getDownloadManager().getState() == DownloadManager.STATE_STOPPED;
            MenuItem itemStop = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemStop, "v3.MainWindow.button.stop");
            itemStop.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_SKIPPED, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemStop.setEnabled(!canStart);
            MenuItem itemStart = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemStart, "v3.MainWindow.button.start");
            itemStart.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    if (fileInfo.getDownloadManager().getState() == DownloadManager.STATE_STOPPED) {
                        TorrentUtil.queueDataSources(new Object[] { dataSource }, true);
                    }
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_NORMAL, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemStart.setEnabled(canStart);
            new MenuItem(menu, SWT.SEPARATOR);
            MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemDelete, "v3.MainWindow.button.delete");
            itemDelete.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_DELETE, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            menu.setVisible(true);
            event.skipCoreFunctionality = true;
        }
    /*
			if (buttonBounds != null && buttonBounds.contains(event.x, event.y)) {
				int st = fileInfo.getStorageType();
				if ((st == DiskManagerFileInfo.ST_COMPACT || st == DiskManagerFileInfo.ST_REORDER_COMPACT)
						&& fileInfo.isSkipped()) {
					// deleted: Move to normal
					fileInfo.setPriority(0);
					fileInfo.setSkipped(false);
				} else if (fileInfo.isSkipped()) {
					// skipped: move to normal
					fileInfo.setPriority(0);
					fileInfo.setSkipped(false);
				} else if (fileInfo.getPriority() > 0) {

					// high: move to skipped
					fileInfo.setSkipped(true);
				} else {
					// normal: move to high
					fileInfo.setPriority(1);
				}
				//((TableRowCore) event.row).invalidate();
				((TableRowCore) event.row).redraw();
			}
			*/
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TableCellMouseEvent(com.biglybt.pif.ui.tables.TableCellMouseEvent) TableRowMouseEvent(com.biglybt.pif.ui.tables.TableRowMouseEvent)

Example 85 with DiskManagerFileInfo

use of com.biglybt.core.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class ColumnUnopened method refresh.

// @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
@Override
public void refresh(TableCell cell) {
    Object ds = cell.getDataSource();
    if (ds == null) {
        return;
    }
    if (ds instanceof DownloadManager) {
        DownloadManager dm = (DownloadManager) ds;
        int sortVal;
        boolean complete = dm.getAssumedComplete();
        boolean hasBeenOpened = false;
        if (complete) {
            hasBeenOpened = PlatformTorrentUtils.getHasBeenOpened(dm);
            sortVal = hasBeenOpened ? 1 : 0;
        } else {
            sortVal = isSortAscending() ? 2 : -1;
        }
        if (!cell.setSortValue(sortVal) && cell.isValid()) {
            if (complete) {
                return;
            }
        }
        if (!cell.isShown()) {
            return;
        }
        if (complete) {
            cell.setGraphic(hasBeenOpened ? graphicUnCheck : graphicCheck);
        } else {
            if (dm.getState() == DownloadManager.STATE_DOWNLOADING) {
                int i = TableCellRefresher.getRefreshIndex(1, graphicsProgress.length);
                cell.setGraphic(graphicsProgress[i]);
                TableCellRefresher.addCell(this, cell);
            } else {
                cell.setGraphic(null);
            }
        }
    } else {
        DiskManagerFileInfo file = (DiskManagerFileInfo) ds;
        int sortVal;
        long len = file.getLength();
        boolean complete = len > 0 && len == file.getDownloaded();
        boolean hasBeenOpened = false;
        if (complete) {
            DownloadManager dm = file.getDownloadManager();
            if (dm == null) {
                hasBeenOpened = false;
                sortVal = 0;
            } else {
                int ff = dm.getDownloadState().getFileFlags(file.getIndex());
                hasBeenOpened = (ff & DownloadManagerState.FILE_FLAG_NOT_NEW) != 0;
                sortVal = hasBeenOpened ? 1 : 0;
            }
        } else {
            sortVal = isSortAscending() ? 2 : -1;
        }
        if (!cell.setSortValue(sortVal) && cell.isValid()) {
            if (complete) {
                return;
            }
        }
        if (!cell.isShown()) {
            return;
        }
        if (complete) {
            cell.setGraphic(hasBeenOpened ? graphicUnCheck : graphicCheck);
        } else {
            cell.setGraphic(null);
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)107 DownloadManager (com.biglybt.core.download.DownloadManager)54 File (java.io.File)16 TOTorrent (com.biglybt.core.torrent.TOTorrent)15 PEPeerManager (com.biglybt.core.peer.PEPeerManager)9 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)8 TableRowCore (com.biglybt.ui.common.table.TableRowCore)8 DiskManager (com.biglybt.core.disk.DiskManager)7 IOException (java.io.IOException)7 Point (org.eclipse.swt.graphics.Point)7 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)6 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)6 FilesView (com.biglybt.ui.swt.views.FilesView)6 List (java.util.List)6 Image (org.eclipse.swt.graphics.Image)6 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)5 PEPeer (com.biglybt.core.peer.PEPeer)5 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)5 UIFunctions (com.biglybt.ui.UIFunctions)5 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)5