Search in sources :

Example 6 with Graphic

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

the class Utils method setMenuItemImage.

public static void setMenuItemImage(final com.biglybt.pif.ui.menus.MenuItem item, final String repoKey) {
    if (Constants.isOSX || repoKey == null) {
        return;
    }
    if (Utils.isSWTThread()) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        Graphic graphic = new UISWTGraphicImpl(imageLoader.getImage(repoKey));
        item.setGraphic(graphic);
    } else {
        execSWTThread(new Runnable() {

            @Override
            public void run() {
                ImageLoader imageLoader = ImageLoader.getInstance();
                Graphic graphic = new UISWTGraphicImpl(imageLoader.getImage(repoKey));
                item.setGraphic(graphic);
            }
        });
    }
}
Also used : UISWTGraphicImpl(com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl) Graphic(com.biglybt.pif.ui.Graphic) SWTRunnable(com.biglybt.ui.swt.utils.SWTRunnable) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 7 with Graphic

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

the class TorrentMenuFancy method addPluginItem.

private void addPluginItem(Composite detailArea, final com.biglybt.pif.ui.menus.MenuItem item) {
    // menuWillBeShown listeners might change the visibility, so run before check
    MenuItemImpl menuImpl = ((MenuItemImpl) item);
    menuImpl.invokeMenuWillBeShownListeners(getTarget(item));
    if (!item.isVisible()) {
        if (DEBUG_MENU) {
            System.out.println("Menu Not Visible: " + item.getText() + ": " + item.getMenuID());
        }
        return;
    }
    if (!item.isEnabled()) {
        if (DEBUG_MENU) {
            System.out.println("Menu Not enabled: " + item.getText() + ": " + item.getMenuID());
        }
        return;
    }
    Graphic graphic = item.getGraphic();
    FancyRowInfo row;
    if (DEBUG_MENU) {
        System.out.println("Menu " + item.getText() + ": " + item.getMenuID());
    }
    int style = item.getStyle();
    if (style == com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU) {
        row = createMenuRow(detailArea, item.getResourceKey(), null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                if (dms.length != 0) {
                    MenuBuilder submenuBuilder = ((MenuItemImpl) item).getSubmenuBuilder();
                    if (submenuBuilder != null) {
                        try {
                            item.removeAllChildItems();
                            submenuBuilder.buildSubmenu(item, getTarget(item));
                        } catch (Throwable t) {
                            Debug.out(t);
                        }
                    }
                    MenuBuildUtils.addPluginMenuItems(item.getItems(), menu, false, true, new MenuBuildUtils.PluginMenuController() {

                        @Override
                        public Listener makeSelectionListener(final com.biglybt.pif.ui.menus.MenuItem plugin_menu_item) {
                            return new TableSelectedRowsListener(tv, false) {

                                @Override
                                public boolean run(TableRowCore[] rows) {
                                    if (rows.length != 0) {
                                        ((MenuItemImpl) plugin_menu_item).invokeListenersMulti(getTarget(item));
                                    }
                                    return true;
                                }
                            };
                        }

                        @Override
                        public void notifyFillListeners(com.biglybt.pif.ui.menus.MenuItem menu_item) {
                            ((MenuItemImpl) menu_item).invokeMenuWillBeShownListeners(getTarget(item));
                        }

                        // @see com.biglybt.ui.swt.MenuBuildUtils.PluginMenuController#buildSubmenu(com.biglybt.pif.ui.menus.MenuItem)
                        @Override
                        public void buildSubmenu(com.biglybt.pif.ui.menus.MenuItem parent) {
                            com.biglybt.pif.ui.menus.MenuBuilder submenuBuilder = ((MenuItemImpl) parent).getSubmenuBuilder();
                            if (submenuBuilder != null) {
                                try {
                                    parent.removeAllChildItems();
                                    submenuBuilder.buildSubmenu(parent, getTarget(item));
                                } catch (Throwable t) {
                                    Debug.out(t);
                                }
                            }
                        }

                        @Override
                        public void buildComplete(Menu menu) {
                            addMenuItemListener(menu, listenerForTrigger);
                        }
                    });
                }
            }
        });
    } else {
        row = createRow(detailArea, item.getResourceKey(), null, new TableSelectedRowsListener(tv, false) {

            @Override
            public boolean run(TableRowCore[] rows) {
                if (style == com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK) {
                    Boolean b = (Boolean) item.getData();
                    boolean newSel = !(b != null && b);
                    item.setData(newSel);
                }
                if (rows.length != 0) {
                    ((MenuItemImpl) item).invokeListenersMulti(getTarget(item));
                }
                return true;
            }
        });
        if (style == com.biglybt.pif.ui.menus.MenuItem.STYLE_CHECK) {
            Boolean b = (Boolean) item.getData();
            row.setSelection(b != null && b);
        }
    }
    row.setEnabled(item.isEnabled());
    if (graphic instanceof UISWTGraphic) {
        row.getIconLabel().setImage(((UISWTGraphic) graphic).getImage());
    } else if (graphic instanceof GraphicURI) {
        ImageLoader.getInstance().setLabelImage(row.getIconLabel(), ((GraphicURI) graphic).getURI().toString());
    }
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuBuilder(com.biglybt.pif.ui.menus.MenuBuilder) TableRowCore(com.biglybt.ui.common.table.TableRowCore) GraphicURI(com.biglybt.pif.ui.GraphicURI) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) MenuItemImpl(com.biglybt.pifimpl.local.ui.menus.MenuItemImpl) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic)

Example 8 with Graphic

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

the class MenuBuildUtils method addPluginMenuItems.

/**
 * Creates menu items inside the given menu based on the plugin API MenuItem
 * instances provided. This method is provided mainly as a utility method to
 * make it easier for menus to incorporate menu components specified by
 * plugins.
 *
 * Usually, the list of array items will be extracted from a class like
 * MenuItemManager or TableContextMenuManager, where plugins will usually
 * register menu items they have created.
 *
 * @param items The list of plugin MenuItem to add
 * @param parent The SWT Menu to add to.
 * @param prev_was_separator Indicates if the previous item in the menu is
 *            a separator or not
 * @param enable_items Indicates whether you want generated items to be
 *            enabled or not. If false, all items will be disabled. If true,
 *            then the items *may* be enabled, depending on how each MenuItem
 *            is configured.
 * @param controller The callback object used by this method when creating the
 *            SWT menus (used for invoking fill and selection listeners).
 */
public static void addPluginMenuItems(MenuItem[] items, Menu parent, boolean prev_was_separator, final boolean enable_items, final PluginMenuController controller) {
    for (int i = 0; i < items.length; i++) {
        final MenuItemImpl az_menuitem = (MenuItemImpl) items[i];
        controller.notifyFillListeners(az_menuitem);
        if (!az_menuitem.isVisible()) {
            continue;
        }
        final int style = az_menuitem.getStyle();
        final int swt_style;
        boolean this_is_separator = false;
        // Do we have any children? If so, we override any manually defined
        // style.
        boolean is_container = false;
        if (style == TableContextMenuItem.STYLE_MENU) {
            swt_style = SWT.CASCADE;
            is_container = true;
        } else if (style == TableContextMenuItem.STYLE_PUSH) {
            swt_style = SWT.PUSH;
        } else if (style == TableContextMenuItem.STYLE_CHECK) {
            swt_style = SWT.CHECK;
        } else if (style == TableContextMenuItem.STYLE_RADIO) {
            swt_style = SWT.RADIO;
        } else if (style == TableContextMenuItem.STYLE_SEPARATOR) {
            this_is_separator = true;
            swt_style = SWT.SEPARATOR;
        } else {
            swt_style = SWT.PUSH;
        }
        // Skip contiguous separators
        if (prev_was_separator && this_is_separator) {
            continue;
        }
        // Skip trailing separator
        if (this_is_separator && i == items.length - 1) {
            continue;
        }
        prev_was_separator = this_is_separator;
        final org.eclipse.swt.widgets.MenuItem menuItem;
        if (this_is_separator) {
            addSeparator(parent);
            continue;
        } else {
            menuItem = new org.eclipse.swt.widgets.MenuItem(parent, swt_style);
        }
        if (enable_items) {
            if (style == TableContextMenuItem.STYLE_CHECK || style == TableContextMenuItem.STYLE_RADIO) {
                Boolean selection_value = (Boolean) az_menuitem.getData();
                if (selection_value == null) {
                    throw new RuntimeException("MenuItem with resource name \"" + az_menuitem.getResourceKey() + "\" needs to have a boolean value entered via setData before being used!");
                }
                menuItem.setSelection(selection_value.booleanValue());
            }
        }
        final Listener main_listener = controller.makeSelectionListener(az_menuitem);
        menuItem.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                if (az_menuitem.getStyle() == MenuItem.STYLE_CHECK || az_menuitem.getStyle() == MenuItem.STYLE_RADIO) {
                    if (!menuItem.isDisposed()) {
                        az_menuitem.setData(Boolean.valueOf(menuItem.getSelection()));
                    }
                }
                main_listener.handleEvent(e);
            }
        });
        if (is_container) {
            Menu this_menu = new Menu(parent);
            menuItem.setMenu(this_menu);
            addMaintenanceListenerForMenu(this_menu, new MenuBuilder() {

                @Override
                public void buildMenu(Menu root_menu, MenuEvent menuEvent) {
                    controller.buildSubmenu(az_menuitem);
                    addPluginMenuItems(az_menuitem.getItems(), root_menu, false, enable_items, controller);
                }
            });
        }
        String custom_title = az_menuitem.getText();
        menuItem.setText(custom_title);
        Graphic g = az_menuitem.getGraphic();
        if (g instanceof UISWTGraphic) {
            Utils.setMenuItemImage(menuItem, ((UISWTGraphic) g).getImage());
        } else if (g instanceof GraphicURI) {
            Utils.setMenuItemImage(menuItem, ((GraphicURI) g).getURI().toString());
        }
        menuItem.setEnabled(enable_items && az_menuitem.isEnabled());
    }
    controller.buildComplete(parent);
}
Also used : MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Listener(org.eclipse.swt.widgets.Listener) MenuListener(org.eclipse.swt.events.MenuListener) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) MenuItemImpl(com.biglybt.pifimpl.local.ui.menus.MenuItemImpl) GraphicURI(com.biglybt.pif.ui.GraphicURI) Event(org.eclipse.swt.widgets.Event) MenuEvent(org.eclipse.swt.events.MenuEvent) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) Menu(org.eclipse.swt.widgets.Menu) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 9 with Graphic

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

the class BlocksItem method refresh.

@Override
public void refresh(final TableCell cell) {
    final PEPiece pePiece = (PEPiece) cell.getDataSource();
    if (pePiece == null) {
        cell.setSortValue(0);
        dispose(cell);
        cell.setGraphic(null);
        return;
    }
    boolean is_uploading = pePiece instanceof PiecesView.PEPieceUploading;
    cell.setSortValue(pePiece.getNbWritten());
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            PiecePicker picker = pePiece.getPiecePicker();
            long lNumBlocks = pePiece.getNbBlocks();
            int newWidth = cell.getWidth();
            if (newWidth <= 0) {
                dispose(cell);
                cell.setGraphic(null);
                return;
            }
            int newHeight = cell.getHeight();
            int x1 = newWidth - 2;
            int y1 = newHeight - 3;
            if (x1 < 10 || y1 < 3) {
                dispose(cell);
                cell.setGraphic(null);
                return;
            }
            Image image = new Image(Utils.getDisplay(), newWidth, newHeight);
            Color color;
            GC gcImage = new GC(image);
            gcImage.setForeground(Colors.grey);
            gcImage.drawRectangle(0, 0, x1 + 1, y1 + 1);
            int blocksPerPixel = 0;
            int iPixelsPerBlock = 0;
            int pxRes = 0;
            long pxBlockStep = 0;
            int factor = 4;
            while (iPixelsPerBlock <= 0) {
                blocksPerPixel++;
                iPixelsPerBlock = (int) ((x1 + 1) / (lNumBlocks / blocksPerPixel));
            }
            pxRes = (int) (x1 - ((lNumBlocks / blocksPerPixel) * iPixelsPerBlock));
            if (pxRes <= 0)
                pxRes = 1;
            pxBlockStep = (lNumBlocks * factor) / pxRes;
            long addBlocks = (lNumBlocks * factor) / pxBlockStep;
            if ((addBlocks * iPixelsPerBlock) > pxRes)
                pxBlockStep += 1;
            /*      String msg = "iPixelsPerBlock = "+iPixelsPerBlock + ", blocksPerPixel = " + blocksPerPixel;
				      msg += ", pxRes = " + pxRes + ", pxBlockStep = " + pxBlockStep + ", addBlocks = " + addBlocks + ", x1 = " + x1;
				      Debug.out(msg);*/
            TOTorrent torrent = pePiece.getManager().getDiskManager().getTorrent();
            boolean[] written = pePiece.getDMPiece().getWritten();
            boolean piece_written = pePiece.isWritten();
            int drawnWidth = 0;
            int blockStep = 0;
            int pieceNumber = pePiece.getPieceNumber();
            long[] offsets = new long[(int) lNumBlocks];
            long[] lengths = (long[]) offsets.clone();
            Arrays.fill(offsets, (long) pePiece.getManager().getDiskManager().getPieceLength() * (long) pieceNumber);
            for (int i = 0; i < lNumBlocks; lengths[i] = pePiece.getBlockSize(i), offsets[i] += DiskManager.BLOCK_SIZE * i, i++) ;
            boolean egm = picker.isInEndGameMode();
            boolean[] isCached = cacheStats == null ? new boolean[(int) lNumBlocks] : cacheStats.getBytesInCache(torrent, offsets, lengths);
            for (int i = 0; i < lNumBlocks; i += blocksPerPixel) {
                int nextWidth = iPixelsPerBlock;
                blockStep += blocksPerPixel * factor;
                if (blockStep >= pxBlockStep) {
                    nextWidth += (int) (blockStep / pxBlockStep);
                    blockStep -= pxBlockStep;
                }
                if (i >= lNumBlocks - blocksPerPixel) {
                    nextWidth = x1 - drawnWidth;
                }
                color = Colors.white;
                int num = -1;
                if ((written == null && piece_written) || (written != null && written[i])) {
                    color = colors[COLOR_WRITTEN];
                } else if (pePiece.isDownloaded(i)) {
                    color = colors[is_uploading ? COLOR_UPLOADING : COLOR_DOWNLOADED];
                } else if (pePiece.isRequested(i)) {
                    if (egm) {
                        int req_count = picker.getEGMRequestCount(pieceNumber, i);
                        if (req_count < 2) {
                            color = colors[COLOR_REQUESTED];
                        } else {
                            color = colors[COLOR_EGM];
                            num = req_count;
                        }
                    } else {
                        color = colors[COLOR_REQUESTED];
                    }
                }
                gcImage.setBackground(color);
                gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, y1);
                if (isCached[i]) {
                    gcImage.setBackground(colors[COLOR_INCACHE]);
                    gcImage.fillRectangle(drawnWidth + 1, 1, nextWidth, 3);
                }
                if (num >= 0) {
                    gcImage.setForeground(Colors.black);
                    gcImage.drawString(String.valueOf(num), drawnWidth + 1, 0, true);
                }
                drawnWidth += nextWidth;
            }
            gcImage.dispose();
            Image oldImage = null;
            Graphic graphic = cell.getGraphic();
            if (graphic instanceof UISWTGraphic) {
                oldImage = ((UISWTGraphic) graphic).getImage();
            }
            if (cell instanceof TableCellSWT) {
                ((TableCellSWT) cell).setGraphic(image);
            } else {
                cell.setGraphic(new UISWTGraphicImpl(image));
            }
            if (oldImage != null && !oldImage.isDisposed())
                oldImage.dispose();
            gcImage.dispose();
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) PiecePicker(com.biglybt.core.peermanager.piecepicker.PiecePicker) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) PEPiece(com.biglybt.core.peer.PEPiece) UISWTGraphicImpl(com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl) TOTorrent(com.biglybt.core.torrent.TOTorrent) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) GC(org.eclipse.swt.graphics.GC)

Example 10 with Graphic

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

the class PiecesItem method refresh.

@Override
public void refresh(final TableCell cell) {
    /* Notes:
		 * We store our image and imageBufer in PEPeer using
		 * setData & getData.
		 */
    // Named infoObj so code can be copied easily to the other PiecesItem
    final PEPeer infoObj = (PEPeer) cell.getDataSource();
    long lCompleted = (infoObj == null) ? 0 : infoObj.getPercentDoneInThousandNotation();
    if (!cell.setSortValue(lCompleted) && cell.isValid()) {
        return;
    }
    if (infoObj == null)
        return;
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            if (cell.isDisposed()) {
                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;
            int[] imageBuffer = (int[]) infoObj.getData("PiecesImageBuffer");
            boolean bImageBufferValid = imageBuffer != null && imageBuffer.length == drawWidth;
            Image image = (Image) infoObj.getData("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);
            }
            final BitFlags peerHave = infoObj.getAvailable();
            boolean established;
            if (infoObj instanceof PEPeerTransport) {
                established = ((PEPeerTransport) infoObj).getConnectionState() == PEPeerTransport.CONNECTION_FULLY_ESTABLISHED;
            } else {
                // hack for 'my-peer'
                established = true;
            }
            if (established && peerHave != null && peerHave.flags.length > 0) {
                if (imageBuffer == null || imageBuffer.length != drawWidth) {
                    imageBuffer = new int[drawWidth];
                }
                final boolean[] available = peerHave.flags;
                try {
                    int nbComplete = 0;
                    int nbPieces = available.length;
                    DiskManager disk_manager = infoObj.getManager().getDiskManager();
                    DiskManagerPiece[] pieces = disk_manager == null ? null : disk_manager.getPieces();
                    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;
                        int nbNeeded = 0;
                        if (a1 <= a0) {
                            index = imageBuffer[i - 1];
                        } else {
                            int nbAvailable = 0;
                            for (int j = a0; j < a1; j++) {
                                if (available[j]) {
                                    if (pieces == null || !pieces[j].isDone()) {
                                        nbNeeded++;
                                    }
                                    nbAvailable++;
                                }
                            }
                            nbComplete += nbAvailable;
                            index = (nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0);
                            if (nbNeeded <= nbAvailable / 2)
                                index += INDEX_COLOR_FADEDSTARTS;
                        }
                        if (imageBuffer[i] != index) {
                            imageBuffer[i] = index;
                            if (bImageBufferValid) {
                                bImageChanged = true;
                                if (imageBuffer[i] >= INDEX_COLOR_FADEDSTARTS)
                                    gcImage.setForeground(Colors.faded[index - INDEX_COLOR_FADEDSTARTS]);
                                else
                                    gcImage.setForeground(Colors.blues[index]);
                                gcImage.drawLine(i + x0, y0, i + x0, y1);
                            }
                        }
                    }
                    if (!bImageBufferValid) {
                        if (established) {
                            int iLastIndex = imageBuffer[0];
                            int iWidth = 1;
                            for (int i = 1; i < drawWidth; i++) {
                                if (iLastIndex == imageBuffer[i]) {
                                    iWidth++;
                                } else {
                                    if (iLastIndex >= INDEX_COLOR_FADEDSTARTS) {
                                        gcImage.setBackground(Colors.faded[iLastIndex - INDEX_COLOR_FADEDSTARTS]);
                                    } else
                                        gcImage.setBackground(Colors.blues[iLastIndex]);
                                    gcImage.fillRectangle(i - iWidth + x0, y0, iWidth, y1 - y0 + 1);
                                    iWidth = 1;
                                    iLastIndex = imageBuffer[i];
                                }
                            }
                            if (iLastIndex >= INDEX_COLOR_FADEDSTARTS)
                                gcImage.setBackground(Colors.faded[iLastIndex - INDEX_COLOR_FADEDSTARTS]);
                            else
                                gcImage.setBackground(Colors.blues[iLastIndex]);
                            gcImage.fillRectangle(x1 - iWidth + 1, y0, iWidth, y1 - y0 + 1);
                            bImageChanged = true;
                        }
                    }
                    int limit = (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);
                }
            } else {
                gcImage.setForeground(Colors.grey);
                gcImage.setBackground(Colors.grey);
                gcImage.fillRectangle(x0, y0, newWidth, y1);
            }
            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 (oldImage != null && image != oldImage && !oldImage.isDisposed()) {
                    oldImage.dispose();
                }
                if (bImageChanged || image != oldImage) {
                    cell.invalidate();
                }
                infoObj.setData("PiecesImage", image);
                infoObj.setData("PiecesImageBuffer", imageBuffer);
            }
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) BitFlags(com.biglybt.core.peermanager.piecepicker.util.BitFlags) PEPeer(com.biglybt.core.peer.PEPeer) 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) UISWTGraphicImpl(com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl) PEPeerTransport(com.biglybt.core.peer.impl.PEPeerTransport) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) GC(org.eclipse.swt.graphics.GC)

Aggregations

Graphic (com.biglybt.pif.ui.Graphic)10 UISWTGraphic (com.biglybt.ui.swt.pif.UISWTGraphic)9 Image (org.eclipse.swt.graphics.Image)5 UISWTGraphicImpl (com.biglybt.ui.swt.pifimpl.UISWTGraphicImpl)4 AERunnable (com.biglybt.core.util.AERunnable)3 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)3 GC (org.eclipse.swt.graphics.GC)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 PEPeer (com.biglybt.core.peer.PEPeer)2 GraphicURI (com.biglybt.pif.ui.GraphicURI)2 MenuItemImpl (com.biglybt.pifimpl.local.ui.menus.MenuItemImpl)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 DiskManager (com.biglybt.core.disk.DiskManager)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 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 MenuBuilder (com.biglybt.pif.ui.menus.MenuBuilder)1