Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

/**
 * AntShield - A project release tool for ant.
 */
package com.erggroup.mass.ant;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * AntShieldRetryDialog
 * A dialog box that displays a message.
 */
public class AntShieldRetryDialog extends JDialog {

    private String message = null;
    private int width_ = 300;
    private int height_ = 200;

    /**
     * Constructor.
     * @param msg
     */
    public AntShieldRetryDialog(String msg)
    {
        message = msg;
        init();
        setPosition();
        show();
    }

    /**
     * Build this dialog box from components.
     */
    private void init()
    {
        this.setTitle("Antshield Error");
        this.setModal(true);

        JButton okButton = new JButton("OK");
        okButton.addActionListener(new AntShieldRetryOKAction(this));

        JTextArea textArea = new JTextArea();
        textArea.setEditable(false);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setText(message);

        JPanel sePanel = new JPanel();
        sePanel.add(okButton);

        JPanel southPanel = new JPanel();
        southPanel.setLayout(new BorderLayout());
        southPanel.add(sePanel, BorderLayout.EAST);

        JPanel centrePanel = new JPanel();
        centrePanel.setLayout(new BorderLayout());
        centrePanel.add(textArea, BorderLayout.CENTER);

        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(centrePanel, BorderLayout.CENTER);
        getContentPane().add(southPanel, BorderLayout.SOUTH);

        getRootPane().setDefaultButton(okButton);

        pack();
    }

    /**
     * Resize and osition this dialog box in the centre of the screen.
     */
    private void setPosition()
    {
        setSize(width_, height_);
        setResizable(false);
        int xpos = Toolkit.getDefaultToolkit().getScreenSize().width/2 - width_/2;
        if (xpos < 0) xpos = 0;
        int ypos = Toolkit.getDefaultToolkit().getScreenSize().height/2 - height_/2;
        if (ypos < 0) ypos = 0;
        this.setLocation(xpos, ypos);
    }

    /**
     * Handle the OK button.
     */
    public void handleOk()
    {
        setVisible(false);
    }
}

class AntShieldRetryOKAction implements ActionListener
{
    private AntShieldRetryDialog adaptee;

    public AntShieldRetryOKAction(AntShieldRetryDialog a)
    {
        adaptee = a;
    }

    public void actionPerformed(ActionEvent e)
    {
        adaptee.handleOk();
    }
}