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