]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PackagingMain.java
bca1108045e935894e8b109048ec8d908530b440
2 Java class PackagingMain is top level GUI for PackageEditor.
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
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.
13 package org
.tianocore
.packaging
;
15 import java
.awt
.BorderLayout
;
16 import java
.awt
.Dimension
;
17 import java
.awt
.Toolkit
;
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
;
27 import java
.io
.FileOutputStream
;
28 import java
.util
.jar
.JarOutputStream
;
31 GUI for show various GUI wizards for create, update spd file; install, remove package;
32 create distributable package file.
34 @since PackageEditor 1.0
36 public class PackagingMain
extends JFrame
{
40 private JPanel jContentPane
= null;
42 private JButton jButton
= null;
44 private JButton jButton1
= null;
46 private JButton jButton2
= null;
48 private JButton jButton3
= null;
50 private JButton jButton4
= null;
52 private JButton jButton5
= null;
54 private JFrame pThis
= null;
57 This method initializes jButton
59 @return javax.swing.JButton
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
) {
76 This method initializes jButton1
78 @return javax.swing.JButton
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
) {
88 JFileChooser chooser
= new JFileChooser();
90 // select the directory that contains files to be distribute
92 chooser
.setMultiSelectionEnabled(false);
93 chooser
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
94 int retval
= chooser
.showOpenDialog(frame
);
95 if (retval
== JFileChooser
.APPROVE_OPTION
) {
97 theFile
= chooser
.getSelectedFile();
99 // find the FDPManifest.xml file that should exist
100 // in the root directory of package
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;
110 if (!manifestExists
) {
111 JOptionPane
.showMessageDialog(frame
,
112 "Please Put the FDPManifest.xml File under the Directory You Selected!");
116 // create the distribute package .fdp file in the same directory with
117 // the package root directory selected above.
119 JarOutputStream jos
= new JarOutputStream(new FileOutputStream(theFile
.getPath() + ".fdp"));
120 CreateFdp
.create(theFile
, jos
, theFile
.getPath());
122 JOptionPane
.showMessageDialog(frame
,
123 "FDP File Created Successfully!");
126 } catch (Exception ee
) {
127 System
.out
.println(ee
.toString());
139 This method initializes jButton2
141 @return javax.swing.JButton
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
);
158 This method initializes jButton3
160 @return javax.swing.JButton
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
);
176 This method initializes jButton4
178 @return javax.swing.JButton
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
) {
187 JFileChooser chooser
= new JFileChooser();
189 // select the spd file to be updated first
191 chooser
.setMultiSelectionEnabled(false);
192 chooser
.setFileFilter(new PkgFileFilter("spd"));
193 int retval
= chooser
.showOpenDialog(frame
);
194 if (retval
== JFileChooser
.APPROVE_OPTION
) {
196 theFile
= chooser
.getSelectedFile();
197 if (!theFile
.isFile()) {
198 JOptionPane
.showMessageDialog(frame
, "Please Select one Spd File!");
202 } catch (Exception ee
) {
203 System
.out
.println(ee
.toString());
209 // create a SpdFileContents for this file and pass it to GUI
211 SpdFileContents sfc
= new SpdFileContents(theFile
);
212 ModalFrameUtil
.showAsModal(new UpdateAction(sfc
), pThis
);
220 This method initializes jButton5
222 @return javax.swing.JButton
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
);
239 Main for all package editor
243 public static void main(String
[] args
) {
244 // TODO Auto-generated method stub
245 new PackagingMain().setVisible(true);
249 This is the default constructor
251 public PackagingMain() {
258 This method initializes this
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());
271 Start the window at the center of screen
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);
280 Start the window at the center of screen
283 protected void centerWindow() {
284 centerWindow(this.getSize().width
, this.getSize().height
);
288 This method initializes jContentPane
290 @return javax.swing.JPanel
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);
309 } // @jve:decl-index=0:visual-constraint="125,31"