private JProgressBar getOrCreateProgressBar ( Progress prog ) { JProgressBar pbar = pbarmap . get ( prog ) ; // Add a new progress bar. if ( pbar == null ) { synchronized ( pbarmap ) { if ( prog instanceof FiniteProgress ) { pbar = new JProgressBar ( 0 , ( ( FiniteProgress ) prog ) . getTotal ( ) ) ; pbar . setStringPainted ( true ) ; } else if ( prog instanceof IndefiniteProgress ) { pbar = new JProgressBar ( ) ; pbar . setIndeterminate ( true ) ; pbar . setStringPainted ( true ) ; } else if ( prog instanceof MutableProgress ) { pbar = new JProgressBar ( 0 , ( ( MutableProgress ) prog ) . getTotal ( ) ) ; pbar . setStringPainted ( true ) ; } else { throw new RuntimeException ( "Unsupported progress record" ) ; } pbarmap . put ( prog , pbar ) ; final JProgressBar pbar2 = pbar ; // Make final SwingUtilities . invokeLater ( ( ) -> addProgressBar ( pbar2 ) ) ; } } return pbar ; }
Get an existing or create a new progress bar .