Search in sources :

Example 61 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class PMSWTImpl method initialise.

@Override
public void initialise(final PluginInterface pi, final BooleanParameter icon_enable) {
    final NetworkAdmin na = NetworkAdmin.getSingleton();
    na.addPropertyChangeListener(new NetworkAdminPropertyChangeListener() {

        @Override
        public void propertyChanged(String property) {
            if (property == NetworkAdmin.PR_NETWORK_INTERFACES) {
                updateLocalAddresses(na);
            }
        }
    });
    updateLocalAddresses(na);
    pi.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                ui_attached = true;
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uiUpdaterListener = new UIUpdaterListener() {

                        @Override
                        public void updateComplete(int count) {
                            last_update_count = count;
                            updateStatus(true);
                        }
                    };
                    uif.getUIUpdater().addListener(uiUpdaterListener);
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        ImageLoader imageLoader = ImageLoader.getInstance();
                        icon_idle = imageLoader.getImage("pair_sb_idle");
                        icon_green = imageLoader.getImage("pair_sb_green");
                        icon_red = imageLoader.getImage("pair_sb_red");
                        UISWTInstance ui_instance = (UISWTInstance) instance;
                        status = ui_instance.createStatusEntry();
                        last_tooltip_text = MessageText.getString("pairing.ui.icon.tip");
                        Utils.setTT(status, last_tooltip_text);
                        status.setImageEnabled(true);
                        status.setImage(icon_idle);
                        last_image = icon_idle;
                        boolean is_visible = icon_enable.getValue();
                        status.setVisible(is_visible);
                        if (is_visible) {
                            updateStatus(false);
                        }
                        final MenuItem mi_show = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "pairing.ui.icon.show");
                        mi_show.setStyle(MenuItem.STYLE_CHECK);
                        mi_show.setData(Boolean.valueOf(is_visible));
                        mi_show.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                icon_enable.setValue(false);
                            }
                        });
                        iconEnableListener = new ParameterListener() {

                            @Override
                            public void parameterChanged(Parameter param) {
                                boolean is_visible = icon_enable.getValue();
                                status.setVisible(is_visible);
                                mi_show.setData(Boolean.valueOf(is_visible));
                                if (is_visible) {
                                    updateStatus(false);
                                }
                            }
                        };
                        icon_enable.addListener(iconEnableListener);
                        MenuItem mi_pairing = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.pairing");
                        mi_pairing.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif == null) {
                                    Debug.out("UIFunctions not available, can't open remote pairing window");
                                } else {
                                    uif.openRemotePairingWindow();
                                }
                            }
                        });
                        MenuItem mi_sep = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "");
                        mi_sep.setStyle(MenuItem.STYLE_SEPARATOR);
                        MenuItem mi_options = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.view.configuration");
                        mi_options.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        });
                        UISWTStatusEntryListener click_listener = new UISWTStatusEntryListener() {

                            @Override
                            public void entryClicked(UISWTStatusEntry entry) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        };
                        status.setListener(click_listener);
                    }
                });
            }
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                ui_attached = false;
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null && uiUpdaterListener != null) {
                    uif.getUIUpdater().removeListener(uiUpdaterListener);
                    uiUpdaterListener = null;
                }
                if (status != null) {
                    // menu items get destroyed with this call
                    status.destroy();
                    status = null;
                }
                if (icon_enable != null && iconEnableListener != null) {
                    icon_enable.removeListener(iconEnableListener);
                    iconEnableListener = null;
                }
            }
        }
    });
}
Also used : UIUpdaterListener(com.biglybt.ui.common.updater.UIUpdater.UIUpdaterListener) UISWTStatusEntryListener(com.biglybt.ui.swt.pif.UISWTStatusEntryListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) NetworkAdminPropertyChangeListener(com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) UIFunctions(com.biglybt.ui.UIFunctions) UISWTStatusEntry(com.biglybt.ui.swt.pif.UISWTStatusEntry) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 62 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class AboutWindow method disposeImage.

public static void disposeImage() {
    try {
        class_mon.enter();
        Utils.disposeSWTObjects(new Object[] { imageToDispose });
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.releaseImage(IMG_SPLASH);
        image = null;
        imgSrc = null;
    } finally {
        class_mon.exit();
    }
}
Also used : ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 63 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class ColumnTJ_Completion method cellPaint.

@Override
public void cellPaint(GC gcImage, TableCellSWT cell) {
    TranscodeFile tf = (TranscodeFile) cell.getDataSource();
    int perThouDone = getPerThouDone(tf);
    Rectangle bounds = cell.getBounds();
    int yOfs = (bounds.height - 13) / 2;
    int x1 = bounds.width - borderWidth - 2;
    int y1 = bounds.height - 3 - yOfs;
    if (x1 < 10 || y1 < 3) {
        return;
    }
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgEnd = imageLoader.getImage("tc_bar_end");
    Image img0 = imageLoader.getImage("tc_bar_0");
    Image img1 = imageLoader.getImage("tc_bar_1");
    // draw begining and end
    if (!imgEnd.isDisposed()) {
        gcImage.drawImage(imgEnd, bounds.x, bounds.y + yOfs);
        gcImage.drawImage(imgEnd, bounds.x + x1 + 1, bounds.y + yOfs);
    }
    int limit = (x1 * perThouDone) / 1000;
    if (!img1.isDisposed() && limit > 0) {
        Rectangle imgBounds = img1.getBounds();
        gcImage.drawImage(img1, 0, 0, imgBounds.width, imgBounds.height, bounds.x + 1, bounds.y + yOfs, limit, imgBounds.height);
    }
    if (perThouDone < 1000 && !img0.isDisposed()) {
        Rectangle imgBounds = img0.getBounds();
        gcImage.drawImage(img0, 0, 0, imgBounds.width, imgBounds.height, bounds.x + limit + 1, bounds.y + yOfs, x1 - limit, imgBounds.height);
    }
    imageLoader.releaseImage("tc_bar_end");
    imageLoader.releaseImage("tc_bar_0");
    imageLoader.releaseImage("tc_bar_1");
    if (textColor == null) {
        textColor = ColorCache.getColor(gcImage.getDevice(), "#006600");
    }
    gcImage.setForeground(textColor);
    if (fontText == null) {
        fontText = FontUtils.getFontWithHeight(gcImage.getFont(), 10, SWT.DEFAULT);
    }
    gcImage.setFont(fontText);
    String sText;
    if (tf != null && perThouDone == 1000 && !tf.getTranscodeRequired()) {
        sText = na_text;
    } else {
        // DisplayFormatters.formatPercentFromThousands(perThouDone);
        sText = percentage_format.format(perThouDone / 1000.0);
        if (tf != null && perThouDone < 1000) {
            String eta = getETA(tf);
            if (eta != null) {
                sText += " - " + eta;
            }
        }
    }
    GCStringPrinter.printString(gcImage, sText, new Rectangle(bounds.x + 4, bounds.y + yOfs, bounds.width - 4, 13), true, false, SWT.CENTER);
}
Also used : TranscodeFile(com.biglybt.core.devices.TranscodeFile) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 64 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader 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();
        final int EXPANDOPADLEFT = 3;
        int paddingX = EXPANDOPADLEFT;
        final int EXPANDOWIDTH = 7;
        paddingX += depth * EXPANDOWIDTH;
        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;
        }
        final int CHECKPADLEFT = 2;
        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 + EXPANDOWIDTH, middleY - halfHeight, startX + (EXPANDOWIDTH / 2), middleY + (halfHeight * 2) + 1 });
            } else {
                gc.fillPolygon(new int[] { startX, middleY - halfHeight, startX + EXPANDOWIDTH, middleY + halfHeight, startX, middleY + (halfHeight * 2) + 1 });
            }
            gc.setBackground(bg);
            // Rectangle hitArea = new Rectangle(paddingX*2, middleY - halfHeight
            // - cellBounds.y, width, (halfHeight * 4) + 1);
            // expando is quite small, make it easier to hit
            Rectangle hitArea = new Rectangle(startX - originalBoundxsX - EXPANDOPADLEFT, 0, EXPANDOWIDTH + EXPANDOPADLEFT + CHECKPADLEFT, cellBounds.height);
            rowCore.setData(TableRowCore.ID_EXPANDOHITAREA, hitArea);
            rowCore.setData(TableRowCore.ID_EXPANDOHITCOLUMN, getName());
        }
        if (!NEVER_SHOW_TWISTY) {
            cellBounds.x += paddingX + EXPANDOWIDTH;
            cellBounds.width -= paddingX + EXPANDOWIDTH;
        }
        ImageLoader im = ImageLoader.getInstance();
        String check_key;
        boolean is_ro = false;
        TOTorrentFile tf = fileInfo.getTorrentFile();
        if (tf != null && tf.isPadFile()) {
            is_ro = true;
            check_key = "check_ro_no";
        } else {
            if (is_leaf) {
                Boolean isSkipped = fileInfo.isSkipping();
                if (isSkipped == null) {
                    isSkipped = fileInfo.isSkipped();
                }
                if (isSkipped) {
                    int st = fileInfo.getStorageType();
                    if (st == DiskManagerFileInfo.ST_COMPACT || st == DiskManagerFileInfo.ST_REORDER_COMPACT) {
                        check_key = "check_no";
                    } else {
                        check_key = "check_no_grey";
                    }
                } 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 + CHECKPADLEFT, 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 = null;
    if (fileInfo != null) {
        File file = fileInfo.getFile(true);
        Object piCache = cell.getData(KEY_PATH_ICON);
        if (piCache != null) {
            Object[] temp = (Object[]) piCache;
            if (FileUtil.areFilePathsIdentical((File) temp[0], file)) {
                imgThumbnail = (Image[]) temp[1];
            }
        }
        if (imgThumbnail == null) {
            imgThumbnail = new Image[] { ImageRepository.getPathIcon(file.getPath(), cell.getHeight() > 32, false) };
            cell.setData(KEY_PATH_ICON, new Object[] { file, imgThumbnail });
        }
    }
    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) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) FilesView(com.biglybt.ui.swt.views.FilesView) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) File(java.io.File)

Example 65 with ImageLoader

use of com.biglybt.ui.swt.imageloader.ImageLoader in project BiglyBT by BiglySoftware.

the class SWTSkin method getImageLoader.

public ImageLoader getImageLoader(SkinProperties properties) {
    if (is_default) {
        return ImageLoader.getInstance();
    }
    ImageLoader loader = mapImageLoaders.get(properties);
    if (loader != null) {
        return loader;
    }
    loader = new ImageLoader(Display.getDefault(), properties);
    mapImageLoaders.put(properties, loader);
    return loader;
}
Also used : ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Aggregations

ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)78 Image (org.eclipse.swt.graphics.Image)20 GridData (org.eclipse.swt.layout.GridData)16 GridLayout (org.eclipse.swt.layout.GridLayout)16 Rectangle (org.eclipse.swt.graphics.Rectangle)6 MessageText (com.biglybt.core.internat.MessageText)5 AERunnable (com.biglybt.core.util.AERunnable)5 UIFunctions (com.biglybt.ui.UIFunctions)5 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Core (com.biglybt.core.Core)4 CoreRunningListener (com.biglybt.core.CoreRunningListener)4 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Point (org.eclipse.swt.graphics.Point)4 Subscription (com.biglybt.core.subs.Subscription)3 MenuItem (com.biglybt.pif.ui.menus.MenuItem)3 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)3