]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PackagingMain.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 / PackagingMain.java
1 /** @file
2 Java class PackagingMain is top level GUI for PackageEditor.
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.FlowLayout;
24 import javax.swing.JButton;
25 import java.awt.GridLayout;
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.util.jar.JarOutputStream;
29
30 /**
31 GUI for show various GUI wizards for create, update spd file; install, remove package;
32 create distributable package file.
33
34 @since PackageEditor 1.0
35 **/
36 public class PackagingMain extends JFrame {
37
38 static JFrame frame;
39
40 static String dirForNewSpd = null;
41
42 private JPanel jContentPane = null;
43
44 private JButton jButton = null;
45
46 private JButton jButton1 = null;
47
48 private JButton jButton2 = null;
49
50 private JButton jButton3 = null;
51
52 private JButton jButton4 = null;
53
54 private JButton jButton5 = null;
55
56 private JFrame pThis = null;
57
58 /**
59 This method initializes jButton
60
61 @return javax.swing.JButton
62 **/
63 private JButton getJButton() {
64 if (jButton == null) {
65 jButton = new JButton();
66 jButton.setEnabled(true);
67 jButton.setText("Exit");
68 jButton.addMouseListener(new java.awt.event.MouseAdapter() {
69 public void mouseClicked(java.awt.event.MouseEvent e) {
70 pThis.dispose();
71 }
72 });
73 }
74 return jButton;
75 }
76
77 /**
78 This method initializes jButton1
79
80 @return javax.swing.JButton
81 **/
82 private JButton getJButton1() {
83 if (jButton1 == null) {
84 jButton1 = new JButton();
85 jButton1.setText("Create an Installable Package");
86 jButton1.setEnabled(true);
87 jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
88 public void mouseClicked(java.awt.event.MouseEvent e) {
89 File theFile = null;
90 JFileChooser chooser = new JFileChooser();
91 //
92 // select the directory that contains files to be distribute
93 //
94 chooser.setMultiSelectionEnabled(false);
95 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
96 int retval = chooser.showOpenDialog(frame);
97 if (retval == JFileChooser.APPROVE_OPTION) {
98 try {
99 theFile = chooser.getSelectedFile();
100 //
101 // find the FDPManifest.xml file that should exist
102 // in the root directory of package
103 //
104 String[] list = theFile.list();
105 boolean manifestExists = false;
106 for (int i = 0; i < list.length; i++) {
107 if (list[i].equals("FDPManifest.xml")) {
108 manifestExists = true;
109 break;
110 }
111 }
112 if (!manifestExists) {
113 JOptionPane.showMessageDialog(frame,
114 "Please Put the FDPManifest.xml File under the Directory You Selected!");
115 return;
116 }
117 //
118 // create the distribute package .fdp file in the same directory with
119 // the package root directory selected above.
120 //
121 JarOutputStream jos = new JarOutputStream(new FileOutputStream(theFile.getPath() + ".fdp"));
122 CreateFdp.create(theFile, jos, theFile.getPath());
123 jos.close();
124 JOptionPane.showMessageDialog(frame,
125 "FDP File Created Successfully!");
126
127
128 } catch (Exception ee) {
129 System.out.println(ee.toString());
130 }
131 } else {
132 return;
133 }
134 }
135 });
136 }
137 return jButton1;
138 }
139
140 /**
141 This method initializes jButton2
142
143 @return javax.swing.JButton
144 **/
145 private JButton getJButton2() {
146 if (jButton2 == null) {
147 jButton2 = new JButton();
148 jButton2.setText("Remove Package");
149 jButton2.setEnabled(true);
150 jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
151 public void mouseClicked(java.awt.event.MouseEvent e) {
152 ModalFrameUtil.showAsModal(new GuiPkgUninstall(), pThis);
153 }
154 });
155 }
156 return jButton2;
157 }
158
159 /**
160 This method initializes jButton3
161
162 @return javax.swing.JButton
163 **/
164 private JButton getJButton3() {
165 if (jButton3 == null) {
166 jButton3 = new JButton();
167 jButton3.setText("Install Package");
168 jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
169 public void mouseClicked(java.awt.event.MouseEvent e) {
170 ModalFrameUtil.showAsModal(new GuiPkgInstall(), pThis);
171 }
172 });
173 }
174 return jButton3;
175 }
176
177 /**
178 This method initializes jButton4
179
180 @return javax.swing.JButton
181 **/
182 private JButton getJButton4() {
183 if (jButton4 == null) {
184 jButton4 = new JButton();
185 jButton4.setText("Update Package Description File");
186 jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
187 public void mouseClicked(java.awt.event.MouseEvent e) {
188 File theFile = null;
189 JFileChooser chooser = new JFileChooser();
190 //
191 // select the spd file to be updated first
192 //
193 chooser.setMultiSelectionEnabled(false);
194 chooser.setFileFilter(new PkgFileFilter("spd"));
195 int retval = chooser.showOpenDialog(frame);
196 if (retval == JFileChooser.APPROVE_OPTION) {
197 try {
198 theFile = chooser.getSelectedFile();
199 if (!theFile.isFile()) {
200 JOptionPane.showMessageDialog(frame, "Please Select one Spd File!");
201 return;
202 }
203
204 } catch (Exception ee) {
205 System.out.println(ee.toString());
206 }
207 } else {
208 return;
209 }
210 //
211 // create a SpdFileContents for this file and pass it to GUI
212 //
213 SpdFileContents sfc = new SpdFileContents(theFile);
214 ModalFrameUtil.showAsModal(new UpdateAction(sfc), pThis);
215 }
216 });
217 }
218 return jButton4;
219 }
220
221 /**
222 This method initializes jButton5
223
224 @return javax.swing.JButton
225 **/
226 private JButton getJButton5() {
227 if (jButton5 == null) {
228 jButton5 = new JButton();
229 jButton5.setText("Create Package Description File");
230 jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
231 public void mouseClicked(java.awt.event.MouseEvent e) {
232 JFileChooser chooser = new JFileChooser(System.getenv("WORKSPACE"));
233 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
234 chooser.setMultiSelectionEnabled(false);
235 chooser.setDialogTitle("Please specify where to save the new spd file");
236
237 int retval = chooser.showSaveDialog(frame);
238 if (retval == JFileChooser.APPROVE_OPTION) {
239 try {
240 File theFile = chooser.getSelectedFile();
241 PackagingMain.dirForNewSpd = theFile.getPath();
242
243 } catch (Exception ee) {
244 System.out.println(ee.toString());
245 }
246 // pThis.dispose();
247 }
248 else {
249 return;
250 }
251 SpdFileContents sfc = new SpdFileContents();
252 ModalFrameUtil.showAsModal(new PackageAction(sfc), pThis);
253 }
254 });
255 }
256 return jButton5;
257 }
258
259 /**
260 Main for all package editor
261
262 @param args
263 **/
264 public static void main(String[] args) {
265 // TODO Auto-generated method stub
266 new PackagingMain().setVisible(true);
267 }
268
269 /**
270 This is the default constructor
271 **/
272 public PackagingMain() {
273 super();
274 initialize();
275 pThis = this;
276 }
277
278 /**
279 This method initializes this
280
281 @return void
282 **/
283 private void initialize() {
284 this.setSize(300, 357);
285 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
286 this.setTitle("Packaging");
287 this.setContentPane(getJContentPane());
288 this.centerWindow();
289 }
290
291 /**
292 Start the window at the center of screen
293
294 **/
295 protected void centerWindow(int intWidth, int intHeight) {
296 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
297 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
298 }
299
300 /**
301 Start the window at the center of screen
302
303 **/
304 protected void centerWindow() {
305 centerWindow(this.getSize().width, this.getSize().height);
306 }
307
308 /**
309 This method initializes jContentPane
310
311 @return javax.swing.JPanel
312 **/
313 private JPanel getJContentPane() {
314 if (jContentPane == null) {
315 GridLayout gridLayout = new GridLayout();
316 gridLayout.setRows(6);
317 gridLayout.setColumns(1);
318 jContentPane = new JPanel();
319 jContentPane.setLayout(gridLayout);
320 jContentPane.add(getJButton5(), null);
321 jContentPane.add(getJButton4(), null);
322 jContentPane.add(getJButton3(), null);
323 jContentPane.add(getJButton2(), null);
324 jContentPane.add(getJButton1(), null);
325 jContentPane.add(getJButton(), null);
326 }
327 return jContentPane;
328 }
329
330 } // @jve:decl-index=0:visual-constraint="125,31"