]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PackagingMain.java
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 static String dirForNewSpd
= null;
42 private JPanel jContentPane
= null;
44 private JButton jButton
= null;
46 private JButton jButton1
= null;
48 private JButton jButton2
= null;
50 private JButton jButton3
= null;
52 private JButton jButton4
= null;
54 private JButton jButton5
= null;
56 private JFrame pThis
= null;
59 This method initializes jButton
61 @return javax.swing.JButton
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
) {
78 This method initializes jButton1
80 @return javax.swing.JButton
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
) {
90 JFileChooser chooser
= new JFileChooser();
92 // select the directory that contains files to be distribute
94 chooser
.setMultiSelectionEnabled(false);
95 chooser
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
96 int retval
= chooser
.showOpenDialog(frame
);
97 if (retval
== JFileChooser
.APPROVE_OPTION
) {
99 theFile
= chooser
.getSelectedFile();
101 // find the FDPManifest.xml file that should exist
102 // in the root directory of package
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;
112 if (!manifestExists
) {
113 JOptionPane
.showMessageDialog(frame
,
114 "Please Put the FDPManifest.xml File under the Directory You Selected!");
118 // create the distribute package .fdp file in the same directory with
119 // the package root directory selected above.
121 JarOutputStream jos
= new JarOutputStream(new FileOutputStream(theFile
.getPath() + ".fdp"));
122 CreateFdp
.create(theFile
, jos
, theFile
.getPath());
124 JOptionPane
.showMessageDialog(frame
,
125 "FDP File Created Successfully!");
128 } catch (Exception ee
) {
129 System
.out
.println(ee
.toString());
141 This method initializes jButton2
143 @return javax.swing.JButton
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
);
160 This method initializes jButton3
162 @return javax.swing.JButton
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
);
178 This method initializes jButton4
180 @return javax.swing.JButton
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
) {
189 JFileChooser chooser
= new JFileChooser();
191 // select the spd file to be updated first
193 chooser
.setMultiSelectionEnabled(false);
194 chooser
.setFileFilter(new PkgFileFilter("spd"));
195 int retval
= chooser
.showOpenDialog(frame
);
196 if (retval
== JFileChooser
.APPROVE_OPTION
) {
198 theFile
= chooser
.getSelectedFile();
199 if (!theFile
.isFile()) {
200 JOptionPane
.showMessageDialog(frame
, "Please Select one Spd File!");
204 } catch (Exception ee
) {
205 System
.out
.println(ee
.toString());
211 // create a SpdFileContents for this file and pass it to GUI
213 SpdFileContents sfc
= new SpdFileContents(theFile
);
214 ModalFrameUtil
.showAsModal(new UpdateAction(sfc
), pThis
);
222 This method initializes jButton5
224 @return javax.swing.JButton
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");
237 int retval
= chooser
.showSaveDialog(frame
);
238 if (retval
== JFileChooser
.APPROVE_OPTION
) {
240 File theFile
= chooser
.getSelectedFile();
241 PackagingMain
.dirForNewSpd
= theFile
.getPath();
243 } catch (Exception ee
) {
244 System
.out
.println(ee
.toString());
251 SpdFileContents sfc
= new SpdFileContents();
252 ModalFrameUtil
.showAsModal(new PackageAction(sfc
), pThis
);
260 Main for all package editor
264 public static void main(String
[] args
) {
265 // TODO Auto-generated method stub
266 new PackagingMain().setVisible(true);
270 This is the default constructor
272 public PackagingMain() {
279 This method initializes this
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());
292 Start the window at the center of screen
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);
301 Start the window at the center of screen
304 protected void centerWindow() {
305 centerWindow(this.getSize().width
, this.getSize().height
);
309 This method initializes jContentPane
311 @return javax.swing.JPanel
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);
330 } // @jve:decl-index=0:visual-constraint="125,31"