3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * ident "%Z%%M% %I% %E% SMI"
24 *
25 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
26 * All rights reserved.
27 */
28
29 import java.awt.*;
30 import java.awt.event.*;
31 import java.text.NumberFormat;
32 import java.util.ResourceBundle;
33 import java.util.MissingResourceException;
34
35 /**
36 * This creates a modal dialog box that lets the user enter a duration of
37 * time in seconds/minutes/hours/days/weeks/months/years.
38 */
39 public class DurationHelper extends Dialog {
40
41 private boolean save;
42
43 private Frame parent;
44
265 */
266 private class DHWindowListener extends WindowAdapter {
267 public void windowClosing(WindowEvent e) {
268 durationHelperClose(false);
269 }
270 }
271
272 /**
273 * Listener for all the buttons.
274 * The listener is shared for the sake
275 * of reducing the number of overall listeners.
276 */
277 private class ButtonListener implements ActionListener {
278 public void actionPerformed(ActionEvent e) {
279 if (e.getSource() == ok) {
280 DurationHelper.this.durationHelperClose(true);
281 } else if (e.getSource() == cancel) {
282 DurationHelper.this.durationHelperClose(false);
283 } 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 }
297 }
298
299 /**
300 * Call rb.getString(), but catch exception
301 * and return English
302 * key so that small spelling errors don't cripple the GUI
303 *
304 */
305 private static final String getString(String key) {
306 return (getString(rb, key));
307 }
308
309 private static final String getString(ResourceBundle rb, String key) {
310 try {
311 String res = rb.getString(key);
312 return res;
313 } catch (MissingResourceException e) {
314 System.out.println("Missing resource "+key+", using English.");
315 return key;
316 }
317 }
318
319 /*
320 * A main method to test this class.
321 */
322 /*
323 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);
329 }
330 */
331 }
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 import java.awt.*;
28 import java.awt.event.*;
29 import java.text.NumberFormat;
30 import java.util.ResourceBundle;
31 import java.util.MissingResourceException;
32
33 /**
34 * This creates a modal dialog box that lets the user enter a duration of
35 * time in seconds/minutes/hours/days/weeks/months/years.
36 */
37 public class DurationHelper extends Dialog {
38
39 private boolean save;
40
41 private Frame parent;
42
263 */
264 private class DHWindowListener extends WindowAdapter {
265 public void windowClosing(WindowEvent e) {
266 durationHelperClose(false);
267 }
268 }
269
270 /**
271 * Listener for all the buttons.
272 * The listener is shared for the sake
273 * of reducing the number of overall listeners.
274 */
275 private class ButtonListener implements ActionListener {
276 public void actionPerformed(ActionEvent e) {
277 if (e.getSource() == ok) {
278 DurationHelper.this.durationHelperClose(true);
279 } else if (e.getSource() == cancel) {
280 DurationHelper.this.durationHelperClose(false);
281 } else if (e.getSource() == help) {
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 }
295 }
296
297 /**
298 * Call rb.getString(), but catch exception
299 * and return English
300 * key so that small spelling errors don't cripple the GUI
301 *
302 */
303 private static final String getString(String key) {
304 return (getString(rb, key));
305 }
306
307 private static final String getString(ResourceBundle rb, String key) {
308 try {
309 String res = rb.getString(key);
310 return res;
311 } catch (MissingResourceException e) {
312 System.out.println("Missing resource "+key+", using English.");
313 return key;
314 }
315 }
316
317 /*
318 * A main method to test this class.
319 */
320 /* BEGIN JSTYLED */
321 /*
322 public static void main(String args[]) {
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);
328 }
329 */
330 /* END JSTYLED */
331 }
|