Search in sources :

Example 21 with TableRowCore

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

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

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

the class TableRowPainted method heightChanged.

/* (non-Javadoc)
	 * @see com.biglybt.ui.swt.views.table.impl.TableRowSWTBase#heightChanged(int, int)
	 */
public void heightChanged(int oldHeight, int newHeight) {
    getViewPainted().rowHeightChanged(this, oldHeight, newHeight);
    TableRowCore row = getParentRowCore();
    if (row instanceof TableRowPainted) {
        ((TableRowPainted) row).subRowHeightChanged(oldHeight, newHeight);
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore)

Example 24 with TableRowCore

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

the class TableRowPainted method refilter.

public boolean refilter() {
    boolean changed = false;
    synchronized (subRows_sync) {
        if (subRows != null) {
            for (TableRowPainted subrow : subRows) {
                if (subrow.refilter()) {
                    changed = true;
                }
            }
        }
        Object ds = getDataSource(true);
        boolean newHidden = !getViewPainted().isFiltered(ds);
        if (newHidden != isHidden) {
            TableRowCore row = this;
            boolean expanded = true;
            while (expanded) {
                row = row.getParentRowCore();
                if (row == null) {
                    break;
                }
                expanded = row.isExpanded();
            }
            int old_height = getHeight();
            isHidden = newHidden;
            int new_height = getHeight();
            if (expanded) {
                heightChanged(old_height, new_height);
                changed = true;
            } else {
                row = getParentRowCore();
                if (row instanceof TableRowPainted) {
                    ((TableRowPainted) row).subRowHeightChanged(old_height, new_height);
                }
            }
        }
    }
    return (changed);
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore)

Example 25 with TableRowCore

use of com.biglybt.ui.common.table.TableRowCore 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)

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