JGoDocument pack or re-size

Hi,

I’ve got a JGoDocument that I’m adding JGoObjects to and that works fine. However, when I delete JGoObjects, I’d like to “pack” or re-size the document so that any excess “empty space” is removed.

Is there a simple method (like pack()) to do this? I know they have specific locations and I don’t want to change them, I just want the document size to shrink.

I’ve gone down the path of using computeBounds() but that doesn’t get rid of the empty space on the left and my JGoOverview gets a bit out of sync:

Rectangle jgoDocumentBounds = jgoDocument.computeBounds();
jgoDocument.setDocumentSize(new Dimension(jgoDocumentBounds.width, jgoDocumentBounds.height));
jgoDocument.update();

Am I going down the wrong path? Is there a better way of doing this?

Thanks,
JoJo

That looks like a good start, but you may also want to consider document.setDocumentTopLeft, view.setViewPosition, and view.setScale.

If you specify all 4 properties (DocumentTopLeft, DocumentSize, ViewPosition, and Scale), you can fully determine the document dimensions and what portion of that document is shown in the view.
There's a zoomToFitAction defined in Demo1 that you might want to look at for an example.

Thanks for that, ssmith, that helped a lot.

I played around with those methods, but there’s still a tiny part that I need that I think I’m missing. The view location is set to the new document top left but the actual document still contains the empty space on the left (after deleting objects on the left) and thus the scrollbars in the view are still adherering to the original document size and panning still goes out to the original document width and height. I can make it work if the objects on the right are deleted though.

What am I missing?

Thanks in advance,
JoJo

Rather than trying to move the origin of the document, try something like the following:

Rectangle bounds = this.goView.getDocument().computeBounds();
goView.selectAll();
goView.moveSelection(null, 0, -bounds.x, -bounds.y, JGoView.EventMouseMove);
bounds = this.goView.getDocument().computeBounds();
goView.getDocument().setDocumentSize(bounds.width, bounds.height);
goView.setViewPosition(bounds.x, bounds.y);

That’s neat.
Thanks!