FileDocCategorySizeDatePackage
ProgressPanel.javaAPI DocExample5965Sat Sep 12 03:01:00 BST 1998None

ProgressPanel

public class ProgressPanel extends JPanel
Demo the Progress Bar
version
1.5 02/02/98
author
Jeff Dinkins # @author Peter Korn (accessibility support)

Fields Summary
SwingSet
swing
JProgressBar
progressBar
JTextArea
progressTextArea
JButton
loadButton
JButton
stopButton
LoadThread
loadThread
boolean
shouldStop
Object
lock
Constructors Summary
public ProgressPanel(SwingSet swing)


       
	this.swing = swing;

	setLayout(new BorderLayout());

	JPanel textWrapper = new JPanel(new BorderLayout());
	textWrapper.setBorder(swing.loweredBorder);
	textWrapper.setAlignmentX(LEFT_ALIGNMENT);
	progressTextArea = new MyTextArea();
	progressTextArea.getAccessibleContext().setAccessibleName("Text progressively being loaded in");
	progressTextArea.getAccessibleContext().setAccessibleDescription("This JTextArea is being filled with text from a buffer progressively a character at a time while the progress bar a the bottom of the window shows the loading progress");
	textWrapper.add(progressTextArea, BorderLayout.CENTER);

	add(textWrapper, BorderLayout.CENTER);

	JPanel progressPanel = new JPanel();
	add(progressPanel, BorderLayout.SOUTH);

	progressBar = new JProgressBar() {
	    public Dimension getPreferredSize() {
		return new Dimension(300, super.getPreferredSize().height);
	    }
	};
	progressBar.getAccessibleContext().setAccessibleName("Text loading progress");
	progressPanel.add(progressBar);

	loadButton = new JButton("Start Loading Text");
	loadButton.addActionListener(new ActionListener() {
	    public void actionPerformed(ActionEvent e) {
		startLoading((JButton)e.getSource());
	    }
	});
	progressPanel.add(loadButton);

        stopButton = new JButton("Stop Loading Text");
        stopButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                stopLoading((JButton)e.getSource());
            }
        });
        stopButton.setEnabled(false);
	progressPanel.add(stopButton);
    
Methods Summary
public java.awt.InsetsgetInsets()

	return new Insets(10,10,10,10);
    
public voidstartLoading(JButton b)

        if(loadThread == null) {
            Rectangle r;
            loadThread = new LoadThread();
            loadButton.setEnabled(false);
            stopButton.setEnabled(true);
            r = loadButton.getBounds();
            r.x = 0;
            r.y = 0;
            loadButton.paintImmediately(r);
            r = stopButton.getBounds();
            r.x = 0;
            r.y = 0;
            stopButton.paintImmediately(r);
            stopButton.requestFocus();
            shouldStop = false;
            loadThread.start();
        }
    
public voidstopLoading(JButton b)

        synchronized(lock) {
            shouldStop = true;
            lock.notify();
        }