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