Search in sources :

Example 76 with ImageLoader

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

the class SWTSkinObjectImage method createImageWidget.

private Canvas createImageWidget(String sConfigID) {
    String propImageID = properties.getStringValue(sConfigID + ".imageid");
    if (propImageID != null) {
        currentImageID = customImageID = propImageID;
    }
    int style = SWT.WRAP | SWT.DOUBLE_BUFFERED;
    String sAlign = properties.getStringValue(sConfigID + ".align");
    if (sAlign != null && !Constants.isUnix) {
        h_align = SWTSkinUtils.getAlignment(sAlign, SWT.NONE);
        if (h_align != SWT.NONE) {
            style |= h_align;
        }
    }
    if (properties.getIntValue(sConfigID + ".border", 0) == 1) {
        style |= SWT.BORDER;
    }
    Composite createOn;
    if (parent == null) {
        createOn = skin.getShell();
    } else {
        createOn = (Composite) parent.getControl();
    }
    canvas = new Canvas(createOn, style);
    canvas.setData("SkinObject", this);
    // {
    // public Point computeSize(int wHint, int hHint) {
    // Object image = canvas.getData("image");
    // Object imageID = canvas.getData("ImageID");
    // if (image == null
    // && (imageID == null || ((String) imageID).length() == 0)) {
    // return new Point(0, 0);
    // }
    // return super.computeSize(wHint, hHint);
    // };
    // 
    // public Point computeSize(int wHint, int hHint, boolean changed) {
    // Object image = canvas.getData("image");
    // Object imageID = canvas.getData("ImageID");
    // if (image == null
    // && (imageID == null || ((String) imageID).length() == 0)) {
    // return new Point(0, 0);
    // }
    // return super.computeSize(wHint, hHint, changed);
    // };
    // };
    Color color = properties.getColor(sConfigID + ".color");
    if (color != null) {
        canvas.setBackground(color);
    }
    final String sURL = properties.getStringValue(sConfigID + ".url");
    if (sURL != null && sURL.length() > 0) {
        Utils.setTT(canvas, sURL);
        canvas.addListener(SWT.MouseUp, new Listener() {

            @Override
            public void handleEvent(Event arg0) {
                Utils.launch(UrlUtils.encode(sURL));
            }
        });
    }
    String sCursor = properties.getStringValue(sConfigID + ".cursor");
    if (sCursor != null && sCursor.length() > 0) {
        if (sCursor.equalsIgnoreCase("hand")) {
            canvas.addListener(SWT.MouseEnter, skin.getHandCursorListener(canvas.getDisplay()));
            canvas.addListener(SWT.MouseExit, skin.getHandCursorListener(canvas.getDisplay()));
        }
    }
    // SWTBGImagePainter painter = (SWTBGImagePainter) parent.getData("BGPainter");
    // if (painter != null) {
    // canvas.addListener(SWT.Paint, painter);
    // }
    canvas.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            String oldImageID = (String) canvas.getData("ImageID");
            if (oldImageID != null && canvas.getData("image") != null) {
                ImageLoader imageLoader = skin.getImageLoader(properties);
                imageLoader.releaseImage(oldImageID);
            }
        }
    });
    // needed to set paint listener and canvas size
    swt_reallySetImage();
    return canvas;
}
Also used : ImageDownloaderListener(com.biglybt.ui.swt.imageloader.ImageLoader.ImageDownloaderListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 77 with ImageLoader

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

the class SWTSkinObjectImage method swt_reallySetImage.

protected void swt_reallySetImage() {
    if (currentImageID == null || customImage) {
        drawAlpha = 255;
        return;
    }
    boolean removedDisabled = false;
    ImageLoader imageLoader = skin.getImageLoader(properties);
    boolean imageExists = imageLoader.imageExists(currentImageID);
    if (!imageExists && imageLoader.imageExists(currentImageID + ".image")) {
        currentImageID = sConfigID + ".image";
        imageExists = true;
    }
    if (!imageExists && suffixes != null) {
        for (int i = suffixes.length - 1; i >= 0; i--) {
            String suffixToRemove = suffixes[i];
            if (suffixToRemove != null) {
                if (suffixToRemove.equals("-disabled")) {
                    removedDisabled = true;
                }
                currentImageID = currentImageID.substring(0, currentImageID.length() - suffixToRemove.length());
                if (imageLoader.imageExists(currentImageID)) {
                    imageExists = true;
                    break;
                }
            }
        }
    }
    if (imageExists) {
        drawAlpha = removedDisabled ? 64 : 255;
        setCanvasImage(currentImageID, null);
    } else {
        drawAlpha = 255;
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                FormData fd = (FormData) canvas.getLayoutData();
                if (fd == null) {
                    fd = new FormData(0, 0);
                } else {
                    fd.width = 0;
                    fd.height = 0;
                }
                canvas.setLayoutData(fd);
                if (initialized) {
                    Utils.relayout(canvas);
                }
            }
        });
    }
}
Also used : FormData(org.eclipse.swt.layout.FormData) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 78 with ImageLoader

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

the class SWTSkinObjectImage2 method createImageWidget.

private Canvas createImageWidget(String sConfigID) {
    String propImageID = properties.getStringValue(sConfigID + ".imageid");
    if (propImageID != null) {
        currentImageID = customImageID = propImageID;
    } else {
        currentImageID = sConfigID;
    }
    int style = SWT.WRAP | SWT.DOUBLE_BUFFERED;
    String sAlign = properties.getStringValue(sConfigID + ".align");
    if (sAlign != null && !Constants.isUnix) {
        h_align = SWTSkinUtils.getAlignment(sAlign, SWT.NONE);
        if (h_align != SWT.NONE) {
            style |= h_align;
        }
    }
    if (properties.getIntValue(sConfigID + ".border", 0) == 1) {
        style |= SWT.BORDER;
    }
    Composite createOn;
    if (parent == null) {
        createOn = skin.getShell();
    } else {
        createOn = (Composite) parent.getControl();
    }
    canvas = new Canvas(createOn, style);
    canvas.setData("SkinObject", this);
    // {
    // public Point computeSize(int wHint, int hHint) {
    // Object image = canvas.getData("image");
    // Object imageID = canvas.getData("ImageID");
    // if (image == null
    // && (imageID == null || ((String) imageID).length() == 0)) {
    // return new Point(0, 0);
    // }
    // return super.computeSize(wHint, hHint);
    // };
    // 
    // public Point computeSize(int wHint, int hHint, boolean changed) {
    // Object image = canvas.getData("image");
    // Object imageID = canvas.getData("ImageID");
    // if (image == null
    // && (imageID == null || ((String) imageID).length() == 0)) {
    // return new Point(0, 0);
    // }
    // return super.computeSize(wHint, hHint, changed);
    // };
    // };
    Color color = properties.getColor(sConfigID + ".color");
    if (color != null) {
        canvas.setBackground(color);
    }
    final String sURL = properties.getStringValue(sConfigID + ".url");
    if (sURL != null && sURL.length() > 0) {
        Utils.setTT(canvas, sURL);
        canvas.addListener(SWT.MouseUp, new Listener() {

            @Override
            public void handleEvent(Event arg0) {
                Utils.launch(UrlUtils.encode(sURL));
            }
        });
    }
    String sCursor = properties.getStringValue(sConfigID + ".cursor");
    if (sCursor != null && sCursor.length() > 0) {
        if (sCursor.equalsIgnoreCase("hand")) {
            canvas.addListener(SWT.MouseEnter, skin.getHandCursorListener(canvas.getDisplay()));
            canvas.addListener(SWT.MouseExit, skin.getHandCursorListener(canvas.getDisplay()));
        }
    }
    // SWTBGImagePainter painter = (SWTBGImagePainter) parent.getData("BGPainter");
    // if (painter != null) {
    // canvas.addListener(SWT.Paint, painter);
    // }
    canvas.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            String oldImageID = (String) canvas.getData("ImageID");
            if (oldImageID != null && canvas.getData("image") != null) {
                ImageLoader imageLoader = skin.getImageLoader(properties);
                imageLoader.releaseImage(oldImageID);
            }
        }
    });
    // needed to set paint listener and canvas size
    swt_reallySetImage();
    return canvas;
}
Also used : ImageDownloaderListener(com.biglybt.ui.swt.imageloader.ImageLoader.ImageDownloaderListener) 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