Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Capturing drawing image WITHOUT showing it on screen
Capturing drawing image WITHOUT showing it on screen [message #210947] Tue, 07 March 2006 11:33 Go to next message
Eclipse UserFriend
Originally posted by: vikram.sjn+eclipsezone.gmail.com

------=_Part_5883_14232826.1141731370560
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

In a particular scenario, I have to grab image of draw2d drawing WITHOUT showing it on screen. So on the interface, I have a button which when pressed should internally draw the drawing and grab its image.

I wrote following code, but only the last shape is drawn on the image, that too to the top left corner. What should be done to resolve the problem (please ignore the background color in the image).

Please help. Thanks

//-------------------------
final LightweightSystem lws = new LightweightSystem(canvas);
final IFigure panel = new Figure();
panel.setLayoutManager(new FlowLayout());
lws.setContents(panel);

Shape rectangle = new RectangleFigure();
rectangle.setBackgroundColor(ColorConstants.lightBlue);
Shape ellipse = new Ellipse();
ellipse.setBackgroundColor(ColorConstants.yellow);
Clickable button = new Button("Click me");

panel.add(button);
panel.add(ellipse);
panel.add(rectangle);

Display display = Display.getDefault();

Image image = new Image(display, 1152, 864);
Rectangle bounds = image.getBounds();

GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
panel.paint(graphics);

ImageUtils.saveImage(image, "widgetImage.jpg", SWT.IMAGE_JPEG);
//----------------------end
------=_Part_5883_14232826.1141731370560
Content-Type: image/gif; name=CapturedImage.gif
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=CapturedImage.gif

R0lGODdhqABIAOcAAAcGAAUNAAsEAAwLAAYRAAsSABEEABMLABkKABMSABQZ ABoUABoZACMaACci
AFxXW2VsS2xtTmVkW2ZoXGhnUmhgXWptXm5xTG10U25xXnNlS3JjUHxyTnV4 U3Z5WmdnZ2psYm1v
bG1kd21wZHdkZnFuZHJrc3hrdXF0ZXN0aXZ5bHd4cn50fHt9cndfgXxxgX9z i32FboN2TI1/UIFr
h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CKAwQsqUAMAKACvBFAAAGpQgRfAQAQmkAAF ItCBC3ggAzaYwAhU
YIEZz3gEYFZBCnSKYi11qB75QIn+PjqykTajhB3syIc7zJESj9gDze2IR098 Eo92cIQe9siIRszh
jnzA2c1t7kiac1JmM5egKRiZR6CVEmh9oMPS+rBHplPSkUvbQ9OXZvOmQY3p fUw6KfaQtKDb22iu
lUAj9qBHnZmiD3okJSW6WLNQ8nGOlIAkJefQCUrqsQ9dCDoptn5KSuiR7Fb3 NNNLATRGyrGUZVc7
zSi5tEZ+fWlsS8rWKVEKtecha1o7e0MCsYyxZr3qW4e73XVGirHOjbN0Vybe 625zvlet5lXLm9X0
RvejNbMRnZhkKJTRiMFNkuaAV87eVJm3UoTCcDX/O80HR0m1Ae5w73QI3yBX OMiz2z3xiec73hYP
ebw7XttXqxzfCGd3wv+dcHfXedEvXznL3zvwiDN81ti2+K8Vjm1/G1ziO09x z6dicItnRNgpHzrG
NZ4ThiddlUuXir6vlBOk27zfEwf71ZU+dpZDvOz0Pjvana32tTe67W5HMdzj Ttu5072rdr97RvOu
927yve+p/Dvg7yj4wROx8IbHIOITT7/FMz55jn98/SS/96xTnvCWv/zhM695 xXO+843/POiTFxAA
Ow==
------=_Part_5883_14232826.1141731370560--
Re: Capturing drawing image WITHOUT showing it on screen [message #210956 is a reply to message #210947] Tue, 07 March 2006 11:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vikram.sjn+eclipsezone.gmail.com

oops ! Code in previous post is slightly incorrect.
Correct code follows...

//-------------------
final LightweightSystem lws = new LightweightSystem(canvas);
final IFigure panel = new Figure();
panel.setLayoutManager(new FlowLayout());
lws.setContents(panel);

Clickable button = new Button("Click me");
Clickable checkbox = new CheckBox("Check box");

Shape ellipse = new Ellipse();
ellipse.setBackgroundColor(ColorConstants.yellow);

panel.add(button);
panel.add(checkbox);
panel.add(ellipse);

Display display = Display.getDefault();

Image image = new Image(display, 1152, 864);
Rectangle bounds = image.getBounds();

GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
panel.paint(graphics);

ImageUtils.saveImage(image, "widgetImage.jpg", SWT.IMAGE_JPEG);
//-------------------end

Thanks
Re: Capturing drawing image WITHOUT showing it on screen [message #211004 is a reply to message #210947] Tue, 07 March 2006 17:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

The logic example contains a print diagram action which prints a .logic file
without opening or displaying an editor.

Perhaps you aren't setting a font?

"Vikram Sujanani" <vikram.sjn+eclipsezone@gmail.com> wrote in message
news:1567005.1141731370562.JavaMail.root@cp1.javalobby.org...
> Hi,
>
> In a particular scenario, I have to grab image of draw2d drawing WITHOUT
> showing it on screen. So on the interface, I have a button which when
> pressed should internally draw the drawing and grab its image.
>
> I wrote following code, but only the last shape is drawn on the image,
> that too to the top left corner. What should be done to resolve the
> problem (please ignore the background color in the image).
>
> Please help. Thanks
>
> //-------------------------
> final LightweightSystem lws = new LightweightSystem(canvas);
> final IFigure panel = new Figure();
> panel.setLayoutManager(new FlowLayout());
> lws.setContents(panel);
>
> Shape rectangle = new RectangleFigure();
> rectangle.setBackgroundColor(ColorConstants.lightBlue);
> Shape ellipse = new Ellipse();
> ellipse.setBackgroundColor(ColorConstants.yellow);
> Clickable button = new Button("Click me");
>
> panel.add(button);
> panel.add(ellipse);
> panel.add(rectangle);
>
> Display display = Display.getDefault();
>
> Image image = new Image(display, 1152, 864);
> Rectangle bounds = image.getBounds();
>
> GC gc = new GC(image);
> SWTGraphics graphics = new SWTGraphics(gc);
> panel.paint(graphics);
>
> ImageUtils.saveImage(image, "widgetImage.jpg", SWT.IMAGE_JPEG);
> //----------------------end
Re: Capturing drawing image WITHOUT showing it on screen [message #211131 is a reply to message #211004] Wed, 08 March 2006 10:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vikram.sjn+eclipsezone.gmail.com

Thanks for replying, and indicating the 'print' function on logic example.

Now I have set the font, but there is no change - still only the last shape is available in the image.

Any other clues?
Re: Capturing drawing image WITHOUT showing it on screen [message #211147 is a reply to message #211131] Wed, 08 March 2006 13:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vikram.sjn+eclipsezone.gmail.com

Typically printing too has the same problem - only the last shape is drawn.

Here is the code...

//----------------------
final LightweightSystem lws = new LightweightSystem(shell);
final IFigure panel = new Figure();
panel.setLayoutManager(new FlowLayout());
lws.setContents(panel);

Clickable button = new Button("Click me");
Clickable checkbox = new CheckBox("Check box");
Shape ellipse = new Ellipse();
ellipse.setBackgroundColor(ColorConstants.yellow);
Shape rectangle = new RectangleFigure();
rectangle.setBackgroundColor(ColorConstants.lightBlue);

panel.add(button);
panel.add(checkbox);
panel.add(ellipse);
panel.add(rectangle);

final Display display = Display.getDefault();

Shell shell2 = new Shell();
PrintDialog dialog = new PrintDialog(shell2, SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
PrintFigureOperation op =
new PrintFigureOperation(new Printer(data), panel);
op.setPrintMode(PrintFigureOperation.TILE);
op.run("demo2");
}
//---------------------end
Re: Capturing drawing image WITHOUT showing it on screen [message #211155 is a reply to message #211131] Wed, 08 March 2006 13:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vikram.sjn+eclipsezone.gmail.com

Here is the complete code...
<pre>
public class Demo2 {

public static void main(String[] args) {
Shell shell = new Shell();
shell.setText("Draw2d");
final LightweightSystem lws = new LightweightSystem(shell);
final IFigure panel = new Figure();
panel.setLayoutManager(new FlowLayout());
lws.setContents(panel);

Clickable button = new Button("Click me");
Clickable checkbox = new CheckBox("Check box");
Shape ellipse = new Ellipse();
ellipse.setBackgroundColor(ColorConstants.yellow);
Shape rectangle = new RectangleFigure();
rectangle.setBackgroundColor(ColorConstants.lightBlue);

panel.add(button);
panel.add(checkbox);
panel.add(ellipse);
panel.add(rectangle);

final Display display = Display.getDefault();

// here printout prints only the last figure
Shell shell2 = new Shell();
PrintDialog dialog = new PrintDialog(shell2, SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
PrintFigureOperation op = new PrintFigureOperation(new Printer(data), panel);
op.setPrintMode(PrintFigureOperation.TILE);
op.run("demo2");
}

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

// here printout is proper, and has all figures
Shell shell = new Shell();
PrintDialog dialog = new PrintDialog(shell, SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
PrintFigureOperation op = new PrintFigureOperation(new Printer(data), panel);
op.setPrintMode(PrintFigureOperation.FIT_PAGE);
op.run("demo2");
}

}
});

shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
}
}
</pre>
Re: Capturing drawing image WITHOUT showing it on screen [message #211272 is a reply to message #211131] Thu, 09 March 2006 07:53 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vikram.sjn+eclipsezone.gmail.com

Additional information...

Eclipse version is 3.0.2
GEF version 3.0.1
Re: Capturing drawing image WITHOUT showing it on screen [message #212250 is a reply to message #210947] Mon, 20 March 2006 13:12 Go to previous message
Eclipse UserFriend
Originally posted by: vikram.sjn+eclipsezone.gmail.com

------=_Part_1142_6047780.1142860381138
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I have finally resolved the problem. The problem was because I was printing/capturing image before the start of display's event/message loop.

Attached java file has the code which works.

Thanks to Randy Hudson, his post atleast indicated that my approach was not incorrect.

Vikram
------=_Part_1142_6047780.1142860381138
Content-Type: application/octet-stream; name=CaptureHiddenWidgetImage4.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=CaptureHiddenWidgetImage4.java


package com.vikramsjn.swtapp.componenttoimage;
import org.eclipse.draw2d.ActionEvent;
import org.eclipse.draw2d.ActionListener;
import org.eclipse.draw2d.CheckBox;
import org.eclipse.draw2d.Clickable;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.PrintFigureOperation;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.Shape;
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.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import com.sun.imageio.plugins.common.ImageUtil;

/*
* Created on Feb 28, 2006
* @author vikram
*
* TODO Comment CaptureHiddenWidgetImage class description
*/
public class CaptureHiddenWidgetImage4 {

public static void main(String[] args) {

// create & preapre the shell
final Display display = new Display();
Shell shell = new Shell(display);
shell.setText("CaptureHiddenWidgetImage");
shell.setBounds(10, 10, 200, 200);

// create 'Play' button to allow capture
Button button = new Button(shell, SWT.PUSH);
button.setText("Play");
button.setBounds(10, 140, 50, 20);

final InternalDemo2 internalDemo2 = new InternalDemo2();
internalDemo2.initialize();

button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
doPlay(display, internalDemo2);
}
});

shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

private static void doPlay(final Display display,
final InternalDemo2 internalDemo2) {

//----------------------
Shell shell2 = new Shell();
PrintDialog dialog = new PrintDialog(shell2, SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
PrintFigureOperation op =
new PrintFigureOperation(new Printer(data),
internalDemo2.panel);
op.setPrintMode(PrintFigureOperation.TILE);
op.run("demo2");
}
//---------------------

//--------------------
Image image = new Image(display, 1152, 864);
Rectangle bounds = image.getBounds();

GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
internalDemo2.panel.paint(graphics);

ImageUtils.saveImage(image, "fianlAttempt.jpg", SWT.IMAGE_JPEG);

image.dispose();
graphics.dispose();
gc.dispose();
//--------------------
}
}

class InternalDemo2 {
Shell shell;
public IFigure panel;
LightweightSystem lws;

// public static void main(String[] args) {
public void initialize() {

shell = new Shell();
//shell.setText("Draw2d");
lws = new LightweightSystem(shell);
panel = new Figure();
panel.setLayoutManager(new FlowLayout());
lws.setContents(panel);

Clickable button = new org.eclipse.draw2d.Button("Click me");
Clickable checkbox = new CheckBox("Check box");

Shape ellipse = new Ellipse();
ellipse.setBackgroundColor(ColorConstants.yellow);

Shape rectangle = new RectangleFigure();
rectangle.setBackgroundColor(ColorConstants.lightBlue);

panel.add(button);
panel.add(checkbox);
panel.add(ellipse);
panel.add(rectangle);

}
}

------=_Part_1142_6047780.1142860381138--
Previous Topic:GEF problem - Needed help urgently
Next Topic:Selection Problem when two GEF editor instances are running
Goto Forum:
  


Current Time: Thu Apr 25 09:56:33 GMT 2024

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

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

Back to the top