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