]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/GenListDialog.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / GenListDialog.java
1 /** @file
2 Java class GenListDialog.
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.frameworkwizard.platform.ui;
14
15 import java.awt.BorderLayout;
16 import java.awt.Dimension;
17 import java.awt.Toolkit;
18
19 import javax.swing.JComponent;
20 import javax.swing.JPanel;
21 import javax.swing.JDialog;
22 import javax.swing.KeyStroke;
23
24 import javax.swing.JButton;
25
26
27 import java.awt.FlowLayout;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.KeyEvent;
31 import java.util.Vector;
32
33 import javax.swing.JScrollPane;
34
35 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
36
37
38 /**
39 Dialog for List generation.
40 @since PackageEditor 1.0
41 **/
42 public class GenListDialog extends JDialog implements ActionListener{
43
44 /**
45 *
46 */
47 private static final long serialVersionUID = 1L;
48
49 private JPanel jContentPane = null;
50 private JPanel jPanelContentEast = null;
51 private JPanel jPanelContentCenter = null;
52 private JButton jButtonCancel = null;
53 private JButton jButtonOk = null;
54 private ICheckBoxList checkBoxList = null;
55
56
57 private JScrollPane jScrollPane = null;
58
59
60
61 public void actionPerformed(ActionEvent arg0) {
62
63 if (arg0.getSource() == jButtonOk){
64
65 // this.dispose();
66 }
67
68 if (arg0.getSource() == jButtonCancel){
69 this.dispose();
70 }
71 }
72
73 /**
74 * This method initializes jPanel
75 *
76 * @return javax.swing.JPanel
77 */
78 private JPanel getJPanelContentEast() {
79 if (jPanelContentEast == null) {
80 FlowLayout flowLayout = new FlowLayout();
81 flowLayout.setVgap(10);
82 jPanelContentEast = new JPanel();
83 jPanelContentEast.setLayout(flowLayout);
84 jPanelContentEast.setPreferredSize(new java.awt.Dimension(100,30));
85 jPanelContentEast.add(getJButtonOk(), null);
86 jPanelContentEast.add(getJButtonCancel(), null);
87 }
88 return jPanelContentEast;
89 }
90
91 /**
92 * This method initializes jPanel4
93 *
94 * @return javax.swing.JPanel
95 */
96 private JPanel getJPanelContentCenter() {
97 if (jPanelContentCenter == null) {
98 jPanelContentCenter = new JPanel();
99 jPanelContentCenter.setLayout(new FlowLayout());
100 jPanelContentCenter.add(getJScrollPane(), null);
101
102 }
103 return jPanelContentCenter;
104 }
105
106 /**
107 * This method initializes jButton
108 *
109 * @return javax.swing.JButton
110 */
111 private JButton getJButtonCancel() {
112 if (jButtonCancel == null) {
113 jButtonCancel = new JButton();
114 jButtonCancel.setPreferredSize(new java.awt.Dimension(80,20));
115 jButtonCancel.setText("Cancel");
116 jButtonCancel.addActionListener(this);
117 jButtonCancel.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);
118 }
119 return jButtonCancel;
120 }
121
122 /**
123 * This method initializes jButton2
124 *
125 * @return javax.swing.JButton
126 */
127 private JButton getJButtonOk() {
128 if (jButtonOk == null) {
129 jButtonOk = new JButton();
130 jButtonOk.setPreferredSize(new java.awt.Dimension(80,20));
131 jButtonOk.setText("Ok");
132 jButtonOk.setActionCommand("GenGuidValue");
133 jButtonOk.addActionListener(this);
134 }
135 return jButtonOk;
136 }
137
138 /**
139 * This method initializes jScrollPane
140 *
141 * @return javax.swing.JScrollPane
142 */
143 private JScrollPane getJScrollPane() {
144 if (jScrollPane == null) {
145 jScrollPane = new JScrollPane();
146 jScrollPane.setPreferredSize(new java.awt.Dimension(300,100));
147 jScrollPane.setViewportView(getICheckBoxList());
148 }
149 return jScrollPane;
150 }
151
152 private ICheckBoxList getICheckBoxList() {
153 if (checkBoxList == null) {
154 checkBoxList = new ICheckBoxList();
155 checkBoxList.setBounds(new java.awt.Rectangle(40,20,177,74));
156
157 }
158 return checkBoxList;
159 }
160
161 public void initList(Vector<String> v){
162 checkBoxList.setAllItems(v);
163 }
164 public Vector<String> getList(){
165 Vector<String> v = checkBoxList.getAllCheckedItemsString();
166 return v;
167 }
168
169 public void setList(String s){
170 Vector<String> v = new Vector<String>();
171 if (s == null) {
172 checkBoxList.setAllItemsUnchecked();
173 return;
174 }
175 String[] sArray = s.split(" ");
176 for (int i = 0; i < sArray.length; ++i){
177 v.add(sArray[i]);
178 }
179 checkBoxList.initCheckedItem(true, v);
180 }
181 /**
182 * This is the default constructor
183 */
184 public GenListDialog() {
185 super();
186 initialize();
187 }
188
189 public GenListDialog(ActionListener i){
190 this();
191 jButtonOk.addActionListener(i);
192 jButtonOk.registerKeyboardAction(i, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);
193 }
194
195 /**
196 * This method initializes this
197 *
198 * @return void
199 */
200 private void initialize() {
201 this.setSize(466, 157);
202 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
203 this.setModal(true);
204 this.setTitle("List");
205 this.setContentPane(getJContentPane());
206 this.centerWindow();
207 }
208
209 /**
210 * This method initializes jContentPane
211 *
212 * @return javax.swing.JPanel
213 */
214 private JPanel getJContentPane() {
215 if (jContentPane == null) {
216 jContentPane = new JPanel();
217 jContentPane.setLayout(new BorderLayout());
218 jContentPane.add(getJPanelContentEast(), java.awt.BorderLayout.EAST);
219 jContentPane.add(getJPanelContentCenter(), java.awt.BorderLayout.CENTER);
220 }
221 return jContentPane;
222 }
223
224 /**
225 Start the window at the center of screen
226
227 **/
228 protected void centerWindow(int intWidth, int intHeight) {
229 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
230 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
231 }
232
233 /**
234 Start the window at the center of screen
235
236 **/
237 protected void centerWindow() {
238 centerWindow(this.getSize().width, this.getSize().height);
239 }
240
241
242
243 } // @jve:decl-index=0:visual-constraint="10,10"