Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Is this a legal way to create an image?
Is this a legal way to create an image? [message #249140] Wed, 03 June 2009 19:04 Go to next message
Eclipse UserFriend
Originally posted by: thomas.cranksoftware.com

I have an application that displays layers similarly to Photoshop, but there are
some circumstances where the layer that I want to display is not part of the
active model, and so it doesn't have an EditPart (or an IFigure) associated
with it.

I want to create thumbnails of these items, so I've crafted a bit of code that
looks something like:

protected void displayThumbnail(Object modelObject) {
IFigure modelFigure = getModelObjectFigure(modelObject);
if(modelFigure != null) {
... Use the standard Thumbnail in an SWT widget
} else {
Image image = createLayerImage(modelObject);
... Use the image in an SWT widget
}
}

The createLayerImage() routine is where I'm wondering how completely out to
lunch I am and what issues I should be aware of (or if there is a better
way to achieve what I want ... drawing a not-yet-existing model object to
an SWT Image):

protected Image createLayerImage(Object layer) {
ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
viewer.setEditPartFactory(new MyEditPartFactory());
viewer.setContents(layer);

Map map = viewer.getEditPartRegistry();
GraphicalEditPart ep = (GraphicalEditPart)map.get(layer);
IFigure rootFigure = ep.getFigure();

ep.refresh();

rootFigure.setSize(getWidth(), getHeight());
rootFigure.getLayoutManager().layout(rootFigure);

ep.refresh();

Image image = new Image(null, app.getWidth(), app.getHeight());
GC gc = new GC(image);

SWTGraphics graphics = new SWTGraphics(gc);
rootFigure.paint(graphics);
graphics.dispose();

gc.dispose();

return image;
}

Any and all comments appreciated.

Thanks,
Thomas
---
http://www.cranksoftware.com
Re: Is this a legal way to create an image? [message #249151 is a reply to message #249140] Thu, 04 June 2009 05:14 Go to previous messageGo to next message
Alex Boyko is currently offline Alex BoykoFriend
Messages: 200
Registered: July 2009
Senior Member
Hi,

Doesn't seem to be legal.

I'll try to sketch something that I'd do:

protected Image createLayerImage(Object modelObject) {
Shell shell = new Shell(PlatformUI.getWorkbench().getDisplay());
ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
viewer.createControl(shell);

viewer.setEditPartFactory(new MyEditPartFactory());
viewer.setContents(layer);

/*
* may be unnecessary
* start
*/
viewer.setEditDomain(new DefaultEditDomain());
/*
* may want to attch the command stack and etc.
* end.
*/
/* better to set the root editpart that you have for your viewer */
viewer.setRootEditPart(new ScalableRootEditPart());

viewer.setEditPartFactory(new MyCustomEditPartFactory);

/*
* if your image layer can be contained by the root. Otherwise you might
want *to generate a diagram model that containts your modelObject
*/
viewer.setContents(modelObject);

/*
* flush all viewer events.
*/
viewer.flush();

/*
* flush all deferred layout and paints from the Display
*/
while (shell.getDisplay().readAndDispatch());

/*
* Now export to image (the root or the figure for contents editpart)
*/


IFigure figure = ((LayerManager)
viewer.getRootEditPart()).getLayer(MY_IMAGE_LAYER);


Image image = new Image(shell.getDisplay(), figure.getBounds().width,
app.getBounds().height);


GC gc = new GC(image);

SWTGraphics graphics = new SWTGraphics(gc);
figure.paint(graphics);
graphics.dispose();

gc.dispose();

return image;
}
Re: Is this a legal way to create an image? [message #510416 is a reply to message #249151] Wed, 27 January 2010 13:46 Go to previous message
Brezensalzer Mising name is currently offline Brezensalzer Mising nameFriend
Messages: 11
Registered: January 2010
Junior Member
I want to make a picture of the full [/SIZE]gef(scrollingGraphicalViewer). I get the picture in the right size, but i became not the whole components. But if I run the Method a second time, I get the whole image of all components.

Code:

ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart)graphicalViewer.getRootEditPar t();

IFigure rootFigure = rootEditPart.getLayer(ScalableFreeformRootEditPart.PRINTABLE _LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
Image img = new Image(null, rootFigureBounds.width, rootFigureBounds.height);
GC imageGC = new GC(img);
Graphics graphics = new SWTGraphics(imageGC);
rootFigure.paint(graphics);

ImageLoader imgLoader = new ImageLoader();
imgLoader.data = new ImageData[] { img.getImageData() };
imgLoader.save(m_IreportDir + "test.jpeg", SWT.IMAGE_JPEG);
Previous Topic:How to create read only properties in properties view.
Next Topic:show image during dragging
Goto Forum:
  


Current Time: Sat Dec 21 15:45:35 GMT 2024

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

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

Back to the top