Question

Is it possible to use a progress bar with an mxIGraphLayout? I have a graph that takes a non-trivial time to layout, and I would like the user to be able to see that, yes, something is happening.

Ideally, I would like something that I can interpret (even roughly) as a percent done, but there does not even seem to be a way to add any listeners that are called during the layout.

If it matters, I am using mxOrganicLayout but I might change in the future.

Was it helpful?

Solution

The can be accomplished somewhat by extending mxOrganicLayout and overriding the following methods

    @Override
    public void execute(Object cell)
    {
        progress.setProgress(0);
        try
        {
            super.execute(cell);
        }
        finally
        {
            progress.setProgress(maxIterations);
        }

    }

    @Override
    protected void performRound()
    {
        progress.setNote("Iteration " + iteration);
        progress.setProgress(iteration);
        super.performRound();
    }

    final ProgressMonitor progress;

Obviously, you need to set progress at some point as well. execute notifies the progress monitor that execution has started, and closes it when it is done.

performRound is called to do the actual updates, so incrementing the progress there will cause the progress bar to advance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top