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