FileDocCategorySizeDatePackage
ProgressDialog.javaAPI DocJMF 2.1.1e4998Mon May 12 12:20:30 BST 2003jmapps.ui

ProgressDialog

public class ProgressDialog extends JMDialog

Fields Summary
public static final String
ACTION_ABORT
public static final String
ACTION_STOP
public static final String
ACTION_PAUSE
public static final String
ACTION_RESUME
private int
nMinPos
private int
nMaxPos
private String
strMessage
private ActionListener
listener
private ProgressBar
progressBar
private Label
labelProgress
private Button
buttonPause
private Component
component
Constructors Summary
public ProgressDialog(Frame frame, String strTitle, int nMin, int nMax, ActionListener listener)



                  
        super ( frame, strTitle, false );

        nMinPos = nMin;
        nMaxPos = nMax;
        this.listener = listener;
        try {
            init();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    
public ProgressDialog(Frame frame, String strTitle, String strMessage, Component component, ActionListener listener)

        super ( frame, strTitle, false );

        this.strMessage = strMessage;
        this.listener = listener;
        this.component = component;
        try {
            init();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    
Methods Summary
private voidinit()

        Panel          panel;
        Panel          panelGrid;
        Panel          panelComp;
        Button         button;
        Dimension      dimDialog;
        Dimension      dimScreen;


        this.setLayout ( new BorderLayout() );
        this.setBackground ( Color.lightGray );

        panel = new JMPanel ( new BorderLayout(6,6) );
        ((JMPanel)panel).setEmptyBorder ( 6, 6, 6, 6 );
        if ( nMaxPos > nMinPos ) {
            this.add ( panel, BorderLayout.CENTER );
            progressBar = new ProgressBar ( nMinPos, nMaxPos );
            panel.add ( progressBar, BorderLayout.CENTER );
            labelProgress = new Label ( "100%" );
            panel.add ( labelProgress, BorderLayout.EAST );
        }
        else if ( strMessage != null ) {
            this.add(panel, BorderLayout.CENTER);
            labelProgress = new Label ( strMessage );
            panel.add ( labelProgress, BorderLayout.NORTH );
            if (component != null) {
                panelComp = new Panel( new FlowLayout() );
                panel.add(panelComp, BorderLayout.CENTER);
                panelComp.add(component);
            }
        }

        panel = new Panel ( new FlowLayout(FlowLayout.CENTER) );
        this.add ( panel, BorderLayout.SOUTH );
        panelGrid = new Panel ( new GridLayout(1,0,6,6) );
        panel.add ( panelGrid );
        buttonPause = new Button ( ACTION_PAUSE );
        buttonPause.addActionListener ( listener );
        panelGrid.add ( buttonPause );
        if (strMessage == null)
            button = new Button ( ACTION_ABORT );
        else
            button = new Button ( ACTION_STOP );
        button.addActionListener ( listener );
        panelGrid.add ( button );

        panel = new Panel ();
        this.add ( panel, BorderLayout.NORTH );

        this.pack ();
        dimDialog = this.getPreferredSize ();
        this.setSize ( dimDialog );
        dimScreen = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation ( (dimScreen.width - dimDialog.width) / 2, (dimScreen.height - dimDialog.height) / 2 );
        this.setResizable ( false );

        if (progressBar != null)
            labelProgress.setText ( "" + progressBar.getCurPercent() + "%" );
        repaint ();
    
public voidsetCurPos(int nPos)

        if ( progressBar != null ) {
            progressBar.setCurPos ( nPos );
            labelProgress.setText ( "" + progressBar.getCurPercent() + "%" );
            repaint ();
        }
        else {
            labelProgress.setText ( JMFI18N.getResource("jmstudio.saveprogress.saved")
                                + " " + nPos + " "
                                + JMFI18N.getResource("jmstudio.saveprogress.seconds") + "...");
        }
    
public voidsetPauseButtonText(java.lang.String strButton)

        buttonPause.setLabel ( strButton );
        this.repaint ();
    
public voidwindowClosing(java.awt.event.WindowEvent event)

        ActionEvent     eventAction;

        eventAction = new ActionEvent ( this, ActionEvent.ACTION_PERFORMED, ACTION_ABORT );
        listener.actionPerformed ( eventAction );