]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PackageMsaFile.java
Initial import.
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / PackageMsaFile.java
1 /** @file
2 Java class PackageMsaFile is GUI for create MsaFile elements of 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 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.io.File;
21 import java.util.Vector;
22
23 import javax.swing.DefaultListModel;
24 import javax.swing.JFileChooser;
25 import javax.swing.JOptionPane;
26 import javax.swing.JPanel;
27 import javax.swing.JRadioButton;
28 import javax.swing.JTextField;
29 import javax.swing.JComboBox;
30 import javax.swing.JLabel;
31 import javax.swing.JList;
32 import javax.swing.JScrollPane;
33 import javax.swing.JButton;
34 import javax.swing.JFrame;
35
36 /**
37 GUI for create MsaFile elements of spd file
38
39 @since PackageEditor 1.0
40 **/
41 public class PackageMsaFile extends JFrame implements ActionListener {
42 static JFrame frame;
43
44 private DefaultListModel listItem = new DefaultListModel();
45
46 private SpdFileContents sfc = null;
47
48 private JPanel jContentPane = null;
49
50 private JScrollPane jScrollPane = null;
51
52 private JList jListLibraryClassDefinitions = null;
53
54 private JButton jButtonAdd = null;
55
56 private JButton jButtonRemove = null;
57
58 private JButton jButtonClearAll = null;
59
60 private JButton jButtonCancel = null;
61
62 private JButton jButtonOk = null;
63
64 private JLabel jLabel = null;
65
66 private JTextField jTextField = null;
67
68 private JButton jButton = null;
69
70 /**
71 This method initializes this
72
73 **/
74 private void initialize() {
75 this.setTitle("MSA Files");
76 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
77
78 }
79
80 /**
81 This method initializes jScrollPane
82
83 @return javax.swing.JScrollPane
84 **/
85 private JScrollPane getJScrollPane() {
86 if (jScrollPane == null) {
87 jScrollPane = new JScrollPane();
88 jScrollPane.setBounds(new java.awt.Rectangle(10, 85, 350, 210));
89 jScrollPane.setViewportView(getJListLibraryClassDefinitions());
90 }
91 return jScrollPane;
92 }
93
94 /**
95 This method initializes jListLibraryClassDefinitions
96
97 @return javax.swing.JList
98 **/
99 private JList getJListLibraryClassDefinitions() {
100 if (jListLibraryClassDefinitions == null) {
101 jListLibraryClassDefinitions = new JList(listItem);
102 }
103 return jListLibraryClassDefinitions;
104 }
105
106 /**
107 This method initializes jButtonAdd
108
109 @return javax.swing.JButton
110 **/
111 private JButton getJButtonAdd() {
112 if (jButtonAdd == null) {
113 jButtonAdd = new JButton();
114 jButtonAdd.setBounds(new java.awt.Rectangle(375, 132, 90, 20));
115 jButtonAdd.setText("Add");
116 jButtonAdd.addActionListener(this);
117 }
118 return jButtonAdd;
119 }
120
121 /**
122 This method initializes jButtonRemove
123
124 @return javax.swing.JButton
125 **/
126 private JButton getJButtonRemove() {
127 if (jButtonRemove == null) {
128 jButtonRemove = new JButton();
129 jButtonRemove.setBounds(new java.awt.Rectangle(375, 230, 90, 20));
130 jButtonRemove.setText("Remove");
131 jButtonRemove.addActionListener(this);
132 }
133 return jButtonRemove;
134 }
135
136 /**
137 This method initializes jButtonRemoveAll
138
139 @return javax.swing.JButton
140 **/
141 private JButton getJButtonClearAll() {
142 if (jButtonClearAll == null) {
143 jButtonClearAll = new JButton();
144 jButtonClearAll.setBounds(new java.awt.Rectangle(375, 260, 90, 20));
145 jButtonClearAll.setText("Clear All");
146 jButtonClearAll.addActionListener(this);
147 }
148 return jButtonClearAll;
149 }
150
151 /**
152 This method initializes jButtonCancel
153
154 @return javax.swing.JButton
155 **/
156 private JButton getJButtonCancel() {
157 if (jButtonCancel == null) {
158 jButtonCancel = new JButton();
159 jButtonCancel.setPreferredSize(new java.awt.Dimension(90, 20));
160 jButtonCancel.setLocation(new java.awt.Point(390, 305));
161 jButtonCancel.setText("Cancel");
162 jButtonCancel.setSize(new java.awt.Dimension(90, 20));
163 jButtonCancel.addActionListener(this);
164 }
165 return jButtonCancel;
166 }
167
168 /**
169 This method initializes jButton
170
171 @return javax.swing.JButton
172 **/
173 private JButton getJButtonOk() {
174 if (jButtonOk == null) {
175 jButtonOk = new JButton();
176 jButtonOk.setSize(new java.awt.Dimension(90, 20));
177 jButtonOk.setText("OK");
178 jButtonOk.setLocation(new java.awt.Point(290, 305));
179 jButtonOk.addActionListener(this);
180 }
181 return jButtonOk;
182 }
183
184 /**
185 This is the default constructor
186 **/
187 public PackageMsaFile(SpdFileContents sfc) {
188 super();
189 initialize();
190 init();
191 this.sfc = sfc;
192 }
193
194 /**
195 Start the window at the center of screen
196
197 */
198 protected void centerWindow(int intWidth, int intHeight) {
199 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
200 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
201 }
202
203 /**
204 Start the window at the center of screen
205
206 **/
207 protected void centerWindow() {
208 centerWindow(this.getSize().width, this.getSize().height);
209 }
210
211 /**
212 This method initializes this
213
214 @return void
215 **/
216 private void init() {
217 this.setContentPane(getJContentPane());
218 this.setTitle("Library Class Declarations");
219 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
220 this.centerWindow();
221 initFrame();
222 }
223
224 /**
225 This method initializes jContentPane
226
227 @return javax.swing.JPanel
228 **/
229 private JPanel getJContentPane() {
230 if (jContentPane == null) {
231 jLabel = new JLabel();
232 jLabel.setBounds(new java.awt.Rectangle(11,20,143,22));
233 jLabel.setText("Msa File Path and Name");
234 jContentPane = new JPanel();
235 jContentPane.setLayout(null);
236 jContentPane.add(getJScrollPane(), null);
237 jContentPane.add(getJButtonAdd(), null);
238 jContentPane.add(getJButtonRemove(), null);
239 jContentPane.add(getJButtonClearAll(), null);
240 jContentPane.add(getJButtonCancel(), null);
241 jContentPane.add(getJButtonOk(), null);
242 jContentPane.add(jLabel, null);
243 jContentPane.add(getJTextField(), null);
244 jContentPane.add(getJButton(), null);
245 }
246 return jContentPane;
247 }
248
249 private void initFrame() {
250
251 }
252
253 public void actionPerformed(ActionEvent arg0) {
254 if (arg0.getSource() == jButtonOk) {
255 this.dispose();
256 this.save();
257 }
258 if (arg0.getSource() == jButtonCancel) {
259 this.dispose();
260 }
261
262 if (arg0.getSource() == jButtonAdd) {
263
264 listItem.addElement(jTextField.getText());
265 }
266
267 if (arg0.getSource() == jButtonRemove) {
268 int intSelected[] = jListLibraryClassDefinitions.getSelectedIndices();
269 if (intSelected.length > 0) {
270 for (int index = intSelected.length - 1; index > -1; index--) {
271 listItem.removeElementAt(intSelected[index]);
272 }
273 }
274 jListLibraryClassDefinitions.getSelectionModel().clearSelection();
275 }
276
277 if (arg0.getSource() == jButtonClearAll) {
278 listItem.removeAllElements();
279 }
280
281 }
282
283 protected void save() {
284 try {
285 int intLibraryCount = listItem.getSize();
286
287 if (intLibraryCount > 0) {
288
289 for (int index = 0; index < intLibraryCount; index++) {
290 String strAll = listItem.get(index).toString();
291 sfc.genSpdMsaFiles(strAll, null);
292 }
293 } else {
294
295 }
296
297 } catch (Exception e) {
298 System.out.println(e.toString());
299 }
300 }
301
302 /**
303 This method initializes jTextField
304
305 @return javax.swing.JTextField
306 **/
307 private JTextField getJTextField() {
308 if (jTextField == null) {
309 jTextField = new JTextField();
310 jTextField.setBounds(new java.awt.Rectangle(11,44,349,21));
311 }
312 return jTextField;
313 }
314
315 /**
316 This method initializes jButton
317
318 @return javax.swing.JButton
319 **/
320 private JButton getJButton() {
321 if (jButton == null) {
322 jButton = new JButton();
323 jButton.setBounds(new java.awt.Rectangle(377,46,89,20));
324 jButton.setText("Browse");
325 jButton.setPreferredSize(new java.awt.Dimension(34,20));
326 jButton.addMouseListener(new java.awt.event.MouseAdapter() {
327 public void mouseClicked(java.awt.event.MouseEvent e) {
328 JFileChooser chooser = new JFileChooser(System.getenv("WORKSPACE"));
329
330 chooser.setMultiSelectionEnabled(false);
331 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
332 chooser.setFileFilter(new PkgFileFilter("msa"));
333 int retval = chooser.showOpenDialog(frame);
334 if (retval == JFileChooser.APPROVE_OPTION) {
335
336 File theFile = chooser.getSelectedFile();
337 String file = theFile.getPath();
338 if (!file.startsWith(System.getenv("WORKSPACE"))) {
339 JOptionPane.showMessageDialog(frame, "You can only select files in current workspace!");
340 return;
341 }
342 int fileIndex = file.indexOf(System.getProperty("file.separator"), System.getenv("WORKSPACE").length() + 1);
343 jTextField.setText(file.substring(fileIndex + 1));
344
345 }
346 }
347 });
348 }
349 return jButton;
350 }
351
352 }