Is this a legal way to create an image? [message #249140] |
Wed, 03 June 2009 19:04 |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03398 seconds