Home » Eclipse Projects » Nebula » Eclipse PaperClip vs Google PaperClip(Which one to choose)
| |
Re: Eclipse PaperClip vs Google PaperClip [message #653071 is a reply to message #653031] |
Tue, 08 February 2011 11:01 |
tenor Messages: 57 Registered: October 2010 |
Member |
|
|
public Print printImage() {
// Image image = null;
int h =0;
int w = 0;
GC gc = null;
//GraphicalViewer graphicalViewer = null;
GraphicalViewer graphicalViewer = new ScrollingGraphicalViewer();
ScalableFreeformRootEditPart rootEditPart =
(ScalableFreeformRootEditPart)
graphicalViewer.getEditPartRegistry().get(LayerManager.ID);
graphicalViewer.setEditDomain(new DefaultEditDomain(null));
graphicalViewer.setRootEditPart(new ScalableFreeformRootEditPart());
graphicalViewer.setEditPartFactory(new MYEditPartFactory(context));
graphicalViewer.setContents(getContents());
graphicalViewer.flush();
IFigure rootFigure = ((LayerManager)
rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
// rootFigure.add(new TLDSatellitePart());
Printer printer = new Printer(new PrinterData());
DefaultGridLook look = new DefaultGridLook();
look.setCellBorder(new LineBorder());
GridPrint grid = new GridPrint(look);
IFigure topFigure = new Figure();
//topFigure.add(new MYLoadingFigure());
topFigure.add(new MYEditPartFactory(context))
//Rectangle r = topFigure.getBounds().getCopy();
Rectangle r = rootFigure.getBounds().getCopy();
//h = r.height;
//w = r.width;
w = topFigure.getBounds().width;
h = topFigure.getBounds().height;
/*h = 10;
w= 20;*/
Image image = new Image(printer, w, h);
//Image image = new Image(printer,r.getSize().width, r.getSize().height);
gc = new GC(image);
//gc.drawRectangle(0, 0, 50, 70);
SWTGraphics g = new SWTGraphics(gc);
//g.translate(r.x * -1, r.y * -1);
g.translate(w -1, h -1);
topFigure.paint(g);
grid.add(new ImagePrint(image.getImageData()));
// grid.add( new ImagePrint(imageData));
//return new BigPrint(grid);
return new BigPrint(grid);
}
I get exception as
java.lang.ClassCastException: org.eclipse.gef.editparts.ScalableRootEditPart cannot be cast to org.eclipse.gef.editparts.ScalableFreeformRootEditPart
My Qs are
1) Is it the right way of getting IFigure and hooking to GEF piece of code through, MYEditPartFactory, as i have seen
in PrintLogicExample of GEF.
2) is paperclip suited for printing GEF, if so, how.
3) How image is to be used? if i donot need to use image, ie want GEF screen to be printed to printer
can i do gc = new GC(printer) , donot think so, so , how to get gc ?
Ignore the comment out portion,as i earlier i tried for getting Ifigure but it was all null, during debug.
Hope to have EARLY reply.
|
|
|
Re: Eclipse PaperClip vs Google PaperClip [message #653259 is a reply to message #653071] |
Wed, 09 February 2011 04:59 |
Matthew Hall Messages: 368 Registered: July 2009 |
Senior Member |
|
|
There was a question about this some time ago (back when the project was
still on Sourceforge). The solution:
http://sourceforge.net/tracker/index.php?func=detail&aid =1633591&group_id=148509&atid=771875
If you want to print a figure with higher fidelity, you'll need to
implement FigurePrint, FigureIterator and FigurePiece.
class FigurePrint implements Print {
private IFigure figure;
public FigurePrint(IFigure figure) {
this.figure = figure;
}
public PrintIterator iterator(Device device, GC gc) {
return new FigureIterator(figure, device, gc);
}
}
class FigureIterator implements PrintIterator {
public FigureIterator(IFigure figure, Device device, GC gc) {
...
}
...
public PrintPiece next(int width, int height) {
if (width and height big enough) {
return new FigurePiece(figure, device, gc);
}
}
}
class FigurePiece implements PrintPiece {
private SWTGraphics graphics;
public void paint(GC gc, int x, int y) {
if (graphics == null) {
graphics = new SWTGraphics(gc);
}
graphics.translate(x, y);
try {
figure.setSize(width, height);
figure.paint(graphics);
}
finally {
graphics.translate(-x, -y);
}
}
public void dispose() {
graphics.dispose();
}
}
Obviously there are several missing parts here that you will need to
fill in, but this should get you going.
One problem you may come across is that pixel density is much lower on a
monitor (typically 72DPI) vs printers which range between 300-600DPI, so
the lines in the figure may not scale relative to the font sizes.
Potentially you could get around this by calling graphics.scale()
instead of figure.setSize(), so that the whole figure scales.
Hope this helps,
Matthew
|
|
| | | | | | |
Goto Forum:
Current Time: Mon Sep 23 02:50:09 GMT 2024
Powered by FUDForum. Page generated in 0.07204 seconds
|