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