xref: /onnv-gate/usr/src/cmd/print/printmgr/com/sun/admin/pm/client/pmLoad.java (revision 11262:b7ebfbf2359e)
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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * pmLoad.java
27  * Load a Naming Context implementation
28  */
29 
30 package com.sun.admin.pm.client;
31 
32 import java.awt.*;
33 import java.awt.event.*;
34 import javax.swing.JPanel;
35 import javax.swing.*;
36 
37 import com.sun.admin.pm.server.*;
38 
39 public class pmLoad extends JPanel {
40 
41 	final static int OK =  1;
42 	final static int APPLY =  2;
43 	final static int RESET =  3;
44 	final static int CANCEL =  4;
45 	final static int HELP =  5;
46 
47 	final static int NIS =  6;
48 	final static int NONE =  7;
49 
50 	pmFrame frame = new pmFrame(
51 		pmUtility.getResource("SPM:Select.Naming.Service"));
52 	JComboBox nameserviceCombo = new JComboBox();
53 	pmTop mytop = null;
54 	int resetIndex;
55 
56     pmButton okButton = null;
57     pmButton cancelButton = null;
58     pmButton resetButton = null;
59     pmButton helpButton = null;
60 
61 
pmLoad(pmTop mytop)62     public pmLoad(pmTop mytop) {
63 	this.mytop = mytop;
64 
65 	Debug.message("CLNT:pmLoad()");
66 	setLayout(new BorderLayout());
67 	resetIndex = mytop.actionindex;
68 
69 	northPanel();
70 	southPanel();
71 
72 
73     }
74 
northPanel()75     public void northPanel() {
76 	JPanel north = new JPanel();
77 	north.setLayout(new GridBagLayout());
78 	GridBagConstraints c = new GridBagConstraints();
79 	c.weightx = c.weighty = 0.0;
80 	c.fill = GridBagConstraints.NONE;
81 	c.anchor = GridBagConstraints.WEST;
82 	c.insets = new Insets(15, 15, 5, 15);
83 	c.gridheight = 1;
84 	c.gridwidth = 1;
85 
86 	c.gridy = 1;
87 	c.gridx = 0;
88 	north.add(new JLabel
89 		(pmUtility.getResource("Naming.Service:")), c);
90 
91 	c.gridy = 1;
92 	c.gridx = 2;
93 	c.ipadx = 15;
94 
95 	nameserviceCombo.addItem("files");
96 
97 	if (mytop.nisns != null)
98 		nameserviceCombo.addItem("NIS");
99 
100 	if (mytop.ldapns != null)
101 		nameserviceCombo.addItem("LDAP");
102 
103 	nameserviceCombo.setSelectedIndex(mytop.actionindex);
104 	north.add(nameserviceCombo, c);
105 
106 	nameserviceCombo.addActionListener(new nsListener());
107 	nameserviceCombo.addItemListener(mytop.new topnsListener());
108 
109 	add("North", north);
110 
111     }
112 
113     class nsListener implements ActionListener {
nsListener()114 	public nsListener() {}
115 
actionPerformed(ActionEvent e)116 	public void actionPerformed(ActionEvent e)
117 	{
118 		mytop.actionindex = nameserviceCombo.getSelectedIndex();
119 		if (mytop.actionindex == 0) {
120 			Debug.message("CLNT:pmLoad:0: NONE");
121 		} else if (mytop.actionindex == 1) {
122 			Debug.message("CLNT:pmLoad:1: NIS");
123 		} else if (mytop.actionindex == 4) {
124 			Debug.message("CLNT:pmLoad:2: LDAP");
125 		}
126 	};
127     }
128 
southPanel()129     public void southPanel() {
130         JPanel south = new JPanel();
131 
132         south.setLayout(new GridBagLayout());
133         GridBagConstraints c = new GridBagConstraints();
134 
135         c.gridheight = 1;
136         c.gridwidth = 1;
137         c.weightx = c.weighty = 1.0;
138         c.anchor = GridBagConstraints.CENTER;
139         c.fill = GridBagConstraints.HORIZONTAL;
140         c.insets = new Insets(15, 15, 15, 15);
141         c.gridy = 0;
142 
143 	okButton = new pmButton(
144             pmUtility.getResource("OK"));
145         okButton.setMnemonic(
146             pmUtility.getIntResource("OK.mnemonic"));
147 
148         resetButton = new pmButton(
149             pmUtility.getResource("Reset"));
150         resetButton.setMnemonic(
151             pmUtility.getIntResource("Reset.mnemonic"));
152 
153         cancelButton = new pmButton(
154             pmUtility.getResource("Cancel"));
155         cancelButton.setMnemonic(
156             pmUtility.getIntResource("Cancel.mnemonic"));
157 
158         helpButton = new pmButton(
159             pmUtility.getResource("Help"));
160         helpButton.setMnemonic(
161             pmUtility.getIntResource("Help.mnemonic"));
162 
163         okButton.addActionListener(new ButtonListener(OK));
164         resetButton.addActionListener(new ButtonListener(RESET));
165         cancelButton.addActionListener(new ButtonListener(CANCEL));
166         helpButton.addActionListener(new ButtonListener(HELP));
167 
168         c.gridx = 0;
169         south.add(okButton, c);
170         c.gridx = 1;
171         south.add(resetButton, c);
172         c.gridx = 2;
173         south.add(cancelButton, c);
174         c.gridx = 3;
175         south.add(helpButton, c);
176 
177         add("South", south);
178     }
179 
180     class ButtonListener implements ActionListener {
181 	int activeButton;
182 
183 	// Constructor
ButtonListener(int aButton)184 	public ButtonListener(int aButton)
185 	{
186 		activeButton = aButton;
187 	}
188 
189 	// Select Active Button and call routine
190 
actionPerformed(ActionEvent e)191 	public void actionPerformed(ActionEvent e)
192 	{
193 
194 		switch (activeButton) {
195 		case OK:
196 			actionokButton();
197 			break;
198 		case RESET:
199 			actionresetButton();
200 			break;
201 		case CANCEL:
202 			actioncancelButton();
203 			break;
204 		case HELP:
205 			actionhelpButton();
206 			break;
207 		}
208 
209 	}
210     }
211 
pmScreendispose()212     public void pmScreendispose() {
213 	frame.dispose();
214     }
215 
216 	// Action for buttons
217 
actionokButton()218     public void actionokButton() {
219 	Debug.message("CLNT:pmLoad:actionokButton()");
220 	mytop.pmsetNS();
221 	mytop.pmsetNSLabel();
222 	mytop.pmsetPrinterList();
223 	mytop.pmsetdefaultpLabel();
224 	frame.setVisible(false);
225 	frame.repaint();
226 	frame.dispose();
227     }
228 
actionresetButton()229     public void actionresetButton() {
230 	Debug.message("CLNT:pmLoad:actionresetButton()");
231 	nameserviceCombo.setSelectedIndex(resetIndex);
232 	frame.repaint();
233     }
234 
actioncancelButton()235     public void actioncancelButton() {
236 	Debug.message("CLNT:pmLoad:actioncancelButton()");
237 	nameserviceCombo.setSelectedIndex(resetIndex);
238 	frame.setVisible(false);
239 	frame.repaint();
240 	frame.dispose();
241     }
242 
actionhelpButton()243     public void actionhelpButton() {
244 	Debug.message("CLNT:pmLoad:actionhelpButton()");
245 	mytop.showHelpItem("NameService");
246     }
247 
Show()248     public void Show() {
249 	Debug.message("CLNT:pmLoad:Show()");
250 
251 	frame.getContentPane().add("North", this);
252 	frame.pack();
253 
254         // handle Esc as cancel
255         frame.getRootPane().registerKeyboardAction(new ActionListener() {
256             public void actionPerformed(ActionEvent e) {
257                 Debug.message("CLNT:  default cancel action");
258                 actioncancelButton();
259             }},
260             KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false),
261             JComponent.WHEN_IN_FOCUSED_WINDOW);
262 
263         // default button is always OK, for now...
264         okButton.setAsDefaultButton();
265 
266         frame.setDefaultComponent(nameserviceCombo);
267 
268         nameserviceCombo.requestFocus();
269 
270 	frame.setVisible(true);
271 	frame.repaint();
272 
273     }
274 
275 }
276