Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1974 jgill 1
/**
2
 * AntShield - A project release tool for ant.
3
 */
4
package com.erggroup.mass.ant;
5
 
6
import javax.swing.*;
7
import java.awt.*;
8
import java.awt.event.ActionListener;
9
import java.awt.event.ActionEvent;
10
 
11
/**
12
 * AntShieldRetryDialog
13
 * A dialog box that displays a message.
14
 */
15
public class AntShieldRetryDialog extends JDialog {
16
 
17
    private String message = null;
18
    private int width_ = 300;
19
    private int height_ = 200;
20
 
21
    /**
22
     * Constructor.
23
     * @param msg
24
     */
25
    public AntShieldRetryDialog(String msg)
26
    {
27
        message = msg;
28
        init();
29
        setPosition();
30
        show();
31
    }
32
 
33
    /**
34
     * Build this dialog box from components.
35
     */
36
    private void init()
37
    {
38
        this.setTitle("Antshield Error");
39
        this.setModal(true);
40
 
41
        JButton okButton = new JButton("OK");
42
        okButton.addActionListener(new AntShieldRetryOKAction(this));
43
 
44
        JTextArea textArea = new JTextArea();
45
        textArea.setEditable(false);
46
        textArea.setLineWrap(true);
47
        textArea.setWrapStyleWord(true);
48
        textArea.setText(message);
49
 
50
        JPanel sePanel = new JPanel();
51
        sePanel.add(okButton);
52
 
53
        JPanel southPanel = new JPanel();
54
        southPanel.setLayout(new BorderLayout());
55
        southPanel.add(sePanel, BorderLayout.EAST);
56
 
57
        JPanel centrePanel = new JPanel();
58
        centrePanel.setLayout(new BorderLayout());
59
        centrePanel.add(textArea, BorderLayout.CENTER);
60
 
61
        getContentPane().setLayout(new BorderLayout());
62
        getContentPane().add(centrePanel, BorderLayout.CENTER);
63
        getContentPane().add(southPanel, BorderLayout.SOUTH);
64
 
65
        getRootPane().setDefaultButton(okButton);
66
 
67
        pack();
68
    }
69
 
70
    /**
71
     * Resize and osition this dialog box in the centre of the screen.
72
     */
73
    private void setPosition()
74
    {
75
        setSize(width_, height_);
76
        setResizable(false);
77
        int xpos = Toolkit.getDefaultToolkit().getScreenSize().width/2 - width_/2;
78
        if (xpos < 0) xpos = 0;
79
        int ypos = Toolkit.getDefaultToolkit().getScreenSize().height/2 - height_/2;
80
        if (ypos < 0) ypos = 0;
81
        this.setLocation(xpos, ypos);
82
    }
83
 
84
    /**
85
     * Handle the OK button.
86
     */
87
    public void handleOk()
88
    {
89
        setVisible(false);
90
    }
91
}
92
 
93
class AntShieldRetryOKAction implements ActionListener
94
{
95
    private AntShieldRetryDialog adaptee;
96
 
97
    public AntShieldRetryOKAction(AntShieldRetryDialog a)
98
    {
99
        adaptee = a;
100
    }
101
 
102
    public void actionPerformed(ActionEvent e)
103
    {
104
        adaptee.handleOk();
105
    }
106
}