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