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 (c) 1999 by Sun Microsystems, Inc.
26  * All rights reserved.
27  *
28  * pmFindFrame.java
29  * Find Printer dialog implementation
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 public class pmFindFrame extends pmFrame {
43 
44     JLabel statusText = null;
45     pmButton okButton = null;
46     pmButton cancelButton = null;
47     pmButton helpButton = null;
48     pmTop theTop = null;
49 
50     String label = pmUtility.getResource("Enter.name.of.printer.to.find");
51     String helpTag = "ToFindPrinter";
52 
pmFindFrame(pmTop t)53     public pmFindFrame(pmTop t) {
54 
55         super(pmUtility.getResource("SPM:Find.Printer"));
56 
57         setLocation(100, 100);
58 
59         theTop = t;
60 
61 
62         JLabel l;
63         JPanel p;
64 
65         // initialize constraints
66         GridBagConstraints c = new GridBagConstraints();
67         c.gridx = 0;
68         c.gridy = GridBagConstraints.RELATIVE;
69         c.gridwidth = 1;
70         c.gridheight = 1;
71         c.insets = new Insets(10, 10, 5, 10);
72         c.anchor = GridBagConstraints.WEST;
73         c.fill = GridBagConstraints.HORIZONTAL;
74         c.weightx = 1.0;
75 
76         // top panel contains the message
77         p = new JPanel();
78         p.setLayout(new GridBagLayout());
79 
80         l = new JLabel(label, SwingConstants.LEFT);
81         p.add(l, c);
82 
83         getContentPane().add(p, "North");
84 
85         // middle panel contains "other" text field
86         p = new JPanel();
87         p.setLayout(new GridBagLayout());
88 
89         printerName = new pmTextField(30);
90         printerName.addActionListener(new ActionListener() {
91             public void actionPerformed(ActionEvent e) {
92                 okPressed();
93             }
94         });
95         l.setLabelFor(printerName);
96 
97         c.gridx = 1;
98         c.gridy = 0;
99         c.weightx = 1.0;
100         c.fill = GridBagConstraints.HORIZONTAL;
101         c.anchor = GridBagConstraints.CENTER;
102         c.insets = new Insets(0, 10, 5, 10);
103 
104         p.add(printerName, c);
105 
106         statusText = new JLabel(" ", SwingConstants.LEFT);
107 
108         c.gridy = GridBagConstraints.RELATIVE;
109         c.gridx = 0;
110         c.gridwidth = 2;
111 
112         c.insets = new Insets(5, 10, 5, 10);
113         p.add(statusText, c);
114 
115         getContentPane().add(p, "Center");
116 
117         // bottom panel contains buttons
118         c.gridx = 0;
119         c.weightx = 1.0;
120         c.weighty = 0.0;
121         c.gridwidth = GridBagConstraints.REMAINDER;
122         c.fill = GridBagConstraints.HORIZONTAL;
123         c.anchor = GridBagConstraints.CENTER;
124         c.insets = new Insets(5, 10, 10, 10);
125 
126         JPanel thePanel = new JPanel();
127 
128         okButton = new pmButton(
129             pmUtility.getResource("Find"));
130         okButton.setMnemonic(
131             pmUtility.getIntResource("Find.mnemonic"));
132         okButton.addActionListener(new ActionListener() {
133             public void actionPerformed(ActionEvent evt) {
134                 okPressed();
135             }
136         });
137         thePanel.add(okButton, c);
138 
139         cancelButton = new pmButton(
140             pmUtility.getResource("Dismiss"));
141         cancelButton.setMnemonic(
142             pmUtility.getIntResource("Dismiss.mnemonic"));
143         cancelButton.addActionListener(new ActionListener() {
144             public void actionPerformed(ActionEvent evt) {
145                 cancelPressed();
146             }
147         });
148         thePanel.add(cancelButton, c);
149 
150         helpButton = new pmButton(
151             pmUtility.getResource("Help"));
152         helpButton.setMnemonic(
153             pmUtility.getIntResource("Help.mnemonic"));
154         helpButton.addActionListener(new ActionListener() {
155             public void actionPerformed(ActionEvent evt) {
156                 theTop.showHelpItem(helpTag);
157             }
158         });
159         thePanel.add(helpButton, c);
160 
161         getContentPane().add(thePanel, "South");
162 
163         // lay out the dialog
164         pack();
165 
166         // handle Esc as dismiss in any case
167         getRootPane().registerKeyboardAction(new ActionListener() {
168             public void actionPerformed(ActionEvent e) {
169                 Debug.message("CLNT:  default cancel action");
170                 cancelPressed();
171             }},
172             KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
173             JComponent.WHEN_IN_FOCUSED_WINDOW);
174 
175 
176         // set focus to initial field, depending on which action is tbd
177         // this seems to work best after pack()
178 
179 	/*
180 	 * frame.setVisible(true);
181 	 * frame.repaint();
182 	 */
183 
184         // getRootPane().setDefaultButton (okButton);
185         okButton.setAsDefaultButton();
186 
187         printerName.requestFocus();
188 
189 		// enable improved focus handling
190 		setDefaultComponent(printerName);
191 
192     }
193 
194 
okPressed()195 	public void okPressed() {
196 	    Debug.message("CLNT:  pmFindFrame:okPressed():" +
197 			  printerName.getText());
198 
199 	    String name = printerName.getText();
200 	    boolean result = theTop.findPrinterInList(name.trim());
201 	    if (!result)
202 		statusText.setText(new String(
203                     pmUtility.getResource("Unable.to.find.printer") + name));
204 	    else
205 		statusText.setText(" ");
206 
207 	// pmFindPanel.this.frame.setVisible (false);
208 
209 	}
210 
cancelPressed()211 	public void cancelPressed() {
212 	    Debug.message("CLNT:  pmFindFrame: cancelPressed()");
213 	    statusText.setText(" ");
214 	    printerName.setText("");
215 	    pmFindFrame.this.setVisible(false);
216 
217 	}
218 
219     public pmTextField printerName = null;
220 
221 }
222