]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/ToolChainConfig.java
1. Restructure some folders and files
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / ToolChainConfig.java
1 /** @file
2
3 The file is used to setup tool chain configuration
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15 package org.tianocore.frameworkwizard;
16
17 import java.awt.event.ActionEvent;
18 import java.io.File;
19 import java.io.IOException;
20
21 import javax.swing.JButton;
22 import javax.swing.JFileChooser;
23 import javax.swing.JPanel;
24 import javax.swing.JScrollPane;
25 import javax.swing.JTable;
26 import javax.swing.table.DefaultTableModel;
27
28 import org.tianocore.frameworkwizard.common.DataType;
29 import org.tianocore.frameworkwizard.common.Log;
30 import org.tianocore.frameworkwizard.common.Tools;
31 import org.tianocore.frameworkwizard.common.Identifications.ToolChainConfigVector;
32 import org.tianocore.frameworkwizard.common.ui.IDialog;
33 import org.tianocore.frameworkwizard.common.ui.IFrame;
34 import org.tianocore.frameworkwizard.workspace.Workspace;
35
36 public class ToolChainConfig extends IDialog {
37
38 ///
39 /// Define Class Members
40 ///
41 private static final long serialVersionUID = 1486930966278269085L;
42
43 private JPanel jContentPane = null;
44
45 private JScrollPane jScrollPane = null;
46
47 private DefaultTableModel model = null;
48
49 private JTable jTable = null;
50
51 private JButton jButtonOpen = null;
52
53 private JButton jButtonSave = null;
54
55 private JButton jButtonClose = null;
56
57 private String toolsDir = Tools.addFileSeparator(Workspace.getCurrentWorkspace()) + "Tools"
58 + DataType.FILE_SEPARATOR + "Conf";
59
60 private String currentFile = Tools.addFileSeparator(toolsDir) + "tools_def.template";
61
62 private ToolChainConfigVector vtcc = new ToolChainConfigVector();
63
64 /**
65 * This method initializes jScrollPane
66 *
67 * @return javax.swing.JScrollPane
68 */
69 private JScrollPane getJScrollPane() {
70 if (jScrollPane == null) {
71 jScrollPane = new JScrollPane();
72 jScrollPane.setBounds(new java.awt.Rectangle(15, 15, 555, 345));
73 jScrollPane.setViewportView(getJTable());
74 }
75 return jScrollPane;
76 }
77
78 /**
79 * This method initializes jTable
80 *
81 * @return javax.swing.JTable
82 */
83 private JTable getJTable() {
84 if (jTable == null) {
85 jTable = new JTable();
86 // model = new DefaultTableModel();
87 // jTable = new JTable(model);
88 // jTable.setRowHeight(20);
89 }
90 return jTable;
91 }
92
93 /**
94 * This method initializes jButtonOpen
95 *
96 * @return javax.swing.JButton
97 */
98 private JButton getJButtonOpen() {
99 if (jButtonOpen == null) {
100 jButtonOpen = new JButton();
101 jButtonOpen.setBounds(new java.awt.Rectangle(140, 390, 120, 25));
102 jButtonOpen.setText("Open a file");
103 jButtonOpen.addActionListener(this);
104 }
105 return jButtonOpen;
106 }
107
108 /**
109 * This method initializes jButtonSave
110 *
111 * @return javax.swing.JButton
112 */
113 private JButton getJButtonSave() {
114 if (jButtonSave == null) {
115 jButtonSave = new JButton();
116 jButtonSave.setBounds(new java.awt.Rectangle(280, 390, 120, 25));
117 jButtonSave.setText("Save to a file");
118 jButtonSave.addActionListener(this);
119 }
120 return jButtonSave;
121 }
122
123 /**
124 * This method initializes jButtonClose
125 *
126 * @return javax.swing.JButton
127 */
128 private JButton getJButtonClose() {
129 if (jButtonClose == null) {
130 jButtonClose = new JButton();
131 jButtonClose.setBounds(new java.awt.Rectangle(465, 390, 100, 25));
132 jButtonClose.setText("Close");
133 jButtonClose.addActionListener(this);
134 }
135 return jButtonClose;
136 }
137
138 /**
139
140 @param args
141
142 **/
143 public static void main(String[] args) {
144 // TODO Auto-generated method stub
145
146 }
147
148 /**
149 * This is the default constructor
150 */
151 public ToolChainConfig(IFrame parentFrame, boolean modal) {
152 super(parentFrame, modal);
153 init();
154 }
155
156 /**
157 * This method initializes this
158 *
159 * @return void
160 */
161 private void init() {
162 this.setSize(600, 480);
163 this.setContentPane(getJContentPane());
164 this.setTitle("Tool Chain Configuration");
165 this.centerWindow();
166
167 //
168 // Read default file
169 //
170 File f = new File(currentFile);
171 if (f.exists()) {
172 try {
173 vtcc.removeAll();
174 vtcc.parseFile(this.currentFile);
175 this.setTitle("Tool Chain Configuration" + " [" + currentFile + "]");
176 } catch (IOException e) {
177 Log.log(this.currentFile + "Read Error", e.getMessage());
178 e.printStackTrace();
179 }
180 } else {
181 Log.log("Open file", this.currentFile + " Not Found");
182 }
183
184 showTable();
185 }
186
187 /**
188 * This method initializes jContentPane
189 *
190 * @return javax.swing.JPanel
191 */
192 private JPanel getJContentPane() {
193 if (jContentPane == null) {
194 jContentPane = new JPanel();
195 jContentPane.setLayout(null);
196 jContentPane.add(getJScrollPane(), null);
197 jContentPane.add(getJButtonOpen(), null);
198 jContentPane.add(getJButtonSave(), null);
199 jContentPane.add(getJButtonClose(), null);
200 }
201 return jContentPane;
202 }
203
204 /* (non-Javadoc)
205 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
206 *
207 * Override actionPerformed to listen all actions
208 */
209 public void actionPerformed(ActionEvent arg0) {
210 if (arg0.getSource() == jButtonClose) {
211 this.setVisible(false);
212 this.returnType = DataType.RETURN_TYPE_CANCEL;
213 }
214
215 if (arg0.getSource() == jButtonOpen) {
216 JFileChooser fc = new JFileChooser();
217 fc.setAcceptAllFileFilterUsed(false);
218 fc.setCurrentDirectory(new File(toolsDir));
219
220 int result = fc.showSaveDialog(new JPanel());
221 if (result == JFileChooser.APPROVE_OPTION) {
222 try {
223 vtcc.removeAll();
224 vtcc.parseFile(fc.getSelectedFile().getPath());
225 currentFile = fc.getSelectedFile().getPath();
226 this.setTitle("Tool Chain Configuration" + " [" + currentFile + "]");
227 } catch (IOException e) {
228 Log.err(this.currentFile + "Read Error", e.getMessage());
229 e.printStackTrace();
230 return;
231 }
232 this.showTable();
233 }
234 }
235
236 if (arg0.getSource() == jButtonSave) {
237 JFileChooser fc = new JFileChooser();
238 fc.setAcceptAllFileFilterUsed(false);
239 fc.setCurrentDirectory(new File(toolsDir));
240
241 int result = fc.showOpenDialog(new JPanel());
242 if (result == JFileChooser.APPROVE_OPTION) {
243 }
244 }
245 }
246
247 /**
248 Read content of vector and put then into table
249
250 **/
251 private void showTable() {
252 model = new DefaultTableModel();
253 jTable = new JTable(model);
254 jTable.setRowHeight(20);
255
256 model.addColumn("Name");
257 model.addColumn("Value");
258 if (vtcc.size() > 0) {
259 for (int index = 0; index < vtcc.size(); index++) {
260 model.addRow(vtcc.toStringVector(index));
261 }
262 }
263 this.jScrollPane.setViewportView(this.jTable);
264 }
265 }