]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PackageAction.java
71d291548da76755847259df940a6526397c5546
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / PackageAction.java
1 /** @file
2 Java class PackageAction is GUI for create spd file.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 **/
13 package org.tianocore.packaging;
14
15 import java.awt.BorderLayout;
16 import java.awt.Dimension;
17 import java.awt.Toolkit;
18
19 import javax.swing.JFileChooser;
20 import javax.swing.JOptionPane;
21 import javax.swing.JPanel;
22 import javax.swing.JFrame;
23 import java.awt.GridLayout;
24 import java.io.File;
25
26 import javax.swing.JButton;
27
28 /**
29 GUI for create spd file
30
31 @since PackageEditor 1.0
32 **/
33 public class PackageAction extends JFrame {
34
35 static JFrame frame;
36
37 private JPanel jContentPane = null;
38
39 private JButton jButton = null;
40
41 private JButton jButton1 = null;
42
43 private JButton jButton2 = null;
44
45 private JButton jButton3 = null;
46
47 private JButton jButton4 = null;
48
49 private JButton jButton5 = null;
50
51 private JButton jButton6 = null;
52
53 private JButton jButton7 = null;
54
55 ///
56 /// SpdFileContents object passed from main
57 ///
58 private SpdFileContents sfc = null;
59
60 private JFrame pThis = null; // @jve:decl-index=0:visual-constraint="304,10"
61
62 private JButton jButton8 = null;
63
64 private JButton jButton9 = null; // @jve:decl-index=0:visual-constraint="116,388"
65
66 /**
67 This is the default constructor
68 **/
69 public PackageAction(SpdFileContents sfc) {
70 super();
71 initialize();
72 this.sfc = sfc;
73 }
74
75 /**
76 This method initializes this
77
78 @return void
79 **/
80 private void initialize() {
81 this.setSize(305, 385);
82 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
83 this.setContentPane(getJContentPane());
84 this.setTitle("Please Choose an Action");
85 this.centerWindow();
86 this.pThis = this;
87
88 }
89
90 /**
91 Start the window at the center of screen
92
93 **/
94 protected void centerWindow(int intWidth, int intHeight) {
95 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
96 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
97 }
98
99 /**
100 Start the window at the center of screen
101
102 **/
103 protected void centerWindow() {
104 centerWindow(this.getSize().width, this.getSize().height);
105 }
106
107 /**
108 This method initializes jContentPane
109
110 @return javax.swing.JPanel
111 **/
112 private JPanel getJContentPane() {
113 if (jContentPane == null) {
114 GridLayout gridLayout = new GridLayout();
115 gridLayout.setRows(10);
116 gridLayout.setColumns(1);
117 jContentPane = new JPanel();
118 jContentPane.setPreferredSize(new java.awt.Dimension(200,300));
119 jContentPane.setLayout(gridLayout);
120 jContentPane.add(getJButton8(), null);
121 jContentPane.add(getJButton7(), null);
122 jContentPane.add(getJButton6(), null);
123 jContentPane.add(getJButton5(), null);
124 jContentPane.add(getJButton4(), null);
125 jContentPane.add(getJButton3(), null);
126 jContentPane.add(getJButton2(), null);
127 jContentPane.add(getJButton1(), null);
128 jContentPane.add(getJButton(), null);
129 jContentPane.add(getJButton9(), null);
130 }
131 return jContentPane;
132 }
133
134 /**
135 This method initializes jButton
136
137 @return javax.swing.JButton
138 **/
139 private JButton getJButton() {
140 if (jButton == null) {
141 jButton = new JButton();
142 jButton.setText("Save");
143 jButton.addMouseListener(new java.awt.event.MouseAdapter() {
144 public void mouseClicked(java.awt.event.MouseEvent e) {
145 //
146 // save sfc contents to file
147 //
148 JFileChooser chooser = new JFileChooser(System.getenv("WORKSPACE"));
149 chooser.setMultiSelectionEnabled(false);
150
151 int retval = chooser.showSaveDialog(frame);
152 if (retval == JFileChooser.APPROVE_OPTION) {
153 try {
154 File theFile = chooser.getSelectedFile();
155 if (theFile.exists()) {
156 int retVal = JOptionPane.showConfirmDialog(frame, "Are you sure to replace the exising one?", "File Exists",
157 JOptionPane.YES_NO_OPTION);
158 if (retVal == JOptionPane.NO_OPTION) {
159 return;
160 }
161 }
162 sfc.saveAs(theFile);
163
164 } catch (Exception ee) {
165 System.out.println(ee.toString());
166 }
167 // pThis.dispose();
168 }
169
170 }
171 });
172 }
173 return jButton;
174 }
175
176 /**
177 This method initializes jButton1
178
179 @return javax.swing.JButton
180 **/
181 private JButton getJButton1() {
182 if (jButton1 == null) {
183 jButton1 = new JButton();
184 jButton1.setText("Add PCD Information");
185 jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
186 public void mouseClicked(java.awt.event.MouseEvent e) {
187 //
188 // Add PCD frame show modal
189 //
190 ModalFrameUtil.showAsModal(new PackagePCD(sfc), pThis);
191 }
192 });
193 }
194 return jButton1;
195 }
196
197 /**
198 This method initializes jButton2
199
200 @return javax.swing.JButton
201 **/
202 private JButton getJButton2() {
203 if (jButton2 == null) {
204 jButton2 = new JButton();
205 jButton2.setText("Add PPI Declarations");
206 jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
207 public void mouseClicked(java.awt.event.MouseEvent e) {
208 //
209 // Add PPI frame show modal
210 //
211 ModalFrameUtil.showAsModal(new PackagePpi(sfc), pThis);
212 }
213 });
214 }
215 return jButton2;
216 }
217
218 /**
219 This method initializes jButton3
220
221 @return javax.swing.JButton
222 **/
223 private JButton getJButton3() {
224 if (jButton3 == null) {
225 jButton3 = new JButton();
226 jButton3.setText("Add Protocol Declarations");
227 jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
228 public void mouseClicked(java.awt.event.MouseEvent e) {
229 ModalFrameUtil.showAsModal(new PackageProtocols(sfc), pThis);
230 }
231 });
232 }
233 return jButton3;
234 }
235
236 /**
237 This method initializes jButton4
238
239 @return javax.swing.JButton
240 **/
241 private JButton getJButton4() {
242 if (jButton4 == null) {
243 jButton4 = new JButton();
244 jButton4.setText("Add GUID Declarations");
245 jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
246 public void mouseClicked(java.awt.event.MouseEvent e) {
247 ModalFrameUtil.showAsModal(new PackageGuids(sfc), pThis);
248 }
249 });
250 }
251 return jButton4;
252 }
253
254 /**
255 This method initializes jButton5
256
257 @return javax.swing.JButton
258 **/
259 private JButton getJButton5() {
260 if (jButton5 == null) {
261 jButton5 = new JButton();
262 jButton5.setText("Add Package Headers");
263 jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
264 public void mouseClicked(java.awt.event.MouseEvent e) {
265 ModalFrameUtil.showAsModal(new PackagePkgHeader(sfc), pThis);
266 }
267 });
268 }
269 return jButton5;
270 }
271
272 /**
273 This method initializes jButton6
274
275 @return javax.swing.JButton
276 **/
277 private JButton getJButton6() {
278 if (jButton6 == null) {
279 jButton6 = new JButton();
280 jButton6.setText("Add MSA Files");
281 jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
282 public void mouseClicked(java.awt.event.MouseEvent e) {
283 ModalFrameUtil.showAsModal(new PackageMsaFile(sfc), pThis);
284 }
285 });
286 }
287 return jButton6;
288 }
289
290 /**
291 This method initializes jButton7
292
293 @return javax.swing.JButton
294 **/
295 private JButton getJButton7() {
296 if (jButton7 == null) {
297 jButton7 = new JButton();
298 jButton7.setText("Add Library Classes");
299 jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
300 public void mouseClicked(java.awt.event.MouseEvent e) {
301 ModalFrameUtil.showAsModal(new PackageLibraryClass(sfc), pThis);
302 }
303 });
304 }
305 return jButton7;
306 }
307
308 /**
309 This method initializes jButton8
310
311 @return javax.swing.JButton
312 **/
313 private JButton getJButton8() {
314 if (jButton8 == null) {
315 jButton8 = new JButton();
316 jButton8.setText("Add SPD Header");
317 jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
318 public void mouseClicked(java.awt.event.MouseEvent e) {
319 ModalFrameUtil.showAsModal(new PackageNew(sfc), pThis);
320 }
321 });
322 }
323 return jButton8;
324 }
325
326 /**
327 This method initializes jButton9
328
329 @return javax.swing.JButton
330 **/
331 private JButton getJButton9() {
332 if (jButton9 == null) {
333 jButton9 = new JButton();
334 jButton9.setText("Done");
335 jButton9.addMouseListener(new java.awt.event.MouseAdapter() {
336 public void mouseClicked(java.awt.event.MouseEvent e) {
337 //
338 // quit current frame
339 //
340 pThis.dispose();
341
342 }
343 });
344 }
345 return jButton9;
346 }
347
348 } // @jve:decl-index=0:visual-constraint="104,41"