xref: /onnv-gate/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmOther.java (revision 2141:8b55f69b9419)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  *
23  * ident	"%Z%%M%	%I%	%E% SMI"
24  *
25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  *
28  * pmOther.java
29  *
30  */
31 
32 package com.sun.admin.pm.client;
33 
34 import java.awt.*;
35 import java.awt.event.*;
36 import javax.swing.JPanel;
37 import javax.swing.*;
38 
39 import com.sun.admin.pm.server.*;
40 
41 
42 /*
43  * panel dialog which captures "other"
44  */
45 
46 public class pmOther extends pmDialog {
47 
48     private pmTop theTop;
49     private String theTag;
50     pmButton okButton = null;
51     pmButton cancelButton = null;
52     pmButton helpButton = null;
53 
pmOther(JFrame f, String title, String msg)54     public pmOther(JFrame f, String title, String msg) {
55         this(f, title, msg, null, null);
56     }
57 
pmOther(JFrame f, String title, String msg, pmTop t, String h)58     public pmOther(JFrame f, String title, String msg, pmTop t, String h) {
59 
60 	super(f, title, true);		// modal
61 
62         theTop = t;
63         theTag = h;
64 
65         JLabel l;
66         pmButton b;
67         JPanel p;
68 
69         Debug.message("CLNT:pmOther()");
70 
71         // initialize constraints
72         GridBagConstraints c = new GridBagConstraints();
73         c.gridx = 0;
74         c.gridy = GridBagConstraints.RELATIVE;
75         c.gridwidth = 1;
76         c.gridheight = 1;
77         c.insets = new Insets(10, 10, 5, 10);
78         c.anchor = GridBagConstraints.WEST;
79         c.fill = GridBagConstraints.HORIZONTAL;
80         c.weightx = 1.0;
81 
82         // top panel contains the message
83         p = new JPanel();
84         p.setLayout(new GridBagLayout());
85 
86         l = new JLabel(msg, SwingConstants.LEFT);
87         p.add(l, c);
88         this.getContentPane().add(p, "North");
89 
90         c.insets = new Insets(5, 10, 5, 10);
91 
92         // middle panel contains "other" text field
93         p = new JPanel();
94         p.setLayout(new GridBagLayout());
95 
96         deviceName.addActionListener(new ActionListener() {
97             public void actionPerformed(ActionEvent evt) {
98                 okPressed();
99             }
100         });
101 
102         l.setLabelFor(deviceName);
103 
104         c.gridx = 1;
105         c.gridy = 0;
106         c.weightx = 1.0;
107         c.fill = GridBagConstraints.HORIZONTAL;
108         c.anchor = GridBagConstraints.CENTER;
109 
110         p.add(deviceName, c);
111 
112         c.gridy = GridBagConstraints.RELATIVE;
113 
114         this.getContentPane().add(p, "Center");
115 
116         // bottom panel contains buttons
117         c.gridx = 0;
118         c.weightx = 1.0;
119         c.weighty = 0.0;
120         c.gridwidth = GridBagConstraints.REMAINDER;
121         c.fill = GridBagConstraints.HORIZONTAL;
122         c.anchor = GridBagConstraints.CENTER;
123         c.insets = new Insets(5, 10, 10, 10);
124 
125         JPanel thePanel = new JPanel();
126         okButton = new pmButton(
127             pmUtility.getResource("OK"));
128         okButton.setMnemonic(
129             pmUtility.getIntResource("OK.mnemonic"));
130         thePanel.add(okButton, c);
131         okButton.addActionListener(new ActionListener() {
132             public void actionPerformed(ActionEvent evt) {
133                 okPressed();
134             }
135         });
136 
137         cancelButton = new pmButton(
138             pmUtility.getResource("Cancel"));
139         cancelButton.setMnemonic(
140             pmUtility.getIntResource("Cancel.mnemonic"));
141         thePanel.add(cancelButton, c);
142         cancelButton.addActionListener(new ActionListener() {
143             public void actionPerformed(ActionEvent evt) {
144                 cancelPressed();
145             }
146         });
147 
148         if (theTop != null && theTag != null) {
149             helpButton = new pmButton(
150                 pmUtility.getResource("Help"));
151             helpButton.setMnemonic(
152                 pmUtility.getIntResource("Help.mnemonic"));
153             thePanel.add(helpButton, c);
154             helpButton.addActionListener(new ActionListener() {
155                 public void actionPerformed(ActionEvent evt) {
156                     theTop.showHelpItem(theTag);
157                 }
158             });
159         }
160 
161 
162         this.getContentPane().add(thePanel, "South");
163 
164         // lay out the dialog
165         this.pack();
166 
167         this.addWindowListener(new WindowAdapter() {
168             public void windowClosing(WindowEvent evt) {
169                 returnValue = JOptionPane.CLOSED_OPTION;
170                 pmOther.this.setVisible(false);
171             }
172         });
173 
174         // this.getRootPane().setDefaultButton(okButton);
175         okButton.setAsDefaultButton();
176 
177         // handle Esc as cancel in any case
178         this.getRootPane().registerKeyboardAction(new ActionListener() {
179             public void actionPerformed(ActionEvent e) {
180                 Debug.message("CLNT:  default cancel action");
181                 cancelPressed();
182             }},
183             KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
184             JComponent.WHEN_IN_FOCUSED_WINDOW);
185 
186         deviceName.requestFocus();
187 
188     }
189 
getValue()190     public int getValue() {
191         return returnValue;
192     }
193 
194 
okPressed()195     public void okPressed() {
196         Debug.message("CLNT:pmOther: " + deviceName.getText());
197         returnValue = JOptionPane.OK_OPTION;
198         pmOther.this.setVisible(false);
199     }
200 
cancelPressed()201 	public void cancelPressed() {
202 		Debug.message("CLNT:pmOther: cancelPressed");
203 		pmOther.this.dispose();
204 	}
205 
206 
main(String[] args)207     public static void main(String[] args) {
208         JFrame f = new JFrame("Other test");
209 
210         f.setSize(300, 100);
211         f.addWindowListener(new WindowAdapter() {
212             public void windowClosing(WindowEvent e) {
213                 System.exit(0);
214             }
215         });
216         f.setVisible(true);
217 
218 	while (true) {
219 	    pmOther d = new pmOther(f, "Test pmOther", "Enter Printer Port");
220         d.setVisible(true);
221 
222         Debug.message("CLNT:pmOther: Dialog login returns " + d.getValue());
223 
224     }
225      // System.exit(0);
226     }
227 
228 
229     public pmTextField deviceName = new pmTextField(30);
230     protected int returnValue = JOptionPane.CLOSED_OPTION;
231 
232 }
233