d5298df38b09e7cbdba3506200b18b9a02195fb5
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / ui / ExitConfirm.java
1 /** @file
2
3 The file is used to popup a exit confirmation window when program exists
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 package org.tianocore.frameworkwizard.common.ui;
17
18 import java.awt.Dimension;
19 import java.awt.Toolkit;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.awt.event.WindowEvent;
23 import java.awt.event.WindowListener;
24
25 import javax.swing.JButton;
26 import javax.swing.JDialog;
27 import javax.swing.JFrame;
28 import javax.swing.JLabel;
29 import javax.swing.JPanel;
30
31 /**
32 The class is used to popup a exit confirmation window when program exists
33 It extends JDialog and implements ActionListener and WindowListener
34
35 **/
36 public class ExitConfirm extends JDialog implements ActionListener, WindowListener {
37
38 ///
39 /// Define class Serial Version UID
40 ///
41 private static final long serialVersionUID = -5875921789385911029L;
42
43 private JPanel jContentPane = null;
44
45 private JLabel jLabelMessage = null;
46
47 private JLabel jLabelResume = null;
48
49 private JLabel jLabelExit = null;
50
51 private JButton jButtonResume = null;
52
53 private JButton jButtonExit = null;
54
55 public boolean isCancel = false;
56
57 /**
58 This method initializes jButtonResume
59
60 @return javax.swing.JButton jButtonResume
61
62 **/
63 private JButton getJButtonResume() {
64 if (jButtonResume == null) {
65 jButtonResume = new JButton();
66 jButtonResume.setText("Resume");
67 jButtonResume.setSize(new java.awt.Dimension(90, 20));
68 jButtonResume.setLocation(new java.awt.Point(150, 105));
69 jButtonResume.setMnemonic('R');
70 jButtonResume.addActionListener(this);
71 }
72 return jButtonResume;
73 }
74
75 /**
76 This method initializes jButtonExit
77
78 @return javax.swing.JButton jButtonExit
79
80 **/
81 private JButton getJButtonExit() {
82 if (jButtonExit == null) {
83 jButtonExit = new JButton();
84 jButtonExit.setText("Exit");
85 jButtonExit.setSize(new java.awt.Dimension(90, 20));
86 jButtonExit.setLocation(new java.awt.Point(260, 105));
87 jButtonExit.setMnemonic('x');
88 jButtonExit.addActionListener(this);
89 }
90 return jButtonExit;
91 }
92
93 /**
94 Main clasee, reserved for test
95
96 @param args
97
98 **/
99 public static void main(String[] args) {
100 // TODO Auto-generated method stub
101
102 }
103
104 /**
105 This is the default constructor
106
107 **/
108 public ExitConfirm(IFrame parentFrame, boolean modal) {
109 super(parentFrame, modal);
110 initialize();
111 }
112
113 /**
114 This method initializes this
115
116 @return void
117
118 **/
119 private void initialize() {
120 this.setSize(500, 170);
121 this.setTitle("Exit");
122 this.setResizable(false);
123 this.setContentPane(getJContentPane());
124 this.addWindowListener(this);
125 //
126 //Set DO_NOTHING_ON_CLOSE when click Close button on title bar
127 //
128 this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
129 centerWindow();
130 }
131
132 /**
133 This method initializes jContentPane
134
135 @return javax.swing.JPanel jContentPane
136
137 **/
138 private JPanel getJContentPane() {
139 if (jContentPane == null) {
140 jLabelExit = new JLabel();
141 jLabelExit.setSize(new java.awt.Dimension(450, 20));
142 jLabelExit.setLocation(new java.awt.Point(25, 70));
143 jLabelResume = new JLabel();
144 jLabelResume.setSize(new java.awt.Dimension(450, 20));
145 jLabelResume.setLocation(new java.awt.Point(25, 40));
146 jLabelMessage = new JLabel();
147 jLabelMessage.setSize(new java.awt.Dimension(450, 20));
148 jLabelMessage.setLocation(new java.awt.Point(25, 10));
149 jContentPane = new JPanel();
150 jContentPane.setLayout(null);
151 jContentPane.add(jLabelMessage, null);
152 jContentPane.add(jLabelResume, null);
153 jContentPane.add(jLabelExit, null);
154 jContentPane.add(getJButtonResume(), null);
155 jContentPane.add(getJButtonExit(), null);
156 }
157 return jContentPane;
158 }
159
160 /**
161 Call setWarningMessage to set messages of frame when it is used for Setup
162
163 **/
164 public void setSetupMessage() {
165 String strTitle = "Exit Setup";
166 String strMessage = "Setup is not complete. If you quit now, the program will not be installed.";
167 String strResume = "You may run the setup program at a later time to complete the installation.";
168 String strExit = "To continue installing, click Resume. To quit the Setup program, click Exit.";
169 setWarningMessage(strTitle, strMessage, strResume, strExit);
170 }
171
172 /**
173 Call setWarningMessage to set messages of frame when it is used for Module Main GUI
174
175 **/
176 public void setModuleMessage() {
177 String strTitle = "Exit";
178 String strMessage = "Do you really want to quit now?";
179 String strResume = "All unsaved module information will be lost.";
180 String strExit = "To continue editing module, click Resume. To quit the program, click Exit.";
181 setWarningMessage(strTitle, strMessage, strResume, strExit);
182 }
183
184 /**
185 Set message information via input data
186
187 @param strTitle The title value
188 @param strMessage The main message value
189 @param strResume The resume message value
190 @param strExit The exit message value
191
192 **/
193 private void setWarningMessage(String strTitle, String strMessage, String strResume, String strExit) {
194 this.setTitle(strTitle);
195 jLabelMessage.setText(strMessage);
196 jLabelResume.setText(strResume);
197 jLabelExit.setText(strExit);
198 }
199
200 /* (non-Javadoc)
201 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
202 *
203 * Override actionPerformed to listern all actions
204 *
205 */
206 public void actionPerformed(ActionEvent arg0) {
207 //
208 //Set isCancel true when click button "Exit"
209 //
210 Object obj = arg0.getSource();
211 if (obj == jButtonResume) {
212 isCancel = false;
213 }
214 if (obj == jButtonExit) {
215 isCancel = true;
216 }
217 this.setVisible(false);
218 }
219
220 /**
221 Make the window in the center of the screen
222
223 **/
224 private void centerWindow() {
225 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
226 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
227 }
228
229 public void windowActivated(WindowEvent arg0) {
230 // TODO Auto-generated method stub
231
232 }
233
234 public void windowClosed(WindowEvent arg0) {
235 // TODO Auto-generated method stub
236
237 }
238
239 public void windowClosing(WindowEvent arg0) {
240 isCancel = false;
241 this.setVisible(false);
242 }
243
244 public void windowDeactivated(WindowEvent arg0) {
245 // TODO Auto-generated method stub
246
247 }
248
249 public void windowDeiconified(WindowEvent arg0) {
250 // TODO Auto-generated method stub
251
252 }
253
254 public void windowIconified(WindowEvent arg0) {
255 // TODO Auto-generated method stub
256
257 }
258
259 public void windowOpened(WindowEvent arg0) {
260 // TODO Auto-generated method stub
261
262 }
263 }