Example usage for org.eclipse.jface.resource ImageDescriptor createImage

List of usage examples for org.eclipse.jface.resource ImageDescriptor createImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageDescriptor createImage.

Prototype

public Image createImage() 

Source Link

Document

Creates and returns a new SWT image for this image descriptor.

Usage

From source file:eu.geclipse.ui.widgets.DateTimeText.java

License:Open Source License

private Image getImage() {
    if (DateTimeText.image == null) {
        ImageDescriptor imageDescriptor = Activator.getDefault().getImageRegistry().getDescriptor("calendar"); //$NON-NLS-1$
        DateTimeText.image = imageDescriptor.createImage();
    }//from   w  w w. ja  v  a 2s  .  co m
    return DateTimeText.image;
}

From source file:eu.geclipse.ui.wizards.VoServiceSelectionPage.java

License:Open Source License

protected static Image getImage(final String name) {

    Image result = images.get(name);

    if (result == null) {
        URL url = Activator.getDefault().getBundle().getResource(name);
        ImageDescriptor desc = ImageDescriptor.createFromURL(url);
        result = desc.createImage();
        images.put(name, result);/*from www.j av a2  s  .c o  m*/
    }

    return result;

}

From source file:eu.hydrologis.jgrass.annotationlayer.AnnotationsPropertiesView.java

License:Open Source License

public void createPartControl(Composite parent) {

    Composite propsComposite = new Composite(parent, SWT.None);
    propsComposite.setLayout(new RowLayout());
    propsComposite.setLayoutData(//from w ww  . j av  a  2 s  .c  o  m
            new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));

    // stroke width
    Image img1 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_1.png").createImage();
    Image img2 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_2.png").createImage();
    Image img3 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_3.png").createImage();
    Image img4 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_4.png").createImage();
    Image img5 = AbstractUIPlugin
            .imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, "/icons/strokewidth_5.png").createImage();

    Composite strokeComposite = new Composite(propsComposite, SWT.None);
    strokeComposite.setLayout(new GridLayout(2, false));
    final ImageCombo strokeWidthCombo = new ImageCombo(strokeComposite, SWT.READ_ONLY);
    GridData gridDataWidth = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridDataWidth.widthHint = 30;
    strokeWidthCombo.setLayoutData(gridDataWidth);
    strokeWidthCombo.add("1", img1);
    strokeWidthCombo.add("2", img2);
    strokeWidthCombo.add("3", img3);
    strokeWidthCombo.add("4", img4);
    strokeWidthCombo.add("5", img5);
    strokeWidthCombo.select(0);
    strokeWidthCombo.setToolTipText("stroke width");
    strokeWidthCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = strokeWidthCombo.getSelectionIndex();
            int strokeWidth = STROKES[selectedIndex];

            AnnotationPlugin.getDefault().setCurrentStrokeWidth(strokeWidth);
            double scale = ApplicationGIS.getActiveMap().getViewportModel().getScaleDenominator();
            AnnotationPlugin.getDefault().setCurrentScale(scale);
        }
    });

    // alpha
    final Combo alphaCombo = new Combo(strokeComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    alphaCombo.setLayoutData(gridData2);
    String[] items = new String[ALPHAS.length];
    for (int i = 0; i < items.length; i++) {
        items[i] = ALPHAS[i] + "%";
    }
    alphaCombo.setItems(items);
    alphaCombo.select(ALPHAS.length - 1);
    alphaCombo.setToolTipText("stroke alpha");
    alphaCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = alphaCombo.getSelectionIndex();
            int alphaInPercent = ALPHAS[selectedIndex];
            int strokeAlpha = 255 * alphaInPercent / 100;

            Color c = AnnotationPlugin.getDefault().getCurrentStrokeColor();
            AnnotationPlugin.getDefault()
                    .setCurrentStrokeColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), strokeAlpha));
        }
    });

    // color
    // final Label strokeColLabel = new Label(propsComposite, SWT.NONE);
    // strokeColLabel.setText("Stroke color");
    final ColorSelector cs = new ColorSelector(propsComposite);
    RowData rd1 = new RowData();
    rd1.height = 30;
    rd1.width = 50;
    cs.getButton().setLayoutData(rd1);
    // new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    int[] cc = AnnotationPlugin.getDefault().getCurrentStrokeColorInt();
    cs.setColorValue(new RGB(cc[0], cc[1], cc[2]));
    cs.getButton().setToolTipText("stroke color");
    cs.getButton().addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            RGB rgb = cs.getColorValue();
            int alpha = AnnotationPlugin.getDefault().getCurrentStrokeColorInt()[3];
            AnnotationPlugin.getDefault().setCurrentStrokeColor(new Color(rgb.red, rgb.green, rgb.blue, alpha));
        }
    });

    // clear all
    ImageDescriptor clearID = AbstractUIPlugin.imageDescriptorFromPlugin(AnnotationPlugin.PLUGIN_ID,
            "icons/trash.gif"); //$NON-NLS-1$
    final Button clearButton = new Button(propsComposite, SWT.PUSH);
    // GridData gd1 = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    // clearButton.setLayoutData(gd1);
    RowData rd2 = new RowData();
    rd2.height = 30;
    rd2.width = 50;
    clearButton.setLayoutData(rd2);
    clearButton.setImage(clearID.createImage());
    clearButton.setToolTipText("clear the area from all drawings");
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            boolean answer = MessageDialog.openQuestion(clearButton.getShell(), "Removal warning",
                    "Do you really want to remove all annotations?");
            if (!answer) {
                return;
            }

            AnnotationPlugin.getDefault().getStrokes().clear();
            JGrassCatalogUtilities.getMapgraphicLayerByClass(AnnotationLayerMapGraphic.class).refresh(null);
        }
    });

    // clear last
    ImageDescriptor clearLast = AbstractUIPlugin.imageDescriptorFromPlugin(AnnotationPlugin.PLUGIN_ID,
            "icons/trashlast.gif"); //$NON-NLS-1$
    Button clearLastButton = new Button(propsComposite, SWT.PUSH);
    RowData rd3 = new RowData();
    rd3.height = 30;
    rd3.width = 50;
    clearLastButton.setLayoutData(rd3);
    // GridData gd2 = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    // clearLastButton.setLayoutData(gd2);
    clearLastButton.setImage(clearLast.createImage());
    clearLastButton.setToolTipText("remove last stroke from annotations layer");
    clearLastButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            List<DressedWorldStroke> strokes = AnnotationPlugin.getDefault().getStrokes();
            int size = strokes.size();
            if (size < 1)
                return;
            strokes.remove(size - 1);
            JGrassCatalogUtilities.getMapgraphicLayerByClass(AnnotationLayerMapGraphic.class).refresh(null);
        }
    });

}

From source file:eu.hydrologis.jgrass.beegisutils.utils.ImageCache.java

License:Open Source License

private Image createImage(String key) {
    ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(BeegisUtilsPlugin.PLUGIN_ID, key);
    Image image = id.createImage();
    return image;
}

From source file:eu.hydrologis.jgrass.database.utils.ImageCache.java

License:Open Source License

private Image createImage(String key) {
    ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(DatabasePlugin.PLUGIN_ID, key);
    Image image = id.createImage();
    return image;
}

From source file:eu.hydrologis.jgrass.formeditor.utils.ImageCache.java

License:Open Source License

private Image createImage(String key) {
    ImageDescriptor id = AbstractUIPlugin.imageDescriptorFromPlugin(FormEditorPlugin.PLUGIN_ID, key);
    Image image = id.createImage();
    return image;
}

From source file:eu.hydrologis.jgrass.geonotes.util.ImageManager.java

License:Open Source License

private void createImages() {
    try {/*  w w  w  . j  av a2s  . com*/
        URL fileURL = FileLocator.find(Platform.getBundle(GeonotesPlugin.PLUGIN_ID), new Path(path), null);
        fileURL = FileLocator.toFileURL(fileURL);
        String fileUrlPath = fileURL.getPath();
        ImageIcon ii = new ImageIcon(fileUrlPath);
        Image awtImage = ii.getImage();

        ImageDescriptor iD = AbstractUIPlugin.imageDescriptorFromPlugin(GeonotesPlugin.PLUGIN_ID, path);
        org.eclipse.swt.graphics.Image swtImage = iD.createImage();

        awtImageMap.put(path, awtImage);
        swtImageMap.put(path, swtImage);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:eu.hydrologis.jgrass.ui.utilities.editors.SimpleSWTImageEditor.java

License:Open Source License

/**
 * Constructor for the image editor.//from  ww  w .j  a  v a 2  s  .c  om
 * 
 * @param parent the parent composite.
 * @param style the swt style for the component.
 * @param preloadedLines a list of lines to be drawn.
 * @param backGroundImage a background image to use in the canvas.
 * @param minScroll the minimum dimension for the scrolling.
 * @param doZoom flag that defines if the zoom tools should be added.
 */
public SimpleSWTImageEditor(Composite parent, int style, List<DressedStroke> preloadedLines,
        Image backGroundImage, Point minScroll, boolean doZoom) {
    this.doZoom = doZoom;
    if (backGroundImage != null)
        this.backImage = backGroundImage;
    if (preloadedLines == null) {
        this.lines = new ArrayList<DressedStroke>();
    } else {
        this.lines = preloadedLines;
    }
    mainComposite = new Composite(parent, style);
    mainComposite.setLayout(new GridLayout());
    propsComposite = new Composite(mainComposite, style);
    propsComposite.setLayout(new RowLayout());
    propsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

    // stroke width
    Image img1 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_1.png").createImage();
    Image img2 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_2.png").createImage();
    Image img3 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_3.png").createImage();
    Image img4 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_4.png").createImage();
    Image img5 = AbstractUIPlugin
            .imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID, "/icons/strokewidth_5.png").createImage();

    Composite strokeComposite = new Composite(propsComposite, SWT.None);
    strokeComposite.setLayout(new GridLayout(2, false));

    final ImageCombo strokeWidthCombo = new ImageCombo(strokeComposite, SWT.READ_ONLY);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.widthHint = 30;
    strokeWidthCombo.setLayoutData(gridData);
    strokeWidthCombo.add("1", img1);
    strokeWidthCombo.add("2", img2);
    strokeWidthCombo.add("3", img3);
    strokeWidthCombo.add("4", img4);
    strokeWidthCombo.add("5", img5);
    strokeWidthCombo.select(0);
    strokeWidthCombo.setToolTipText("stroke width");
    strokeWidthCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = strokeWidthCombo.getSelectionIndex();
            strokeWidth[0] = STROKES[selectedIndex];
        }
    });

    // alpha
    final Combo alphaCombo = new Combo(strokeComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    alphaCombo.setLayoutData(gridData2);
    String[] items = new String[ALPHAS.length];
    for (int i = 0; i < items.length; i++) {
        items[i] = ALPHAS[i] + "%";
    }
    alphaCombo.setItems(items);
    alphaCombo.select(ALPHAS.length - 1);
    alphaCombo.setToolTipText("stroke alpha");
    alphaCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            int selectedIndex = alphaCombo.getSelectionIndex();
            int alphaInPercent = ALPHAS[selectedIndex];
            strokeAlpha = 255 * alphaInPercent / 100;
        }
    });

    Composite buttonsComposite = new Composite(propsComposite, SWT.NONE);
    if (doZoom) {
        buttonsComposite.setLayout(new GridLayout(6, false));
    } else {
        buttonsComposite.setLayout(new GridLayout(3, false));
    }

    // color
    final ColorSelector cs = new ColorSelector(buttonsComposite);
    Button csButton = cs.getButton();
    GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData3.widthHint = 25;
    csButton.setLayoutData(gridData3);

    cs.setColorValue(new RGB(strokeRGB[0], strokeRGB[1], strokeRGB[2]));
    cs.getButton().setToolTipText("stroke color");
    cs.getButton().addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            RGB rgb = cs.getColorValue();
            strokeRGB = new int[] { rgb.red, rgb.green, rgb.blue };
        }
    });

    // clear all
    ImageDescriptor clearID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
            "icons/trash.gif"); //$NON-NLS-1$
    Button clearButton = new Button(buttonsComposite, SWT.BORDER | SWT.PUSH);
    clearButton.setImage(clearID.createImage());
    clearButton.setToolTipText("clear the area from drawings");
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            lines.removeAll(lines);
            drawArea.redraw();
        }
    });
    // clear shape
    ImageDescriptor removeID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
            "icons/close.gif"); //$NON-NLS-1$
    Button removeButton = new Button(buttonsComposite, SWT.BORDER | SWT.PUSH);
    removeButton.setImage(removeID.createImage());
    removeButton.setToolTipText("remove selected line");
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            isRemoveMode = true;
            final Cursor cursor = new Cursor(drawArea.getDisplay(), SWT.CURSOR_CROSS);
            drawArea.setCursor(cursor);
        }
    });

    if (doZoom) {
        // zoom all
        ImageDescriptor zoomAllID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
                "icons/zoom_all.gif"); //$NON-NLS-1$
        Button zoomAllButton = new Button(buttonsComposite, SWT.PUSH);
        zoomAllButton.setImage(zoomAllID.createImage());
        zoomAllButton.setToolTipText("zoom to the whole extend");
        zoomAllButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                calculateBaseScaleFactor();
                scaleFactor = baseScaleFactor;
                drawArea.redraw();
            }
        });

        // zoom in
        ImageDescriptor zoomInID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
                "icons/zoom_in.gif"); //$NON-NLS-1$
        Button zoomInButton = new Button(buttonsComposite, SWT.PUSH);
        zoomInButton.setImage(zoomInID.createImage());
        zoomInButton.setToolTipText("zoom in");
        zoomInButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                scaleFactor = scaleFactor * 1.2;
                drawArea.redraw();
            }
        });

        // zoom out
        ImageDescriptor zoomOutID = AbstractUIPlugin.imageDescriptorFromPlugin(UiUtilitiesPlugin.PLUGIN_ID,
                "icons/zoom_out.gif"); //$NON-NLS-1$
        Button zoomOutButton = new Button(buttonsComposite, SWT.PUSH);
        zoomOutButton.setImage(zoomOutID.createImage());
        zoomOutButton.setToolTipText("zoom out");
        zoomOutButton.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                scaleFactor = scaleFactor / 1.2;
                drawArea.redraw();
            }
        });
    }

    drawAreaScroller = new ScrolledComposite(mainComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    drawArea = new Canvas(drawAreaScroller, SWT.None);
    defaultCursor = drawArea.getCursor();
    drawAreaScroller.setContent(drawArea);
    drawAreaScroller.setExpandHorizontal(true);
    drawAreaScroller.setExpandVertical(true);
    if (minScroll != null) {
        drawAreaScroller.setMinWidth(minScroll.x);
        drawAreaScroller.setMinHeight(minScroll.y);
    }
    drawAreaScroller.setLayoutData(
            new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));

    Listener drawListener = new Listener() {
        int lastX = 0, lastY = 0;
        List<Integer> line = null;
        GC gc = null;

        public void handleEvent(Event event) {

            /*
             * REMOVE MODE
             */
            if (isRemoveMode && event.type == SWT.MouseDown) {
                for (int i = 0; i < lines.size(); i++) {
                    DressedStroke stroke = lines.get(i);
                    int x = event.x;
                    int y = event.y;
                    int[] nodes = stroke.getScaledNodes(baseScaleFactor);
                    for (int j = 0; j < nodes.length - 1; j = j + 2) {
                        Point2f linePoint = new Point2f(nodes[j], nodes[j + 1]);
                        Point2f clickPoint = new Point2f(x, y);
                        int threshold = stroke.strokeWidth[0];
                        threshold = (int) Math.round((double) threshold * baseScaleFactor);
                        threshold = threshold < 10 ? 10 : threshold;
                        if (clickPoint.distance(linePoint) < threshold) {
                            lines.remove(i);
                            isRemoveMode = false;
                            drawArea.setCursor(defaultCursor);
                            drawArea.redraw();
                            return;
                        }
                    }

                }

            }
            if (isRemoveMode && (event.type == SWT.MouseMove || event.type == SWT.MouseUp)) {
                return;
            }

            /*
             * DRAWING MODE
             */
            if (scaleFactor == -1) {
                calculateBaseScaleFactor();
                scaleFactor = baseScaleFactor;
            }

            switch (event.type) {
            case SWT.Paint:
                if (drawnImage != null)
                    drawnImage.dispose();
                drawnImage = new Image(drawArea.getDisplay(), drawArea.getBounds());
                GC gcImage = new GC(drawnImage);
                // draw the background image
                if (backImage != null) {
                    Rectangle imgBounds = backImage.getBounds();
                    ImageData newImageData = backImage.getImageData().scaledTo(
                            (int) Math.round(imgBounds.width * scaleFactor),
                            (int) Math.round(imgBounds.height * scaleFactor));
                    Image newImage = new Image(drawArea.getDisplay(), newImageData);
                    gcImage.drawImage(newImage, 0, 0);
                }
                // draw the lines
                for (int i = 0; i < lines.size(); i = i + 1) {
                    DressedStroke tmpStroke = lines.get(i);
                    gcImage.setLineWidth((int) Math.round(tmpStroke.strokeWidth[0] * scaleFactor));
                    gcImage.setLineCap(SWT.CAP_ROUND);
                    gcImage.setLineJoin(SWT.JOIN_ROUND);
                    gcImage.setLineStyle(SWT.LINE_SOLID);
                    int[] rgb = tmpStroke.rgb;
                    gcImage.setForeground(new Color(drawArea.getDisplay(), rgb[0], rgb[1], rgb[2]));
                    gcImage.setAlpha(tmpStroke.strokeAlpha);
                    int[] nodes = tmpStroke.getScaledNodes(scaleFactor);
                    // at least 4 values to have two points
                    if (nodes.length > 3) {
                        Path p = new Path(drawArea.getDisplay());
                        p.moveTo(nodes[0], nodes[1]);
                        for (int j = 2; j < nodes.length - 1; j = j + 2) {
                            p.lineTo(nodes[j], nodes[j + 1]);
                        }
                        gcImage.drawPath(p);
                    }
                }
                gc = new GC(drawArea);
                gc.drawImage(drawnImage, 0, 0);

                gcImage.dispose();

                break;
            case SWT.MouseMove:
                if ((event.stateMask & SWT.BUTTON1) == 0)
                    break;
                if (line == null)
                    break;
                line.add(event.x);
                line.add(event.y);
                gc = new GC(drawArea);
                gc.setLineWidth((int) Math.round(strokeWidth[0] * scaleFactor));
                gc.setLineCap(SWT.CAP_ROUND);
                gc.setLineJoin(SWT.JOIN_ROUND);
                gc.setLineStyle(SWT.LINE_SOLID);
                Color color = new Color(drawArea.getDisplay(), strokeRGB[0], strokeRGB[1], strokeRGB[2]);
                gc.setForeground(color);
                gc.setAlpha(255 * strokeAlpha / 100);
                gc.drawLine(lastX, lastY, event.x, event.y);
                lastX = event.x;
                lastY = event.y;
                gc.dispose();
                color.dispose();
                break;
            case SWT.MouseDown:
                if (isRemoveMode) {
                    break;
                }
                lastX = event.x;
                lastY = event.y;
                line = new ArrayList<Integer>();
                line.add(lastX);
                line.add(lastY);
                isDrawMode = true;
                break;
            case SWT.MouseUp:
                if (isRemoveMode || !isDrawMode)
                    break;

                lastX = event.x;
                lastY = event.y;
                DressedStroke newLine = new DressedStroke();
                newLine.nodes = new int[line.size()];
                for (int i = 0; i < line.size(); i++) {
                    newLine.nodes[i] = (int) Math.round((double) line.get(i) / scaleFactor);
                }
                newLine.strokeAlpha = strokeAlpha;
                newLine.strokeWidth = new int[] { strokeWidth[0] };
                newLine.rgb = new int[] { strokeRGB[0], strokeRGB[1], strokeRGB[2] };
                lines.add(newLine);
                line.clear();
                drawArea.redraw();
                break;

            }
        }
    };

    drawArea.addListener(SWT.MouseDown, drawListener);
    drawArea.addListener(SWT.MouseMove, drawListener);
    drawArea.addListener(SWT.MouseUp, drawListener);
    drawArea.addListener(SWT.Paint, drawListener);

    // add popup menu
    MenuManager popManager = new MenuManager();
    Menu menu = popManager.createContextMenu(drawArea);
    drawArea.setMenu(menu);
    IAction menuAction = new SaveAction(this);
    popManager.add(menuAction);

}

From source file:eu.numberfour.n4js.tests.bugs.GH_170_ImageCaching_PluginUITest.java

License:Open Source License

/**
 * Checks the indirect {@link Image image} caching.
 *///  w  w w  .jav  a  2 s.  c om
@Test
public void testIndirectImageCaching() {
    final ImageDescriptor desc1 = ImageRef.LIB_PATH.asImageDescriptor().orNull();
    final ImageDescriptor desc2 = ImageRef.LIB_PATH.asImageDescriptor().orNull();
    final Image img1 = desc1.createImage();
    final Image img2 = desc2.createImage();
    assertTrue("Expected different reference of images.", img1 != img2);
}

From source file:eu.numberfour.n4js.xpect.ui.results.XpectLabelProvider.java

License:Open Source License

@Override
public Image getImage(Object element) {
    ImageDescriptor descriptor = getImageDescriptor(element);

    if (descriptor == null) {
        return null;
    }/*w  ww  . j av  a2  s. c om*/

    // obtain the cached image corresponding to the descriptor
    Image image = imageCache.get(descriptor);
    if (image == null) {
        image = descriptor.createImage();
        imageCache.put(descriptor, image);
    }
    return image;

}