Package shared.dialog

Source Code of shared.dialog.JWaitDialog

/*
*  JWaitDialog.java
*
*  Created on 18.12.2009, 13:14:23
*
*  Copyright (C) 18.12.2009  reiner

*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/


/**
*
* @author reiner
*/

package shared.dialog;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SpringLayout;
import shared.aa.JAALabel;
import shared.progbar.JProgBar;
import shared.proglistener.ProgListener;
import shared.proglistener.ProgNotify;

public class JWaitDialog extends JDialog implements ProgListener
{
    private JAALabel m_label;
    private JProgBar m_bar;
    private JFrame m_frame;
    private String m_cancelStr;
    private boolean m_bCancel = false;
    private int m_width = 450;
    private String m_labelText;
    private int m_min = 0;
    private int m_max = 1000;
    private boolean m_bIndeterminate;

    public JWaitDialog(JFrame frame, String captionStr, String cancelStr)
    {
        super(frame, captionStr, true);
        m_frame = frame;
        m_cancelStr = cancelStr;
    }
    public JWaitDialog(JFrame frame, String captionStr)
    {
        super(frame, captionStr, false);
        m_frame = frame;
        m_cancelStr = null;
    }
    public JWaitDialog(JFrame frame, String captionStr, int width)
    {
        super(frame, captionStr, false);
        m_frame = frame;
        m_cancelStr = null;
        m_width = width;
    }
    public JWaitDialog(JFrame frame, String captionStr, String cancelStr, int width)
    {
        super(frame, captionStr, false);
        m_frame = frame;
        m_cancelStr = null;
        m_width = width;
    }
    public void setIndeterminate(boolean bIndeterminate)
    {
        m_bIndeterminate = bIndeterminate;
    }

    public boolean wasCancelled()
    {
        return m_bCancel;
    }

  protected void doInit()
  {
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        Container contentPane = getContentPane();
        SpringLayout layout = new SpringLayout();
        contentPane.setLayout(layout);

        m_label = new JAALabel(m_labelText);
        contentPane.add(m_label);
        layout.putConstraint(SpringLayout.WEST, m_label, 10, SpringLayout.WEST, contentPane);
        layout.putConstraint(SpringLayout.NORTH, m_label, 10, SpringLayout.NORTH, contentPane);

        m_bar = new JProgBar(m_min, m_max);
        m_bar.setIndeterminate(m_bIndeterminate);
        contentPane.add(m_bar);
        layout.putConstraint(SpringLayout.WEST, m_bar, 0, SpringLayout.WEST, m_label);
        layout.putConstraint(SpringLayout.SOUTH, m_bar, 30, SpringLayout.NORTH, m_bar);
        layout.putConstraint(SpringLayout.EAST, m_bar, -10, SpringLayout.EAST, contentPane);
        layout.putConstraint(SpringLayout.NORTH, m_bar, 5, SpringLayout.SOUTH, m_label);

        if (m_cancelStr != null)
        {
            JButton cancel = new JButton(m_cancelStr);
            contentPane.add(cancel);
            layout.putConstraint(SpringLayout.HORIZONTAL_CENTER, cancel, 0, SpringLayout.HORIZONTAL_CENTER, contentPane);
            layout.putConstraint(SpringLayout.SOUTH, cancel, -10, SpringLayout.SOUTH, contentPane);
            //layout.putConstraint(SpringLayout.SOUTH, m_bar, -20, SpringLayout.NORTH, cancel);
            cancel.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent ev)
                {
                    m_bCancel = true;
                    stop();
                }
            });
        }
        /*
        else
            layout.putConstraint(SpringLayout.SOUTH, m_bar, -10, SpringLayout.NORTH, contentPane);
         */
        pack();
        setSize(m_width, m_cancelStr != null ? 130 : 100);
        setResizable(false);
        setLocationRelativeTo(m_frame);
  }

    public void setRange(int min, int max)
    {
        m_min = min;
        m_max = max;
    }

    public void getRangeMin()
    {
        int m_min;
    }

    public int getRangeMax()
    {
        return m_max;
    }

    public boolean start()
    {
        doInit();
    setVisible(true);
        return !m_bCancel;
    }

    public boolean stop()
    {
    setVisible(false);
        dispose();
        return !m_bCancel;
    }

    public void setLabel(String label)
    {
        m_labelText = label;
        if (m_label != null)
            m_label.setText(label);
    }

    public boolean notify(ProgNotify progNotify)
    {
        m_bar.setValue(progNotify.getProgress());
        m_bar.setString(progNotify.getMessage());
        return m_bCancel;
    }
}
TOP

Related Classes of shared.dialog.JWaitDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.