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