xref: /titanic_44/usr/src/cmd/krb5/kadmin/gui/util/HelpDialog.java (revision a60349c89adffc0902b2353230891d8e7f2b24d9)
1 /*
2  * CDDL HEADER START
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.util.StringTokenizer;
32 import java.util.ResourceBundle;
33 import java.util.MissingResourceException;
34 
35 /**
36  *  Dialog box for diaplaying Help
37  *
38  */
39 public class HelpDialog extends Dialog {
40 
41     protected Button b;
42     protected TextArea t;
43     private Frame parent;
44 
45     public static int NUM_ROWS = 10;
46     public static int NUM_COLS = 45;
47 
48     // For I18N
49     private static ResourceBundle rb =
50     ResourceBundle.getBundle("GuiResource" /* NOI18N */);
51 
52     public HelpDialog(Frame parent, String title, boolean mode) {
53         this(parent, title, mode, NUM_ROWS, NUM_COLS);
54     }
55 
56     public HelpDialog(Frame parent, String title, boolean mode, int numRows,
57                       int numCols) {
58         super(parent, title, mode);
59         this.parent = parent;
60         setBackground(parent.getBackground());
61         setForeground(parent.getForeground());
62         addButtonAndTextArea(numRows, numCols);
63         addWindowListener(new WindowAdapter() {
64 	    public void windowClosing(WindowEvent e) {
65 	        quit();
66 	    }
67         });
68     }
69 
70     protected void quit() {
71         dispose();
72     }
73 
74     private void addButtonAndTextArea(int numRows, int numCols) {
75         t = new TextArea(null, numRows, numCols,
76                          TextArea.SCROLLBARS_VERTICAL_ONLY);
77         t.setEditable(false);
78         b = new Button(getString("Dismiss"));
79 
80         setLayout(new GridBagLayout());
81         GridBagConstraints gbc = new GridBagConstraints();
82         gbc.weightx = gbc.weighty = 1;
83         gbc.fill = GridBagConstraints.BOTH;
84         gbc.gridwidth = GridBagConstraints.REMAINDER;
85         add(t, gbc);
86         gbc.fill = GridBagConstraints.NONE;
87         add(b, gbc);
88 
89         pack();
90         setResizable(false);
91         setLocationBesideParent(parent);
92 
93         b.addActionListener(new ActionListener() {
94 	    public void actionPerformed(ActionEvent e) {
95 	        quit();
96 	    }
97         });
98     }
99 
100     private void setLocationBesideParent(Frame parent) {
101         Point p = parent.getLocationOnScreen();
102         Dimension parentSize = parent.getSize();
103         Dimension mySize = getSize();
104         p.x += parentSize.width;
105         p.y += parentSize.height/2 - mySize.height/2;
106         setLocation(p.x, p.y);
107     }
108 
109 
110     public void setText(String text) {
111         t.setText(text);
112     }
113 
114     /**
115      * Call rb.getString(), but catch exception and return English
116      * key so that small spelling errors don't cripple the GUI
117      *
118      */
119     private static final String getString(String key) {
120         try {
121 	    String res = rb.getString(key);
122 	    return res;
123         } catch (MissingResourceException e) {
124 	    System.out.println("Missing resource "+key+", using English.");
125 	    return key;
126         }
127     }
128 
129     /*
130     public static void main(String args[]) {
131         Frame f = new Frame();
132         f.setVisible(true);
133         HelpDialog hd = new HelpDialog(f, "Test HelpDialog", false);
134         hd.setVisible(true);
135     }
136     */
137 }
138