]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/common/ui/ExitConfirm.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / 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.packaging.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 @since ModuleEditor 1.0
36
37 **/
38 public class ExitConfirm extends JDialog implements ActionListener, WindowListener {
39
40 ///
41 /// Define class Serial Version UID
42 ///
43 private static final long serialVersionUID = -5875921789385911029L;
44
45 private JPanel jContentPane = null;
46
47 private JLabel jLabelMessage = null;
48
49 private JLabel jLabelResume = null;
50
51 private JLabel jLabelExit = null;
52
53 private JButton jButtonResume = null;
54
55 private JButton jButtonExit = null;
56
57 public boolean isCancel = false;
58
59 /**
60 This method initializes jButtonResume
61
62 @return javax.swing.JButton jButtonResume
63
64 **/
65 private JButton getJButtonResume() {
66 if (jButtonResume == null) {
67 jButtonResume = new JButton();
68 jButtonResume.setText("Resume");
69 jButtonResume.setSize(new java.awt.Dimension(90, 20));
70 jButtonResume.setLocation(new java.awt.Point(150, 105));
71 jButtonResume.setMnemonic('R');
72 jButtonResume.addActionListener(this);
73 }
74 return jButtonResume;
75 }
76
77 /**
78 This method initializes jButtonExit
79
80 @return javax.swing.JButton jButtonExit
81
82 **/
83 private JButton getJButtonExit() {
84 if (jButtonExit == null) {
85 jButtonExit = new JButton();
86 jButtonExit.setText("Exit");
87 jButtonExit.setSize(new java.awt.Dimension(90, 20));
88 jButtonExit.setLocation(new java.awt.Point(260, 105));
89 jButtonExit.setMnemonic('x');
90 jButtonExit.addActionListener(this);
91 }
92 return jButtonExit;
93 }
94
95 /**
96 Main clasee, reserved for test
97
98 @param args
99
100 **/
101 public static void main(String[] args) {
102 // TODO Auto-generated method stub
103
104 }
105
106 /**
107 This is the default constructor
108
109 **/
110 public ExitConfirm(IFrame parentFrame, boolean modal) {
111 super(parentFrame, modal);
112 initialize();
113 }
114
115 /**
116 This method initializes this
117
118 @return void
119
120 **/
121 private void initialize() {
122 this.setSize(500, 170);
123 this.setTitle("Exit");
124 this.setResizable(false);
125 this.setContentPane(getJContentPane());
126 this.addWindowListener(this);
127 //
128 //Set DO_NOTHING_ON_CLOSE when click Close button on title bar
129 //
130 this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
131 centerWindow();
132 }
133
134 /**
135 This method initializes jContentPane
136
137 @return javax.swing.JPanel jContentPane
138
139 **/
140 private JPanel getJContentPane() {
141 if (jContentPane == null) {
142 jLabelExit = new JLabel();
143 jLabelExit.setSize(new java.awt.Dimension(450, 20));
144 jLabelExit.setLocation(new java.awt.Point(25, 70));
145 jLabelResume = new JLabel();
146 jLabelResume.setSize(new java.awt.Dimension(450, 20));
147 jLabelResume.setLocation(new java.awt.Point(25, 40));
148 jLabelMessage = new JLabel();
149 jLabelMessage.setSize(new java.awt.Dimension(450, 20));
150 jLabelMessage.setLocation(new java.awt.Point(25, 10));
151 jContentPane = new JPanel();
152 jContentPane.setLayout(null);
153 jContentPane.add(jLabelMessage, null);
154 jContentPane.add(jLabelResume, null);
155 jContentPane.add(jLabelExit, null);
156 jContentPane.add(getJButtonResume(), null);
157 jContentPane.add(getJButtonExit(), null);
158 }
159 return jContentPane;
160 }
161
162 /**
163 Call setWarningMessage to set messages of frame when it is used for Setup
164
165 **/
166 public void setSetupMessage() {
167 String strTitle = "Exit Setup";
168 String strMessage = "Setup is not complete. If you quit now, the program will not be installed.";
169 String strResume = "You may run the setup program at a later time to complete the installation.";
170 String strExit = "To continue installing, click Resume. To quit the Setup program, click Exit.";
171 setWarningMessage(strTitle, strMessage, strResume, strExit);
172 }
173
174 /**
175 Call setWarningMessage to set messages of frame when it is used for Module Main GUI
176
177 **/
178 public void setModuleMessage() {
179 String strTitle = "Exit";
180 String strMessage = "Do you really want to quit now?";
181 String strResume = "All unsaved module information will be lost.";
182 String strExit = "To continue editing module, click Resume. To quit the program, click Exit.";
183 setWarningMessage(strTitle, strMessage, strResume, strExit);
184 }
185
186 /**
187 Set message information via input data
188
189 @param strTitle The title value
190 @param strMessage The main message value
191 @param strResume The resume message value
192 @param strExit The exit message value
193
194 **/
195 private void setWarningMessage(String strTitle, String strMessage, String strResume, String strExit) {
196 this.setTitle(strTitle);
197 jLabelMessage.setText(strMessage);
198 jLabelResume.setText(strResume);
199 jLabelExit.setText(strExit);
200 }
201
202 /* (non-Javadoc)
203 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
204 *
205 * Override actionPerformed to listern all actions
206 *
207 */
208 public void actionPerformed(ActionEvent arg0) {
209 //
210 //Set isCancel true when click button "Exit"
211 //
212 Object obj = arg0.getSource();
213 if (obj == jButtonResume) {
214 isCancel = false;
215 }
216 if (obj == jButtonExit) {
217 isCancel = true;
218 }
219 this.setVisible(false);
220 }
221
222 /**
223 Make the window in the center of the screen
224
225 **/
226 private void centerWindow() {
227 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
228 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
229 }
230
231 public void windowActivated(WindowEvent arg0) {
232 // TODO Auto-generated method stub
233
234 }
235
236 public void windowClosed(WindowEvent arg0) {
237 // TODO Auto-generated method stub
238
239 }
240
241 public void windowClosing(WindowEvent arg0) {
242 isCancel = false;
243 this.setVisible(false);
244 }
245
246 public void windowDeactivated(WindowEvent arg0) {
247 // TODO Auto-generated method stub
248
249 }
250
251 public void windowDeiconified(WindowEvent arg0) {
252 // TODO Auto-generated method stub
253
254 }
255
256 public void windowIconified(WindowEvent arg0) {
257 // TODO Auto-generated method stub
258
259 }
260
261 public void windowOpened(WindowEvent arg0) {
262 // TODO Auto-generated method stub
263
264 }
265 }