Santy, Michael wrote:
> Thanks for the hints. I did a bit more digging, and the image fetching
> is actually happening after the Application::addOpenedDocument call
> completes. The vast majority of time is being spent in the initial call
> to the RootGadget's layout method.
>
> I did some timing tests on a small document that has 30 images and 23
> seconds were spend in the RootGadget's layout method on the initial
> call. Since I'm using my own custom gadget for figures, I created a
> buffered image on the client side to eliminate image fetching from the
> timing. When I did this, the time in RootGadget's layout dropped to 2
> seconds (on my old linux machine). So this confirmed my suspicion that
> the image fetching latency was the killer.
>
> I was planning on opening a dialog that shows an indeterminate progress
> bar upon the first call to the RootGadget's layout method. When this
> method completes, I would close the dialog. The only way that I've
> found to get to the RootGadget's layout method without modifying XXE
> code is by adding the following to my existing Application subclass:
>
> @Override
> public Editor createEditor() {
> return new Editor(this) {
> @Override
> public StyledDocumentPane createStyledDocumentPane() {
> return new StyledDocumentPane() {
> @Override
> protected RootGadget createRootGadget() {
> return new StyledDocumentView(this) {
> boolean hasBeenLayedOut = false;
> @Override
> public void layout(int constrainedWidth, int
> constrainedHeight) {
> long timestart = 0;
> if(!hasBeenLayedOut) {
> System.err.println("laying out view ... "); // this
> is where I would open a progress dialog
> timestart = System.currentTimeMillis();
> }
> super.layout(constrainedWidth, constrainedHeight);
> if(!hasBeenLayedOut) {
> hasBeenLayedOut = true;
> long currentTime = System.currentTimeMillis();
> float seconds = (currentTime - timestart)/1000.0f;
> System.err.println("done laying out view in
> "+seconds+" s"); // close progress dialog
> }
> }
> };
> }
> };
> }
> };
> }
>
>
> I know the code itself is ugly, but I hate to create four more classes
> just to add special behavior to the RootGadget's layout method. Can you
> immediately see any better approach? Am I missing something obvious?
>
No, what you did is the simplest, cleanest way to do it.