Search in sources :

Example 56 with ImageLoader

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

the class Utils method setMenuItemImage.

/**
 * <p>
 * Set a MenuItem's image with the given ImageRepository key. In compliance with platform
 * human interface guidelines, the images are not set under Mac OS X.
 * </p>
 * @param item SWT MenuItem
 * @param repoKey ImageRepository image key
 * @see <a href="http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGMenus/chapter_7_section_3.html#//apple_ref/doc/uid/TP30000356/TPXREF116">Apple HIG</a>
 */
public static void setMenuItemImage(final MenuItem item, final String repoKey) {
    if (Constants.isOSX || repoKey == null) {
        return;
    }
    ImageLoader imageLoader = ImageLoader.getInstance();
    item.setImage(imageLoader.getImage(repoKey));
    item.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            ImageLoader imageLoader = ImageLoader.getInstance();
            imageLoader.releaseImage(repoKey);
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 57 with ImageLoader

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

the class QuickLinksView method addItem.

private static void addItem(BaseMDI mdi, ToolBar toolBar, QuickLinkItem qli) {
    String tt_id = qli.tt_id;
    ToolItem item = new ToolItem(toolBar, SWT.PUSH);
    if (MessageText.keyExists(tt_id)) {
        Messages.setLanguageTooltip(item, tt_id);
    } else {
        Utils.setTT(item, tt_id);
    }
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image image = imageLoader.getImage(qli.image_id);
    Image resized = imageLoader.resizeImageIfLarger(image, new Point(15, 15));
    if (resized == null) {
        item.setImage(image);
    } else {
        item.setImage(resized);
        item.addListener(SWT.Dispose, (ev) -> {
            resized.dispose();
        });
    }
    item.addListener(SWT.Selection, ev -> {
        qli.show(mdi);
    });
    item.setData("qli", qli);
}
Also used : Point(org.eclipse.swt.graphics.Point) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Image(org.eclipse.swt.graphics.Image) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 58 with ImageLoader

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

the class ViewQuickNotifications method refresh.

private void refresh() {
    Object[] temp = ActivitiesManager.getMostRecentUnseen();
    ActivitiesEntry entry = (ActivitiesEntry) temp[0];
    String old_text = (String) notification_text.getData();
    if (entry == null) {
        notification_icon.setImage(null);
        if (old_text.length() > 0) {
            notification_text.setData("");
            notification_text.redraw();
        }
        more_text.setText("");
    } else {
        String cur_text = entry.getText();
        if (!old_text.equals(cur_text)) {
            notification_text.setData(cur_text);
            notification_text.redraw();
        }
        String icon_id = entry.getIconID();
        if (icon_id != null) {
            String existing = (String) notification_icon.getData();
            if (existing == null || notification_icon.getImage() == null || !existing.equals(icon_id)) {
                ImageLoader imageLoader = ImageLoader.getInstance();
                if (existing != null) {
                    imageLoader.releaseImage(existing);
                }
                Image image = imageLoader.getImage(icon_id);
                notification_icon.setImage(image);
                notification_icon.setData(icon_id);
            }
        } else {
            notification_icon.setImage(null);
        }
        int num = (Integer) temp[1];
        if (num <= 1) {
            more_text.setText("");
        } else {
            more_text.setText(MessageText.getString("popup.more.waiting", new String[] { String.valueOf(num - 1) }));
        }
    }
}
Also used : ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Image(org.eclipse.swt.graphics.Image)

Example 59 with ImageLoader

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

the class TranscodeChooser method addImageBox.

/**
 * @since 4.1.0.5
 */
public static void addImageBox(Composite parent, Listener clickListener, Listener listenerMouseInout, Object obj, String iconURL, String name) {
    GridData gridData;
    final Shell shell = parent.getShell();
    final Composite c = new Composite(parent, SWT.NONE);
    GridLayout clayout = new GridLayout();
    clayout.marginWidth = clayout.horizontalSpacing = 0;
    c.setLayout(clayout);
    c.setCursor(c.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    c.addListener(SWT.MouseUp, clickListener);
    c.addListener(SWT.MouseDown, clickListener);
    c.setData("obj", obj);
    if (listenerMouseInout != null) {
        c.addListener(SWT.MouseEnter, listenerMouseInout);
        c.addListener(SWT.MouseExit, listenerMouseInout);
    }
    final Canvas lblImage = new Canvas(c, SWT.DOUBLE_BUFFERED);
    if (listenerMouseInout != null) {
        lblImage.addListener(SWT.MouseEnter, listenerMouseInout);
        lblImage.addListener(SWT.MouseExit, listenerMouseInout);
    }
    lblImage.addListener(SWT.MouseUp, clickListener);
    lblImage.addListener(SWT.MouseDown, clickListener);
    lblImage.setData("obj", obj);
    lblImage.addListener(SWT.Paint, new Listener() {

        @Override
        public void handleEvent(Event event) {
            Rectangle area = lblImage.getBounds();
            Rectangle carea = c.getBounds();
            Point ptInDisplay = c.toDisplay(0, 0);
            event.gc.setAdvanced(true);
            event.gc.setAntialias(SWT.ON);
            event.gc.setLineWidth(2);
            if (new Rectangle(ptInDisplay.x, ptInDisplay.y, carea.width, carea.height).contains(event.display.getCursorLocation())) {
                // if (event.display.getCursorControl() == lblImage) {
                Color color1 = ColorCache.getColor(event.gc.getDevice(), 252, 253, 255);
                Color color2 = ColorCache.getColor(event.gc.getDevice(), 169, 195, 252);
                Pattern pattern = new Pattern(event.gc.getDevice(), 0, 0, 0, area.height, color1, 0, color2, 200);
                event.gc.setBackgroundPattern(pattern);
                event.gc.fillRoundRectangle(0, 0, area.width - 1, area.height - 1, 20, 20);
                event.gc.setBackgroundPattern(null);
                pattern.dispose();
                pattern = new Pattern(event.gc.getDevice(), 0, 0, 0, area.height, color2, 50, color2, 255);
                event.gc.setForegroundPattern(pattern);
                event.gc.drawRoundRectangle(0, 0, area.width - 1, area.height - 1, 20, 20);
                event.gc.setForegroundPattern(null);
                pattern.dispose();
            }
            Image image = (Image) lblImage.getData("Image");
            if (image != null) {
                Rectangle bounds = image.getBounds();
                event.gc.drawImage(image, bounds.x, bounds.y, bounds.width, bounds.height, 8, 5, bounds.width, bounds.height);
            } else {
                Rectangle ca = lblImage.getClientArea();
                event.gc.setAdvanced(true);
                event.gc.setAntialias(SWT.ON);
                event.gc.setAlpha(50);
                event.gc.setBackground(event.gc.getForeground());
                event.gc.fillRoundRectangle(ca.x + 10, ca.y + 5, ca.width - 21, ca.height - 11, 20, 20);
            }
        }
    });
    gridData = new GridData(GridData.FILL_VERTICAL);
    gridData.heightHint = 50;
    gridData.widthHint = 100;
    if (iconURL != null && iconURL.length() > 0) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        Image image = imageLoader.getUrlImage(iconURL, new ImageLoader.ImageDownloaderListener() {

            @Override
            public void imageDownloaded(Image image, String key, boolean returnedImmediately) {
                if (!returnedImmediately) {
                    if (lblImage.isDisposed()) {
                        return;
                    }
                    lblImage.setData("Image", image);
                    Rectangle bounds = image.getBounds();
                    GridData gridData = (GridData) lblImage.getLayoutData();
                    gridData.heightHint = bounds.height + 10;
                    gridData.widthHint = bounds.width + 16;
                    lblImage.setLayoutData(gridData);
                    lblImage.getShell().layout(new Control[] { lblImage });
                    Point computeSize = shell.computeSize(600, SWT.DEFAULT, true);
                    shell.setSize(computeSize);
                }
            }
        });
        if (image != null) {
            lblImage.setData("Image", image);
            Rectangle bounds = image.getBounds();
            gridData.heightHint = bounds.height + 10;
            gridData.widthHint = bounds.width + 16;
        }
    }
    lblImage.setLayoutData(gridData);
    Label label = new Label(c, SWT.WRAP | SWT.CENTER);
    if (listenerMouseInout != null) {
        label.addListener(SWT.MouseEnter, listenerMouseInout);
    }
    label.addListener(SWT.MouseUp, clickListener);
    label.addListener(SWT.MouseDown, clickListener);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(gridData);
    String s = name;
    // s += " (via " + profile.getProvider().getName() + ")";
    label.setText(s);
    label.setCursor(c.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 60 with ImageLoader

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

the class ColumnFO_Progress method cellPaint.

@Override
public void cellPaint(GC gcImage, TableCellSWT cell) {
    CoreOperation op = (CoreOperation) cell.getDataSource();
    int progress = 0;
    boolean has_progress = false;
    if (op != null) {
        ProgressCallback cb = op.getTask().getProgressCallback();
        if (cb != null) {
            progress = cb.getProgress();
            has_progress = true;
        }
    }
    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 * progress) / 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 (progress < 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 (!has_progress) {
        sText = na_text;
    } else {
        sText = DisplayFormatters.formatPercentFromThousands(progress);
    }
    GCStringPrinter.printString(gcImage, sText, new Rectangle(bounds.x + 4, bounds.y + yOfs, bounds.width - 4, 13), true, false, SWT.CENTER);
}
Also used : CoreOperation(com.biglybt.core.CoreOperation) ProgressCallback(com.biglybt.core.CoreOperationTask.ProgressCallback) 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