Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How do I copy a part of Zest Graph to SWT Canvas
How do I copy a part of Zest Graph to SWT Canvas [message #1393256] Thu, 03 July 2014 13:55
Nikolaos Koutsopoulos is currently offline Nikolaos KoutsopoulosFriend
Messages: 1
Registered: July 2014
Junior Member
Hi all,

I am developing a new Eclipse plug-in, using the GEF (Draw2d 3.9, Zest 1.5.0) with custom figures in order to represent some data. I am now trying to develop an adjustable lens view. The desired functionality is that the mouse will be dragged on the main window, and the "lens view window" will represent the selected area.

To do that I use a window with a SWT canvas for the lens view. The main window's (graph) contents are painted in the lens canvas. Then I copy another area (could be outside from the visible area) of the lens canvas to the point 0,0 (of the lens canvas). The problem is that the lens canvas ignores everything that is painted outside its visible area and when I copy the above mentioned area I get black instead of contents.

Copying the graph's contents to image and after that to drawing a part of the image is not a solution, because my graph might be gigantic (> 200000 x 200000).

Below you can find a part of my code and a screen shoot with the problem:

import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;

public class LensView {
private final Shell shell;
private final Canvas canvas;

private final Point focalPoint;
private float lensScaleFactor;
private float mainScaleFactor;

public LensView(final Graph graph, Display d) {
    this.visualizer = visualizer;
    focalPoint = new Point(0, 0);

    lensScaleFactor     = 1.0f;
    mainScaleFactor = 1.0f;

    shell = new Shell(d, SWT.SHELL_TRIM);
    shell.setSize(640, 480);
    shell.setLayout(new FillLayout());  
    canvas = new Canvas(shell, SWT.NO_REDRAW_RESIZE);
    canvas.setLayout(new FillLayout());

    canvas.addPaintListener(new PaintListener() {   
        @Override
        public void paintControl(PaintEvent e) {
            Rectangle area  = getClientArea();
            float scale = lensScaleFactor/mainScaleFactor; 

            Point viewLocation = graph.getViewport().getViewLocation();
            int tmpx = normaliseDec(Math.round((focalPoint.x + viewLocation.x) * scale) - Math.round(area.width/2.0f));
            int tmpy = normaliseDec(Math.round((focalPoint.y + viewLocation.y) * scale) - Math.round(area.height/2.0f));

            GC gc = new GC(canvas);
            SWTGraphics graphics = new SWTGraphics(gc);
            graphics.scale(scale);  
            graph.getContents().paint(graphics);                

            e.gc.copyArea(tmpx, tmpy, area.width, area.height, 0, 0);

            graphics.dispose();
            gc.dispose();
        }
    });
}

public void redraw (int x, int y) {
    focalPoint.x = normaliseDec(x);
    focalPoint.y = normaliseDec(y);
    canvas.redraw();
    canvas.update();
}

private int normaliseDec (int i) {
    return i < 0 ? 0 : i;
}

}
  • Attachment: Selection.png
    (Size: 31.15KB, Downloaded 193 times)

[Updated on: Fri, 04 July 2014 07:06]

Report message to a moderator

Previous Topic:Add button to palette
Next Topic:Export a GEF diagram as a PNG
Goto Forum:
  


Current Time: Thu Apr 25 19:54:08 GMT 2024

Powered by FUDForum. Page generated in 0.03439 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top