Saving view background

Ok… I am trying to leverage SVG to save the background image of a view. Currently I am doing to the following (which isn’t working):

// Load the image
JGoImage bgImage = new JGoImage();
bgImage.loadImage(selectedImg, true);

// Set the bg to this image
view.setBackgroundImage(new Image(view.getDisplay(),bgImage.getImage()) );

This doesn’t save the background image since JGoView doesn’t have the SVGread/write methods. What am I doing wrong?


I'm assuming you're trying to serialize (save and restore) the JGoView background image and not just create SVG output that includes the background image.
The JGo SVG package is intended to store the persistent data in the JGoDocument, and the SVGWriteDoc method that takes the JGoDocument as a parameter to identify what document to save. As a single JGoDocument can have multiple JGoViews and the JGoView objects are typically transient (selection handles, resize handles, etc.), JGoView objects are not saved.
Furthermore, the JGoImage class will not save and restore the actual image. It will only save and restore an image filename or image url.
However, if your application has just one JGoView associated with a JGoDocument, or at least if all the JGoViews associated with a particular JGoDocument share the same background image, you could do the following:
Subclass JGoDocument and add a new JGoDocument property to store your background image.
Override SVGWriteObject and SVGReadObject on your subclass to save and restore the background image property. You could either store the embedded JGoImage (see JGoIconicNode for an example) or more simply, just store the image filename or url yourself directly as a string. Once the call to the SVGReadDoc has completed, just reinitialize the background image from the JGoDocument property.