Print this page
4719 update gate build environment to [open]jdk7 4742 update manifests for javadoc7 4743 Fix deprecated /usr/j2se usage in slp and remove from filesystem(5) manpage 4744 remove traces of /var/sadm/system/admin/default_java Reviewed by: Dan McDonald <danmcd@omniti.com> Reviewed by: Richard Lowe <richlowe@richlowe.net>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/krb5/kadmin/gui/dchanger/DurationHelper.java
+++ new/usr/src/cmd/krb5/kadmin/gui/dchanger/DurationHelper.java
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 - * ident "%Z%%M% %I% %E% SMI"
24 - *
25 23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
26 24 * All rights reserved.
27 25 */
28 26
29 27 import java.awt.*;
30 28 import java.awt.event.*;
31 29 import java.text.NumberFormat;
32 30 import java.util.ResourceBundle;
33 31 import java.util.MissingResourceException;
34 32
35 33 /**
36 34 * This creates a modal dialog box that lets the user enter a duration of
37 35 * time in seconds/minutes/hours/days/weeks/months/years.
38 36 */
39 37 public class DurationHelper extends Dialog {
40 38
41 39 private boolean save;
42 40
43 41 private Frame parent;
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
44 42
45 43 private Choice unit;
46 44 private TextField value;
47 45 private Label total;
48 46
49 47 private Button ok;
50 48 private Button cancel;
51 49 private Button help;
52 50 private Button compute;
53 51
54 - private HelpDialog hd = null;
52 + private HelpDialog hd = null;
55 53
56 54 // For I18N
57 55 private static ResourceBundle rb =
58 56 ResourceBundle.getBundle("GuiResource" /* NOI18N */);
59 - private static ResourceBundle hrb =
57 + private static ResourceBundle hrb =
60 58 ResourceBundle.getBundle("HelpData" /* NOI18N */);
61 59
62 60 private static String[] units = { getString("Seconds"),
63 - getString("Minutes"),
64 - getString("Hours"),
65 - getString("Days"),
66 - getString("Weeks"),
67 - getString("Months"),
68 - getString("Years") };
61 + getString("Minutes"),
62 + getString("Hours"),
63 + getString("Days"),
64 + getString("Weeks"),
65 + getString("Months"),
66 + getString("Years") };
69 67 private static int[] unitMultipliers = {1, 60, 60*60, 60*60*24,
70 - 60*60*24*7, 60*60*24*30,
71 - 60*60*24*365 };
72 - private static NumberFormat nf = NumberFormat.getInstance();
68 + 60*60*24*7, 60*60*24*30,
69 + 60*60*24*365 };
70 + private static NumberFormat nf = NumberFormat.getInstance();
73 71 private static Toolkit toolkit = Toolkit.getDefaultToolkit();
74 72
75 - /**
76 - * Constructor for DurationHelper.
77 - * @param parent the parent Frame to whom input will be blocked
78 - * while this dialog box is begin shown(modal behaviour).
79 - */
80 - public DurationHelper(Frame parent, Color background, Color foreground) {
73 + /**
74 + * Constructor for DurationHelper.
75 + * @param parent the parent Frame to whom input will be blocked
76 + * while this dialog box is begin shown(modal behaviour).
77 + */
78 + public DurationHelper(Frame parent, Color background, Color foreground) {
81 79 super(parent, getString("SEAM Duration Helper"), true);
82 80
83 81 this.parent = parent;
84 82
85 83 setLayout(new GridBagLayout());
86 84 addLabels();
87 85 addFields(background, foreground);
88 86 addButtons();
89 87 setSize(350, 150);
90 88 setResizable(false);
91 89 addWindowListener(new DHWindowListener());
92 90 }
93 91
94 92 /**
95 93 * Adds all the labels.
96 94 */
97 95 private void addLabels() {
98 - GridBagConstraints gbc = new GridBagConstraints();
96 + GridBagConstraints gbc = new GridBagConstraints();
99 97 gbc.weightx = gbc.weighty = 1;
100 98 add(new Label(getString("Unit")), gbc);
101 99 add(new Label(getString("Value")), gbc);
102 100
103 101 gbc.gridx = 3;
104 102 gbc.gridy = 0;
105 103 add(new Label(getString("Seconds")), gbc);
106 104 }
107 105
108 106 /**
109 107 * Initializes the strings for the units.
110 108 */
111 109 private void initUnits() {
112 - unit = new Choice();
110 + unit = new Choice();
113 111 for (int i = 0; i < units.length; i++)
114 112 unit.add(units[i]);
115 113 unit.select(getString("Hours"));
116 114 unit.addItemListener(new ItemListener() {
117 115 public void itemStateChanged(ItemEvent e) {
118 116 DurationHelper.this.checkErrorAndSetTotal();
119 117 }
120 118 });
121 119 }
122 120
123 121 /**
124 122 * Adds all the fields
125 123 */
126 124 private void addFields(Color background, Color foreground) {
127 - GridBagConstraints gbc = new GridBagConstraints();
125 + GridBagConstraints gbc = new GridBagConstraints();
128 126 gbc.weightx = gbc.weighty = 1;
129 127 initUnits();
130 128 value = new TextField();
131 129 value.setBackground(background);
132 130 value.setForeground(foreground);
133 131 value.setColumns(10);
134 132
135 - // TBD: make total large enough to hold the largest int
136 - total = new Label(" " /* NO18N */,
137 - Label.RIGHT);
133 + // TBD: make total large enough to hold the largest int
134 + total = new Label(" " /* NO18N */,
135 + Label.RIGHT);
138 136 gbc.gridx = 0;
139 137 gbc.gridy = 1;
140 138 add(unit, gbc);
141 139 gbc.gridx = 1;
142 140 add(value, gbc);
143 141 gbc.gridx = 3;
144 142 add(total, gbc);
145 143
146 144 value.addActionListener(new ActionListener() {
147 145 public void actionPerformed(ActionEvent e) {
148 146 DurationHelper.this.durationHelperClose(true);
149 147 }
150 148 });
151 149 }
152 150
153 151 /**
154 152 * Adds all the buttons.
155 153 */
156 154 private void addButtons() {
157 155
158 - GridBagConstraints gbc = new GridBagConstraints();
156 + GridBagConstraints gbc = new GridBagConstraints();
159 157 gbc.weightx = gbc.weighty = 1;
160 158
161 159 gbc.gridwidth = GridBagConstraints.REMAINDER;
162 160 gbc.fill = GridBagConstraints.BOTH;
163 161 gbc.gridx = 0;
164 162 gbc.gridy = 2;
165 163 gbc.insets = new Insets(0, 10, 0, 10);
166 164 add(new LineSeparator(), gbc);
167 165 gbc.insets = new Insets(0, 0, 0, 0);
168 166
169 167 Panel p = new Panel();
170 168 p.setLayout(new GridBagLayout());
171 169 ok = new Button(getString("OK"));
172 170 cancel = new Button(getString("Cancel"));
173 171 help = new Button(getString("Help"));
174 172 gbc = new GridBagConstraints();
175 - gbc.weightx = gbc.weighty = 1;
173 + gbc.weightx = gbc.weighty = 1;
176 174 p.add(ok, gbc);
177 175 p.add(cancel, gbc);
178 176 p.add(help, gbc);
179 177
180 178 ActionListener bl = new ButtonListener();
181 179 ok.addActionListener(bl);
182 180 cancel.addActionListener(bl);
183 181 help.addActionListener(bl);
184 182
185 183 gbc.gridy = 3;
186 184 gbc.gridwidth = GridBagConstraints.REMAINDER;
187 185 gbc.fill = GridBagConstraints.HORIZONTAL;
188 186 add(p, gbc);
189 187
190 188 gbc = new GridBagConstraints();
191 189 gbc.gridx = 2;
192 190 gbc.gridy = 1;
193 191 compute = new Button(getString("="));
194 192 add(compute, gbc);
|
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
195 193 compute.addActionListener(bl);
196 194
197 195 }
198 196
199 197 /**
200 198 * Updates the label called total.
201 199 * @return false if the text entry in the value
202 200 * field is not parseable, true otherwise.
203 201 */
204 202 private boolean checkErrorAndSetTotal() {
205 - try {
206 - String noSpaces = value.getText().trim();
203 + try {
204 + String noSpaces = value.getText().trim();
207 205 value.setText(noSpaces);
208 206 Long l = Long.valueOf(noSpaces);
209 207 total.setText(nf.format(l.longValue() *
210 - unitMultipliers[unit.getSelectedIndex()]));
211 - } catch (NumberFormatException e) {
212 - value.requestFocus();
213 - value.selectAll();
214 - toolkit.beep();
208 + unitMultipliers[unit.getSelectedIndex()]));
209 + } catch (NumberFormatException e) {
210 + value.requestFocus();
211 + value.selectAll();
212 + toolkit.beep();
215 213 return false;
216 - }
214 + }
217 215
218 216 return true;
219 217 }
220 218
221 219 /**
222 220 * Hides the duration helper.
223 221 * @param save true if the user wants to save the current value in
224 222 * the dialog box, false if it is to be discarded. This is decided
225 223 * based on whether the user clicked on the "Ok" button or the
226 224 * "Cancel" button. Choosing the window close menu is equivalent to
227 - * clicking on "Cancel."
225 + * clicking on "Cancel."
228 226 */
229 227 private void durationHelperClose(boolean save) {
230 - if (save == true) {
228 + if (save == true) {
231 229 if (!checkErrorAndSetTotal())
232 230 return;
233 231 }
234 232 this.save = save;
235 233 setVisible(false);
236 234 }
237 235
238 236 /**
239 237 * Determine whether or not the user wanted to save the value in
240 238 * this Dialog box. The user indicates this by clicking on the Ok
241 239 * button to save it and on the Cancel button to discard it. Using the
242 - * window close menu responds the same way as cancel.
240 + * window close menu responds the same way as cancel.
243 241 * @return true if the user wanted to use this value,
244 242 * false if it is to be discarded.
245 243 */
246 244 public boolean isSaved() {
247 245 return save;
248 246 }
249 247
250 248 /**
251 249 * The string representation of the contents of this dialog box.
252 250 * @return a String with the total number of seconds entered.
253 251 */
254 252 public String toString() {
255 253 return total.getText();
256 254 }
257 255
258 256 // * **********************************************
259 - // I N N E R C L A S S E S F O L L O W
257 + // I N N E R C L A S S E S F O L L O W
260 258 // * **********************************************
261 259
262 260 /**
263 261 * Listener for closing the dialog box through the window close
264 262 * menu.
265 263 */
266 264 private class DHWindowListener extends WindowAdapter {
267 - public void windowClosing(WindowEvent e) {
265 + public void windowClosing(WindowEvent e) {
268 266 durationHelperClose(false);
269 267 }
270 268 }
271 269
272 270 /**
273 271 * Listener for all the buttons.
274 272 * The listener is shared for the sake
275 273 * of reducing the number of overall listeners.
276 274 */
277 275 private class ButtonListener implements ActionListener {
278 - public void actionPerformed(ActionEvent e) {
279 - if (e.getSource() == ok) {
280 - DurationHelper.this.durationHelperClose(true);
276 + public void actionPerformed(ActionEvent e) {
277 + if (e.getSource() == ok) {
278 + DurationHelper.this.durationHelperClose(true);
281 279 } else if (e.getSource() == cancel) {
282 - DurationHelper.this.durationHelperClose(false);
280 + DurationHelper.this.durationHelperClose(false);
283 281 } else if (e.getSource() == help) {
284 - if (hd != null)
285 - hd.show();
286 - else {
287 - hd = new HelpDialog(DurationHelper. this.parent,
288 - getString("Help for entering time duration"),
289 - false, 5, 45);
290 - hd.setVisible(true);
291 - hd.setText(getString(hrb, "DurationHelperHelp"));
292 - }
293 - } else if (e.getSource() == compute) {
294 - checkErrorAndSetTotal();
295 - }
296 - }
282 + if (hd != null)
283 + hd.setVisible(true);
284 + else {
285 + hd = new HelpDialog(DurationHelper. this.parent,
286 + getString("Help for entering time duration"),
287 + false, 5, 45);
288 + hd.setVisible(true);
289 + hd.setText(getString(hrb, "DurationHelperHelp"));
290 + }
291 + } else if (e.getSource() == compute) {
292 + checkErrorAndSetTotal();
293 + }
294 + }
297 295 }
298 296
299 297 /**
300 298 * Call rb.getString(), but catch exception
301 299 * and return English
302 300 * key so that small spelling errors don't cripple the GUI
303 301 *
304 302 */
305 303 private static final String getString(String key) {
306 304 return (getString(rb, key));
307 305 }
308 306
309 307 private static final String getString(ResourceBundle rb, String key) {
310 - try {
308 + try {
311 309 String res = rb.getString(key);
312 - return res;
310 + return res;
313 311 } catch (MissingResourceException e) {
314 312 System.out.println("Missing resource "+key+", using English.");
315 313 return key;
316 314 }
317 315 }
318 316
319 317 /*
320 318 * A main method to test this class.
321 319 */
320 + /* BEGIN JSTYLED */
322 321 /*
323 322 public static void main(String args[]) {
324 - Frame f = new Frame("Test DurationHelper");
325 - f.setVisible(true); // for help dialog to use this as parent
326 - DurationHelper dh = new DurationHelper(f, Color.white, Color.black);
327 - dh.setVisible(true);
328 - System.out.println("Save is " + dh.save);
323 + Frame f = new Frame("Test DurationHelper");
324 + f.setVisible(true); // for help dialog to use this as parent
325 + DurationHelper dh = new DurationHelper(f, Color.white, Color.black);
326 + dh.setVisible(true);
327 + System.out.println("Save is " + dh.save);
329 328 }
330 329 */
330 + /* END JSTYLED */
331 331 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX