Print this page
4719 Common patchset for jdk1.7 support preparation
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/krb5/kadmin/gui/dchanger/EncListDialog.java
+++ new/usr/src/cmd/krb5/kadmin/gui/dchanger/EncListDialog.java
1 1 /*
2 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 3 * Use is subject to license terms.
4 4 *
5 5 * ident "%Z%%M% %I% %E% SMI"
6 6 */
7 7
8 8 import java.awt.*;
9 9 import java.awt.event.*;
10 10 import java.text.*;
11 11 import java.util.*;
12 12
13 13 /*
14 14 * This class creates a dialog box that helps the user select encryption types
15 15 * with some mouse clicks. The dialog box need only be created
16 16 * once. The Ok and Cancel buttons merely call setVisible with an
17 17 * argument of false.
18 18 */
19 19
20 20 // The layout will consist of 2 panels:
21 21 // topPanel contains the dynamic list of encryption type check boxes.
22 22 // bottomPanel contains the buttons ok, clear, cancel, and help.
23 23 // The two panels are separated by a LineSeparator.
24 24
25 25 public class EncListDialog extends Dialog {
26 26
27 27 private boolean save;
28 28
29 29 private int i;
30 30
31 31 private Frame parent;
32 32
33 33 private Button ok;
34 34 private Button clear;
35 35 private Button cancel;
36 36 private Button help;
37 37
38 38 private HelpDialog hd = null;
39 39
40 40 private Panel topPanel;
41 41 private Panel bottomPanel;
42 42
43 43 private static Toolkit toolkit = Toolkit.getDefaultToolkit();
44 44
45 45 private Kadmin kadmin;
46 46 private Checkbox cb[];
47 47 private Integer grp_num[];
48 48 private String encList = "";
49 49
50 50 // For I18N
51 51 private static ResourceBundle rb =
52 52 ResourceBundle.getBundle("GuiResource" /* NOI18N */);
53 53 private static ResourceBundle hrb =
54 54 ResourceBundle.getBundle("HelpData" /* NOI18N */);
55 55
56 56 /*
57 57 * Constructor that lays out the components and sets the different
58 58 * event handlers.
59 59 */
60 60 public EncListDialog(Frame parent, Color background, Color foreground,
61 61 Kadmin session) {
62 62 super(parent, getString("SEAM Encryption Type List Helper"),
63 63 true);
64 64
65 65 this.parent = parent;
66 66
67 67 this.kadmin = session;
68 68
69 69 setLayout(new GridBagLayout());
70 70 addCheckboxes();
71 71
72 72 addButtons();
73 73 setSize(250, 300);
74 74 setResizable(true);
75 75
76 76 addWindowListener(new DCWindowListener());
77 77 }
78 78
79 79 /*
80 80 * Adds the check boxes only
81 81 */
82 82 private void addCheckboxes() {
83 83
84 84 GridBagConstraints gbc = new GridBagConstraints();
85 85
86 86 gbc.weighty = 1;
87 87
88 88 topPanel = new Panel();
89 89 topPanel.setLayout(new GridBagLayout());
90 90 gbc.gridwidth = GridBagConstraints.REMAINDER;
91 91 gbc.fill = GridBagConstraints.BOTH;
92 92 gbc.anchor = GridBagConstraints.CENTER;
93 93 gbc.gridx = 0;
94 94 gbc.gridy = 0;
95 95 add(topPanel, gbc);
96 96
97 97 gbc.fill = GridBagConstraints.NONE;
98 98 gbc.anchor = GridBagConstraints.WEST;
99 99 gbc.gridx = 0;
100 100 gbc.gridwidth = 1;
101 101
102 102 String et[] = kadmin.getEncList();
103 103
104 104 cb = new Checkbox[et.length];
105 105 grp_num = new Integer[et.length];
106 106
107 107 for (int i = 0; i < et.length; i++) {
108 108 String[] grp_enc = et[i].split(" ");
109 109 cb[i] = new Checkbox(grp_enc[1]);
110 110 CBListener cbl = new CBListener();
111 111 cb[i].addItemListener(cbl);
112 112 grp_num[i] = new Integer(grp_enc[0]);
113 113 gbc.gridy = i;
114 114 topPanel.add(cb[i], gbc);
115 115 }
116 116 }
117 117
118 118 // Adds all the buttons
119 119 private void addButtons() {
120 120
121 121 GridBagConstraints gbc = new GridBagConstraints();
122 122 gbc.weighty = 1;
123 123
124 124 gbc.gridwidth = GridBagConstraints.REMAINDER;
125 125 gbc.gridheight = 1;
126 126 gbc.fill = GridBagConstraints.BOTH;
127 127 gbc.gridx = 0;
128 128 gbc.gridy = 2;
129 129 add(new LineSeparator(), gbc);
130 130
131 131 bottomPanel = new Panel();
132 132 ok = new Button(getString("OK"));
133 133 clear = new Button(getString("Clear"));
134 134 cancel = new Button(getString("Cancel"));
135 135 help = new Button(getString("Help"));
136 136 bottomPanel.add(ok);
137 137 bottomPanel.add(clear);
138 138 bottomPanel.add(cancel);
139 139 bottomPanel.add(help);
140 140 gbc.fill = GridBagConstraints.HORIZONTAL;
141 141 gbc.gridwidth = GridBagConstraints.REMAINDER;
142 142 gbc.gridx = 0;
143 143 gbc.gridy = 3;
144 144 add(bottomPanel, gbc);
145 145
146 146 DCButtonListener bl = new DCButtonListener();
147 147 ok.addActionListener(bl);
148 148 clear.addActionListener(bl);
149 149 cancel.addActionListener(bl);
150 150 help.addActionListener(bl);
151 151 }
152 152
153 153 /*
154 154 * Closes (hides) the dialog box when the user is done
155 155 * @param save true if the box is being dismissed by clicking on
156 156 * "ok" and the user wants to retain the modified value, false
157 157 * otherwise.
158 158 */
159 159 private void encListDialogClose(boolean save) {
160 160 this.save = save;
161 161 setVisible(false);
162 162 }
163 163
164 164 /*
165 165 * Checks if the user requested that the value in this
166 166 * EncListDialog be used e.g., by clicking on "Ok" instead of
167 167 * "Cancel."
168 168 * @return true if the user wants to save the value in the
169 169 * EncListDialog, false otherwise.
170 170 */
171 171
172 172 public boolean isSaved() {
173 173 return save;
174 174 }
175 175 /*
176 176 * Sets the current enc list for the principal during modification.
177 177 * @param enc types of current principal.
178 178 */
179 179 public void setEncTypes(String e_str) {
180 180
181 181 if (e_str.compareTo("") == 0)
182 182 return;
183 183
184 184 String[] e_list = e_str.split(" ");
185 185
186 186 for (int i = 0; i < e_list.length; i++) {
187 187 for (int j = 0; j < cb.length; j++) {
188 188 if (cb[j].getLabel().compareTo(e_list[i])
189 189 == 0) {
190 190 cb[j].setState(true);
191 191 break;
192 192 }
193 193 }
194 194 }
195 195 }
196 196
197 197 // ***********************************************
198 198 // I N N E R C L A S S E S F O L L O W
199 199 // ***********************************************
200 200
201 201 /*
202 202 * Listener for an annoying work around in deselection of a check box
203 203 * in case the user doesn't want any items in a grouped list.
204 204 */
205 205 private class CBListener implements ItemListener {
206 206
207 207 public void itemStateChanged(ItemEvent e) {
208 208 Checkbox c = (Checkbox) e.getItemSelectable();
209 209
210 210 if (e.getStateChange() == e.DESELECTED) {
211 211 c.setState(false);
212 212 } else if (e.getStateChange() == e.SELECTED) {
213 213 for (int i = 0; i < cb.length; i++) {
214 214 if (c == cb[i]) {
215 215 for (int j = 0; j < cb.length; j++) {
216 216 if (grp_num[j].equals(grp_num[i])
217 217 == true) {
218 218 cb[j].setState(false);
219 219 }
220 220 }
221 221 break;
222 222 }
223 223 }
224 224 c.setState(true);
225 225 // else what else is there
226 226 }
227 227 }
228 228 }
229 229
230 230 /*
231 231 * Listener for closing the dialog box through the window close
232 232 * menu.
233 233 */
234 234 private class DCWindowListener extends WindowAdapter {
235 235
236 236 public void windowClosing(WindowEvent e) {
237 237 encListDialogClose(false);
238 238 }
239 239 }
240 240
241 241 /*
242 242 * Listener for all the buttons. The listener is shared for the sake
243 243 * of reducing the number of overall listeners.
244 244 * TBD: I18N the help
245 245 */
246 246 private class DCButtonListener implements ActionListener {
247 247
248 248 public void actionPerformed(ActionEvent e) {
↓ open down ↓ |
248 lines elided |
↑ open up ↑ |
249 249 if (e.getSource() == ok) {
250 250 EncListDialog.this.encListDialogClose(true);
251 251 } else if (e.getSource() == cancel) {
252 252 EncListDialog.this.encListDialogClose(false);
253 253 } else if (e.getSource() == clear) {
254 254 for (int i = 0; i < cb.length; i++) {
255 255 cb[i].setState(false);
256 256 }
257 257 } else if (e.getSource() == help) {
258 258 if (hd != null)
259 - hd.show();
259 + hd.setVisible(true);
260 260 else {
261 261 hd = new HelpDialog(
262 262 EncListDialog.this.parent,
263 263 getString(
264 264 "Help for Encryption Type Dialog"),
265 265 false);
266 266 hd.setVisible(true);
267 267 hd.setText(getString(hrb,
268 268 "EncryptionTypeDialogHelp"));
269 269 }
270 270 }
271 271 } // actionPerformed
272 272 }
273 273
274 274 /*
275 275 * The string representation of the dialog box.
276 276 * @return a String which contians the encryption type list
277 277 */
278 278 public String toString() {
279 279
280 280 for (int i = 0; i < cb.length; i++) {
281 281 if (cb[i].getState() == true)
282 282 encList = encList.concat(cb[i].getLabel() +
283 283 " ");
284 284 }
285 285 return encList;
286 286 }
287 287
288 288 /*
289 289 * Call rb.getString(), but catch exception and return English
290 290 * key so that small spelling errors don't cripple the GUI
291 291 */
292 292 private static final String getString(String key) {
293 293 return (getString(rb, key));
294 294 }
295 295
296 296 private static final String getString(ResourceBundle rb, String key) {
297 297 try {
298 298 String res = rb.getString(key);
299 299 return res;
300 300 } catch (MissingResourceException e) {
301 301 System.out.println("Missing resource "+key+
302 302 ", using English.");
303 303 return key;
304 304 }
305 305 }
306 306 }
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX