Search in sources :

Example 91 with DiskManagerFileInfo

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

the class NameItem method inplaceValueSet.

@Override
public boolean inplaceValueSet(TableCell cell, String value, boolean finalEdit) {
    if (value.equalsIgnoreCase(cell.getText()) || "".equals(value) || "".equals(cell.getText()))
        return true;
    final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource();
    final File target;
    try {
        target = new File(fileInfo.getFile(true).getParentFile(), value).getCanonicalFile();
    } catch (IOException e) {
        return false;
    }
    if (!finalEdit)
        return !target.exists();
    if (target.exists())
        return false;
    // code stolen from FilesView
    final boolean[] result = { false };
    boolean paused = fileInfo.getDownloadManager().pause();
    FileUtil.runAsTask(new CoreOperationTask() {

        @Override
        public void run(CoreOperation operation) {
            result[0] = fileInfo.setLink(target);
        }

        @Override
        public ProgressCallback getProgressCallback() {
            return null;
        }
    });
    if (paused)
        fileInfo.getDownloadManager().resume();
    if (!result[0]) {
        new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("FilesView.rename.failed.title"), MessageText.getString("FilesView.rename.failed.text")).open(null);
    }
    return true;
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) CoreOperation(com.biglybt.core.CoreOperation) CoreOperationTask(com.biglybt.core.CoreOperationTask) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) IOException(java.io.IOException) File(java.io.File)

Example 92 with DiskManagerFileInfo

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

the class NameItem 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;
        }
        boolean inArea = false;
        Object data = row.getData(ID_EXPANDOHITAREA);
        if (data instanceof Rectangle) {
            Rectangle hitArea = (Rectangle) data;
            boolean inExpando = hitArea.contains(event.x, event.y);
            if (inExpando) {
                inArea = true;
                if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
                    if (row instanceof TableRowCore) {
                        TableRowCore rowCore = (TableRowCore) row;
                        rowCore.setExpanded(!rowCore.isExpanded());
                    }
                }
            }
        }
        data = row.getData(ID_CHECKHITAREA);
        if (data instanceof Rectangle) {
            Rectangle hitArea = (Rectangle) data;
            boolean inCheck = hitArea.contains(event.x, event.y);
            if (inCheck) {
                inArea = true;
                if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
                    if (row instanceof TableRowCore) {
                        TableRowCore rowCore = (TableRowCore) row;
                        if (rowCore != null) {
                            final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) event.cell.getDataSource();
                            if (fileInfo instanceof FilesView.FilesViewTreeNode) {
                                FilesView.FilesViewTreeNode node = (FilesView.FilesViewTreeNode) fileInfo;
                                if (!node.isLeaf()) {
                                    int old_skipped = node.getSkippedState();
                                    boolean new_skipped;
                                    if (old_skipped == 0) {
                                        new_skipped = false;
                                    } else if (old_skipped == 1) {
                                        new_skipped = true;
                                    } else {
                                        new_skipped = true;
                                    }
                                    node.setSkipped(new_skipped);
                                    return;
                                }
                            }
                            fileInfo.setSkipped(!fileInfo.isSkipped());
                        }
                    }
                }
            }
        }
        if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE) {
            ((TableCellCore) event.cell).setCursorID(inArea ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW);
        }
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) FilesView(com.biglybt.ui.swt.views.FilesView) Rectangle(org.eclipse.swt.graphics.Rectangle) TableCellCore(com.biglybt.ui.common.table.TableCellCore) Point(org.eclipse.swt.graphics.Point)

Example 93 with DiskManagerFileInfo

use of com.biglybt.core.disk.DiskManagerFileInfo 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 94 with DiskManagerFileInfo

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

the class ColumnDoneWithDND method refresh.

@Override
public void refresh(TableCell cell) {
    int value;
    Object ds = cell.getDataSource();
    if (ds instanceof DownloadManager) {
        // show amount completed of non-dnd files as makes more sense
        DownloadManager dm = (DownloadManager) ds;
        DownloadManagerStats stats = dm.getStats();
        value = stats.getDownloadCompleted(true);
    } else if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
        long length = fileInfo.getLength();
        if (length == 0) {
            value = 1000;
        } else {
            value = (int) (fileInfo.getDownloaded() * 1000 / length);
        }
    } else {
        return;
    }
    if (!cell.setSortValue(value) && cell.isValid())
        return;
    cell.setText(DisplayFormatters.formatPercentFromThousands(value));
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 95 with DiskManagerFileInfo

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

the class DoneItem method refresh.

@Override
public void refresh(TableCell cell) {
    int value;
    Object ds = cell.getDataSource();
    if (ds instanceof DownloadManager) {
        // show amount completed of non-dnd files as makes more sense
        DownloadManager dm = (DownloadManager) ds;
        DownloadManagerStats stats = dm.getStats();
        value = stats.getPercentDoneExcludingDND();
    } else if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
        long length = fileInfo.getLength();
        if (length == 0) {
            value = 1000;
        } else {
            value = (int) (fileInfo.getDownloaded() * 1000 / length);
        }
    } else {
        return;
    }
    if (!cell.setSortValue(value) && cell.isValid())
        return;
    cell.setText(DisplayFormatters.formatPercentFromThousands(value));
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) 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