1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * ident	"%Z%%M%	%I%	%E% SMI"
24*0Sstevel@tonic-gate  *
25*0Sstevel@tonic-gate  * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
26*0Sstevel@tonic-gate  * All rights reserved.
27*0Sstevel@tonic-gate  */
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate import java.awt.*;
30*0Sstevel@tonic-gate import java.awt.event.*;
31*0Sstevel@tonic-gate import java.util.*;
32*0Sstevel@tonic-gate import java.text.*;
33*0Sstevel@tonic-gate import java.io.*;
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate /**
36*0Sstevel@tonic-gate  * Defaults class stores all defaults that are recorded locally on the
37*0Sstevel@tonic-gate  * client side.  It is also resonsible for showing the DefaultsFrame
38*0Sstevel@tonic-gate  * which allows the user to see and change these values.
39*0Sstevel@tonic-gate  */
40*0Sstevel@tonic-gate public class Defaults {
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate   // These gui components are the actual components that go on the editing frame
43*0Sstevel@tonic-gate   // that  allows the user to change the defaults. The reason they are public is
44*0Sstevel@tonic-gate   // that they  need to be accessible to KdcGui so that it can set up the
45*0Sstevel@tonic-gate   // listeners for them in  setupDefaultsNormalListeners() and
46*0Sstevel@tonic-gate   // setupDefaultsHelpListeners().
47*0Sstevel@tonic-gate     public Checkbox disableAccount;
48*0Sstevel@tonic-gate     public Checkbox forcePasswordChange;
49*0Sstevel@tonic-gate     public Checkbox allowPostdatedTix;
50*0Sstevel@tonic-gate     public Checkbox allowForwardableTix;
51*0Sstevel@tonic-gate     public Checkbox allowRenewableTix;
52*0Sstevel@tonic-gate     public Checkbox allowProxiableTix;
53*0Sstevel@tonic-gate     public Checkbox allowServiceTix;
54*0Sstevel@tonic-gate     public Checkbox allowTGTAuth;
55*0Sstevel@tonic-gate     public Checkbox allowDupAuth;
56*0Sstevel@tonic-gate     public Checkbox requirePreauth;
57*0Sstevel@tonic-gate     public Checkbox requireHWAuth;
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate     public Checkbox serverSide;
60*0Sstevel@tonic-gate     public TextField maxTicketLife;
61*0Sstevel@tonic-gate     public TextField maxTicketRenewableLife;
62*0Sstevel@tonic-gate     public TextField accountExpiryDate;
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate     public Label maxTicketLifeLabel;
65*0Sstevel@tonic-gate     public Label maxTicketRenewableLifeLabel;
66*0Sstevel@tonic-gate     public Label accountExpiryDateLabel;
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate     public Checkbox showLists;
69*0Sstevel@tonic-gate     public Checkbox staticLists;
70*0Sstevel@tonic-gate     public TextField cacheTime;
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate     public Label cacheTimeLabel;
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate     public Button lifeMoreButton;
75*0Sstevel@tonic-gate     public Button renewalMoreButton;
76*0Sstevel@tonic-gate     public Button dateMoreButton;
77*0Sstevel@tonic-gate     public Button cacheMoreButton;
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate     public Button saveButton;
80*0Sstevel@tonic-gate     public Button applyButton;
81*0Sstevel@tonic-gate     public Button cancelButton;
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate     public MenuItem csHelp;
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate   // These data items correspond to fields in struct struct
86*0Sstevel@tonic-gate   // _kadm5_config_params
87*0Sstevel@tonic-gate     private Flags flags;
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate     private boolean serverSideValue;
90*0Sstevel@tonic-gate     private int maxTicketLifeValue;
91*0Sstevel@tonic-gate     private int maxTicketRenewableLifeValue;
92*0Sstevel@tonic-gate     private Date accountExpiryDateValue;
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate     private boolean showListsValue;
95*0Sstevel@tonic-gate     private boolean staticListsValue;
96*0Sstevel@tonic-gate     private long cacheTimeValue;
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate     private String defaultsFile;
99*0Sstevel@tonic-gate     private Color background;
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate     private EditingFrame frame = null;
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate     private boolean helpMode = false;
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate   // For I18N
106*0Sstevel@tonic-gate     private static DateFormat df;
107*0Sstevel@tonic-gate     private static NumberFormat nf;
108*0Sstevel@tonic-gate     private static ResourceBundle rb;
109*0Sstevel@tonic-gate   // no help data since help is handled by KdcGui class
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate     private static String neverString;
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate   // For debugging the window arrangement
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate     Color SEPERATOR_COLOR = Color.blue;
116*0Sstevel@tonic-gate     Color CHECKBOX_COLOR = Color.orange;
117*0Sstevel@tonic-gate     Color LABEL_COLOR = Color.pink;
118*0Sstevel@tonic-gate     Color PANEL_COLOR1 = Color.lightGray;
119*0Sstevel@tonic-gate     Color PANEL_COLOR2 = Color.darkGray;
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate     /**
122*0Sstevel@tonic-gate      * Constructor for Defaults.
123*0Sstevel@tonic-gate      * @param defaultsFile the file from which to read the defaults.
124*0Sstevel@tonic-gate      */
Defaults(String defaultsFile, Color background)125*0Sstevel@tonic-gate     Defaults(String defaultsFile, Color background) {
126*0Sstevel@tonic-gate         this.defaultsFile = defaultsFile;
127*0Sstevel@tonic-gate         this.background = background;
128*0Sstevel@tonic-gate         flags = new Flags();
129*0Sstevel@tonic-gate         serverSideValue = true;
130*0Sstevel@tonic-gate         maxTicketLifeValue = 144000;
131*0Sstevel@tonic-gate         maxTicketRenewableLifeValue = 144000;
132*0Sstevel@tonic-gate         // set expiry to now + one year
133*0Sstevel@tonic-gate         Calendar c = Calendar.getInstance();
134*0Sstevel@tonic-gate         c.roll(Calendar.YEAR, true);
135*0Sstevel@tonic-gate         accountExpiryDateValue = c.getTime();
136*0Sstevel@tonic-gate         showListsValue = true;
137*0Sstevel@tonic-gate         staticListsValue = false;
138*0Sstevel@tonic-gate         cacheTimeValue = 300;
139*0Sstevel@tonic-gate         readFromFile();
140*0Sstevel@tonic-gate     }
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate     /**
143*0Sstevel@tonic-gate      * Constructor for Defaults.
144*0Sstevel@tonic-gate      * @param old an existing defaults object to clone
145*0Sstevel@tonic-gate      */
Defaults(Defaults old)146*0Sstevel@tonic-gate     Defaults(Defaults old) {
147*0Sstevel@tonic-gate         defaultsFile = old.defaultsFile;
148*0Sstevel@tonic-gate         background = old.background;
149*0Sstevel@tonic-gate         flags = new Flags(old.flags.getBits());
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate         maxTicketLifeValue = old.maxTicketLifeValue;
152*0Sstevel@tonic-gate         maxTicketRenewableLifeValue = old.maxTicketRenewableLifeValue;
153*0Sstevel@tonic-gate         accountExpiryDateValue = old.accountExpiryDateValue;
154*0Sstevel@tonic-gate         showListsValue = old.showListsValue;
155*0Sstevel@tonic-gate         staticListsValue = old.staticListsValue;
156*0Sstevel@tonic-gate         cacheTimeValue = old.cacheTimeValue;
157*0Sstevel@tonic-gate     }
158*0Sstevel@tonic-gate 
restoreValues(Defaults old)159*0Sstevel@tonic-gate     public void restoreValues(Defaults old) {
160*0Sstevel@tonic-gate         flags = new Flags(old.flags.getBits());
161*0Sstevel@tonic-gate         maxTicketLifeValue = old.maxTicketLifeValue;
162*0Sstevel@tonic-gate         maxTicketRenewableLifeValue = old.maxTicketRenewableLifeValue;
163*0Sstevel@tonic-gate         accountExpiryDateValue = old.accountExpiryDateValue;
164*0Sstevel@tonic-gate         showListsValue = old.showListsValue;
165*0Sstevel@tonic-gate         staticListsValue = old.staticListsValue;
166*0Sstevel@tonic-gate         cacheTimeValue = old.cacheTimeValue;
167*0Sstevel@tonic-gate         updateGuiComponents();
168*0Sstevel@tonic-gate     }
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate     /**
171*0Sstevel@tonic-gate      * Returns a gui Frame with the defaults on it for editing.
172*0Sstevel@tonic-gate      */
getEditingFrame()173*0Sstevel@tonic-gate     public Frame getEditingFrame() {
174*0Sstevel@tonic-gate         if (frame == null) {
175*0Sstevel@tonic-gate        	    frame = new EditingFrame();
176*0Sstevel@tonic-gate 	    updateGuiComponents();
177*0Sstevel@tonic-gate        	    frame.setSize(500, 680);
178*0Sstevel@tonic-gate 	    frame.setResizable(true);
179*0Sstevel@tonic-gate 	    frame.setBackground(background);
180*0Sstevel@tonic-gate         }
181*0Sstevel@tonic-gate         return frame;
182*0Sstevel@tonic-gate     }
183*0Sstevel@tonic-gate 
184*0Sstevel@tonic-gate     /**
185*0Sstevel@tonic-gate      * Reread the defaults file in case it has changed, and refresh view
186*0Sstevel@tonic-gate      */
refreshDefaults()187*0Sstevel@tonic-gate     public void refreshDefaults() {
188*0Sstevel@tonic-gate         readFromFile();
189*0Sstevel@tonic-gate         updateGuiComponents();
190*0Sstevel@tonic-gate     }
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate     /**
194*0Sstevel@tonic-gate      * Update the duration and date text fields from gui.
195*0Sstevel@tonic-gate      * Check to see if any one of them had a parse error.
196*0Sstevel@tonic-gate      * @return true if all is ok, false if an error occurs
197*0Sstevel@tonic-gate      */
198*0Sstevel@tonic-gate     // Quits as soon as the first error is detected. The method that
199*0Sstevel@tonic-gate     // detects the error also shows a dialog box with a message.
updateFromGui()200*0Sstevel@tonic-gate     public final boolean updateFromGui() {
201*0Sstevel@tonic-gate         return (setMaxTicketLife() && setMaxTicketRenewableLife()
202*0Sstevel@tonic-gate 	      && setAccountExpiryDate()	&& setCacheTime());
203*0Sstevel@tonic-gate     }
204*0Sstevel@tonic-gate 
setServerSide()205*0Sstevel@tonic-gate     boolean setServerSide() {
206*0Sstevel@tonic-gate         serverSideValue = serverSide.getState();
207*0Sstevel@tonic-gate         enableTicketLifeFields(serverSideValue);
208*0Sstevel@tonic-gate         return true;
209*0Sstevel@tonic-gate     }
210*0Sstevel@tonic-gate 
enableTicketLifeFields(boolean fromServer)211*0Sstevel@tonic-gate     private void enableTicketLifeFields(boolean fromServer) {
212*0Sstevel@tonic-gate         maxTicketLifeLabel.setEnabled(!fromServer);
213*0Sstevel@tonic-gate         maxTicketLife.setEnabled(!fromServer);
214*0Sstevel@tonic-gate         maxTicketRenewableLifeLabel.setEnabled(!fromServer);
215*0Sstevel@tonic-gate         maxTicketRenewableLife.setEnabled(!fromServer);
216*0Sstevel@tonic-gate         lifeMoreButton.setEnabled(!fromServer);
217*0Sstevel@tonic-gate         renewalMoreButton.setEnabled(!fromServer);
218*0Sstevel@tonic-gate     }
219*0Sstevel@tonic-gate 
setMaxTicketLife()220*0Sstevel@tonic-gate     boolean setMaxTicketLife() {
221*0Sstevel@tonic-gate         try {
222*0Sstevel@tonic-gate             maxTicketLifeValue =
223*0Sstevel@tonic-gate                 nf.parse(maxTicketLife.getText().trim()).intValue();
224*0Sstevel@tonic-gate         } catch (ParseException e) {
225*0Sstevel@tonic-gate             KdcGui.showDataFormatError(maxTicketLife, KdcGui.DURATION_DATA);
226*0Sstevel@tonic-gate             return false;
227*0Sstevel@tonic-gate         }
228*0Sstevel@tonic-gate 
229*0Sstevel@tonic-gate         return true;
230*0Sstevel@tonic-gate     }
231*0Sstevel@tonic-gate 
232*0Sstevel@tonic-gate     /**
233*0Sstevel@tonic-gate      * Sets the maxTicketRenewable field value from the corresponding text
234*0Sstevel@tonic-gate      * field.
235*0Sstevel@tonic-gate      */
setMaxTicketRenewableLife()236*0Sstevel@tonic-gate     boolean setMaxTicketRenewableLife() {
237*0Sstevel@tonic-gate         try {
238*0Sstevel@tonic-gate             maxTicketRenewableLifeValue =
239*0Sstevel@tonic-gate                 nf.parse(maxTicketRenewableLife.getText().trim()).intValue();
240*0Sstevel@tonic-gate         } catch (ParseException e) {
241*0Sstevel@tonic-gate             KdcGui.showDataFormatError(maxTicketRenewableLife,
242*0Sstevel@tonic-gate                                        KdcGui.DURATION_DATA);
243*0Sstevel@tonic-gate             return false;
244*0Sstevel@tonic-gate         }
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate         return true;
247*0Sstevel@tonic-gate     }
248*0Sstevel@tonic-gate 
249*0Sstevel@tonic-gate     /**
250*0Sstevel@tonic-gate      * Sets the accountExpiryDate field value from the corresponding text field.
251*0Sstevel@tonic-gate      */
setAccountExpiryDate()252*0Sstevel@tonic-gate     boolean setAccountExpiryDate() {
253*0Sstevel@tonic-gate         String value = accountExpiryDate.getText().trim();
254*0Sstevel@tonic-gate         if (value.equalsIgnoreCase(neverString))
255*0Sstevel@tonic-gate             accountExpiryDateValue = new Date(0);
256*0Sstevel@tonic-gate         else {
257*0Sstevel@tonic-gate             try {
258*0Sstevel@tonic-gate         	accountExpiryDateValue = df.parse(value);
259*0Sstevel@tonic-gate             } catch (ParseException e) {
260*0Sstevel@tonic-gate         	KdcGui.showDataFormatError(accountExpiryDate, KdcGui.DATE_DATA);
261*0Sstevel@tonic-gate         	return false;
262*0Sstevel@tonic-gate             } catch (NullPointerException e) {
263*0Sstevel@tonic-gate         	// gets thrown when parse string begins with text
264*0Sstevel@tonic-gate         	// probable JDK bug
265*0Sstevel@tonic-gate         	KdcGui.showDataFormatError(accountExpiryDate, KdcGui.DATE_DATA);
266*0Sstevel@tonic-gate         	return false;
267*0Sstevel@tonic-gate             } catch (IndexOutOfBoundsException e) {
268*0Sstevel@tonic-gate         	// gets thrown when parse string contains only one number
269*0Sstevel@tonic-gate         	// probable JDK bug
270*0Sstevel@tonic-gate         	KdcGui.showDataFormatError(accountExpiryDate, KdcGui.DATE_DATA);
271*0Sstevel@tonic-gate         	return false;
272*0Sstevel@tonic-gate             }
273*0Sstevel@tonic-gate         }
274*0Sstevel@tonic-gate         return true;
275*0Sstevel@tonic-gate     }
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate     /**
278*0Sstevel@tonic-gate      * Sets the cacheTime field value from the corresponding text field.
279*0Sstevel@tonic-gate      */
setCacheTime()280*0Sstevel@tonic-gate     boolean setCacheTime() {
281*0Sstevel@tonic-gate         try {
282*0Sstevel@tonic-gate             cacheTimeValue = nf.parse(cacheTime.getText().trim()).intValue();
283*0Sstevel@tonic-gate         } catch (ParseException e) {
284*0Sstevel@tonic-gate             KdcGui.showDataFormatError(cacheTime, KdcGui.DURATION_DATA);
285*0Sstevel@tonic-gate             return false;
286*0Sstevel@tonic-gate         }
287*0Sstevel@tonic-gate         return true;
288*0Sstevel@tonic-gate     }
289*0Sstevel@tonic-gate 
setShowLists()290*0Sstevel@tonic-gate     boolean setShowLists() {
291*0Sstevel@tonic-gate         showListsValue = showLists.getState();
292*0Sstevel@tonic-gate         return true;
293*0Sstevel@tonic-gate     }
294*0Sstevel@tonic-gate 
setStaticLists()295*0Sstevel@tonic-gate     boolean setStaticLists() {
296*0Sstevel@tonic-gate         staticListsValue = staticLists.getState();
297*0Sstevel@tonic-gate         enableCacheTimeFields(staticListsValue);
298*0Sstevel@tonic-gate         return true;
299*0Sstevel@tonic-gate     }
300*0Sstevel@tonic-gate 
enableCacheTimeFields(boolean staticLists)301*0Sstevel@tonic-gate     private void enableCacheTimeFields(boolean staticLists) {
302*0Sstevel@tonic-gate         cacheTime.setEnabled(!staticLists);
303*0Sstevel@tonic-gate         cacheTimeLabel.setEnabled(!staticLists);
304*0Sstevel@tonic-gate         cacheMoreButton.setEnabled(!staticLists);
305*0Sstevel@tonic-gate     }
306*0Sstevel@tonic-gate 
getServerSide()307*0Sstevel@tonic-gate     public boolean getServerSide() {
308*0Sstevel@tonic-gate         return serverSideValue;
309*0Sstevel@tonic-gate     }
310*0Sstevel@tonic-gate 
getMaxTicketLife()311*0Sstevel@tonic-gate     public Integer getMaxTicketLife() {
312*0Sstevel@tonic-gate         return new Integer(maxTicketLifeValue);
313*0Sstevel@tonic-gate     }
314*0Sstevel@tonic-gate 
getMaxTicketRenewableLife()315*0Sstevel@tonic-gate     public Integer getMaxTicketRenewableLife() {
316*0Sstevel@tonic-gate         return new Integer(maxTicketRenewableLifeValue);
317*0Sstevel@tonic-gate     }
318*0Sstevel@tonic-gate 
getAccountExpiryDate()319*0Sstevel@tonic-gate     public Date getAccountExpiryDate() {
320*0Sstevel@tonic-gate         return new Date(accountExpiryDateValue.getTime());
321*0Sstevel@tonic-gate     }
322*0Sstevel@tonic-gate 
getShowLists()323*0Sstevel@tonic-gate     public boolean getShowLists() {
324*0Sstevel@tonic-gate         return showListsValue;
325*0Sstevel@tonic-gate     }
326*0Sstevel@tonic-gate 
getStaticLists()327*0Sstevel@tonic-gate     public boolean getStaticLists() {
328*0Sstevel@tonic-gate         return staticListsValue;
329*0Sstevel@tonic-gate     }
330*0Sstevel@tonic-gate 
getCacheLists()331*0Sstevel@tonic-gate     public boolean getCacheLists() {
332*0Sstevel@tonic-gate         return staticListsValue;
333*0Sstevel@tonic-gate     }
334*0Sstevel@tonic-gate 
getCacheTime()335*0Sstevel@tonic-gate     public long getCacheTime() {
336*0Sstevel@tonic-gate         return cacheTimeValue;
337*0Sstevel@tonic-gate     }
338*0Sstevel@tonic-gate 
getFlags()339*0Sstevel@tonic-gate     public Flags getFlags() {
340*0Sstevel@tonic-gate         return flags;
341*0Sstevel@tonic-gate     }
342*0Sstevel@tonic-gate 
343*0Sstevel@tonic-gate     /**
344*0Sstevel@tonic-gate      * Toggles the value of the  bit specified.
345*0Sstevel@tonic-gate      */
toggleFlag(int bitmask)346*0Sstevel@tonic-gate     public void toggleFlag(int bitmask) {
347*0Sstevel@tonic-gate         flags.toggleFlags(bitmask);
348*0Sstevel@tonic-gate     }
349*0Sstevel@tonic-gate 
close(boolean save)350*0Sstevel@tonic-gate     public void close(boolean save) {
351*0Sstevel@tonic-gate         if (frame != null)
352*0Sstevel@tonic-gate             frame.close(save);
353*0Sstevel@tonic-gate     }
354*0Sstevel@tonic-gate 
355*0Sstevel@tonic-gate 
356*0Sstevel@tonic-gate     /**
357*0Sstevel@tonic-gate      * Saves the fields onto a file.
358*0Sstevel@tonic-gate      */
saveToFile()359*0Sstevel@tonic-gate     private void saveToFile() {
360*0Sstevel@tonic-gate         try {
361*0Sstevel@tonic-gate             PrintWriter outFile = null;
362*0Sstevel@tonic-gate             outFile = new PrintWriter(
363*0Sstevel@tonic-gate                       new BufferedWriter(new FileWriter(defaultsFile)));
364*0Sstevel@tonic-gate             outFile.println(flags.getBits());
365*0Sstevel@tonic-gate             outFile.println(maxTicketRenewableLifeValue);
366*0Sstevel@tonic-gate             outFile.println(df.format(accountExpiryDateValue));
367*0Sstevel@tonic-gate             outFile.println((new Boolean(showListsValue)).toString());
368*0Sstevel@tonic-gate             outFile.println((new Boolean(staticListsValue)).toString());
369*0Sstevel@tonic-gate             outFile.println((new Long(cacheTimeValue)).toString());
370*0Sstevel@tonic-gate             outFile.println(serverSideValue);
371*0Sstevel@tonic-gate             outFile.println(maxTicketLifeValue);
372*0Sstevel@tonic-gate             outFile.flush();
373*0Sstevel@tonic-gate             outFile.close();
374*0Sstevel@tonic-gate         } catch (IOException e) { /* xxx: warn user */ }
375*0Sstevel@tonic-gate     }
376*0Sstevel@tonic-gate 
377*0Sstevel@tonic-gate     /**
378*0Sstevel@tonic-gate      * Reads the fields from a file.
379*0Sstevel@tonic-gate      */
readFromFile()380*0Sstevel@tonic-gate     private void readFromFile() {
381*0Sstevel@tonic-gate         try {
382*0Sstevel@tonic-gate             BufferedReader inFile = null;
383*0Sstevel@tonic-gate             inFile = new BufferedReader(new FileReader(defaultsFile));
384*0Sstevel@tonic-gate             flags = new Flags(new Integer(inFile.readLine()).intValue());
385*0Sstevel@tonic-gate             maxTicketRenewableLifeValue =
386*0Sstevel@tonic-gate                 new Integer(inFile.readLine()).intValue();
387*0Sstevel@tonic-gate             accountExpiryDateValue = df.parse(inFile.readLine());
388*0Sstevel@tonic-gate             String s;
389*0Sstevel@tonic-gate             s = inFile.readLine();
390*0Sstevel@tonic-gate             if (s == null)
391*0Sstevel@tonic-gate         	showListsValue = true;
392*0Sstevel@tonic-gate             else
393*0Sstevel@tonic-gate         	showListsValue = (new Boolean(s)).booleanValue();
394*0Sstevel@tonic-gate             s = inFile.readLine();
395*0Sstevel@tonic-gate             if (s == null)
396*0Sstevel@tonic-gate         	staticListsValue = false;
397*0Sstevel@tonic-gate             else
398*0Sstevel@tonic-gate         	staticListsValue = (new Boolean(s)).booleanValue();
399*0Sstevel@tonic-gate             s = inFile.readLine();
400*0Sstevel@tonic-gate             if (s == null)
401*0Sstevel@tonic-gate         	cacheTimeValue = 300;
402*0Sstevel@tonic-gate             else try {
403*0Sstevel@tonic-gate         	cacheTimeValue = nf.parse(s).longValue();
404*0Sstevel@tonic-gate             } catch (ParseException e) {
405*0Sstevel@tonic-gate         	cacheTimeValue = 300;
406*0Sstevel@tonic-gate             }
407*0Sstevel@tonic-gate             serverSideValue = new Boolean(inFile.readLine()).booleanValue();
408*0Sstevel@tonic-gate             maxTicketLifeValue = new Integer(inFile.readLine()).intValue();
409*0Sstevel@tonic-gate         } catch (FileNotFoundException e) {
410*0Sstevel@tonic-gate             /* default values. new file will be created automatically. */}
411*0Sstevel@tonic-gate         catch (IOException e) { /* will create new one */}
412*0Sstevel@tonic-gate         catch (ParseException e) { /* leave default values in */}
413*0Sstevel@tonic-gate         catch (NumberFormatException e) { /* leave default values in */}
414*0Sstevel@tonic-gate         catch (NullPointerException e) { /* leave default values in */}
415*0Sstevel@tonic-gate         catch (StringIndexOutOfBoundsException e) {
416*0Sstevel@tonic-gate             /* leave default values in */}
417*0Sstevel@tonic-gate     }
418*0Sstevel@tonic-gate 
419*0Sstevel@tonic-gate     /**
420*0Sstevel@tonic-gate      * Sets the value of the gui components from the instance variables
421*0Sstevel@tonic-gate      * that get filled from the defaultsFile.
422*0Sstevel@tonic-gate      */
updateGuiComponents()423*0Sstevel@tonic-gate     public void updateGuiComponents() {
424*0Sstevel@tonic-gate         if (frame == null)
425*0Sstevel@tonic-gate             getEditingFrame();
426*0Sstevel@tonic-gate         else {
427*0Sstevel@tonic-gate             updateFlags();
428*0Sstevel@tonic-gate             serverSide.setState(serverSideValue);
429*0Sstevel@tonic-gate             enableTicketLifeFields(serverSideValue);
430*0Sstevel@tonic-gate             maxTicketLife.setText(nf.format(maxTicketLifeValue));
431*0Sstevel@tonic-gate             maxTicketRenewableLife.setText(
432*0Sstevel@tonic-gate                 nf.format(maxTicketRenewableLifeValue));
433*0Sstevel@tonic-gate             String text = (accountExpiryDateValue.getTime() == 0 ? neverString
434*0Sstevel@tonic-gate 		     : df.format(accountExpiryDateValue));
435*0Sstevel@tonic-gate             accountExpiryDate.setText(text);
436*0Sstevel@tonic-gate             showLists.setState(showListsValue);
437*0Sstevel@tonic-gate             staticLists.setState(staticListsValue);
438*0Sstevel@tonic-gate             enableCacheTimeFields(staticListsValue);
439*0Sstevel@tonic-gate             cacheTime.setText((new Long(cacheTimeValue)).toString());
440*0Sstevel@tonic-gate         }
441*0Sstevel@tonic-gate     }
442*0Sstevel@tonic-gate 
updateFlags()443*0Sstevel@tonic-gate     private void updateFlags() {
444*0Sstevel@tonic-gate         disableAccount.setState(flags.getFlag(Flags.DISALLOW_ALL_TIX));
445*0Sstevel@tonic-gate         forcePasswordChange.setState(flags.getFlag(Flags.REQUIRES_PWCHANGE));
446*0Sstevel@tonic-gate         allowPostdatedTix.setState(!flags.getFlag(Flags.DISALLOW_POSTDATED));
447*0Sstevel@tonic-gate         allowForwardableTix.setState(!flags.getFlag(
448*0Sstevel@tonic-gate             Flags.DISALLOW_FORWARDABLE));
449*0Sstevel@tonic-gate         allowRenewableTix.setState(!flags.getFlag(Flags.DISALLOW_RENEWABLE));
450*0Sstevel@tonic-gate         allowProxiableTix.setState(!flags.getFlag(Flags.DISALLOW_PROXIABLE));
451*0Sstevel@tonic-gate         allowServiceTix.setState(!flags.getFlag(Flags.DISALLOW_SVR));
452*0Sstevel@tonic-gate         allowTGTAuth.setState(!flags.getFlag(Flags.DISALLOW_TGT_BASED));
453*0Sstevel@tonic-gate         allowDupAuth.setState(!flags.getFlag(Flags.DISALLOW_DUP_SKEY));
454*0Sstevel@tonic-gate         requirePreauth.setState(flags.getFlag(Flags.REQUIRE_PRE_AUTH));
455*0Sstevel@tonic-gate         requireHWAuth.setState(flags.getFlag(Flags.REQUIRE_HW_AUTH));
456*0Sstevel@tonic-gate     }
457*0Sstevel@tonic-gate 
458*0Sstevel@tonic-gate     /**
459*0Sstevel@tonic-gate      * Call rb.getString(), but catch exception and return English
460*0Sstevel@tonic-gate      * key so that small spelling errors don't cripple the GUI
461*0Sstevel@tonic-gate      *
462*0Sstevel@tonic-gate      */
getString(String key)463*0Sstevel@tonic-gate     private static final String getString(String key) {
464*0Sstevel@tonic-gate         try {
465*0Sstevel@tonic-gate             String res = rb.getString(key);
466*0Sstevel@tonic-gate 	    return res;
467*0Sstevel@tonic-gate         } catch (MissingResourceException e) {
468*0Sstevel@tonic-gate 	    System.out.println("Missing resource "+key+", using English.");
469*0Sstevel@tonic-gate 	    return key;
470*0Sstevel@tonic-gate         }
471*0Sstevel@tonic-gate     }
472*0Sstevel@tonic-gate 
473*0Sstevel@tonic-gate     /*
474*0Sstevel@tonic-gate      **********************************************
475*0Sstevel@tonic-gate      *         I N N E R   C L A S S E S
476*0Sstevel@tonic-gate      **********************************************
477*0Sstevel@tonic-gate      */
478*0Sstevel@tonic-gate 
479*0Sstevel@tonic-gate     private class EditingFrame extends Frame {
EditingFrame()480*0Sstevel@tonic-gate         public EditingFrame() {
481*0Sstevel@tonic-gate             super(getString("Properties"));
482*0Sstevel@tonic-gate             setLayout(new GridBagLayout());
483*0Sstevel@tonic-gate             GridBagConstraints gbc = new GridBagConstraints();
484*0Sstevel@tonic-gate             gbc.weightx = gbc.weighty = 1;
485*0Sstevel@tonic-gate             gbc.fill = GridBagConstraints.BOTH;
486*0Sstevel@tonic-gate             gbc.gridwidth = GridBagConstraints.REMAINDER;
487*0Sstevel@tonic-gate             Label l;
488*0Sstevel@tonic-gate             l = new Label(getString("Defaults for New Principals"),
489*0Sstevel@tonic-gate                                     Label.CENTER);
490*0Sstevel@tonic-gate             l.setFont(new Font("Dialog", Font.PLAIN, 16));
491*0Sstevel@tonic-gate             //            l.setBackground(LABEL_COLOR);
492*0Sstevel@tonic-gate             gbc.insets = new Insets(10, 10, 0, 10);
493*0Sstevel@tonic-gate             add(l, gbc);
494*0Sstevel@tonic-gate             addFlags();
495*0Sstevel@tonic-gate             gbc.insets = new Insets(10, 10, 10, 10);
496*0Sstevel@tonic-gate             add(new LineSeparator(), gbc);
497*0Sstevel@tonic-gate             addTextFields();
498*0Sstevel@tonic-gate             add(new LineSeparator(), gbc);
499*0Sstevel@tonic-gate 
500*0Sstevel@tonic-gate             gbc.insets = new Insets(0, 10, 10, 10);
501*0Sstevel@tonic-gate             l = new Label(getString("List Controls"), Label.CENTER);
502*0Sstevel@tonic-gate             l.setFont(new Font("Dialog", Font.PLAIN, 16));
503*0Sstevel@tonic-gate 
504*0Sstevel@tonic-gate             add(l, gbc);
505*0Sstevel@tonic-gate             gbc.insets = new Insets(0, 10, 10, 10);
506*0Sstevel@tonic-gate             add(new LineSeparator(), gbc);
507*0Sstevel@tonic-gate             addListFields();
508*0Sstevel@tonic-gate             addButtons();
509*0Sstevel@tonic-gate             addWindowListener(new WindowCloseListener());
510*0Sstevel@tonic-gate             addHelpMenu();
511*0Sstevel@tonic-gate         }
512*0Sstevel@tonic-gate 
513*0Sstevel@tonic-gate         /**
514*0Sstevel@tonic-gate          * Helper method for constructor to add checkboxes and labels for
515*0Sstevel@tonic-gate          * flags.
516*0Sstevel@tonic-gate          */
addFlags()517*0Sstevel@tonic-gate         private void addFlags() {
518*0Sstevel@tonic-gate             Panel p = new Panel();
519*0Sstevel@tonic-gate             GridBagConstraints gbc = new GridBagConstraints();
520*0Sstevel@tonic-gate             gbc.weightx = gbc.weighty = 1;
521*0Sstevel@tonic-gate             gbc.fill = GridBagConstraints.BOTH;
522*0Sstevel@tonic-gate             gbc.gridwidth = GridBagConstraints.REMAINDER;
523*0Sstevel@tonic-gate             gbc.insets = new Insets(0, 10, 0, 10);
524*0Sstevel@tonic-gate             p.setLayout(new GridBagLayout());
525*0Sstevel@tonic-gate             add(p, gbc);
526*0Sstevel@tonic-gate 
527*0Sstevel@tonic-gate             disableAccount = new Checkbox();
528*0Sstevel@tonic-gate             forcePasswordChange = new Checkbox();
529*0Sstevel@tonic-gate             allowPostdatedTix = new Checkbox();
530*0Sstevel@tonic-gate             allowForwardableTix = new Checkbox();
531*0Sstevel@tonic-gate             allowRenewableTix = new Checkbox();
532*0Sstevel@tonic-gate             allowProxiableTix = new Checkbox();
533*0Sstevel@tonic-gate             allowServiceTix = new Checkbox();
534*0Sstevel@tonic-gate             allowTGTAuth = new Checkbox();
535*0Sstevel@tonic-gate             allowDupAuth = new Checkbox();
536*0Sstevel@tonic-gate             requirePreauth = new Checkbox();
537*0Sstevel@tonic-gate             requireHWAuth = new Checkbox();
538*0Sstevel@tonic-gate 
539*0Sstevel@tonic-gate             addSeperatorPanel(getString("Security"), p);
540*0Sstevel@tonic-gate 
541*0Sstevel@tonic-gate             gbc = new GridBagConstraints();
542*0Sstevel@tonic-gate             gbc.anchor  = GridBagConstraints.WEST;
543*0Sstevel@tonic-gate 
544*0Sstevel@tonic-gate             addFlag(disableAccount,
545*0Sstevel@tonic-gate     		    Flags.DISALLOW_ALL_TIX, p, gbc, false);
546*0Sstevel@tonic-gate             addFlag(forcePasswordChange,
547*0Sstevel@tonic-gate 		    Flags.REQUIRES_PWCHANGE,  p, gbc, true);
548*0Sstevel@tonic-gate 
549*0Sstevel@tonic-gate             addSeperatorPanel(getString("Ticket"), p);
550*0Sstevel@tonic-gate             addFlag(allowPostdatedTix,
551*0Sstevel@tonic-gate 		    Flags.DISALLOW_POSTDATED,  p, gbc, false);
552*0Sstevel@tonic-gate             addFlag(allowForwardableTix,
553*0Sstevel@tonic-gate 		    Flags.DISALLOW_FORWARDABLE,  p, gbc, true);
554*0Sstevel@tonic-gate             addFlag(allowRenewableTix,
555*0Sstevel@tonic-gate 		    Flags.DISALLOW_RENEWABLE,  p, gbc, false);
556*0Sstevel@tonic-gate             addFlag(allowProxiableTix,
557*0Sstevel@tonic-gate 		    Flags.DISALLOW_PROXIABLE,  p, gbc, true);
558*0Sstevel@tonic-gate             addFlag(allowServiceTix,
559*0Sstevel@tonic-gate       		    Flags.DISALLOW_SVR,  p, gbc, true);
560*0Sstevel@tonic-gate 
561*0Sstevel@tonic-gate             addSeperatorPanel(getString("Miscellaneous"), p);
562*0Sstevel@tonic-gate             addFlag(allowTGTAuth,
563*0Sstevel@tonic-gate 		    Flags.DISALLOW_TGT_BASED,  p, gbc, false);
564*0Sstevel@tonic-gate             addFlag(allowDupAuth,
565*0Sstevel@tonic-gate 		    Flags.DISALLOW_DUP_SKEY,  p, gbc, true);
566*0Sstevel@tonic-gate             addFlag(requirePreauth,
567*0Sstevel@tonic-gate 		    Flags.REQUIRE_PRE_AUTH,  p, gbc, false);
568*0Sstevel@tonic-gate             addFlag(requireHWAuth,
569*0Sstevel@tonic-gate 		    Flags.REQUIRE_HW_AUTH,  p, gbc, true);
570*0Sstevel@tonic-gate         }
571*0Sstevel@tonic-gate 
572*0Sstevel@tonic-gate     /**
573*0Sstevel@tonic-gate      * Helper method for addFlags. It adds a line seperator with text
574*0Sstevel@tonic-gate      * inside it.
575*0Sstevel@tonic-gate      * @param text the text to put in the line seperator
576*0Sstevel@tonic-gate      * @p the panel to which this line seperator must be added
577*0Sstevel@tonic-gate      */
addSeperatorPanel(String text, Panel p)578*0Sstevel@tonic-gate     private void addSeperatorPanel(String text, Panel p) {
579*0Sstevel@tonic-gate         GridBagConstraints gbc = new GridBagConstraints();
580*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 1;
581*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.BOTH;
582*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
583*0Sstevel@tonic-gate         gbc.insets = new Insets(7, 0, 7, 0);
584*0Sstevel@tonic-gate 
585*0Sstevel@tonic-gate         Panel subP = new Panel();
586*0Sstevel@tonic-gate         //            subP.setBackground(SEPERATOR_COLOR);
587*0Sstevel@tonic-gate         subP.setLayout(new GridBagLayout());
588*0Sstevel@tonic-gate         p.add(subP, gbc);
589*0Sstevel@tonic-gate 
590*0Sstevel@tonic-gate         gbc = new GridBagConstraints();
591*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.BOTH;
592*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = .02;
593*0Sstevel@tonic-gate         subP.add(new LineSeparator(), gbc);
594*0Sstevel@tonic-gate 
595*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = .001;
596*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.NONE;
597*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.EAST;
598*0Sstevel@tonic-gate         Label l = new Label(text);
599*0Sstevel@tonic-gate         l.setFont(new Font("Dialog", Font.ITALIC, 12));
600*0Sstevel@tonic-gate         subP.add(l, gbc);
601*0Sstevel@tonic-gate 
602*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
603*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 1;
604*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.BOTH;
605*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
606*0Sstevel@tonic-gate         subP.add(new LineSeparator(), gbc);
607*0Sstevel@tonic-gate     }
608*0Sstevel@tonic-gate 
609*0Sstevel@tonic-gate     /**
610*0Sstevel@tonic-gate      * Helper method for addFlags. It adds the label and the checkbox
611*0Sstevel@tonic-gate      * corresponding to the flag specified by the single bit that is set
612*0Sstevel@tonic-gate      * in mask.
613*0Sstevel@tonic-gate      * @param cb the Checkbox which has to be added corresponding to
614*0Sstevel@tonic-gate      *     this flag
615*0Sstevel@tonic-gate      * @param mask the flag
616*0Sstevel@tonic-gate      * @param p the panel to add this to
617*0Sstevel@tonic-gate      */
addFlag(Checkbox cb, int mask, Panel p, GridBagConstraints gbc, boolean eol)618*0Sstevel@tonic-gate     private void addFlag(Checkbox cb, int mask, Panel p,
619*0Sstevel@tonic-gate 			    GridBagConstraints gbc, boolean eol) {
620*0Sstevel@tonic-gate       //      cb.setBackground(CHECKBOX_COLOR);
621*0Sstevel@tonic-gate         cb.setState(flags.getFlag(mask));
622*0Sstevel@tonic-gate         cb.setLabel(Flags.getLabel(mask));
623*0Sstevel@tonic-gate         if (eol)
624*0Sstevel@tonic-gate             gbc.gridwidth = GridBagConstraints.REMAINDER;
625*0Sstevel@tonic-gate         else
626*0Sstevel@tonic-gate             gbc.gridwidth = 1;
627*0Sstevel@tonic-gate         p.add(cb, gbc);
628*0Sstevel@tonic-gate     }
629*0Sstevel@tonic-gate 
630*0Sstevel@tonic-gate     /**
631*0Sstevel@tonic-gate      * Helper method for constructor - adds Max ticket time, max renewal and def
632*0Sstevel@tonic-gate      * account expiry.
633*0Sstevel@tonic-gate      */
addTextFields()634*0Sstevel@tonic-gate     private void addTextFields() {
635*0Sstevel@tonic-gate         GridBagConstraints gbc = new GridBagConstraints();
636*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 1;
637*0Sstevel@tonic-gate 
638*0Sstevel@tonic-gate         Panel p = new Panel();
639*0Sstevel@tonic-gate         //      p.setBackground(PANEL_COLOR1);
640*0Sstevel@tonic-gate         p.setLayout(new GridBagLayout());
641*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.VERTICAL;
642*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
643*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
644*0Sstevel@tonic-gate         gbc.insets = new Insets(0, 10, 0, 10);
645*0Sstevel@tonic-gate         add(p, gbc);
646*0Sstevel@tonic-gate 
647*0Sstevel@tonic-gate         gbc = new GridBagConstraints();
648*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 1;
649*0Sstevel@tonic-gate 
650*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.EAST;
651*0Sstevel@tonic-gate         gbc.weightx = 0;
652*0Sstevel@tonic-gate         gbc.gridx = 0;
653*0Sstevel@tonic-gate         gbc.gridy = 0;
654*0Sstevel@tonic-gate         accountExpiryDateLabel = new Label(getString("Account Expiry:"));
655*0Sstevel@tonic-gate         //      accountExpiryDateLabel.setBackground(LABEL_COLOR);
656*0Sstevel@tonic-gate         p.add(accountExpiryDateLabel, gbc);
657*0Sstevel@tonic-gate         gbc.gridy = 2;
658*0Sstevel@tonic-gate         maxTicketLifeLabel =
659*0Sstevel@tonic-gate 		new Label(getString("Maximum Ticket Lifetime (seconds):"));
660*0Sstevel@tonic-gate         //      maxTicketLifeLabel.setBackground(LABEL_COLOR);
661*0Sstevel@tonic-gate         p.add(maxTicketLifeLabel, gbc);
662*0Sstevel@tonic-gate         gbc.gridy = 3;
663*0Sstevel@tonic-gate         maxTicketRenewableLifeLabel =
664*0Sstevel@tonic-gate 		new Label(getString("Maximum Ticket Renewal (seconds):"));
665*0Sstevel@tonic-gate         //      maxTicketRenewableLifeLabel.setBackground(LABEL_COLOR);
666*0Sstevel@tonic-gate         p.add(maxTicketRenewableLifeLabel, gbc);
667*0Sstevel@tonic-gate 
668*0Sstevel@tonic-gate         gbc.gridx = 1;
669*0Sstevel@tonic-gate         gbc.gridy = 0;
670*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.NONE;
671*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
672*0Sstevel@tonic-gate         accountExpiryDate = new TextField("1-Jan-70 00:00:00 PM");
673*0Sstevel@tonic-gate         accountExpiryDate.setColumns(22);
674*0Sstevel@tonic-gate         p.add(accountExpiryDate, gbc);
675*0Sstevel@tonic-gate         gbc.gridy = 2;
676*0Sstevel@tonic-gate         maxTicketLife = new TextField("144000");
677*0Sstevel@tonic-gate         maxTicketLife.setColumns(22);
678*0Sstevel@tonic-gate         p.add(maxTicketLife, gbc);
679*0Sstevel@tonic-gate         gbc.gridy = 3;
680*0Sstevel@tonic-gate         maxTicketRenewableLife = new TextField("144000");
681*0Sstevel@tonic-gate         maxTicketRenewableLife.setColumns(22);
682*0Sstevel@tonic-gate         p.add(maxTicketRenewableLife, gbc);
683*0Sstevel@tonic-gate 
684*0Sstevel@tonic-gate         gbc = new GridBagConstraints();
685*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 0;
686*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
687*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
688*0Sstevel@tonic-gate         gbc.gridx = 2;
689*0Sstevel@tonic-gate         gbc.gridy = 0;
690*0Sstevel@tonic-gate         dateMoreButton = new Button("...");
691*0Sstevel@tonic-gate         p.add(dateMoreButton, gbc);
692*0Sstevel@tonic-gate         gbc.gridy = 2;
693*0Sstevel@tonic-gate         lifeMoreButton = new Button("...");
694*0Sstevel@tonic-gate         p.add(lifeMoreButton, gbc);
695*0Sstevel@tonic-gate         gbc.gridy = 3;
696*0Sstevel@tonic-gate         renewalMoreButton = new Button("...");
697*0Sstevel@tonic-gate         p.add(renewalMoreButton, gbc);
698*0Sstevel@tonic-gate 
699*0Sstevel@tonic-gate         serverSide = new Checkbox();
700*0Sstevel@tonic-gate         //      serverSide.setBackground(CHECKBOX_COLOR);
701*0Sstevel@tonic-gate         serverSide.setLabel(getString(
702*0Sstevel@tonic-gate             "Let the KDC control the ticket lifetime values"));
703*0Sstevel@tonic-gate 
704*0Sstevel@tonic-gate         gbc = new GridBagConstraints();
705*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
706*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
707*0Sstevel@tonic-gate         gbc.gridx = 0;
708*0Sstevel@tonic-gate         gbc.gridy = 1;
709*0Sstevel@tonic-gate         p.add(serverSide, gbc);
710*0Sstevel@tonic-gate 
711*0Sstevel@tonic-gate     }
712*0Sstevel@tonic-gate 
addListFields()713*0Sstevel@tonic-gate     private void addListFields() {
714*0Sstevel@tonic-gate         Panel p = new Panel();
715*0Sstevel@tonic-gate         GridBagConstraints gbc = new GridBagConstraints();
716*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 1;
717*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.VERTICAL;
718*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
719*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
720*0Sstevel@tonic-gate         //      p.setBackground(PANEL_COLOR1);
721*0Sstevel@tonic-gate         gbc.insets = new Insets(0, 10, 0, 10);
722*0Sstevel@tonic-gate         p.setLayout(new GridBagLayout());
723*0Sstevel@tonic-gate         add(p, gbc);
724*0Sstevel@tonic-gate 
725*0Sstevel@tonic-gate         gbc = new GridBagConstraints();
726*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
727*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
728*0Sstevel@tonic-gate         showLists = new Checkbox();
729*0Sstevel@tonic-gate         //      showLists.setBackground(CHECKBOX_COLOR);
730*0Sstevel@tonic-gate         showLists.setLabel(getString("Show Lists"));
731*0Sstevel@tonic-gate         p.add(showLists, gbc);
732*0Sstevel@tonic-gate 
733*0Sstevel@tonic-gate         gbc.gridwidth = 1;
734*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.EAST;
735*0Sstevel@tonic-gate         staticLists = new Checkbox();
736*0Sstevel@tonic-gate         //      staticLists.setBackground(CHECKBOX_COLOR);
737*0Sstevel@tonic-gate         staticLists.setLabel(getString("Cache Lists Forever"));
738*0Sstevel@tonic-gate         p.add(staticLists, gbc);
739*0Sstevel@tonic-gate 
740*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.EAST;
741*0Sstevel@tonic-gate         cacheTimeLabel = new Label(getString("List Cache Timeout (seconds):"));
742*0Sstevel@tonic-gate         //      cacheTimeLabel.setBackground(Color.green);
743*0Sstevel@tonic-gate         p.add(cacheTimeLabel, gbc);
744*0Sstevel@tonic-gate 
745*0Sstevel@tonic-gate         gbc.anchor = GridBagConstraints.WEST;
746*0Sstevel@tonic-gate         cacheTime = new TextField("300", 8);
747*0Sstevel@tonic-gate         //      cacheTime.setBackground(Color.cyan);
748*0Sstevel@tonic-gate         p.add(cacheTime, gbc);
749*0Sstevel@tonic-gate 
750*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
751*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 0;
752*0Sstevel@tonic-gate         cacheMoreButton = new Button("...");
753*0Sstevel@tonic-gate         p.add(cacheMoreButton, gbc);
754*0Sstevel@tonic-gate     }
755*0Sstevel@tonic-gate 
756*0Sstevel@tonic-gate 
757*0Sstevel@tonic-gate     /**
758*0Sstevel@tonic-gate      * Helper method for constructor - adds Save and Cancel
759*0Sstevel@tonic-gate      * buttons.
760*0Sstevel@tonic-gate      */
addButtons()761*0Sstevel@tonic-gate     private void addButtons() {
762*0Sstevel@tonic-gate         GridBagConstraints gbc = new GridBagConstraints();
763*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 1;
764*0Sstevel@tonic-gate 
765*0Sstevel@tonic-gate         Panel p = new Panel();
766*0Sstevel@tonic-gate         p.setLayout(new GridBagLayout());
767*0Sstevel@tonic-gate         gbc.fill = GridBagConstraints.BOTH;
768*0Sstevel@tonic-gate         gbc.gridwidth = GridBagConstraints.REMAINDER;
769*0Sstevel@tonic-gate         gbc.insets = new Insets(10, 10, 10, 10);
770*0Sstevel@tonic-gate         add(new LineSeparator(), gbc);
771*0Sstevel@tonic-gate         gbc.insets = new Insets(0, 0, 10, 0);
772*0Sstevel@tonic-gate         add(p, gbc);
773*0Sstevel@tonic-gate 
774*0Sstevel@tonic-gate         gbc = new GridBagConstraints();
775*0Sstevel@tonic-gate         gbc.weightx = gbc.weighty = 1;
776*0Sstevel@tonic-gate 
777*0Sstevel@tonic-gate         saveButton = new Button(getString("Save"));
778*0Sstevel@tonic-gate         p.add(saveButton, gbc);
779*0Sstevel@tonic-gate         applyButton = new Button(getString("Apply"));
780*0Sstevel@tonic-gate         p.add(applyButton, gbc);
781*0Sstevel@tonic-gate         cancelButton = new Button(getString("Cancel"));
782*0Sstevel@tonic-gate         p.add(cancelButton, gbc);
783*0Sstevel@tonic-gate     }
784*0Sstevel@tonic-gate 
addHelpMenu()785*0Sstevel@tonic-gate     private void addHelpMenu() {
786*0Sstevel@tonic-gate         MenuBar mb = new MenuBar();
787*0Sstevel@tonic-gate         setMenuBar(mb);
788*0Sstevel@tonic-gate 
789*0Sstevel@tonic-gate         Menu m = new Menu(getString("Help"));
790*0Sstevel@tonic-gate         mb.setHelpMenu(m);
791*0Sstevel@tonic-gate 
792*0Sstevel@tonic-gate         csHelp = new MenuItem(getString("Context-Sensitive Help"));
793*0Sstevel@tonic-gate         m.add(csHelp);
794*0Sstevel@tonic-gate     }
795*0Sstevel@tonic-gate 
796*0Sstevel@tonic-gate         /**
797*0Sstevel@tonic-gate          * Decides whether to save/discard edits and then closes
798*0Sstevel@tonic-gate          * window. If errors exist in the values entered in the fields, then
799*0Sstevel@tonic-gate          * it will not exit.
800*0Sstevel@tonic-gate          */
close(boolean save)801*0Sstevel@tonic-gate         public void close(boolean save) {
802*0Sstevel@tonic-gate             if (save) {
803*0Sstevel@tonic-gate       	        if (!Defaults.this.updateFromGui())
804*0Sstevel@tonic-gate 	            return;
805*0Sstevel@tonic-gate     	        else
806*0Sstevel@tonic-gate 	            Defaults.this.saveToFile();
807*0Sstevel@tonic-gate             }
808*0Sstevel@tonic-gate             setVisible(false);
809*0Sstevel@tonic-gate         }
810*0Sstevel@tonic-gate 
811*0Sstevel@tonic-gate         // Listeners for the gui components:
812*0Sstevel@tonic-gate         private  class WindowCloseListener extends  WindowAdapter {
windowClosing(WindowEvent e)813*0Sstevel@tonic-gate             public void windowClosing(WindowEvent e) {
814*0Sstevel@tonic-gate     	        close(false);
815*0Sstevel@tonic-gate             }
816*0Sstevel@tonic-gate         }
817*0Sstevel@tonic-gate 
818*0Sstevel@tonic-gate     } // class EditingFrame
819*0Sstevel@tonic-gate 
main(String argv[])820*0Sstevel@tonic-gate     public static void main(String argv[]) {
821*0Sstevel@tonic-gate         Defaults d = new Defaults("SomeFile", Color.white);
822*0Sstevel@tonic-gate         Frame f = d.getEditingFrame();
823*0Sstevel@tonic-gate         d.showLists.setSize(new Dimension(18, 22));
824*0Sstevel@tonic-gate         d.staticLists.setSize(new Dimension(18, 22));
825*0Sstevel@tonic-gate         f.setVisible(true);
826*0Sstevel@tonic-gate         System.out.println(d.disableAccount.getSize().toString()); // XXX
827*0Sstevel@tonic-gate         System.out.println(d.showLists.getSize().toString()); // XXX
828*0Sstevel@tonic-gate     }
829*0Sstevel@tonic-gate 
830*0Sstevel@tonic-gate     static {
831*0Sstevel@tonic-gate         df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
832*0Sstevel@tonic-gate                                             DateFormat.MEDIUM);
833*0Sstevel@tonic-gate         nf = NumberFormat.getInstance();
834*0Sstevel@tonic-gate         rb = ResourceBundle.getBundle("GuiResource" /* NOI18N */);
835*0Sstevel@tonic-gate         neverString = getString("Never");
836*0Sstevel@tonic-gate     }
837*0Sstevel@tonic-gate 
838*0Sstevel@tonic-gate }
839