3 The file is used to setup tool chain configuration
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
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.
15 package org
.tianocore
.frameworkwizard
;
17 import java
.awt
.event
.ActionEvent
;
19 import java
.io
.IOException
;
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
;
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
;
36 public class ToolChainConfig
extends IDialog
{
39 /// Define Class Members
41 private static final long serialVersionUID
= 1486930966278269085L;
43 private JPanel jContentPane
= null;
45 private JScrollPane jScrollPane
= null;
47 private DefaultTableModel model
= null;
49 private JTable jTable
= null;
51 private JButton jButtonOpen
= null;
53 private JButton jButtonSave
= null;
55 private JButton jButtonClose
= null;
57 private String toolsDir
= Tools
.addFileSeparator(Workspace
.getCurrentWorkspace()) + "Tools"
58 + DataType
.FILE_SEPARATOR
+ "Conf";
60 private String currentFile
= Tools
.addFileSeparator(toolsDir
) + "tools_def.template";
62 private ToolChainConfigVector vtcc
= new ToolChainConfigVector();
65 * This method initializes jScrollPane
67 * @return javax.swing.JScrollPane
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());
79 * This method initializes jTable
81 * @return javax.swing.JTable
83 private JTable
getJTable() {
85 jTable
= new JTable();
86 // model = new DefaultTableModel();
87 // jTable = new JTable(model);
88 // jTable.setRowHeight(20);
94 * This method initializes jButtonOpen
96 * @return javax.swing.JButton
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);
109 * This method initializes jButtonSave
111 * @return javax.swing.JButton
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);
124 * This method initializes jButtonClose
126 * @return javax.swing.JButton
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);
143 public static void main(String
[] args
) {
144 // TODO Auto-generated method stub
149 * This is the default constructor
151 public ToolChainConfig(IFrame parentFrame
, boolean modal
) {
152 super(parentFrame
, modal
);
157 * This method initializes this
161 private void init() {
162 this.setSize(600, 480);
163 this.setContentPane(getJContentPane());
164 this.setTitle("Tool Chain Configuration");
170 File f
= new File(currentFile
);
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());
181 Log
.log("Open file", this.currentFile
+ " Not Found");
188 * This method initializes jContentPane
190 * @return javax.swing.JPanel
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);
205 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
207 * Override actionPerformed to listen all actions
209 public void actionPerformed(ActionEvent arg0
) {
210 if (arg0
.getSource() == jButtonClose
) {
211 this.setVisible(false);
212 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
215 if (arg0
.getSource() == jButtonOpen
) {
216 JFileChooser fc
= new JFileChooser();
217 fc
.setAcceptAllFileFilterUsed(false);
218 fc
.setCurrentDirectory(new File(toolsDir
));
220 int result
= fc
.showSaveDialog(new JPanel());
221 if (result
== JFileChooser
.APPROVE_OPTION
) {
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());
236 if (arg0
.getSource() == jButtonSave
) {
237 JFileChooser fc
= new JFileChooser();
238 fc
.setAcceptAllFileFilterUsed(false);
239 fc
.setCurrentDirectory(new File(toolsDir
));
241 int result
= fc
.showOpenDialog(new JPanel());
242 if (result
== JFileChooser
.APPROVE_OPTION
) {
248 Read content of vector and put then into table
251 private void showTable() {
252 model
= new DefaultTableModel();
253 jTable
= new JTable(model
);
254 jTable
.setRowHeight(20);
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
));
263 this.jScrollPane
.setViewportView(this.jTable
);