summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/ui/ExitConfirm.java
blob: 836ed7b3869a7e7f380a028b9c5dd694ab1af6f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/** @file
 
 The file is used to popup a exit confirmation window when program exists
 
 Copyright (c) 2006, Intel Corporation
 All rights reserved. This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 **/

package org.tianocore.frameworkwizard.common.ui;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 The class is used to popup a exit confirmation window when program exists
 It extends JDialog and implements ActionListener and WindowListener
 
 **/
public class ExitConfirm extends JDialog implements ActionListener, WindowListener {

    ///
    /// Define class Serial Version UID
    ///
    private static final long serialVersionUID = -5875921789385911029L;

    private JPanel jContentPane = null;

    private JLabel jLabelMessage = null;

    private JLabel jLabelResume = null;

    private JLabel jLabelExit = null;

    private JButton jButtonResume = null;

    private JButton jButtonExit = null;

    public boolean isCancel = false;

    /**
     This method initializes jButtonResume
     
     @return javax.swing.JButton jButtonResume
     
     **/
    private JButton getJButtonResume() {
        if (jButtonResume == null) {
            jButtonResume = new JButton();
            jButtonResume.setText("Resume");
            jButtonResume.setSize(new java.awt.Dimension(90, 20));
            jButtonResume.setLocation(new java.awt.Point(150, 105));
            jButtonResume.setMnemonic('R');
            jButtonResume.addActionListener(this);
        }
        return jButtonResume;
    }

    /**
     This method initializes jButtonExit
     
     @return javax.swing.JButton jButtonExit
     
     **/
    private JButton getJButtonExit() {
        if (jButtonExit == null) {
            jButtonExit = new JButton();
            jButtonExit.setText("Exit");
            jButtonExit.setSize(new java.awt.Dimension(90, 20));
            jButtonExit.setLocation(new java.awt.Point(260, 105));
            jButtonExit.setMnemonic('x');
            jButtonExit.addActionListener(this);
        }
        return jButtonExit;
    }

    /**
     Main clasee, reserved for test
     
     @param args
     
     **/
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

    /**
     This is the default constructor
     
     **/
    public ExitConfirm(IFrame parentFrame, boolean modal) {
        super(parentFrame, modal);
        initialize();
    }

    /**
     This method initializes this
     
     @return void
     
     **/
    private void initialize() {
        this.setSize(500, 170);
        this.setTitle("Exit");
        this.setResizable(false);
        this.setContentPane(getJContentPane());
        this.addWindowListener(this);
        //
        //Set DO_NOTHING_ON_CLOSE when click Close button on title bar
        //
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        centerWindow();
    }

    /**
     This method initializes jContentPane
     
     @return javax.swing.JPanel jContentPane
     
     **/
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jLabelExit = new JLabel();
            jLabelExit.setSize(new java.awt.Dimension(450, 20));
            jLabelExit.setLocation(new java.awt.Point(25, 70));
            jLabelResume = new JLabel();
            jLabelResume.setSize(new java.awt.Dimension(450, 20));
            jLabelResume.setLocation(new java.awt.Point(25, 40));
            jLabelMessage = new JLabel();
            jLabelMessage.setSize(new java.awt.Dimension(450, 20));
            jLabelMessage.setLocation(new java.awt.Point(25, 10));
            jContentPane = new JPanel();
            jContentPane.setLayout(null);
            jContentPane.add(jLabelMessage, null);
            jContentPane.add(jLabelResume, null);
            jContentPane.add(jLabelExit, null);
            jContentPane.add(getJButtonResume(), null);
            jContentPane.add(getJButtonExit(), null);
        }
        return jContentPane;
    }

    /**
     Call setWarningMessage to set messages of frame when it is used for Setup
     
     **/
    public void setSetupMessage() {
        String strTitle = "Exit Setup";
        String strMessage = "Setup is not complete. If you quit now, the program will not be installed.";
        String strResume = "You may run the setup program at a later time to complete the installation.";
        String strExit = "To continue installing, click Resume. To quit the Setup program, click Exit.";
        setWarningMessage(strTitle, strMessage, strResume, strExit);
    }

    /**
     Call setWarningMessage to set messages of frame when it is used for Module Main GUI
     
     **/
    public void setModuleMessage() {
        String strTitle = "Exit";
        String strMessage = "Do you really want to quit now?";
        String strResume = "All unsaved module information will be lost.";
        String strExit = "To continue editing the module, click Resume. To quit the program, click Exit.";
        setWarningMessage(strTitle, strMessage, strResume, strExit);
    }

    /**
     Set message information via input data
     
     @param strTitle The title value
     @param strMessage The main message value
     @param strResume The resume message value
     @param strExit The exit message value
     
     **/
    private void setWarningMessage(String strTitle, String strMessage, String strResume, String strExit) {
        this.setTitle(strTitle);
        jLabelMessage.setText(strMessage);
        jLabelResume.setText(strResume);
        jLabelExit.setText(strExit);
    }

    /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     * 
     * Override actionPerformed to listern all actions
     * 
     */
    public void actionPerformed(ActionEvent arg0) {
        //
        //Set isCancel true when click button "Exit"
        //
        Object obj = arg0.getSource();
        if (obj == jButtonResume) {
            isCancel = false;
        }
        if (obj == jButtonExit) {
            isCancel = true;
        }
        this.setVisible(false);
    }

    /**
     Make the window in the center of the screen
     
     **/
    private void centerWindow() {
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
    }

    public void windowActivated(WindowEvent arg0) {
        // TODO Auto-generated method stub

    }

    public void windowClosed(WindowEvent arg0) {
        // TODO Auto-generated method stub

    }

    public void windowClosing(WindowEvent arg0) {
        isCancel = false;
        this.setVisible(false);
    }

    public void windowDeactivated(WindowEvent arg0) {
        // TODO Auto-generated method stub

    }

    public void windowDeiconified(WindowEvent arg0) {
        // TODO Auto-generated method stub

    }

    public void windowIconified(WindowEvent arg0) {
        // TODO Auto-generated method stub

    }

    public void windowOpened(WindowEvent arg0) {
        // TODO Auto-generated method stub

    }
}