Search in sources :

Example 1 with UISWTGraphic

use of com.biglybt.ui.swt.pif.UISWTGraphic in project BiglyBT by BiglySoftware.

the class CompletionItem method dispose.

// @see com.biglybt.pif.ui.tables.TableCellDisposeListener#dispose(com.biglybt.pif.ui.tables.TableCell)
@Override
public void dispose(TableCell cell) {
    mapCellLastPercentDone.remove(cell);
    Graphic graphic = cell.getGraphic();
    if (graphic instanceof UISWTGraphic) {
        Image img = ((UISWTGraphic) graphic).getImage();
        if (img != null && !img.isDisposed()) {
            img.dispose();
        }
    }
}
Also used : Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic)

Example 2 with UISWTGraphic

use of com.biglybt.ui.swt.pif.UISWTGraphic in project BiglyBT by BiglySoftware.

the class ProgressGraphItem method dispose.

@Override
public void dispose(TableCell cell) {
    // only dispose of image here, this method is reused in other methods
    Graphic graphic = cell.getGraphic();
    if (graphic instanceof UISWTGraphic) {
        final Image img = ((UISWTGraphic) graphic).getImage();
        if (img != null && !img.isDisposed()) {
            img.dispose();
            // see http://forum.vuze.com/thread.jspa?threadID=117243
            // could it be that it isn't being marked as disposed after disposal and
            // being double-disposed?
            ((UISWTGraphic) graphic).setImage(null);
        }
    }
}
Also used : Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) Image(org.eclipse.swt.graphics.Image)

Example 3 with UISWTGraphic

use of com.biglybt.ui.swt.pif.UISWTGraphic in project BiglyBT by BiglySoftware.

the class AlertsItem method refresh.

@Override
public void refresh(TableCell cell) {
    UISWTGraphic icon = null;
    int sort = 0;
    Object ds = cell.getDataSource();
    if (ds instanceof DownloadManager) {
        DownloadManager dm = (DownloadManager) ds;
        Map<String, String> map = dm.getDownloadState().getMapAttribute(DownloadManagerState.AT_DL_FILE_ALERTS);
        if (map != null && map.size() > 0) {
            for (String k : map.keySet()) {
                if (k.length() > 0) {
                    if (Character.isDigit(k.charAt(0))) {
                        icon = gray_tick_icon;
                        sort = 1;
                    } else {
                        icon = black_tick_icon;
                        sort = 2;
                        break;
                    }
                }
            }
        }
    } else if (ds instanceof DiskManagerFileInfo) {
        DiskManagerFileInfo fi = (DiskManagerFileInfo) ds;
        DownloadManager dm = fi.getDownloadManager();
        if (dm != null) {
            Map<String, String> map = dm.getDownloadState().getMapAttribute(DownloadManagerState.AT_DL_FILE_ALERTS);
            if (map != null && map.size() > 0) {
                String prefix = fi.getIndex() + ".";
                for (String k : map.keySet()) {
                    if (k.startsWith(prefix)) {
                        icon = black_tick_icon;
                        sort = 2;
                        break;
                    }
                }
            }
        }
    }
    cell.setSortValue(sort);
    if (cell.getGraphic() != icon) {
        cell.setGraphic(icon);
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) DownloadManager(com.biglybt.core.download.DownloadManager) Map(java.util.Map)

Example 4 with UISWTGraphic

use of com.biglybt.ui.swt.pif.UISWTGraphic in project BiglyBT by BiglySoftware.

the class PiecesItem method refresh.

@Override
public void refresh(TableCell cell) {
    /* Notes:
		 * We store our image and imageBufer in DownloadManager using
		 * setData & getData.
		 */
    // Named infoObj so code can be copied easily to the other PiecesItem
    DownloadManager infoObj = (DownloadManager) cell.getDataSource();
    long lCompleted = (infoObj == null) ? 0 : infoObj.getStats().getCompleted();
    boolean bForce = infoObj != null && infoObj.getUserData("PiecesImage") == null;
    if (!cell.setSortValue(lCompleted) && cell.isValid() && !bForce) {
        return;
    }
    if (infoObj == null)
        return;
    // Compute bounds ...
    int newWidth = cell.getWidth();
    if (newWidth <= 0)
        return;
    int newHeight = cell.getHeight();
    int x0 = borderVerticalSize;
    int x1 = newWidth - 1 - borderVerticalSize;
    int y0 = completionHeight + borderHorizontalSize + borderSplit;
    int y1 = newHeight - 1 - borderHorizontalSize;
    int drawWidth = x1 - x0 + 1;
    if (drawWidth < 10 || y1 < 3)
        return;
    boolean bImageBufferValid = true;
    int[] imageBuffer = (int[]) infoObj.getUserData("PiecesImageBuffer");
    if (imageBuffer == null || imageBuffer.length != drawWidth) {
        imageBuffer = new int[drawWidth];
        bImageBufferValid = false;
    }
    Image image = (Image) infoObj.getUserData("PiecesImage");
    GC gcImage;
    boolean bImageChanged;
    Rectangle imageBounds;
    if (image == null || image.isDisposed()) {
        bImageChanged = true;
    } else {
        imageBounds = image.getBounds();
        bImageChanged = imageBounds.width != newWidth || imageBounds.height != newHeight;
    }
    if (bImageChanged) {
        if (image != null && !image.isDisposed()) {
            image.dispose();
        }
        image = new Image(Utils.getDisplay(), newWidth, newHeight);
        imageBounds = image.getBounds();
        bImageBufferValid = false;
        // draw border
        gcImage = new GC(image);
        gcImage.setForeground(Colors.grey);
        if (borderHorizontalSize > 0) {
            if (borderVerticalSize > 0) {
                gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1);
            } else {
                gcImage.drawLine(0, 0, newWidth - 1, 0);
                gcImage.drawLine(0, newHeight - 1, newWidth - 1, newHeight - 1);
            }
        } else if (borderVerticalSize > 0) {
            gcImage.drawLine(0, 0, 0, newHeight - 1);
            gcImage.drawLine(newWidth - 1, 0, newWidth - 1, newHeight - 1);
        }
        if (borderSplit > 0) {
            gcImage.setForeground(Colors.white);
            gcImage.drawLine(x0, completionHeight + borderHorizontalSize, x1, completionHeight + borderHorizontalSize);
        }
    } else {
        gcImage = new GC(image);
    }
    DiskManager disk_manager = infoObj.getDiskManager();
    DiskManagerPiece[] pieces = disk_manager == null ? null : disk_manager.getPieces();
    int nbPieces = infoObj.getNbPieces();
    try {
        int nbComplete = 0;
        int a0;
        int a1 = 0;
        for (int i = 0; i < drawWidth; i++) {
            if (i == 0) {
                // always start out with one piece
                a0 = 0;
                a1 = nbPieces / drawWidth;
                if (a1 == 0)
                    a1 = 1;
            } else {
                // the last iteration, a1 will be nbPieces
                a0 = a1;
                a1 = ((i + 1) * nbPieces) / (drawWidth);
            }
            int index;
            if (a1 <= a0) {
                index = imageBuffer[i - 1];
            } else {
                int nbAvailable = 0;
                for (int j = a0; j < a1; j++) if (pieces != null && pieces[j].isDone())
                    nbAvailable++;
                nbComplete += nbAvailable;
                index = (nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0);
            // System.out.println("i="+i+";nbAvailable="+nbAvailable+";nbComplete="+nbComplete+";nbPieces="+nbPieces+";a0="+a0+";a1="+a1);
            }
            if (!bImageBufferValid || imageBuffer[i] != index) {
                imageBuffer[i] = index;
                bImageChanged = true;
                gcImage.setForeground(index == INDEX_COLOR_NONEAVAIL ? Colors.red : Colors.blues[index]);
                gcImage.drawLine(i + x0, y0, i + x0, y1);
            }
        }
        // pieces can sometimes be 0 due to timing or bad torrent (well, there's a bug with a /0 error
        // so it can happen somehow :)
        int limit = nbPieces == 0 ? 0 : ((drawWidth * nbComplete) / nbPieces);
        if (limit < drawWidth) {
            gcImage.setBackground(Colors.blues[Colors.BLUES_LIGHTEST]);
            gcImage.fillRectangle(limit + x0, borderHorizontalSize, x1 - limit, completionHeight);
        }
        gcImage.setBackground(Colors.colorProgressBar);
        gcImage.fillRectangle(x0, borderHorizontalSize, limit, completionHeight);
    } catch (Exception e) {
        System.out.println("Error Drawing PiecesItem");
        Debug.printStackTrace(e);
    }
    gcImage.dispose();
    Image oldImage = null;
    Graphic graphic = cell.getGraphic();
    if (graphic instanceof UISWTGraphic) {
        oldImage = ((UISWTGraphic) graphic).getImage();
    }
    if (bImageChanged || image != oldImage || !cell.isValid()) {
        if (cell instanceof TableCellSWT) {
            ((TableCellSWT) cell).setGraphic(image);
        } else {
            cell.setGraphic(new UISWTGraphicImpl(image));
        }
        if (bImageChanged) {
            cell.invalidate();
        }
        infoObj.setUserData("PiecesImage", image);
        infoObj.setUserData("PiecesImageBuffer", imageBuffer);
    }
}
Also used : TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) DiskManager(com.biglybt.core.disk.DiskManager) DownloadManager(com.biglybt.core.download.DownloadManager) UISWTGraphicImpl(com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) DiskManagerPiece(com.biglybt.core.disk.DiskManagerPiece) GC(org.eclipse.swt.graphics.GC)

Example 5 with UISWTGraphic

use of com.biglybt.ui.swt.pif.UISWTGraphic in project BiglyBT by BiglySoftware.

the class IPFilterItem method refresh.

@Override
public void refresh(TableCell cell) {
    // String state = "";
    UISWTGraphic icon = null;
    int sort = 0;
    if (ipfilter == null) {
        ipfilter = IpFilterManagerFactory.getSingleton().getIPFilter();
    }
    if (ipfilter.isEnabled()) {
        if (tick_icon == null) {
            tick_icon = new UISWTGraphicImpl(ImageLoader.getInstance().getImage("tick_mark"));
            cross_icon = new UISWTGraphicImpl(ImageLoader.getInstance().getImage("cross_mark"));
        }
        DownloadManager dm = (DownloadManager) cell.getDataSource();
        if (dm != null) {
            boolean excluded = dm.getDownloadState().getFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER);
            if (excluded) {
                icon = cross_icon;
                sort = 1;
            // state = "\u2718";
            } else {
                icon = tick_icon;
                sort = 2;
            // state = "\u2714";
            }
        }
    }
    cell.setSortValue(sort);
    if (cell.getGraphic() != icon) {
        cell.setGraphic(icon);
    }
}
Also used : UISWTGraphicImpl(com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

UISWTGraphic (com.biglybt.ui.swt.pif.UISWTGraphic)11 Graphic (com.biglybt.pif.ui.Graphic)8 Image (org.eclipse.swt.graphics.Image)5 UISWTGraphicImpl (com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl)4 DownloadManager (com.biglybt.core.download.DownloadManager)3 AERunnable (com.biglybt.core.util.AERunnable)3 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)3 GC (org.eclipse.swt.graphics.GC)3 PEPeer (com.biglybt.core.peer.PEPeer)2 GraphicURI (com.biglybt.pif.ui.GraphicURI)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemImpl (com.biglybt.pifimpl.local.ui.menus.MenuItemImpl)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 DiskManager (com.biglybt.core.disk.DiskManager)1 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)1 PEPiece (com.biglybt.core.peer.PEPiece)1 PEPeerTransport (com.biglybt.core.peer.impl.PEPeerTransport)1 PiecePicker (com.biglybt.core.peermanager.piecepicker.PiecePicker)1 BitFlags (com.biglybt.core.peermanager.piecepicker.util.BitFlags)1