001package jmri.util.swing;
002
003import java.awt.BorderLayout;
004import java.awt.Dimension;
005import javax.swing.BorderFactory;
006import javax.swing.JDialog;
007import javax.swing.JFrame;
008import javax.swing.JProgressBar;
009
010/**
011 * Creates a simple counting progress bar.
012 * <p>
013 * After constructing one, call start() to display it.
014 * Then call count(..) to update the progress count, and
015 * finish() when the operation is done.
016 *
017 * @author   Mark Underwood Copyright (C) 2011
018 * @author   Bob Jacobsen   Copyright (C) 2023
019 *
020 */
021public class CountingBusyDialog extends JDialog {
022
023    JFrame frame;
024    JProgressBar pbar;
025    int maxCount;
026
027    public CountingBusyDialog(JFrame frame, String title, boolean modal, int maxCount) {
028        super(frame, title, modal);
029        this.frame = frame;
030        this.maxCount = maxCount;
031        initComponents();
032    }
033
034    public void initComponents() {
035
036        setLocationRelativeTo(frame);
037        setPreferredSize(new Dimension(200, 100));
038        setMinimumSize(new Dimension(200, 100));
039        setLayout(new BorderLayout(10, 10));
040
041        pbar = new JProgressBar(0, maxCount);
042        pbar.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
043        //pbar.setBorderPainted(true);
044        this.add(pbar, BorderLayout.CENTER);
045    }
046
047    public void start() {
048        this.pack();
049        this.setVisible(true);
050        this.getContentPane().paintAll(pbar.getGraphics());
051    }
052
053    public void count(int now) {
054        pbar.setValue(now);
055    }
056
057    public void finish() {
058        this.dispose();
059
060    }
061
062    // Unused, for now.  Commented out to avoid the compiler warning.
063    //private static final Logger log = LoggerFactory.getLogger(VSDecoderPane.class);
064}