jdk/src/share/classes/sun/security/tools/policytool/PolicyTool.java
changeset 20886 9630bb813a6c
parent 20787 ab071ce90368
child 21365 2a7be11ae905
equal deleted inserted replaced
20885:0fa3d9e636c1 20886:9630bb813a6c
    35 import java.lang.reflect.*;
    35 import java.lang.reflect.*;
    36 import java.text.Collator;
    36 import java.text.Collator;
    37 import java.text.MessageFormat;
    37 import java.text.MessageFormat;
    38 import sun.security.util.PropertyExpander;
    38 import sun.security.util.PropertyExpander;
    39 import sun.security.util.PropertyExpander.ExpandException;
    39 import sun.security.util.PropertyExpander.ExpandException;
    40 import java.awt.*;
    40 import java.awt.Component;
       
    41 import java.awt.Container;
       
    42 import java.awt.Dimension;
       
    43 import java.awt.FileDialog;
       
    44 import java.awt.GridBagConstraints;
       
    45 import java.awt.GridBagLayout;
       
    46 import java.awt.Insets;
       
    47 import java.awt.Point;
       
    48 import java.awt.Toolkit;
       
    49 import java.awt.Window;
    41 import java.awt.event.*;
    50 import java.awt.event.*;
    42 import java.security.cert.Certificate;
    51 import java.security.cert.Certificate;
    43 import java.security.cert.CertificateException;
    52 import java.security.cert.CertificateException;
    44 import java.security.*;
    53 import java.security.*;
    45 import sun.security.provider.*;
    54 import sun.security.provider.*;
    46 import sun.security.util.PolicyUtil;
    55 import sun.security.util.PolicyUtil;
    47 import javax.security.auth.x500.X500Principal;
    56 import javax.security.auth.x500.X500Principal;
       
    57 import javax.swing.*;
       
    58 import javax.swing.border.EmptyBorder;
    48 
    59 
    49 /**
    60 /**
    50  * PolicyTool may be used by users and administrators to configure the
    61  * PolicyTool may be used by users and administrators to configure the
    51  * overall java security policy (currently stored in the policy file).
    62  * overall java security policy (currently stored in the policy file).
    52  * Using PolicyTool administrators may add and remove policies from
    63  * Using PolicyTool administrators may add and remove policies from
    64             "sun.security.tools.policytool.Resources");
    75             "sun.security.tools.policytool.Resources");
    65     static final Collator collator = Collator.getInstance();
    76     static final Collator collator = Collator.getInstance();
    66     static {
    77     static {
    67         // this is for case insensitive string comparisons
    78         // this is for case insensitive string comparisons
    68         collator.setStrength(Collator.PRIMARY);
    79         collator.setStrength(Collator.PRIMARY);
    69     };
    80 
       
    81         // Support for Apple menu bar
       
    82         if (System.getProperty("apple.laf.useScreenMenuBar") == null) {
       
    83             System.setProperty("apple.laf.useScreenMenuBar", "true");
       
    84         }
       
    85         System.setProperty("apple.awt.application.name", getMessage("Policy.Tool"));
       
    86 
       
    87         // Apply the system L&F if not specified with a system property.
       
    88         if (System.getProperty("swing.defaultlaf") == null) {
       
    89             try {
       
    90                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
       
    91             } catch (Exception e) {
       
    92                 // ignore
       
    93             }
       
    94         }
       
    95     }
    70 
    96 
    71     // anyone can add warnings
    97     // anyone can add warnings
    72     Vector<String> warnings;
    98     Vector<String> warnings;
    73     boolean newWarning = false;
    99     boolean newWarning = false;
    74 
   100 
   226                 String signers[] = parseSigners(ge.signedBy);
   252                 String signers[] = parseSigners(ge.signedBy);
   227                 for (int i = 0; i < signers.length; i++) {
   253                 for (int i = 0; i < signers.length; i++) {
   228                     PublicKey pubKey = getPublicKeyAlias(signers[i]);
   254                     PublicKey pubKey = getPublicKeyAlias(signers[i]);
   229                     if (pubKey == null) {
   255                     if (pubKey == null) {
   230                         newWarning = true;
   256                         newWarning = true;
   231                         MessageFormat form = new MessageFormat(rb.getString
   257                         MessageFormat form = new MessageFormat(getMessage
   232                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
   258                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
   233                         Object[] source = {signers[i]};
   259                         Object[] source = {signers[i]};
   234                         warnings.addElement(form.format(source));
   260                         warnings.addElement(form.format(source));
   235                     }
   261                     }
   236                 }
   262                 }
   244                 try {
   270                 try {
   245                     verifyPrincipal(pe.getPrincipalClass(),
   271                     verifyPrincipal(pe.getPrincipalClass(),
   246                                 pe.getPrincipalName());
   272                                 pe.getPrincipalName());
   247                 } catch (ClassNotFoundException fnfe) {
   273                 } catch (ClassNotFoundException fnfe) {
   248                     newWarning = true;
   274                     newWarning = true;
   249                     MessageFormat form = new MessageFormat(rb.getString
   275                     MessageFormat form = new MessageFormat(getMessage
   250                                 ("Warning.Class.not.found.class"));
   276                                 ("Warning.Class.not.found.class"));
   251                     Object[] source = {pe.getPrincipalClass()};
   277                     Object[] source = {pe.getPrincipalClass()};
   252                     warnings.addElement(form.format(source));
   278                     warnings.addElement(form.format(source));
   253                 }
   279                 }
   254             }
   280             }
   260                 PolicyParser.PermissionEntry pe = perms.nextElement();
   286                 PolicyParser.PermissionEntry pe = perms.nextElement();
   261                 try {
   287                 try {
   262                     verifyPermission(pe.permission, pe.name, pe.action);
   288                     verifyPermission(pe.permission, pe.name, pe.action);
   263                 } catch (ClassNotFoundException fnfe) {
   289                 } catch (ClassNotFoundException fnfe) {
   264                     newWarning = true;
   290                     newWarning = true;
   265                     MessageFormat form = new MessageFormat(rb.getString
   291                     MessageFormat form = new MessageFormat(getMessage
   266                                 ("Warning.Class.not.found.class"));
   292                                 ("Warning.Class.not.found.class"));
   267                     Object[] source = {pe.permission};
   293                     Object[] source = {pe.permission};
   268                     warnings.addElement(form.format(source));
   294                     warnings.addElement(form.format(source));
   269                 } catch (InvocationTargetException ite) {
   295                 } catch (InvocationTargetException ite) {
   270                     newWarning = true;
   296                     newWarning = true;
   271                     MessageFormat form = new MessageFormat(rb.getString
   297                     MessageFormat form = new MessageFormat(getMessage
   272                         ("Warning.Invalid.argument.s.for.constructor.arg"));
   298                         ("Warning.Invalid.argument.s.for.constructor.arg"));
   273                     Object[] source = {pe.permission};
   299                     Object[] source = {pe.permission};
   274                     warnings.addElement(form.format(source));
   300                     warnings.addElement(form.format(source));
   275                 }
   301                 }
   276 
   302 
   281 
   307 
   282                     for (int i = 0; i < signers.length; i++) {
   308                     for (int i = 0; i < signers.length; i++) {
   283                         PublicKey pubKey = getPublicKeyAlias(signers[i]);
   309                         PublicKey pubKey = getPublicKeyAlias(signers[i]);
   284                         if (pubKey == null) {
   310                         if (pubKey == null) {
   285                             newWarning = true;
   311                             newWarning = true;
   286                             MessageFormat form = new MessageFormat(rb.getString
   312                             MessageFormat form = new MessageFormat(getMessage
   287                                 ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
   313                                 ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
   288                             Object[] source = {signers[i]};
   314                             Object[] source = {signers[i]};
   289                             warnings.addElement(form.format(source));
   315                             warnings.addElement(form.format(source));
   290                         }
   316                         }
   291                     }
   317                     }
   609         }
   635         }
   610         Class<?> PRIN = Class.forName("java.security.Principal");
   636         Class<?> PRIN = Class.forName("java.security.Principal");
   611         Class<?> pc = Class.forName(type, true,
   637         Class<?> pc = Class.forName(type, true,
   612                 Thread.currentThread().getContextClassLoader());
   638                 Thread.currentThread().getContextClassLoader());
   613         if (!PRIN.isAssignableFrom(pc)) {
   639         if (!PRIN.isAssignableFrom(pc)) {
   614             MessageFormat form = new MessageFormat(rb.getString
   640             MessageFormat form = new MessageFormat(getMessage
   615                         ("Illegal.Principal.Type.type"));
   641                         ("Illegal.Principal.Type.type"));
   616             Object[] source = {type};
   642             Object[] source = {type};
   617             throw new InstantiationException(form.format(source));
   643             throw new InstantiationException(form.format(source));
   618         }
   644         }
   619 
   645 
   688 
   714 
   689             if (collator.compare(flags, "-file") == 0) {
   715             if (collator.compare(flags, "-file") == 0) {
   690                 if (++n == args.length) usage();
   716                 if (++n == args.length) usage();
   691                 policyFileName = args[n];
   717                 policyFileName = args[n];
   692             } else {
   718             } else {
   693                 MessageFormat form = new MessageFormat(rb.getString
   719                 MessageFormat form = new MessageFormat(getMessage
   694                                 ("Illegal.option.option"));
   720                                 ("Illegal.option.option"));
   695                 Object[] source = { flags };
   721                 Object[] source = { flags };
   696                 System.err.println(form.format(source));
   722                 System.err.println(form.format(source));
   697                 usage();
   723                 usage();
   698             }
   724             }
   699         }
   725         }
   700     }
   726     }
   701 
   727 
   702     static void usage() {
   728     static void usage() {
   703         System.out.println(rb.getString("Usage.policytool.options."));
   729         System.out.println(getMessage("Usage.policytool.options."));
   704         System.out.println();
   730         System.out.println();
   705         System.out.println(rb.getString
   731         System.out.println(getMessage
   706                 (".file.file.policy.file.location"));
   732                 (".file.file.policy.file.location"));
   707         System.out.println();
   733         System.out.println();
   708 
   734 
   709         System.exit(1);
   735         System.exit(1);
   710     }
   736     }
   712     /**
   738     /**
   713      * run the PolicyTool
   739      * run the PolicyTool
   714      */
   740      */
   715     public static void main(String args[]) {
   741     public static void main(String args[]) {
   716         parseArgs(args);
   742         parseArgs(args);
   717         ToolWindow tw = new ToolWindow(new PolicyTool());
   743         SwingUtilities.invokeLater(new Runnable() {
   718         tw.displayToolWindow(args);
   744             public void run() {
       
   745                 ToolWindow tw = new ToolWindow(new PolicyTool());
       
   746                 tw.displayToolWindow(args);
       
   747             }
       
   748         });
   719     }
   749     }
   720 
   750 
   721     // split instr to words according to capitalization,
   751     // split instr to words according to capitalization,
   722     // like, AWTControl -> A W T Control
   752     // like, AWTControl -> A W T Control
   723     // this method is for easy pronounciation
   753     // this method is for easy pronounciation
   724     static String splitToWords(String instr) {
   754     static String splitToWords(String instr) {
   725         return instr.replaceAll("([A-Z])", " $1");
   755         return instr.replaceAll("([A-Z])", " $1");
   726     }
   756     }
   727 
   757 
       
   758     /**
       
   759      * Returns the message corresponding to the key in the bundle.
       
   760      * This is preferred over {@link #getString} because it removes
       
   761      * any mnemonic '&' character in the string.
       
   762      *
       
   763      * @param key the key
       
   764      *
       
   765      * @return the message
       
   766      */
       
   767     static String getMessage(String key) {
       
   768         return removeMnemonicAmpersand(rb.getString(key));
       
   769     }
       
   770 
       
   771 
       
   772     /**
       
   773      * Returns the mnemonic for a message.
       
   774      *
       
   775      * @param key the key
       
   776      *
       
   777      * @return the mnemonic <code>int</code>
       
   778      */
       
   779     static int getMnemonicInt(String key) {
       
   780         String message = rb.getString(key);
       
   781         return (findMnemonicInt(message));
       
   782     }
       
   783 
       
   784     /**
       
   785      * Returns the mnemonic display index for a message.
       
   786      *
       
   787      * @param key the key
       
   788      *
       
   789      * @return the mnemonic display index
       
   790      */
       
   791     static int getDisplayedMnemonicIndex(String key) {
       
   792         String message = rb.getString(key);
       
   793         return (findMnemonicIndex(message));
       
   794     }
       
   795 
       
   796     /**
       
   797      * Finds the mnemonic character in a message.
       
   798      *
       
   799      * The mnemonic character is the first character followed by the first
       
   800      * <code>&</code> that is not followed by another <code>&</code>.
       
   801      *
       
   802      * @return the mnemonic as an <code>int</code>, or <code>0</code> if it
       
   803      *         can't be found.
       
   804      */
       
   805     private static int findMnemonicInt(String s) {
       
   806         for (int i = 0; i < s.length() - 1; i++) {
       
   807             if (s.charAt(i) == '&') {
       
   808                 if (s.charAt(i + 1) != '&') {
       
   809                     return KeyEvent.getExtendedKeyCodeForChar(s.charAt(i + 1));
       
   810                 } else {
       
   811                     i++;
       
   812                 }
       
   813             }
       
   814         }
       
   815         return 0;
       
   816     }
       
   817 
       
   818     /**
       
   819      * Finds the index of the mnemonic character in a message.
       
   820      *
       
   821      * The mnemonic character is the first character followed by the first
       
   822      * <code>&</code> that is not followed by another <code>&</code>.
       
   823      *
       
   824      * @return the mnemonic character index as an <code>int</code>, or <code>-1</code> if it
       
   825      *         can't be found.
       
   826      */
       
   827     private static int findMnemonicIndex(String s) {
       
   828         for (int i = 0; i < s.length() - 1; i++) {
       
   829             if (s.charAt(i) == '&') {
       
   830                 if (s.charAt(i + 1) != '&') {
       
   831                     // Return the index of the '&' since it will be removed
       
   832                     return i;
       
   833                 } else {
       
   834                     i++;
       
   835                 }
       
   836             }
       
   837         }
       
   838         return -1;
       
   839     }
       
   840 
       
   841     /**
       
   842      * Removes the mnemonic identifier (<code>&</code>) from a string unless
       
   843      * it's escaped by <code>&&</code> or placed at the end.
       
   844      *
       
   845      * @param message the message
       
   846      *
       
   847      * @return a message with the mnemonic identifier removed
       
   848      */
       
   849     private static String removeMnemonicAmpersand(String message) {
       
   850         StringBuilder s = new StringBuilder();
       
   851         for (int i = 0; i < message.length(); i++) {
       
   852             char current = message.charAt(i);
       
   853             if (current != '&' || i == message.length() - 1
       
   854                     || message.charAt(i + 1) == '&') {
       
   855                 s.append(current);
       
   856             }
       
   857         }
       
   858         return s.toString();
       
   859     }
   728 }
   860 }
   729 
   861 
   730 /**
   862 /**
   731  * Each entry in the policy configuration file is represented by a
   863  * Each entry in the policy configuration file is represented by a
   732  * PolicyEntry object.
   864  * PolicyEntry object.
   878 }
  1010 }
   879 
  1011 
   880 /**
  1012 /**
   881  * The main window for the PolicyTool
  1013  * The main window for the PolicyTool
   882  */
  1014  */
   883 class ToolWindow extends Frame {
  1015 class ToolWindow extends JFrame {
   884     // use serialVersionUID from JDK 1.2.2 for interoperability
  1016     // use serialVersionUID from JDK 1.2.2 for interoperability
   885     private static final long serialVersionUID = 5682568601210376777L;
  1017     private static final long serialVersionUID = 5682568601210376777L;
       
  1018 
       
  1019     /* ESCAPE key */
       
  1020     static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
   886 
  1021 
   887     /* external paddings */
  1022     /* external paddings */
   888     public static final Insets TOP_PADDING = new Insets(25,0,0,0);
  1023     public static final Insets TOP_PADDING = new Insets(25,0,0,0);
   889     public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0);
  1024     public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0);
   890     public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0);
  1025     public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0);
   891     public static final Insets LR_PADDING = new Insets(0,10,0,10);
  1026     public static final Insets LR_PADDING = new Insets(0,10,0,10);
   892     public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0);
  1027     public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0);
   893     public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0);
  1028     public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0);
       
  1029     public static final Insets LR_TOP_BOTTOM_PADDING = new Insets(15, 4, 15, 4);
   894     public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10);
  1030     public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10);
   895     public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0);
  1031     public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0);
   896     public static final Insets R_BOTTOM_PADDING = new Insets(0,0,5,10);
  1032     public static final Insets R_BOTTOM_PADDING = new Insets(0, 0, 25, 5);
       
  1033     public static final Insets R_PADDING = new Insets(0, 0, 0, 5);
   897 
  1034 
   898     /* buttons and menus */
  1035     /* buttons and menus */
   899     public static final String NEW_POLICY_FILE          =
  1036     public static final String NEW_POLICY_FILE          = "New";
   900                         PolicyTool.rb.getString("New");
  1037     public static final String OPEN_POLICY_FILE         = "Open";
   901     public static final String OPEN_POLICY_FILE         =
  1038     public static final String SAVE_POLICY_FILE         = "Save";
   902                         PolicyTool.rb.getString("Open");
  1039     public static final String SAVE_AS_POLICY_FILE      = "Save.As";
   903     public static final String SAVE_POLICY_FILE         =
  1040     public static final String VIEW_WARNINGS            = "View.Warning.Log";
   904                         PolicyTool.rb.getString("Save");
  1041     public static final String QUIT                     = "Exit";
   905     public static final String SAVE_AS_POLICY_FILE      =
  1042     public static final String ADD_POLICY_ENTRY         = "Add.Policy.Entry";
   906                         PolicyTool.rb.getString("Save.As");
  1043     public static final String EDIT_POLICY_ENTRY        = "Edit.Policy.Entry";
   907     public static final String VIEW_WARNINGS            =
  1044     public static final String REMOVE_POLICY_ENTRY      = "Remove.Policy.Entry";
   908                         PolicyTool.rb.getString("View.Warning.Log");
  1045     public static final String EDIT_KEYSTORE            = "Edit";
   909     public static final String QUIT                     =
  1046     public static final String ADD_PUBKEY_ALIAS         = "Add.Public.Key.Alias";
   910                         PolicyTool.rb.getString("Exit");
  1047     public static final String REMOVE_PUBKEY_ALIAS      = "Remove.Public.Key.Alias";
   911     public static final String ADD_POLICY_ENTRY         =
       
   912                         PolicyTool.rb.getString("Add.Policy.Entry");
       
   913     public static final String EDIT_POLICY_ENTRY        =
       
   914                         PolicyTool.rb.getString("Edit.Policy.Entry");
       
   915     public static final String REMOVE_POLICY_ENTRY      =
       
   916                         PolicyTool.rb.getString("Remove.Policy.Entry");
       
   917     public static final String EDIT_KEYSTORE            =
       
   918                         PolicyTool.rb.getString("Edit");
       
   919     public static final String ADD_PUBKEY_ALIAS         =
       
   920                         PolicyTool.rb.getString("Add.Public.Key.Alias");
       
   921     public static final String REMOVE_PUBKEY_ALIAS      =
       
   922                         PolicyTool.rb.getString("Remove.Public.Key.Alias");
       
   923 
  1048 
   924     /* gridbag index for components in the main window (MW) */
  1049     /* gridbag index for components in the main window (MW) */
   925     public static final int MW_FILENAME_LABEL           = 0;
  1050     public static final int MW_FILENAME_LABEL           = 0;
   926     public static final int MW_FILENAME_TEXTFIELD       = 1;
  1051     public static final int MW_FILENAME_TEXTFIELD       = 1;
   927     public static final int MW_PANEL                    = 2;
  1052     public static final int MW_PANEL                    = 2;
   928     public static final int MW_ADD_BUTTON               = 0;
  1053     public static final int MW_ADD_BUTTON               = 0;
   929     public static final int MW_EDIT_BUTTON              = 1;
  1054     public static final int MW_EDIT_BUTTON              = 1;
   930     public static final int MW_REMOVE_BUTTON            = 2;
  1055     public static final int MW_REMOVE_BUTTON            = 2;
   931     public static final int MW_POLICY_LIST              = 3; // follows MW_PANEL
  1056     public static final int MW_POLICY_LIST              = 3; // follows MW_PANEL
   932 
  1057 
       
  1058     /* The preferred height of JTextField should match JComboBox. */
       
  1059     static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;
       
  1060 
   933     private PolicyTool tool;
  1061     private PolicyTool tool;
   934 
  1062 
   935     /**
  1063     /**
   936      * Constructor
  1064      * Constructor
   937      */
  1065      */
   938     ToolWindow(PolicyTool tool) {
  1066     ToolWindow(PolicyTool tool) {
   939         this.tool = tool;
  1067         this.tool = tool;
   940     }
  1068     }
   941 
  1069 
   942     /**
  1070     /**
       
  1071      * Don't call getComponent directly on the window
       
  1072      */
       
  1073     public Component getComponent(int n) {
       
  1074         Component c = getContentPane().getComponent(n);
       
  1075         if (c instanceof JScrollPane) {
       
  1076             c = ((JScrollPane)c).getViewport().getView();
       
  1077         }
       
  1078         return c;
       
  1079     }
       
  1080 
       
  1081     /**
   943      * Initialize the PolicyTool window with the necessary components
  1082      * Initialize the PolicyTool window with the necessary components
   944      */
  1083      */
   945     private void initWindow() {
  1084     private void initWindow() {
       
  1085         // The ToolWindowListener will handle closing the window.
       
  1086         setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
   946 
  1087 
   947         // create the top menu bar
  1088         // create the top menu bar
   948         MenuBar menuBar = new MenuBar();
  1089         JMenuBar menuBar = new JMenuBar();
   949 
  1090 
   950         // create a File menu
  1091         // create a File menu
   951         Menu menu = new Menu(PolicyTool.rb.getString("File"));
  1092         JMenu menu = new JMenu();
   952         menu.add(NEW_POLICY_FILE);
  1093         configureButton(menu, "File");
   953         menu.add(OPEN_POLICY_FILE);
  1094         ActionListener actionListener = new FileMenuListener(tool, this);
   954         menu.add(SAVE_POLICY_FILE);
  1095         addMenuItem(menu, NEW_POLICY_FILE, actionListener);
   955         menu.add(SAVE_AS_POLICY_FILE);
  1096         addMenuItem(menu, OPEN_POLICY_FILE, actionListener);
   956         menu.add(VIEW_WARNINGS);
  1097         addMenuItem(menu, SAVE_POLICY_FILE, actionListener);
   957         menu.add(QUIT);
  1098         addMenuItem(menu, SAVE_AS_POLICY_FILE, actionListener);
   958         menu.addActionListener(new FileMenuListener(tool, this));
  1099         addMenuItem(menu, VIEW_WARNINGS, actionListener);
       
  1100         addMenuItem(menu, QUIT, actionListener);
   959         menuBar.add(menu);
  1101         menuBar.add(menu);
   960         setMenuBar(menuBar);
       
   961 
  1102 
   962         // create a KeyStore menu
  1103         // create a KeyStore menu
   963         menu = new Menu(PolicyTool.rb.getString("KeyStore"));
  1104         menu = new JMenu();
   964         menu.add(EDIT_KEYSTORE);
  1105         configureButton(menu, "KeyStore");
   965         menu.addActionListener(new MainWindowListener(tool, this));
  1106         actionListener = new MainWindowListener(tool, this);
       
  1107         addMenuItem(menu, EDIT_KEYSTORE, actionListener);
   966         menuBar.add(menu);
  1108         menuBar.add(menu);
   967         setMenuBar(menuBar);
  1109         setJMenuBar(menuBar);
   968 
  1110 
       
  1111         // Create some space around components
       
  1112         ((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));
   969 
  1113 
   970         // policy entry listing
  1114         // policy entry listing
   971         Label label = new Label(PolicyTool.rb.getString("Policy.File."));
  1115         JLabel label = new JLabel(PolicyTool.getMessage("Policy.File."));
   972         addNewComponent(this, label, MW_FILENAME_LABEL,
  1116         addNewComponent(this, label, MW_FILENAME_LABEL,
   973                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1117                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
   974                         TOP_BOTTOM_PADDING);
  1118                         LR_TOP_BOTTOM_PADDING);
   975         TextField tf = new TextField(50);
  1119         JTextField tf = new JTextField(50);
       
  1120         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
   976         tf.getAccessibleContext().setAccessibleName(
  1121         tf.getAccessibleContext().setAccessibleName(
   977                 PolicyTool.rb.getString("Policy.File."));
  1122                 PolicyTool.getMessage("Policy.File."));
   978         tf.setEditable(false);
  1123         tf.setEditable(false);
   979         addNewComponent(this, tf, MW_FILENAME_TEXTFIELD,
  1124         addNewComponent(this, tf, MW_FILENAME_TEXTFIELD,
   980                         1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1125                         1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
   981                         TOP_BOTTOM_PADDING);
  1126                         LR_TOP_BOTTOM_PADDING);
   982 
  1127 
   983 
  1128 
   984         // add ADD/REMOVE/EDIT buttons in a new panel
  1129         // add ADD/REMOVE/EDIT buttons in a new panel
   985         Panel panel = new Panel();
  1130         JPanel panel = new JPanel();
   986         panel.setLayout(new GridBagLayout());
  1131         panel.setLayout(new GridBagLayout());
   987 
  1132 
   988         Button button = new Button(ADD_POLICY_ENTRY);
  1133         JButton button = new JButton();
       
  1134         configureButton(button, ADD_POLICY_ENTRY);
   989         button.addActionListener(new MainWindowListener(tool, this));
  1135         button.addActionListener(new MainWindowListener(tool, this));
   990         addNewComponent(panel, button, MW_ADD_BUTTON,
  1136         addNewComponent(panel, button, MW_ADD_BUTTON,
   991                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1137                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
   992                         LR_PADDING);
  1138                         LR_PADDING);
   993 
  1139 
   994         button = new Button(EDIT_POLICY_ENTRY);
  1140         button = new JButton();
       
  1141         configureButton(button, EDIT_POLICY_ENTRY);
   995         button.addActionListener(new MainWindowListener(tool, this));
  1142         button.addActionListener(new MainWindowListener(tool, this));
   996         addNewComponent(panel, button, MW_EDIT_BUTTON,
  1143         addNewComponent(panel, button, MW_EDIT_BUTTON,
   997                         1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1144                         1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
   998                         LR_PADDING);
  1145                         LR_PADDING);
   999 
  1146 
  1000         button = new Button(REMOVE_POLICY_ENTRY);
  1147         button = new JButton();
       
  1148         configureButton(button, REMOVE_POLICY_ENTRY);
  1001         button.addActionListener(new MainWindowListener(tool, this));
  1149         button.addActionListener(new MainWindowListener(tool, this));
  1002         addNewComponent(panel, button, MW_REMOVE_BUTTON,
  1150         addNewComponent(panel, button, MW_REMOVE_BUTTON,
  1003                         2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1151                         2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1004                         LR_PADDING);
  1152                         LR_PADDING);
  1005 
  1153 
  1019         try {
  1167         try {
  1020             // open the policy file
  1168             // open the policy file
  1021             tool.openPolicy(policyFile);
  1169             tool.openPolicy(policyFile);
  1022 
  1170 
  1023             // display the policy entries via the policy list textarea
  1171             // display the policy entries via the policy list textarea
  1024             List list = new List(40, false);
  1172             DefaultListModel listModel = new DefaultListModel();
  1025             list.addActionListener(new PolicyListListener(tool, this));
  1173             JList list = new JList(listModel);
       
  1174             list.setVisibleRowCount(15);
       
  1175             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  1176             list.addMouseListener(new PolicyListListener(tool, this));
  1026             PolicyEntry entries[] = tool.getEntry();
  1177             PolicyEntry entries[] = tool.getEntry();
  1027             if (entries != null) {
  1178             if (entries != null) {
  1028                 for (int i = 0; i < entries.length; i++)
  1179                 for (int i = 0; i < entries.length; i++) {
  1029                     list.add(entries[i].headerToString());
  1180                     listModel.addElement(entries[i].headerToString());
       
  1181                 }
  1030             }
  1182             }
  1031             TextField newFilename = (TextField)
  1183             JTextField newFilename = (JTextField)
  1032                                 getComponent(MW_FILENAME_TEXTFIELD);
  1184                                 getComponent(MW_FILENAME_TEXTFIELD);
  1033             newFilename.setText(policyFile);
  1185             newFilename.setText(policyFile);
  1034             initPolicyList(list);
  1186             initPolicyList(list);
  1035 
  1187 
  1036         } catch (FileNotFoundException fnfe) {
  1188         } catch (FileNotFoundException fnfe) {
  1037             // add blank policy listing
  1189             // add blank policy listing
  1038             List list = new List(40, false);
  1190             JList list = new JList(new DefaultListModel());
  1039             list.addActionListener(new PolicyListListener(tool, this));
  1191             list.setVisibleRowCount(15);
       
  1192             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  1193             list.addMouseListener(new PolicyListListener(tool, this));
  1040             initPolicyList(list);
  1194             initPolicyList(list);
  1041             tool.setPolicyFileName(null);
  1195             tool.setPolicyFileName(null);
  1042             tool.modified = false;
  1196             tool.modified = false;
  1043             setVisible(true);
       
  1044 
  1197 
  1045             // just add warning
  1198             // just add warning
  1046             tool.warnings.addElement(fnfe.toString());
  1199             tool.warnings.addElement(fnfe.toString());
  1047 
  1200 
  1048         } catch (Exception e) {
  1201         } catch (Exception e) {
  1049             // add blank policy listing
  1202             // add blank policy listing
  1050             List list = new List(40, false);
  1203             JList list = new JList(new DefaultListModel());
  1051             list.addActionListener(new PolicyListListener(tool, this));
  1204             list.setVisibleRowCount(15);
       
  1205             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  1206             list.addMouseListener(new PolicyListListener(tool, this));
  1052             initPolicyList(list);
  1207             initPolicyList(list);
  1053             tool.setPolicyFileName(null);
  1208             tool.setPolicyFileName(null);
  1054             tool.modified = false;
  1209             tool.modified = false;
  1055             setVisible(true);
       
  1056 
  1210 
  1057             // display the error
  1211             // display the error
  1058             MessageFormat form = new MessageFormat(PolicyTool.rb.getString
  1212             MessageFormat form = new MessageFormat(PolicyTool.getMessage
  1059                 ("Could.not.open.policy.file.policyFile.e.toString."));
  1213                 ("Could.not.open.policy.file.policyFile.e.toString."));
  1060             Object[] source = {policyFile, e.toString()};
  1214             Object[] source = {policyFile, e.toString()};
  1061             displayErrorDialog(null, form.format(source));
  1215             displayErrorDialog(null, form.format(source));
  1062         }
  1216         }
  1063     }
  1217     }
  1064 
  1218 
  1065 
  1219 
       
  1220     // Platform specific modifier (control / command).
       
  1221     private int shortCutModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
       
  1222 
       
  1223     private void addMenuItem(JMenu menu, String key, ActionListener actionListener) {
       
  1224         JMenuItem menuItem = new JMenuItem();
       
  1225         configureButton(menuItem, key);
       
  1226 
       
  1227         if (PolicyTool.rb.containsKey(key + ".accelerator")) {
       
  1228             String accelerator = PolicyTool.getMessage(key + ".accelerator");
       
  1229             if (accelerator != null && !accelerator.isEmpty()) {
       
  1230                 KeyStroke keyStroke;
       
  1231                 if (accelerator.matches("^control .$")) {
       
  1232                     // Map "control" key to "command" on MacOS
       
  1233                     keyStroke = KeyStroke.getKeyStroke(KeyEvent.getExtendedKeyCodeForChar(accelerator.charAt(8)),
       
  1234                                                        shortCutModifier);
       
  1235                 } else {
       
  1236                     keyStroke = KeyStroke.getKeyStroke(accelerator);
       
  1237                 }
       
  1238                 menuItem.setAccelerator(keyStroke);
       
  1239             }
       
  1240         }
       
  1241 
       
  1242         menuItem.addActionListener(actionListener);
       
  1243         menu.add(menuItem);
       
  1244     }
       
  1245 
       
  1246     static void configureButton(AbstractButton button, String key) {
       
  1247         button.setText(PolicyTool.getMessage(key));
       
  1248         button.setActionCommand(key);
       
  1249 
       
  1250         int mnemonicInt = PolicyTool.getMnemonicInt(key);
       
  1251         if (mnemonicInt > 0) {
       
  1252             button.setMnemonic(mnemonicInt);
       
  1253             button.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));
       
  1254          }
       
  1255     }
       
  1256 
       
  1257     static void configureLabelFor(JLabel label, JComponent component, String key) {
       
  1258         label.setText(PolicyTool.getMessage(key));
       
  1259         label.setLabelFor(component);
       
  1260 
       
  1261         int mnemonicInt = PolicyTool.getMnemonicInt(key);
       
  1262         if (mnemonicInt > 0) {
       
  1263             label.setDisplayedMnemonic(mnemonicInt);
       
  1264             label.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));
       
  1265          }
       
  1266     }
       
  1267 
       
  1268 
  1066     /**
  1269     /**
  1067      * Add a component to the PolicyTool window
  1270      * Add a component to the PolicyTool window
  1068      */
  1271      */
  1069     void addNewComponent(Container container, Component component,
  1272     void addNewComponent(Container container, JComponent component,
  1070         int index, int gridx, int gridy, int gridwidth, int gridheight,
  1273         int index, int gridx, int gridy, int gridwidth, int gridheight,
  1071         double weightx, double weighty, int fill, Insets is) {
  1274         double weightx, double weighty, int fill, Insets is) {
       
  1275 
       
  1276         if (container instanceof JFrame) {
       
  1277             container = ((JFrame)container).getContentPane();
       
  1278         } else if (container instanceof JDialog) {
       
  1279             container = ((JDialog)container).getContentPane();
       
  1280         }
  1072 
  1281 
  1073         // add the component at the specified gridbag index
  1282         // add the component at the specified gridbag index
  1074         container.add(component, index);
  1283         container.add(component, index);
  1075 
  1284 
  1076         // set the constraints
  1285         // set the constraints
  1089 
  1298 
  1090 
  1299 
  1091     /**
  1300     /**
  1092      * Add a component to the PolicyTool window without external padding
  1301      * Add a component to the PolicyTool window without external padding
  1093      */
  1302      */
  1094     void addNewComponent(Container container, Component component,
  1303     void addNewComponent(Container container, JComponent component,
  1095         int index, int gridx, int gridy, int gridwidth, int gridheight,
  1304         int index, int gridx, int gridy, int gridwidth, int gridheight,
  1096         double weightx, double weighty, int fill) {
  1305         double weightx, double weighty, int fill) {
  1097 
  1306 
  1098         // delegate with "null" external padding
  1307         // delegate with "null" external padding
  1099         addNewComponent(container, component, index, gridx, gridy,
  1308         addNewComponent(container, component, index, gridx, gridy,
  1104 
  1313 
  1105     /**
  1314     /**
  1106      * Init the policy_entry_list TEXTAREA component in the
  1315      * Init the policy_entry_list TEXTAREA component in the
  1107      * PolicyTool window
  1316      * PolicyTool window
  1108      */
  1317      */
  1109     void initPolicyList(List policyList) {
  1318     void initPolicyList(JList policyList) {
  1110 
  1319 
  1111         // add the policy list to the window
  1320         // add the policy list to the window
  1112         addNewComponent(this, policyList, MW_POLICY_LIST,
  1321         //policyList.setPreferredSize(new Dimension(500, 350));
       
  1322         JScrollPane scrollPane = new JScrollPane(policyList);
       
  1323         addNewComponent(this, scrollPane, MW_POLICY_LIST,
  1113                         0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH);
  1324                         0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH);
  1114     }
  1325     }
  1115 
  1326 
  1116     /**
  1327     /**
  1117      * Replace the policy_entry_list TEXTAREA component in the
  1328      * Replace the policy_entry_list TEXTAREA component in the
  1118      * PolicyTool window with an updated one.
  1329      * PolicyTool window with an updated one.
  1119      */
  1330      */
  1120     void replacePolicyList(List policyList) {
  1331     void replacePolicyList(JList policyList) {
  1121 
  1332 
  1122         // remove the original list of Policy Entries
  1333         // remove the original list of Policy Entries
  1123         // and add the new list of entries
  1334         // and add the new list of entries
  1124         List list = (List)getComponent(MW_POLICY_LIST);
  1335         JList list = (JList)getComponent(MW_POLICY_LIST);
  1125         list.removeAll();
  1336         list.setModel(policyList.getModel());
  1126         String newItems[] = policyList.getItems();
       
  1127         for (int i = 0; i < newItems.length; i++)
       
  1128             list.add(newItems[i]);
       
  1129     }
  1337     }
  1130 
  1338 
  1131     /**
  1339     /**
  1132      * display the main PolicyTool window
  1340      * display the main PolicyTool window
  1133      */
  1341      */
  1134     void displayToolWindow(String args[]) {
  1342     void displayToolWindow(String args[]) {
  1135 
  1343 
  1136         setTitle(PolicyTool.rb.getString("Policy.Tool"));
  1344         setTitle(PolicyTool.getMessage("Policy.Tool"));
  1137         setResizable(true);
  1345         setResizable(true);
  1138         addWindowListener(new ToolWindowListener(this));
  1346         addWindowListener(new ToolWindowListener(tool, this));
  1139         setBounds(135, 80, 500, 500);
  1347         //setBounds(135, 80, 500, 500);
  1140         setLayout(new GridBagLayout());
  1348         getContentPane().setLayout(new GridBagLayout());
  1141 
  1349 
  1142         initWindow();
  1350         initWindow();
       
  1351         pack();
       
  1352         setLocationRelativeTo(null);
  1143 
  1353 
  1144         // display it
  1354         // display it
  1145         setVisible(true);
  1355         setVisible(true);
  1146 
  1356 
  1147         if (tool.newWarning == true) {
  1357         if (tool.newWarning == true) {
  1148             displayStatusDialog(this, PolicyTool.rb.getString
  1358             displayStatusDialog(this, PolicyTool.getMessage
  1149                 ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
  1359                 ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
  1150         }
  1360         }
  1151     }
  1361     }
  1152 
  1362 
  1153     /**
  1363     /**
  1154      * displays a dialog box describing an error which occurred.
  1364      * displays a dialog box describing an error which occurred.
  1155      */
  1365      */
  1156     void displayErrorDialog(Window w, String error) {
  1366     void displayErrorDialog(Window w, String error) {
  1157         ToolDialog ed = new ToolDialog
  1367         ToolDialog ed = new ToolDialog
  1158                 (PolicyTool.rb.getString("Error"), tool, this, true);
  1368                 (PolicyTool.getMessage("Error"), tool, this, true);
  1159 
  1369 
  1160         // find where the PolicyTool gui is
  1370         // find where the PolicyTool gui is
  1161         Point location = ((w == null) ?
  1371         Point location = ((w == null) ?
  1162                 getLocationOnScreen() : w.getLocationOnScreen());
  1372                 getLocationOnScreen() : w.getLocationOnScreen());
  1163         ed.setBounds(location.x + 50, location.y + 50, 600, 100);
  1373         //ed.setBounds(location.x + 50, location.y + 50, 600, 100);
  1164         ed.setLayout(new GridBagLayout());
  1374         ed.setLayout(new GridBagLayout());
  1165 
  1375 
  1166         Label label = new Label(error);
  1376         JLabel label = new JLabel(error);
  1167         addNewComponent(ed, label, 0,
  1377         addNewComponent(ed, label, 0,
  1168                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1378                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1169 
  1379 
  1170         Button okButton = new Button(PolicyTool.rb.getString("OK"));
  1380         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
  1171         okButton.addActionListener(new ErrorOKButtonListener(ed));
  1381         ActionListener okListener = new ErrorOKButtonListener(ed);
       
  1382         okButton.addActionListener(okListener);
  1172         addNewComponent(ed, okButton, 1,
  1383         addNewComponent(ed, okButton, 1,
  1173                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1384                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1174 
  1385 
       
  1386         ed.getRootPane().setDefaultButton(okButton);
       
  1387         ed.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1388 
  1175         ed.pack();
  1389         ed.pack();
       
  1390         ed.setLocationRelativeTo(w);
  1176         ed.setVisible(true);
  1391         ed.setVisible(true);
  1177     }
  1392     }
  1178 
  1393 
  1179     /**
  1394     /**
  1180      * displays a dialog box describing an error which occurred.
  1395      * displays a dialog box describing an error which occurred.
  1189     /**
  1404     /**
  1190      * displays a dialog box describing the status of an event
  1405      * displays a dialog box describing the status of an event
  1191      */
  1406      */
  1192     void displayStatusDialog(Window w, String status) {
  1407     void displayStatusDialog(Window w, String status) {
  1193         ToolDialog sd = new ToolDialog
  1408         ToolDialog sd = new ToolDialog
  1194                 (PolicyTool.rb.getString("Status"), tool, this, true);
  1409                 (PolicyTool.getMessage("Status"), tool, this, true);
  1195 
  1410 
  1196         // find the location of the PolicyTool gui
  1411         // find the location of the PolicyTool gui
  1197         Point location = ((w == null) ?
  1412         Point location = ((w == null) ?
  1198                 getLocationOnScreen() : w.getLocationOnScreen());
  1413                 getLocationOnScreen() : w.getLocationOnScreen());
  1199         sd.setBounds(location.x + 50, location.y + 50, 500, 100);
  1414         //sd.setBounds(location.x + 50, location.y + 50, 500, 100);
  1200         sd.setLayout(new GridBagLayout());
  1415         sd.setLayout(new GridBagLayout());
  1201 
  1416 
  1202         Label label = new Label(status);
  1417         JLabel label = new JLabel(status);
  1203         addNewComponent(sd, label, 0,
  1418         addNewComponent(sd, label, 0,
  1204                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1419                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1205 
  1420 
  1206         Button okButton = new Button(PolicyTool.rb.getString("OK"));
  1421         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
  1207         okButton.addActionListener(new StatusOKButtonListener(sd));
  1422         ActionListener okListener = new StatusOKButtonListener(sd);
       
  1423         okButton.addActionListener(okListener);
  1208         addNewComponent(sd, okButton, 1,
  1424         addNewComponent(sd, okButton, 1,
  1209                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1425                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
       
  1426 
       
  1427         sd.getRootPane().setDefaultButton(okButton);
       
  1428         sd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1429 
  1210         sd.pack();
  1430         sd.pack();
       
  1431         sd.setLocationRelativeTo(w);
  1211         sd.setVisible(true);
  1432         sd.setVisible(true);
  1212     }
  1433     }
  1213 
  1434 
  1214     /**
  1435     /**
  1215      * display the warning log
  1436      * display the warning log
  1216      */
  1437      */
  1217     void displayWarningLog(Window w) {
  1438     void displayWarningLog(Window w) {
  1218 
  1439 
  1219         ToolDialog wd = new ToolDialog
  1440         ToolDialog wd = new ToolDialog
  1220                 (PolicyTool.rb.getString("Warning"), tool, this, true);
  1441                 (PolicyTool.getMessage("Warning"), tool, this, true);
  1221 
  1442 
  1222         // find the location of the PolicyTool gui
  1443         // find the location of the PolicyTool gui
  1223         Point location = ((w == null) ?
  1444         Point location = ((w == null) ?
  1224                 getLocationOnScreen() : w.getLocationOnScreen());
  1445                 getLocationOnScreen() : w.getLocationOnScreen());
  1225         wd.setBounds(location.x + 50, location.y + 50, 500, 100);
  1446         //wd.setBounds(location.x + 50, location.y + 50, 500, 100);
  1226         wd.setLayout(new GridBagLayout());
  1447         wd.setLayout(new GridBagLayout());
  1227 
  1448 
  1228         TextArea ta = new TextArea();
  1449         JTextArea ta = new JTextArea();
  1229         ta.setEditable(false);
  1450         ta.setEditable(false);
  1230         for (int i = 0; i < tool.warnings.size(); i++) {
  1451         for (int i = 0; i < tool.warnings.size(); i++) {
  1231             ta.append(tool.warnings.elementAt(i));
  1452             ta.append(tool.warnings.elementAt(i));
  1232             ta.append(PolicyTool.rb.getString("NEWLINE"));
  1453             ta.append(PolicyTool.getMessage("NEWLINE"));
  1233         }
  1454         }
  1234         addNewComponent(wd, ta, 0,
  1455         addNewComponent(wd, ta, 0,
  1235                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1456                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1236                         BOTTOM_PADDING);
  1457                         BOTTOM_PADDING);
  1237         ta.setFocusable(false);
  1458         ta.setFocusable(false);
  1238 
  1459 
  1239         Button okButton = new Button(PolicyTool.rb.getString("OK"));
  1460         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
  1240         okButton.addActionListener(new CancelButtonListener(wd));
  1461         ActionListener okListener = new CancelButtonListener(wd);
       
  1462         okButton.addActionListener(okListener);
  1241         addNewComponent(wd, okButton, 1,
  1463         addNewComponent(wd, okButton, 1,
  1242                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1464                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1243                         LR_PADDING);
  1465                         LR_PADDING);
  1244 
  1466 
       
  1467         wd.getRootPane().setDefaultButton(okButton);
       
  1468         wd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1469 
  1245         wd.pack();
  1470         wd.pack();
       
  1471         wd.setLocationRelativeTo(w);
  1246         wd.setVisible(true);
  1472         wd.setVisible(true);
  1247     }
  1473     }
  1248 
  1474 
  1249     char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) {
  1475     char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) {
  1250 
  1476 
  1251         final ToolDialog tw = new ToolDialog
  1477         final ToolDialog tw = new ToolDialog
  1252                 (title, tool, this, true);
  1478                 (title, tool, this, true);
  1253         Point location = ((w == null) ?
  1479         Point location = ((w == null) ?
  1254                 getLocationOnScreen() : w.getLocationOnScreen());
  1480                 getLocationOnScreen() : w.getLocationOnScreen());
  1255         tw.setBounds(location.x + 75, location.y + 100, 400, 150);
  1481         //tw.setBounds(location.x + 75, location.y + 100, 400, 150);
  1256         tw.setLayout(new GridBagLayout());
  1482         tw.setLayout(new GridBagLayout());
  1257 
  1483 
  1258         TextArea ta = new TextArea(prompt, 10, 50, TextArea.SCROLLBARS_VERTICAL_ONLY);
  1484         JTextArea ta = new JTextArea(prompt, 10, 50);
  1259         ta.setEditable(false);
  1485         ta.setEditable(false);
  1260         addNewComponent(tw, ta, 0,
  1486         ta.setLineWrap(true);
       
  1487         ta.setWrapStyleWord(true);
       
  1488         JScrollPane scrollPane = new JScrollPane(ta,
       
  1489                                                  JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
       
  1490                                                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
       
  1491         addNewComponent(tw, scrollPane, 0,
  1261                 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1492                 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1262         ta.setFocusable(false);
  1493         ta.setFocusable(false);
  1263 
  1494 
  1264         Panel panel = new Panel();
  1495         JPanel panel = new JPanel();
  1265         panel.setLayout(new GridBagLayout());
  1496         panel.setLayout(new GridBagLayout());
  1266 
  1497 
  1267         // StringBuffer to store button press. Must be final.
  1498         // StringBuffer to store button press. Must be final.
  1268         final StringBuffer chooseResult = new StringBuffer();
  1499         final StringBuffer chooseResult = new StringBuffer();
  1269 
  1500 
  1270         Button button = new Button(yes);
  1501         JButton button = new JButton(yes);
  1271         button.addActionListener(new ActionListener() {
  1502         button.addActionListener(new ActionListener() {
  1272             public void actionPerformed(ActionEvent e) {
  1503             public void actionPerformed(ActionEvent e) {
  1273                 chooseResult.append('Y');
  1504                 chooseResult.append('Y');
  1274                 tw.setVisible(false);
  1505                 tw.setVisible(false);
  1275                 tw.dispose();
  1506                 tw.dispose();
  1277         });
  1508         });
  1278         addNewComponent(panel, button, 0,
  1509         addNewComponent(panel, button, 0,
  1279                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1510                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1280                            LR_PADDING);
  1511                            LR_PADDING);
  1281 
  1512 
  1282         button = new Button(no);
  1513         button = new JButton(no);
  1283         button.addActionListener(new ActionListener() {
  1514         button.addActionListener(new ActionListener() {
  1284             public void actionPerformed(ActionEvent e) {
  1515             public void actionPerformed(ActionEvent e) {
  1285                 chooseResult.append('N');
  1516                 chooseResult.append('N');
  1286                 tw.setVisible(false);
  1517                 tw.setVisible(false);
  1287                 tw.dispose();
  1518                 tw.dispose();
  1293 
  1524 
  1294         addNewComponent(tw, panel, 1,
  1525         addNewComponent(tw, panel, 1,
  1295                 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1526                 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1296 
  1527 
  1297         tw.pack();
  1528         tw.pack();
       
  1529         tw.setLocationRelativeTo(w);
  1298         tw.setVisible(true);
  1530         tw.setVisible(true);
  1299         if (chooseResult.length() > 0) {
  1531         if (chooseResult.length() > 0) {
  1300             return chooseResult.charAt(0);
  1532             return chooseResult.charAt(0);
  1301         } else {
  1533         } else {
  1302             // I did encounter this once, don't why.
  1534             // I did encounter this once, don't why.
  1307 }
  1539 }
  1308 
  1540 
  1309 /**
  1541 /**
  1310  * General dialog window
  1542  * General dialog window
  1311  */
  1543  */
  1312 class ToolDialog extends Dialog {
  1544 class ToolDialog extends JDialog {
  1313     // use serialVersionUID from JDK 1.2.2 for interoperability
  1545     // use serialVersionUID from JDK 1.2.2 for interoperability
  1314     private static final long serialVersionUID = -372244357011301190L;
  1546     private static final long serialVersionUID = -372244357011301190L;
       
  1547 
       
  1548     /* ESCAPE key */
       
  1549     static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
  1315 
  1550 
  1316     /* necessary constants */
  1551     /* necessary constants */
  1317     public static final int NOACTION            = 0;
  1552     public static final int NOACTION            = 0;
  1318     public static final int QUIT                = 1;
  1553     public static final int QUIT                = 1;
  1319     public static final int NEW                 = 2;
  1554     public static final int NEW                 = 2;
  1327     public static final String X500_PRIN_CLASS         =
  1562     public static final String X500_PRIN_CLASS         =
  1328                 "javax.security.auth.x500.X500Principal";
  1563                 "javax.security.auth.x500.X500Principal";
  1329 
  1564 
  1330     /* popup menus */
  1565     /* popup menus */
  1331     public static final String PERM             =
  1566     public static final String PERM             =
  1332         PolicyTool.rb.getString
  1567         PolicyTool.getMessage
  1333         ("Permission.");
  1568         ("Permission.");
  1334 
  1569 
  1335     public static final String PRIN_TYPE        =
  1570     public static final String PRIN_TYPE        =
  1336         PolicyTool.rb.getString("Principal.Type.");
  1571         PolicyTool.getMessage("Principal.Type.");
  1337     public static final String PRIN_NAME        =
  1572     public static final String PRIN_NAME        =
  1338         PolicyTool.rb.getString("Principal.Name.");
  1573         PolicyTool.getMessage("Principal.Name.");
  1339 
  1574 
  1340     /* more popu menus */
  1575     /* more popu menus */
  1341     public static final String PERM_NAME        =
  1576     public static final String PERM_NAME        =
  1342         PolicyTool.rb.getString
  1577         PolicyTool.getMessage
  1343         ("Target.Name.");
  1578         ("Target.Name.");
  1344 
  1579 
  1345     /* and more popup menus */
  1580     /* and more popup menus */
  1346     public static final String PERM_ACTIONS             =
  1581     public static final String PERM_ACTIONS             =
  1347       PolicyTool.rb.getString
  1582       PolicyTool.getMessage
  1348       ("Actions.");
  1583       ("Actions.");
  1349 
  1584 
  1350     /* gridbag index for display PolicyEntry (PE) components */
  1585     /* gridbag index for display PolicyEntry (PE) components */
  1351     public static final int PE_CODEBASE_LABEL           = 0;
  1586     public static final int PE_CODEBASE_LABEL           = 0;
  1352     public static final int PE_CODEBASE_TEXTFIELD       = 1;
  1587     public static final int PE_CODEBASE_TEXTFIELD       = 1;
  1428     private static final int PERMISSION_NAME            = 1;
  1663     private static final int PERMISSION_NAME            = 1;
  1429     private static final int PERMISSION_ACTIONS         = 2;
  1664     private static final int PERMISSION_ACTIONS         = 2;
  1430     private static final int PERMISSION_SIGNEDBY        = 3;
  1665     private static final int PERMISSION_SIGNEDBY        = 3;
  1431     private static final int PRINCIPAL_TYPE             = 4;
  1666     private static final int PRINCIPAL_TYPE             = 4;
  1432     private static final int PRINCIPAL_NAME             = 5;
  1667     private static final int PRINCIPAL_NAME             = 5;
       
  1668 
       
  1669     /* The preferred height of JTextField should match JComboBox. */
       
  1670     static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;
  1433 
  1671 
  1434     public static java.util.ArrayList<Perm> PERM_ARRAY;
  1672     public static java.util.ArrayList<Perm> PERM_ARRAY;
  1435     public static java.util.ArrayList<Prin> PRIN_ARRAY;
  1673     public static java.util.ArrayList<Prin> PRIN_ARRAY;
  1436     PolicyTool tool;
  1674     PolicyTool tool;
  1437     ToolWindow tw;
  1675     ToolWindow tw;
  1478         super(tw, modal);
  1716         super(tw, modal);
  1479         setTitle(title);
  1717         setTitle(title);
  1480         this.tool = tool;
  1718         this.tool = tool;
  1481         this.tw = tw;
  1719         this.tw = tw;
  1482         addWindowListener(new ChildWindowListener(this));
  1720         addWindowListener(new ChildWindowListener(this));
       
  1721 
       
  1722         // Create some space around components
       
  1723         ((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));
       
  1724     }
       
  1725 
       
  1726     /**
       
  1727      * Don't call getComponent directly on the window
       
  1728      */
       
  1729     public Component getComponent(int n) {
       
  1730         Component c = getContentPane().getComponent(n);
       
  1731         if (c instanceof JScrollPane) {
       
  1732             c = ((JScrollPane)c).getViewport().getView();
       
  1733         }
       
  1734         return c;
  1483     }
  1735     }
  1484 
  1736 
  1485     /**
  1737     /**
  1486      * get the Perm instance based on either the (shortened) class name
  1738      * get the Perm instance based on either the (shortened) class name
  1487      * or the fully qualified class name
  1739      * or the fully qualified class name
  1538 
  1790 
  1539         int listIndex = 0;
  1791         int listIndex = 0;
  1540         PolicyEntry entries[] = null;
  1792         PolicyEntry entries[] = null;
  1541         TaggedList prinList = new TaggedList(3, false);
  1793         TaggedList prinList = new TaggedList(3, false);
  1542         prinList.getAccessibleContext().setAccessibleName(
  1794         prinList.getAccessibleContext().setAccessibleName(
  1543                 PolicyTool.rb.getString("Principal.List"));
  1795                 PolicyTool.getMessage("Principal.List"));
  1544         prinList.addActionListener
  1796         prinList.addMouseListener
  1545                 (new EditPrinButtonListener(tool, tw, this, edit));
  1797                 (new EditPrinButtonListener(tool, tw, this, edit));
  1546         TaggedList permList = new TaggedList(10, false);
  1798         TaggedList permList = new TaggedList(10, false);
  1547         permList.getAccessibleContext().setAccessibleName(
  1799         permList.getAccessibleContext().setAccessibleName(
  1548                 PolicyTool.rb.getString("Permission.List"));
  1800                 PolicyTool.getMessage("Permission.List"));
  1549         permList.addActionListener
  1801         permList.addMouseListener
  1550                 (new EditPermButtonListener(tool, tw, this, edit));
  1802                 (new EditPermButtonListener(tool, tw, this, edit));
  1551 
  1803 
  1552         // find where the PolicyTool gui is
  1804         // find where the PolicyTool gui is
  1553         Point location = tw.getLocationOnScreen();
  1805         Point location = tw.getLocationOnScreen();
  1554         setBounds(location.x + 75, location.y + 200, 650, 500);
  1806         //setBounds(location.x + 75, location.y + 200, 650, 500);
  1555         setLayout(new GridBagLayout());
  1807         setLayout(new GridBagLayout());
  1556         setResizable(true);
  1808         setResizable(true);
  1557 
  1809 
  1558         if (edit) {
  1810         if (edit) {
  1559             // get the selected item
  1811             // get the selected item
  1560             entries = tool.getEntry();
  1812             entries = tool.getEntry();
  1561             List policyList = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  1813             JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  1562             listIndex = policyList.getSelectedIndex();
  1814             listIndex = policyList.getSelectedIndex();
  1563 
  1815 
  1564             // get principal list
  1816             // get principal list
  1565             LinkedList<PolicyParser.PrincipalEntry> principals =
  1817             LinkedList<PolicyParser.PrincipalEntry> principals =
  1566                 entries[listIndex].getGrantEntry().principals;
  1818                 entries[listIndex].getGrantEntry().principals;
  1580                 permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm);
  1832                 permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm);
  1581             }
  1833             }
  1582         }
  1834         }
  1583 
  1835 
  1584         // codebase label and textfield
  1836         // codebase label and textfield
  1585         Label label = new Label(PolicyTool.rb.getString("CodeBase."));
  1837         JLabel label = new JLabel();
  1586         tw.addNewComponent(this, label, PE_CODEBASE_LABEL,
  1838         tw.addNewComponent(this, label, PE_CODEBASE_LABEL,
  1587                 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1839                 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1588         TextField tf;
  1840                 ToolWindow.R_PADDING);
       
  1841         JTextField tf;
  1589         tf = (edit ?
  1842         tf = (edit ?
  1590                 new TextField(entries[listIndex].getGrantEntry().codeBase, 60) :
  1843                 new JTextField(entries[listIndex].getGrantEntry().codeBase) :
  1591                 new TextField(60));
  1844                 new JTextField());
       
  1845         ToolWindow.configureLabelFor(label, tf, "CodeBase.");
       
  1846         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  1592         tf.getAccessibleContext().setAccessibleName(
  1847         tf.getAccessibleContext().setAccessibleName(
  1593                 PolicyTool.rb.getString("Code.Base"));
  1848                 PolicyTool.getMessage("Code.Base"));
  1594         tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD,
  1849         tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD,
  1595                 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1850                 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);
  1596 
  1851 
  1597         // signedby label and textfield
  1852         // signedby label and textfield
  1598         label = new Label(PolicyTool.rb.getString("SignedBy."));
  1853         label = new JLabel();
  1599         tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL,
  1854         tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL,
  1600                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1855                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1856                            ToolWindow.R_PADDING);
  1601         tf = (edit ?
  1857         tf = (edit ?
  1602                 new TextField(entries[listIndex].getGrantEntry().signedBy, 60) :
  1858                 new JTextField(entries[listIndex].getGrantEntry().signedBy) :
  1603                 new TextField(60));
  1859                 new JTextField());
       
  1860         ToolWindow.configureLabelFor(label, tf, "SignedBy.");
       
  1861         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  1604         tf.getAccessibleContext().setAccessibleName(
  1862         tf.getAccessibleContext().setAccessibleName(
  1605                 PolicyTool.rb.getString("Signed.By."));
  1863                 PolicyTool.getMessage("Signed.By."));
  1606         tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD,
  1864         tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD,
  1607                            1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  1865                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);
  1608 
  1866 
  1609         // panel for principal buttons
  1867         // panel for principal buttons
  1610         Panel panel = new Panel();
  1868         JPanel panel = new JPanel();
  1611         panel.setLayout(new GridBagLayout());
  1869         panel.setLayout(new GridBagLayout());
  1612 
  1870 
  1613         Button button = new Button(PolicyTool.rb.getString("Add.Principal"));
  1871         JButton button = new JButton();
       
  1872         ToolWindow.configureButton(button, "Add.Principal");
  1614         button.addActionListener
  1873         button.addActionListener
  1615                 (new AddPrinButtonListener(tool, tw, this, edit));
  1874                 (new AddPrinButtonListener(tool, tw, this, edit));
  1616         tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON,
  1875         tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON,
  1617                 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1876                 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1618 
  1877 
  1619         button = new Button(PolicyTool.rb.getString("Edit.Principal"));
  1878         button = new JButton();
       
  1879         ToolWindow.configureButton(button, "Edit.Principal");
  1620         button.addActionListener(new EditPrinButtonListener
  1880         button.addActionListener(new EditPrinButtonListener
  1621                                                 (tool, tw, this, edit));
  1881                                                 (tool, tw, this, edit));
  1622         tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON,
  1882         tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON,
  1623                 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1883                 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1624 
  1884 
  1625         button = new Button(PolicyTool.rb.getString("Remove.Principal"));
  1885         button = new JButton();
       
  1886         ToolWindow.configureButton(button, "Remove.Principal");
  1626         button.addActionListener(new RemovePrinButtonListener
  1887         button.addActionListener(new RemovePrinButtonListener
  1627                                         (tool, tw, this, edit));
  1888                                         (tool, tw, this, edit));
  1628         tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON,
  1889         tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON,
  1629                 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1890                 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1630 
  1891 
  1631         tw.addNewComponent(this, panel, PE_PANEL0,
  1892         tw.addNewComponent(this, panel, PE_PANEL0,
  1632                 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL);
  1893                 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,
       
  1894                            ToolWindow.LITE_BOTTOM_PADDING);
  1633 
  1895 
  1634         // principal label and list
  1896         // principal label and list
  1635         label = new Label(PolicyTool.rb.getString("Principals."));
  1897         label = new JLabel();
  1636         tw.addNewComponent(this, label, PE_PRIN_LABEL,
  1898         tw.addNewComponent(this, label, PE_PRIN_LABEL,
  1637                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1899                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1900                            ToolWindow.R_BOTTOM_PADDING);
       
  1901         JScrollPane scrollPane = new JScrollPane(prinList);
       
  1902         ToolWindow.configureLabelFor(label, scrollPane, "Principals.");
       
  1903         tw.addNewComponent(this, scrollPane, PE_PRIN_LIST,
       
  1904                            1, 3, 3, 1, 0.0, prinList.getVisibleRowCount(), GridBagConstraints.BOTH,
  1638                            ToolWindow.BOTTOM_PADDING);
  1905                            ToolWindow.BOTTOM_PADDING);
  1639         tw.addNewComponent(this, prinList, PE_PRIN_LIST,
       
  1640                            1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1641                            ToolWindow.BOTTOM_PADDING);
       
  1642 
  1906 
  1643         // panel for permission buttons
  1907         // panel for permission buttons
  1644         panel = new Panel();
  1908         panel = new JPanel();
  1645         panel.setLayout(new GridBagLayout());
  1909         panel.setLayout(new GridBagLayout());
  1646 
  1910 
  1647         button = new Button(PolicyTool.rb.getString(".Add.Permission"));
  1911         button = new JButton();
       
  1912         ToolWindow.configureButton(button, ".Add.Permission");
  1648         button.addActionListener(new AddPermButtonListener
  1913         button.addActionListener(new AddPermButtonListener
  1649                                                 (tool, tw, this, edit));
  1914                                                 (tool, tw, this, edit));
  1650         tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON,
  1915         tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON,
  1651                 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1916                 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1652 
  1917 
  1653         button = new Button(PolicyTool.rb.getString(".Edit.Permission"));
  1918         button = new JButton();
       
  1919         ToolWindow.configureButton(button, ".Edit.Permission");
  1654         button.addActionListener(new EditPermButtonListener
  1920         button.addActionListener(new EditPermButtonListener
  1655                                                 (tool, tw, this, edit));
  1921                                                 (tool, tw, this, edit));
  1656         tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON,
  1922         tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON,
  1657                 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1923                 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1658 
  1924 
  1659 
  1925 
  1660         button = new Button(PolicyTool.rb.getString("Remove.Permission"));
  1926         button = new JButton();
       
  1927         ToolWindow.configureButton(button, "Remove.Permission");
  1661         button.addActionListener(new RemovePermButtonListener
  1928         button.addActionListener(new RemovePermButtonListener
  1662                                         (tool, tw, this, edit));
  1929                                         (tool, tw, this, edit));
  1663         tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON,
  1930         tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON,
  1664                 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1931                 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
  1665 
  1932 
  1666         tw.addNewComponent(this, panel, PE_PANEL1,
  1933         tw.addNewComponent(this, panel, PE_PANEL1,
  1667                 0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,
  1934                 0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,
  1668                 ToolWindow.LITE_BOTTOM_PADDING);
  1935                 ToolWindow.LITE_BOTTOM_PADDING);
  1669 
  1936 
  1670         // permission list
  1937         // permission list
  1671         tw.addNewComponent(this, permList, PE_PERM_LIST,
  1938         scrollPane = new JScrollPane(permList);
  1672                            0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1939         tw.addNewComponent(this, scrollPane, PE_PERM_LIST,
       
  1940                            0, 5, 3, 1, 0.0, permList.getVisibleRowCount(), GridBagConstraints.BOTH,
  1673                            ToolWindow.BOTTOM_PADDING);
  1941                            ToolWindow.BOTTOM_PADDING);
  1674 
  1942 
  1675 
  1943 
  1676         // panel for Done and Cancel buttons
  1944         // panel for Done and Cancel buttons
  1677         panel = new Panel();
  1945         panel = new JPanel();
  1678         panel.setLayout(new GridBagLayout());
  1946         panel.setLayout(new GridBagLayout());
  1679 
  1947 
  1680         // Done Button
  1948         // Done Button
  1681         button = new Button(PolicyTool.rb.getString("Done"));
  1949         JButton okButton = new JButton(PolicyTool.getMessage("Done"));
  1682         button.addActionListener
  1950         okButton.addActionListener
  1683                 (new AddEntryDoneButtonListener(tool, tw, this, edit));
  1951                 (new AddEntryDoneButtonListener(tool, tw, this, edit));
  1684         tw.addNewComponent(panel, button, PE_DONE_BUTTON,
  1952         tw.addNewComponent(panel, okButton, PE_DONE_BUTTON,
  1685                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1953                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1686                            ToolWindow.LR_PADDING);
  1954                            ToolWindow.LR_PADDING);
  1687 
  1955 
  1688         // Cancel Button
  1956         // Cancel Button
  1689         button = new Button(PolicyTool.rb.getString("Cancel"));
  1957         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
  1690         button.addActionListener(new CancelButtonListener(this));
  1958         ActionListener cancelListener = new CancelButtonListener(this);
  1691         tw.addNewComponent(panel, button, PE_CANCEL_BUTTON,
  1959         cancelButton.addActionListener(cancelListener);
       
  1960         tw.addNewComponent(panel, cancelButton, PE_CANCEL_BUTTON,
  1692                            1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1961                            1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1693                            ToolWindow.LR_PADDING);
  1962                            ToolWindow.LR_PADDING);
  1694 
  1963 
  1695         // add the panel
  1964         // add the panel
  1696         tw.addNewComponent(this, panel, PE_PANEL2,
  1965         tw.addNewComponent(this, panel, PE_PANEL2,
  1697                 0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1966                 0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1698 
  1967 
       
  1968         getRootPane().setDefaultButton(okButton);
       
  1969         getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1970 
       
  1971         pack();
       
  1972         setLocationRelativeTo(tw);
  1699         setVisible(true);
  1973         setVisible(true);
  1700     }
  1974     }
  1701 
  1975 
  1702     /**
  1976     /**
  1703      * Read all the Policy information data in the dialog box
  1977      * Read all the Policy information data in the dialog box
  1708         NoSuchMethodException, ClassNotFoundException, InstantiationException,
  1982         NoSuchMethodException, ClassNotFoundException, InstantiationException,
  1709         IllegalAccessException, InvocationTargetException,
  1983         IllegalAccessException, InvocationTargetException,
  1710         CertificateException, IOException, Exception {
  1984         CertificateException, IOException, Exception {
  1711 
  1985 
  1712         // get the Codebase
  1986         // get the Codebase
  1713         TextField tf = (TextField)getComponent(PE_CODEBASE_TEXTFIELD);
  1987         JTextField tf = (JTextField)getComponent(PE_CODEBASE_TEXTFIELD);
  1714         String codebase = null;
  1988         String codebase = null;
  1715         if (tf.getText().trim().equals("") == false)
  1989         if (tf.getText().trim().equals("") == false)
  1716                 codebase = new String(tf.getText().trim());
  1990                 codebase = new String(tf.getText().trim());
  1717 
  1991 
  1718         // get the SignedBy
  1992         // get the SignedBy
  1719         tf = (TextField)getComponent(PE_SIGNEDBY_TEXTFIELD);
  1993         tf = (JTextField)getComponent(PE_SIGNEDBY_TEXTFIELD);
  1720         String signedby = null;
  1994         String signedby = null;
  1721         if (tf.getText().trim().equals("") == false)
  1995         if (tf.getText().trim().equals("") == false)
  1722                 signedby = new String(tf.getText().trim());
  1996                 signedby = new String(tf.getText().trim());
  1723 
  1997 
  1724         // construct a new GrantEntry
  1998         // construct a new GrantEntry
  1726                         new PolicyParser.GrantEntry(signedby, codebase);
  2000                         new PolicyParser.GrantEntry(signedby, codebase);
  1727 
  2001 
  1728         // get the new Principals
  2002         // get the new Principals
  1729         LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>();
  2003         LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>();
  1730         TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);
  2004         TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);
  1731         for (int i = 0; i < prinList.getItemCount(); i++) {
  2005         for (int i = 0; i < prinList.getModel().getSize(); i++) {
  1732             prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i));
  2006             prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i));
  1733         }
  2007         }
  1734         ge.principals = prins;
  2008         ge.principals = prins;
  1735 
  2009 
  1736         // get the new Permissions
  2010         // get the new Permissions
  1737         Vector<PolicyParser.PermissionEntry> perms = new Vector<>();
  2011         Vector<PolicyParser.PermissionEntry> perms = new Vector<>();
  1738         TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);
  2012         TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);
  1739         for (int i = 0; i < permList.getItemCount(); i++) {
  2013         for (int i = 0; i < permList.getModel().getSize(); i++) {
  1740             perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i));
  2014             perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i));
  1741         }
  2015         }
  1742         ge.permissionEntries = perms;
  2016         ge.permissionEntries = perms;
  1743 
  2017 
  1744         // construct a new PolicyEntry object
  2018         // construct a new PolicyEntry object
  1752      */
  2026      */
  1753     void keyStoreDialog(int mode) {
  2027     void keyStoreDialog(int mode) {
  1754 
  2028 
  1755         // find where the PolicyTool gui is
  2029         // find where the PolicyTool gui is
  1756         Point location = tw.getLocationOnScreen();
  2030         Point location = tw.getLocationOnScreen();
  1757         setBounds(location.x + 25, location.y + 100, 500, 300);
  2031         //setBounds(location.x + 25, location.y + 100, 500, 300);
  1758         setLayout(new GridBagLayout());
  2032         setLayout(new GridBagLayout());
  1759 
  2033 
  1760         if (mode == EDIT_KEYSTORE) {
  2034         if (mode == EDIT_KEYSTORE) {
  1761 
  2035 
  1762             // KeyStore label and textfield
  2036             // KeyStore label and textfield
  1763             Label label = new Label
  2037             JLabel label = new JLabel();
  1764                         (PolicyTool.rb.getString("KeyStore.URL."));
       
  1765             tw.addNewComponent(this, label, KSD_NAME_LABEL,
  2038             tw.addNewComponent(this, label, KSD_NAME_LABEL,
  1766                                0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2039                                0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1767                                ToolWindow.BOTTOM_PADDING);
  2040                                ToolWindow.R_BOTTOM_PADDING);
  1768             TextField tf = new TextField(tool.getKeyStoreName(), 30);
  2041             JTextField tf = new JTextField(tool.getKeyStoreName(), 30);
       
  2042             ToolWindow.configureLabelFor(label, tf, "KeyStore.URL.");
       
  2043             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  1769 
  2044 
  1770             // URL to U R L, so that accessibility reader will pronounce well
  2045             // URL to U R L, so that accessibility reader will pronounce well
  1771             tf.getAccessibleContext().setAccessibleName(
  2046             tf.getAccessibleContext().setAccessibleName(
  1772                 PolicyTool.rb.getString("KeyStore.U.R.L."));
  2047                 PolicyTool.getMessage("KeyStore.U.R.L."));
  1773             tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD,
  2048             tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD,
  1774                                1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2049                                1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  1775                                ToolWindow.BOTTOM_PADDING);
  2050                                ToolWindow.BOTTOM_PADDING);
  1776 
  2051 
  1777             // KeyStore type and textfield
  2052             // KeyStore type and textfield
  1778             label = new Label(PolicyTool.rb.getString("KeyStore.Type."));
  2053             label = new JLabel();
  1779             tw.addNewComponent(this, label, KSD_TYPE_LABEL,
  2054             tw.addNewComponent(this, label, KSD_TYPE_LABEL,
  1780                                0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2055                                0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2056                                ToolWindow.R_BOTTOM_PADDING);
       
  2057             tf = new JTextField(tool.getKeyStoreType(), 30);
       
  2058             ToolWindow.configureLabelFor(label, tf, "KeyStore.Type.");
       
  2059             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2060             tf.getAccessibleContext().setAccessibleName(
       
  2061                 PolicyTool.getMessage("KeyStore.Type."));
       
  2062             tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD,
       
  2063                                1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  1781                                ToolWindow.BOTTOM_PADDING);
  2064                                ToolWindow.BOTTOM_PADDING);
  1782             tf = new TextField(tool.getKeyStoreType(), 30);
       
  1783             tf.getAccessibleContext().setAccessibleName(
       
  1784                 PolicyTool.rb.getString("KeyStore.Type."));
       
  1785             tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD,
       
  1786                                1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1787                                ToolWindow.BOTTOM_PADDING);
       
  1788 
  2065 
  1789             // KeyStore provider and textfield
  2066             // KeyStore provider and textfield
  1790             label = new Label(PolicyTool.rb.getString
  2067             label = new JLabel();
  1791                                 ("KeyStore.Provider."));
       
  1792             tw.addNewComponent(this, label, KSD_PROVIDER_LABEL,
  2068             tw.addNewComponent(this, label, KSD_PROVIDER_LABEL,
  1793                                0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2069                                0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2070                                ToolWindow.R_BOTTOM_PADDING);
       
  2071             tf = new JTextField(tool.getKeyStoreProvider(), 30);
       
  2072             ToolWindow.configureLabelFor(label, tf, "KeyStore.Provider.");
       
  2073             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2074             tf.getAccessibleContext().setAccessibleName(
       
  2075                 PolicyTool.getMessage("KeyStore.Provider."));
       
  2076             tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD,
       
  2077                                1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  1794                                ToolWindow.BOTTOM_PADDING);
  2078                                ToolWindow.BOTTOM_PADDING);
  1795             tf = new TextField(tool.getKeyStoreProvider(), 30);
       
  1796             tf.getAccessibleContext().setAccessibleName(
       
  1797                 PolicyTool.rb.getString("KeyStore.Provider."));
       
  1798             tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD,
       
  1799                                1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1800                                ToolWindow.BOTTOM_PADDING);
       
  1801 
  2079 
  1802             // KeyStore password URL and textfield
  2080             // KeyStore password URL and textfield
  1803             label = new Label(PolicyTool.rb.getString
  2081             label = new JLabel();
  1804                                 ("KeyStore.Password.URL."));
       
  1805             tw.addNewComponent(this, label, KSD_PWD_URL_LABEL,
  2082             tw.addNewComponent(this, label, KSD_PWD_URL_LABEL,
  1806                                0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2083                                0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2084                                ToolWindow.R_BOTTOM_PADDING);
       
  2085             tf = new JTextField(tool.getKeyStorePwdURL(), 30);
       
  2086             ToolWindow.configureLabelFor(label, tf, "KeyStore.Password.URL.");
       
  2087             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2088             tf.getAccessibleContext().setAccessibleName(
       
  2089                 PolicyTool.getMessage("KeyStore.Password.U.R.L."));
       
  2090             tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD,
       
  2091                                1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  1807                                ToolWindow.BOTTOM_PADDING);
  2092                                ToolWindow.BOTTOM_PADDING);
  1808             tf = new TextField(tool.getKeyStorePwdURL(), 30);
       
  1809             tf.getAccessibleContext().setAccessibleName(
       
  1810                 PolicyTool.rb.getString("KeyStore.Password.U.R.L."));
       
  1811             tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD,
       
  1812                                1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1813                                ToolWindow.BOTTOM_PADDING);
       
  1814 
  2093 
  1815             // OK button
  2094             // OK button
  1816             Button okButton = new Button(PolicyTool.rb.getString("OK"));
  2095             JButton okButton = new JButton(PolicyTool.getMessage("OK"));
  1817             okButton.addActionListener
  2096             okButton.addActionListener
  1818                         (new ChangeKeyStoreOKButtonListener(tool, tw, this));
  2097                         (new ChangeKeyStoreOKButtonListener(tool, tw, this));
  1819             tw.addNewComponent(this, okButton, KSD_OK_BUTTON,
  2098             tw.addNewComponent(this, okButton, KSD_OK_BUTTON,
  1820                         0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  2099                         0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1821 
  2100 
  1822             // cancel button
  2101             // cancel button
  1823             Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
  2102             JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
  1824             cancelButton.addActionListener(new CancelButtonListener(this));
  2103             ActionListener cancelListener = new CancelButtonListener(this);
       
  2104             cancelButton.addActionListener(cancelListener);
  1825             tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON,
  2105             tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON,
  1826                         1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  2106                         1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
  1827 
  2107 
  1828         }
  2108             getRootPane().setDefaultButton(okButton);
       
  2109             getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2110         }
       
  2111 
       
  2112         pack();
       
  2113         setLocationRelativeTo(tw);
  1829         setVisible(true);
  2114         setVisible(true);
  1830     }
  2115     }
  1831 
  2116 
  1832     /**
  2117     /**
  1833      * display a dialog box for the user to input Principal info
  2118      * display a dialog box for the user to input Principal info
  1849         if (edit) {
  2134         if (edit) {
  1850             editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex);
  2135             editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex);
  1851         }
  2136         }
  1852 
  2137 
  1853         ToolDialog newTD = new ToolDialog
  2138         ToolDialog newTD = new ToolDialog
  1854                 (PolicyTool.rb.getString("Principals"), tool, tw, true);
  2139                 (PolicyTool.getMessage("Principals"), tool, tw, true);
  1855         newTD.addWindowListener(new ChildWindowListener(newTD));
  2140         newTD.addWindowListener(new ChildWindowListener(newTD));
  1856 
  2141 
  1857         // find where the PolicyTool gui is
  2142         // find where the PolicyTool gui is
  1858         Point location = getLocationOnScreen();
  2143         Point location = getLocationOnScreen();
  1859         newTD.setBounds(location.x + 50, location.y + 100, 650, 190);
  2144         //newTD.setBounds(location.x + 50, location.y + 100, 650, 190);
  1860         newTD.setLayout(new GridBagLayout());
  2145         newTD.setLayout(new GridBagLayout());
  1861         newTD.setResizable(true);
  2146         newTD.setResizable(true);
  1862 
  2147 
  1863         // description label
  2148         // description label
  1864         Label label = (edit ?
  2149         JLabel label = (edit ?
  1865                 new Label(PolicyTool.rb.getString(".Edit.Principal.")) :
  2150                 new JLabel(PolicyTool.getMessage(".Edit.Principal.")) :
  1866                 new Label(PolicyTool.rb.getString(".Add.New.Principal.")));
  2151                 new JLabel(PolicyTool.getMessage(".Add.New.Principal.")));
  1867         tw.addNewComponent(newTD, label, PRD_DESC_LABEL,
  2152         tw.addNewComponent(newTD, label, PRD_DESC_LABEL,
  1868                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2153                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1869                            ToolWindow.TOP_BOTTOM_PADDING);
  2154                            ToolWindow.TOP_BOTTOM_PADDING);
  1870 
  2155 
  1871         // principal choice
  2156         // principal choice
  1872         Choice choice = new Choice();
  2157         JComboBox choice = new JComboBox();
  1873         choice.add(PRIN_TYPE);
  2158         choice.addItem(PRIN_TYPE);
  1874         choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
  2159         choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
  1875         for (int i = 0; i < PRIN_ARRAY.size(); i++) {
  2160         for (int i = 0; i < PRIN_ARRAY.size(); i++) {
  1876             Prin next = PRIN_ARRAY.get(i);
  2161             Prin next = PRIN_ARRAY.get(i);
  1877             choice.add(next.CLASS);
  2162             choice.addItem(next.CLASS);
  1878         }
  2163         }
  1879 
  2164 
  1880         choice.addItemListener(new PrincipalTypeMenuListener(newTD));
       
  1881         if (edit) {
  2165         if (edit) {
  1882             if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals
  2166             if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals
  1883                                 (editMe.getPrincipalClass())) {
  2167                                 (editMe.getPrincipalClass())) {
  1884                 choice.select(PRIN_TYPE);
  2168                 choice.setSelectedItem(PRIN_TYPE);
  1885             } else {
  2169             } else {
  1886                 Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);
  2170                 Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);
  1887                 if (inputPrin != null) {
  2171                 if (inputPrin != null) {
  1888                     choice.select(inputPrin.CLASS);
  2172                     choice.setSelectedItem(inputPrin.CLASS);
  1889                 }
  2173                 }
  1890             }
  2174             }
  1891         }
  2175         }
       
  2176         // Add listener after selected item is set
       
  2177         choice.addItemListener(new PrincipalTypeMenuListener(newTD));
  1892 
  2178 
  1893         tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE,
  2179         tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE,
  1894                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2180                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1895                            ToolWindow.LR_PADDING);
  2181                            ToolWindow.LR_PADDING);
  1896 
  2182 
  1897         // principal textfield
  2183         // principal textfield
  1898         TextField tf;
  2184         JTextField tf;
  1899         tf = (edit ?
  2185         tf = (edit ?
  1900                 new TextField(editMe.getDisplayClass(), 30) :
  2186                 new JTextField(editMe.getDisplayClass(), 30) :
  1901                 new TextField(30));
  2187                 new JTextField(30));
       
  2188         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  1902         tf.getAccessibleContext().setAccessibleName(PRIN_TYPE);
  2189         tf.getAccessibleContext().setAccessibleName(PRIN_TYPE);
  1903         tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD,
  2190         tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD,
  1904                            1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2191                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  1905                            ToolWindow.LR_PADDING);
  2192                            ToolWindow.LR_PADDING);
  1906 
  2193 
  1907         // name label and textfield
  2194         // name label and textfield
  1908         label = new Label(PRIN_NAME);
  2195         label = new JLabel(PRIN_NAME);
  1909         tf = (edit ?
  2196         tf = (edit ?
  1910                 new TextField(editMe.getDisplayName(), 40) :
  2197                 new JTextField(editMe.getDisplayName(), 40) :
  1911                 new TextField(40));
  2198                 new JTextField(40));
       
  2199         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  1912         tf.getAccessibleContext().setAccessibleName(PRIN_NAME);
  2200         tf.getAccessibleContext().setAccessibleName(PRIN_NAME);
  1913 
  2201 
  1914         tw.addNewComponent(newTD, label, PRD_NAME_LABEL,
  2202         tw.addNewComponent(newTD, label, PRD_NAME_LABEL,
  1915                            0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2203                            0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1916                            ToolWindow.LR_PADDING);
  2204                            ToolWindow.LR_PADDING);
  1917         tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD,
  2205         tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD,
  1918                            1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2206                            1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  1919                            ToolWindow.LR_PADDING);
  2207                            ToolWindow.LR_PADDING);
  1920 
  2208 
  1921         // OK button
  2209         // OK button
  1922         Button okButton = new Button(PolicyTool.rb.getString("OK"));
  2210         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
  1923         okButton.addActionListener(
  2211         okButton.addActionListener(
  1924             new NewPolicyPrinOKButtonListener
  2212             new NewPolicyPrinOKButtonListener
  1925                                         (tool, tw, this, newTD, edit));
  2213                                         (tool, tw, this, newTD, edit));
  1926         tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON,
  2214         tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON,
  1927                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  2215                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1928                            ToolWindow.TOP_BOTTOM_PADDING);
  2216                            ToolWindow.TOP_BOTTOM_PADDING);
  1929         // cancel button
  2217         // cancel button
  1930         Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
  2218         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
  1931         cancelButton.addActionListener(new CancelButtonListener(newTD));
  2219         ActionListener cancelListener = new CancelButtonListener(newTD);
       
  2220         cancelButton.addActionListener(cancelListener);
  1932         tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON,
  2221         tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON,
  1933                            1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  2222                            1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  1934                            ToolWindow.TOP_BOTTOM_PADDING);
  2223                            ToolWindow.TOP_BOTTOM_PADDING);
  1935 
  2224 
       
  2225         newTD.getRootPane().setDefaultButton(okButton);
       
  2226         newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2227 
       
  2228         newTD.pack();
       
  2229         newTD.setLocationRelativeTo(tw);
  1936         newTD.setVisible(true);
  2230         newTD.setVisible(true);
  1937     }
  2231     }
  1938 
  2232 
  1939     /**
  2233     /**
  1940      * display a dialog box for the user to input Permission info
  2234      * display a dialog box for the user to input Permission info
  1956         if (edit) {
  2250         if (edit) {
  1957             editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex);
  2251             editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex);
  1958         }
  2252         }
  1959 
  2253 
  1960         ToolDialog newTD = new ToolDialog
  2254         ToolDialog newTD = new ToolDialog
  1961                 (PolicyTool.rb.getString("Permissions"), tool, tw, true);
  2255                 (PolicyTool.getMessage("Permissions"), tool, tw, true);
  1962         newTD.addWindowListener(new ChildWindowListener(newTD));
  2256         newTD.addWindowListener(new ChildWindowListener(newTD));
  1963 
  2257 
  1964         // find where the PolicyTool gui is
  2258         // find where the PolicyTool gui is
  1965         Point location = getLocationOnScreen();
  2259         Point location = getLocationOnScreen();
  1966         newTD.setBounds(location.x + 50, location.y + 100, 700, 250);
  2260         //newTD.setBounds(location.x + 50, location.y + 100, 700, 250);
  1967         newTD.setLayout(new GridBagLayout());
  2261         newTD.setLayout(new GridBagLayout());
  1968         newTD.setResizable(true);
  2262         newTD.setResizable(true);
  1969 
  2263 
  1970         // description label
  2264         // description label
  1971         Label label = (edit ?
  2265         JLabel label = (edit ?
  1972                 new Label(PolicyTool.rb.getString(".Edit.Permission.")) :
  2266                 new JLabel(PolicyTool.getMessage(".Edit.Permission.")) :
  1973                 new Label(PolicyTool.rb.getString(".Add.New.Permission.")));
  2267                 new JLabel(PolicyTool.getMessage(".Add.New.Permission.")));
  1974         tw.addNewComponent(newTD, label, PD_DESC_LABEL,
  2268         tw.addNewComponent(newTD, label, PD_DESC_LABEL,
  1975                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2269                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1976                            ToolWindow.TOP_BOTTOM_PADDING);
  2270                            ToolWindow.TOP_BOTTOM_PADDING);
  1977 
  2271 
  1978         // permission choice (added in alphabetical order)
  2272         // permission choice (added in alphabetical order)
  1979         Choice choice = new Choice();
  2273         JComboBox choice = new JComboBox();
  1980         choice.add(PERM);
  2274         choice.addItem(PERM);
  1981         choice.getAccessibleContext().setAccessibleName(PERM);
  2275         choice.getAccessibleContext().setAccessibleName(PERM);
  1982         for (int i = 0; i < PERM_ARRAY.size(); i++) {
  2276         for (int i = 0; i < PERM_ARRAY.size(); i++) {
  1983             Perm next = PERM_ARRAY.get(i);
  2277             Perm next = PERM_ARRAY.get(i);
  1984             choice.add(next.CLASS);
  2278             choice.addItem(next.CLASS);
  1985         }
  2279         }
  1986         choice.addItemListener(new PermissionMenuListener(newTD));
       
  1987         tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,
  2280         tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,
  1988                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2281                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  1989                            ToolWindow.LR_PADDING);
  2282                            ToolWindow.LR_BOTTOM_PADDING);
  1990 
  2283 
  1991         // permission textfield
  2284         // permission textfield
  1992         TextField tf;
  2285         JTextField tf;
  1993         tf = (edit ? new TextField(editMe.permission, 30) : new TextField(30));
  2286         tf = (edit ? new JTextField(editMe.permission, 30) : new JTextField(30));
       
  2287         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  1994         tf.getAccessibleContext().setAccessibleName(PERM);
  2288         tf.getAccessibleContext().setAccessibleName(PERM);
  1995         if (edit) {
  2289         if (edit) {
  1996             Perm inputPerm = getPerm(editMe.permission, true);
  2290             Perm inputPerm = getPerm(editMe.permission, true);
  1997             if (inputPerm != null) {
  2291             if (inputPerm != null) {
  1998                 choice.select(inputPerm.CLASS);
  2292                 choice.setSelectedItem(inputPerm.CLASS);
  1999             }
  2293             }
  2000         }
  2294         }
  2001         tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,
  2295         tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,
  2002                            1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2296                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2003                            ToolWindow.LR_PADDING);
  2297                            ToolWindow.LR_BOTTOM_PADDING);
       
  2298         choice.addItemListener(new PermissionMenuListener(newTD));
  2004 
  2299 
  2005         // name label and textfield
  2300         // name label and textfield
  2006         choice = new Choice();
  2301         choice = new JComboBox();
  2007         choice.add(PERM_NAME);
  2302         choice.addItem(PERM_NAME);
  2008         choice.getAccessibleContext().setAccessibleName(PERM_NAME);
  2303         choice.getAccessibleContext().setAccessibleName(PERM_NAME);
  2009         choice.addItemListener(new PermissionNameMenuListener(newTD));
  2304         tf = (edit ? new JTextField(editMe.name, 40) : new JTextField(40));
  2010         tf = (edit ? new TextField(editMe.name, 40) : new TextField(40));
  2305         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  2011         tf.getAccessibleContext().setAccessibleName(PERM_NAME);
  2306         tf.getAccessibleContext().setAccessibleName(PERM_NAME);
  2012         if (edit) {
  2307         if (edit) {
  2013             setPermissionNames(getPerm(editMe.permission, true), choice, tf);
  2308             setPermissionNames(getPerm(editMe.permission, true), choice, tf);
  2014         }
  2309         }
  2015         tw.addNewComponent(newTD, choice, PD_NAME_CHOICE,
  2310         tw.addNewComponent(newTD, choice, PD_NAME_CHOICE,
  2016                            0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2311                            0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2017                            ToolWindow.LR_PADDING);
  2312                            ToolWindow.LR_BOTTOM_PADDING);
  2018         tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD,
  2313         tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD,
  2019                            1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2314                            1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2020                            ToolWindow.LR_PADDING);
  2315                            ToolWindow.LR_BOTTOM_PADDING);
       
  2316         choice.addItemListener(new PermissionNameMenuListener(newTD));
  2021 
  2317 
  2022         // actions label and textfield
  2318         // actions label and textfield
  2023         choice = new Choice();
  2319         choice = new JComboBox();
  2024         choice.add(PERM_ACTIONS);
  2320         choice.addItem(PERM_ACTIONS);
  2025         choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2321         choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2026         choice.addItemListener(new PermissionActionsMenuListener(newTD));
  2322         tf = (edit ? new JTextField(editMe.action, 40) : new JTextField(40));
  2027         tf = (edit ? new TextField(editMe.action, 40) : new TextField(40));
  2323         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  2028         tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2324         tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
  2029         if (edit) {
  2325         if (edit) {
  2030             setPermissionActions(getPerm(editMe.permission, true), choice, tf);
  2326             setPermissionActions(getPerm(editMe.permission, true), choice, tf);
  2031         }
  2327         }
  2032         tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE,
  2328         tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE,
  2033                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2329                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2034                            ToolWindow.LR_PADDING);
  2330                            ToolWindow.LR_BOTTOM_PADDING);
  2035         tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD,
  2331         tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD,
  2036                            1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2332                            1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2037                            ToolWindow.LR_PADDING);
  2333                            ToolWindow.LR_BOTTOM_PADDING);
       
  2334         choice.addItemListener(new PermissionActionsMenuListener(newTD));
  2038 
  2335 
  2039         // signedby label and textfield
  2336         // signedby label and textfield
  2040         label = new Label(PolicyTool.rb.getString("Signed.By."));
  2337         label = new JLabel(PolicyTool.getMessage("Signed.By."));
  2041         tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL,
  2338         tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL,
  2042                            0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2339                            0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2043                            ToolWindow.LR_PADDING);
  2340                            ToolWindow.LR_BOTTOM_PADDING);
  2044         tf = (edit ? new TextField(editMe.signedBy, 40) : new TextField(40));
  2341         tf = (edit ? new JTextField(editMe.signedBy, 40) : new JTextField(40));
       
  2342         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
  2045         tf.getAccessibleContext().setAccessibleName(
  2343         tf.getAccessibleContext().setAccessibleName(
  2046                 PolicyTool.rb.getString("Signed.By."));
  2344                 PolicyTool.getMessage("Signed.By."));
  2047         tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD,
  2345         tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD,
  2048                            1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2346                            1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
  2049                            ToolWindow.LR_PADDING);
  2347                            ToolWindow.LR_BOTTOM_PADDING);
  2050 
  2348 
  2051         // OK button
  2349         // OK button
  2052         Button okButton = new Button(PolicyTool.rb.getString("OK"));
  2350         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
  2053         okButton.addActionListener(
  2351         okButton.addActionListener(
  2054             new NewPolicyPermOKButtonListener
  2352             new NewPolicyPermOKButtonListener
  2055                                     (tool, tw, this, newTD, edit));
  2353                                     (tool, tw, this, newTD, edit));
  2056         tw.addNewComponent(newTD, okButton, PD_OK_BUTTON,
  2354         tw.addNewComponent(newTD, okButton, PD_OK_BUTTON,
  2057                            0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  2355                            0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  2058                            ToolWindow.TOP_BOTTOM_PADDING);
  2356                            ToolWindow.TOP_BOTTOM_PADDING);
  2059 
  2357 
  2060         // cancel button
  2358         // cancel button
  2061         Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
  2359         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
  2062         cancelButton.addActionListener(new CancelButtonListener(newTD));
  2360         ActionListener cancelListener = new CancelButtonListener(newTD);
       
  2361         cancelButton.addActionListener(cancelListener);
  2063         tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON,
  2362         tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON,
  2064                            1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  2363                            1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
  2065                            ToolWindow.TOP_BOTTOM_PADDING);
  2364                            ToolWindow.TOP_BOTTOM_PADDING);
  2066 
  2365 
       
  2366         newTD.getRootPane().setDefaultButton(okButton);
       
  2367         newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2368 
       
  2369         newTD.pack();
       
  2370         newTD.setLocationRelativeTo(tw);
  2067         newTD.setVisible(true);
  2371         newTD.setVisible(true);
  2068     }
  2372     }
  2069 
  2373 
  2070     /**
  2374     /**
  2071      * construct a Principal object from the Principal Info Dialog Box
  2375      * construct a Principal object from the Principal Info Dialog Box
  2072      */
  2376      */
  2073     PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception {
  2377     PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception {
  2074 
  2378 
  2075         TextField tf = (TextField)getComponent(PRD_PRIN_TEXTFIELD);
  2379         JTextField tf = (JTextField)getComponent(PRD_PRIN_TEXTFIELD);
  2076         String pclass = new String(tf.getText().trim());
  2380         String pclass = new String(tf.getText().trim());
  2077         tf = (TextField)getComponent(PRD_NAME_TEXTFIELD);
  2381         tf = (JTextField)getComponent(PRD_NAME_TEXTFIELD);
  2078         String pname = new String(tf.getText().trim());
  2382         String pname = new String(tf.getText().trim());
  2079         if (pclass.equals("*")) {
  2383         if (pclass.equals("*")) {
  2080             pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS;
  2384             pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS;
  2081         }
  2385         }
  2082         if (pname.equals("*")) {
  2386         if (pname.equals("*")) {
  2086         PolicyParser.PrincipalEntry pppe = null;
  2390         PolicyParser.PrincipalEntry pppe = null;
  2087 
  2391 
  2088         if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) &&
  2392         if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) &&
  2089             (!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) {
  2393             (!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) {
  2090             throw new Exception
  2394             throw new Exception
  2091                         (PolicyTool.rb.getString("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name"));
  2395                         (PolicyTool.getMessage("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name"));
  2092         } else if (pname.equals("")) {
  2396         } else if (pname.equals("")) {
  2093             throw new Exception
  2397             throw new Exception
  2094                         (PolicyTool.rb.getString("Cannot.Specify.Principal.without.a.Name"));
  2398                         (PolicyTool.getMessage("Cannot.Specify.Principal.without.a.Name"));
  2095         } else if (pclass.equals("")) {
  2399         } else if (pclass.equals("")) {
  2096             // make this consistent with what PolicyParser does
  2400             // make this consistent with what PolicyParser does
  2097             // when it sees an empty principal class
  2401             // when it sees an empty principal class
  2098             pclass = PolicyParser.PrincipalEntry.REPLACE_NAME;
  2402             pclass = PolicyParser.PrincipalEntry.REPLACE_NAME;
  2099             tool.warnings.addElement(
  2403             tool.warnings.addElement(
  2128     /**
  2432     /**
  2129      * construct a Permission object from the Permission Info Dialog Box
  2433      * construct a Permission object from the Permission Info Dialog Box
  2130      */
  2434      */
  2131     PolicyParser.PermissionEntry getPermFromDialog() {
  2435     PolicyParser.PermissionEntry getPermFromDialog() {
  2132 
  2436 
  2133         TextField tf = (TextField)getComponent(PD_PERM_TEXTFIELD);
  2437         JTextField tf = (JTextField)getComponent(PD_PERM_TEXTFIELD);
  2134         String permission = new String(tf.getText().trim());
  2438         String permission = new String(tf.getText().trim());
  2135         tf = (TextField)getComponent(PD_NAME_TEXTFIELD);
  2439         tf = (JTextField)getComponent(PD_NAME_TEXTFIELD);
  2136         String name = null;
  2440         String name = null;
  2137         if (tf.getText().trim().equals("") == false)
  2441         if (tf.getText().trim().equals("") == false)
  2138             name = new String(tf.getText().trim());
  2442             name = new String(tf.getText().trim());
  2139         if (permission.equals("") ||
  2443         if (permission.equals("") ||
  2140             (!permission.equals(ALL_PERM_CLASS) && name == null)) {
  2444             (!permission.equals(ALL_PERM_CLASS) && name == null)) {
  2141             throw new InvalidParameterException(PolicyTool.rb.getString
  2445             throw new InvalidParameterException(PolicyTool.getMessage
  2142                 ("Permission.and.Target.Name.must.have.a.value"));
  2446                 ("Permission.and.Target.Name.must.have.a.value"));
  2143         }
  2447         }
  2144 
  2448 
  2145         // When the permission is FilePermission, we need to check the name
  2449         // When the permission is FilePermission, we need to check the name
  2146         // to make sure it's not escaped. We believe --
  2450         // to make sure it's not escaped. We believe --
  2152         // \\server\share     0, legal
  2456         // \\server\share     0, legal
  2153         // \\\\server\share   2, illegal
  2457         // \\\\server\share   2, illegal
  2154 
  2458 
  2155         if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {
  2459         if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {
  2156             char result = tw.displayYesNoDialog(this,
  2460             char result = tw.displayYesNoDialog(this,
  2157                     PolicyTool.rb.getString("Warning"),
  2461                     PolicyTool.getMessage("Warning"),
  2158                     PolicyTool.rb.getString(
  2462                     PolicyTool.getMessage(
  2159                         "Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"),
  2463                         "Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"),
  2160                     PolicyTool.rb.getString("Retain"),
  2464                     PolicyTool.getMessage("Retain"),
  2161                     PolicyTool.rb.getString("Edit")
  2465                     PolicyTool.getMessage("Edit")
  2162                     );
  2466                     );
  2163             if (result != 'Y') {
  2467             if (result != 'Y') {
  2164                 // an invisible exception
  2468                 // an invisible exception
  2165                 throw new NoDisplayException();
  2469                 throw new NoDisplayException();
  2166             }
  2470             }
  2167         }
  2471         }
  2168         // get the Actions
  2472         // get the Actions
  2169         tf = (TextField)getComponent(PD_ACTIONS_TEXTFIELD);
  2473         tf = (JTextField)getComponent(PD_ACTIONS_TEXTFIELD);
  2170         String actions = null;
  2474         String actions = null;
  2171         if (tf.getText().trim().equals("") == false)
  2475         if (tf.getText().trim().equals("") == false)
  2172             actions = new String(tf.getText().trim());
  2476             actions = new String(tf.getText().trim());
  2173 
  2477 
  2174         // get the Signed By
  2478         // get the Signed By
  2175         tf = (TextField)getComponent(PD_SIGNEDBY_TEXTFIELD);
  2479         tf = (JTextField)getComponent(PD_SIGNEDBY_TEXTFIELD);
  2176         String signedBy = null;
  2480         String signedBy = null;
  2177         if (tf.getText().trim().equals("") == false)
  2481         if (tf.getText().trim().equals("") == false)
  2178             signedBy = new String(tf.getText().trim());
  2482             signedBy = new String(tf.getText().trim());
  2179 
  2483 
  2180         PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry
  2484         PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry
  2187                 for (int i = 0; i < signers.length; i++) {
  2491                 for (int i = 0; i < signers.length; i++) {
  2188                 try {
  2492                 try {
  2189                     PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
  2493                     PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
  2190                     if (pubKey == null) {
  2494                     if (pubKey == null) {
  2191                         MessageFormat form = new MessageFormat
  2495                         MessageFormat form = new MessageFormat
  2192                             (PolicyTool.rb.getString
  2496                             (PolicyTool.getMessage
  2193                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
  2497                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
  2194                         Object[] source = {signers[i]};
  2498                         Object[] source = {signers[i]};
  2195                         tool.warnings.addElement(form.format(source));
  2499                         tool.warnings.addElement(form.format(source));
  2196                         tw.displayStatusDialog(this, form.format(source));
  2500                         tw.displayStatusDialog(this, form.format(source));
  2197                     }
  2501                     }
  2207      * confirm that the user REALLY wants to remove the Policy Entry
  2511      * confirm that the user REALLY wants to remove the Policy Entry
  2208      */
  2512      */
  2209     void displayConfirmRemovePolicyEntry() {
  2513     void displayConfirmRemovePolicyEntry() {
  2210 
  2514 
  2211         // find the entry to be removed
  2515         // find the entry to be removed
  2212         List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  2516         JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  2213         int index = list.getSelectedIndex();
  2517         int index = list.getSelectedIndex();
  2214         PolicyEntry entries[] = tool.getEntry();
  2518         PolicyEntry entries[] = tool.getEntry();
  2215 
  2519 
  2216         // find where the PolicyTool gui is
  2520         // find where the PolicyTool gui is
  2217         Point location = tw.getLocationOnScreen();
  2521         Point location = tw.getLocationOnScreen();
  2218         setBounds(location.x + 25, location.y + 100, 600, 400);
  2522         //setBounds(location.x + 25, location.y + 100, 600, 400);
  2219         setLayout(new GridBagLayout());
  2523         setLayout(new GridBagLayout());
  2220 
  2524 
  2221         // ask the user do they really want to do this?
  2525         // ask the user do they really want to do this?
  2222         Label label = new Label
  2526         JLabel label = new JLabel
  2223                 (PolicyTool.rb.getString("Remove.this.Policy.Entry."));
  2527                 (PolicyTool.getMessage("Remove.this.Policy.Entry."));
  2224         tw.addNewComponent(this, label, CRPE_LABEL1,
  2528         tw.addNewComponent(this, label, CRPE_LABEL1,
  2225                            0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2529                            0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2226                            ToolWindow.BOTTOM_PADDING);
  2530                            ToolWindow.BOTTOM_PADDING);
  2227 
  2531 
  2228         // display the policy entry
  2532         // display the policy entry
  2229         label = new Label(entries[index].codebaseToString());
  2533         label = new JLabel(entries[index].codebaseToString());
  2230         tw.addNewComponent(this, label, CRPE_LABEL2,
  2534         tw.addNewComponent(this, label, CRPE_LABEL2,
  2231                         0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  2535                         0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  2232         label = new Label(entries[index].principalsToString().trim());
  2536         label = new JLabel(entries[index].principalsToString().trim());
  2233         tw.addNewComponent(this, label, CRPE_LABEL2+1,
  2537         tw.addNewComponent(this, label, CRPE_LABEL2+1,
  2234                         0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  2538                         0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  2235         Vector<PolicyParser.PermissionEntry> perms =
  2539         Vector<PolicyParser.PermissionEntry> perms =
  2236                         entries[index].getGrantEntry().permissionEntries;
  2540                         entries[index].getGrantEntry().permissionEntries;
  2237         for (int i = 0; i < perms.size(); i++) {
  2541         for (int i = 0; i < perms.size(); i++) {
  2238             PolicyParser.PermissionEntry nextPerm = perms.elementAt(i);
  2542             PolicyParser.PermissionEntry nextPerm = perms.elementAt(i);
  2239             String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm);
  2543             String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm);
  2240             label = new Label("    " + permString);
  2544             label = new JLabel("    " + permString);
  2241             if (i == (perms.size()-1)) {
  2545             if (i == (perms.size()-1)) {
  2242                 tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,
  2546                 tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,
  2243                                  1, 3 + i, 1, 1, 0.0, 0.0,
  2547                                  1, 3 + i, 1, 1, 0.0, 0.0,
  2244                                  GridBagConstraints.BOTH,
  2548                                  GridBagConstraints.BOTH,
  2245                                  ToolWindow.BOTTOM_PADDING);
  2549                                  ToolWindow.BOTTOM_PADDING);
  2250             }
  2554             }
  2251         }
  2555         }
  2252 
  2556 
  2253 
  2557 
  2254         // add OK/CANCEL buttons in a new panel
  2558         // add OK/CANCEL buttons in a new panel
  2255         Panel panel = new Panel();
  2559         JPanel panel = new JPanel();
  2256         panel.setLayout(new GridBagLayout());
  2560         panel.setLayout(new GridBagLayout());
  2257 
  2561 
  2258         // OK button
  2562         // OK button
  2259         Button okButton = new Button(PolicyTool.rb.getString("OK"));
  2563         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
  2260         okButton.addActionListener
  2564         okButton.addActionListener
  2261                 (new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this));
  2565                 (new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this));
  2262         tw.addNewComponent(panel, okButton, CRPE_PANEL_OK,
  2566         tw.addNewComponent(panel, okButton, CRPE_PANEL_OK,
  2263                            0, 0, 1, 1, 0.0, 0.0,
  2567                            0, 0, 1, 1, 0.0, 0.0,
  2264                            GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
  2568                            GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
  2265 
  2569 
  2266         // cancel button
  2570         // cancel button
  2267         Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
  2571         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
  2268         cancelButton.addActionListener(new CancelButtonListener(this));
  2572         ActionListener cancelListener = new CancelButtonListener(this);
       
  2573         cancelButton.addActionListener(cancelListener);
  2269         tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL,
  2574         tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL,
  2270                            1, 0, 1, 1, 0.0, 0.0,
  2575                            1, 0, 1, 1, 0.0, 0.0,
  2271                            GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
  2576                            GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
  2272 
  2577 
  2273         tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(),
  2578         tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(),
  2274                            0, 3 + perms.size(), 2, 1, 0.0, 0.0,
  2579                            0, 3 + perms.size(), 2, 1, 0.0, 0.0,
  2275                            GridBagConstraints.VERTICAL, ToolWindow.TOP_BOTTOM_PADDING);
  2580                            GridBagConstraints.VERTICAL, ToolWindow.TOP_BOTTOM_PADDING);
  2276 
  2581 
       
  2582         getRootPane().setDefaultButton(okButton);
       
  2583         getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2584 
  2277         pack();
  2585         pack();
       
  2586         setLocationRelativeTo(tw);
  2278         setVisible(true);
  2587         setVisible(true);
  2279     }
  2588     }
  2280 
  2589 
  2281     /**
  2590     /**
  2282      * perform SAVE AS
  2591      * perform SAVE AS
  2283      */
  2592      */
  2284     void displaySaveAsDialog(int nextEvent) {
  2593     void displaySaveAsDialog(int nextEvent) {
  2285 
  2594 
  2286         // pop up a dialog box for the user to enter a filename.
  2595         // pop up a dialog box for the user to enter a filename.
  2287         FileDialog fd = new FileDialog
  2596         FileDialog fd = new FileDialog
  2288                 (tw, PolicyTool.rb.getString("Save.As"), FileDialog.SAVE);
  2597                 (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
  2289         fd.addWindowListener(new WindowAdapter() {
  2598         fd.addWindowListener(new WindowAdapter() {
  2290             public void windowClosing(WindowEvent e) {
  2599             public void windowClosing(WindowEvent e) {
  2291                 e.getWindow().setVisible(false);
  2600                 e.getWindow().setVisible(false);
  2292             }
  2601             }
  2293         });
  2602         });
  2306         try {
  2615         try {
  2307             // save the policy entries to a file
  2616             // save the policy entries to a file
  2308             tool.savePolicy(filename);
  2617             tool.savePolicy(filename);
  2309 
  2618 
  2310             // display status
  2619             // display status
  2311             MessageFormat form = new MessageFormat(PolicyTool.rb.getString
  2620             MessageFormat form = new MessageFormat(PolicyTool.getMessage
  2312                     ("Policy.successfully.written.to.filename"));
  2621                     ("Policy.successfully.written.to.filename"));
  2313             Object[] source = {filename};
  2622             Object[] source = {filename};
  2314             tw.displayStatusDialog(null, form.format(source));
  2623             tw.displayStatusDialog(null, form.format(source));
  2315 
  2624 
  2316             // display the new policy filename
  2625             // display the new policy filename
  2317             TextField newFilename = (TextField)tw.getComponent
  2626             JTextField newFilename = (JTextField)tw.getComponent
  2318                             (ToolWindow.MW_FILENAME_TEXTFIELD);
  2627                             (ToolWindow.MW_FILENAME_TEXTFIELD);
  2319             newFilename.setText(filename);
  2628             newFilename.setText(filename);
  2320             tw.setVisible(true);
  2629             tw.setVisible(true);
  2321 
  2630 
  2322             // now continue with the originally requested command
  2631             // now continue with the originally requested command
  2324             userSaveContinue(tool, tw, this, nextEvent);
  2633             userSaveContinue(tool, tw, this, nextEvent);
  2325 
  2634 
  2326         } catch (FileNotFoundException fnfe) {
  2635         } catch (FileNotFoundException fnfe) {
  2327             if (filename == null || filename.equals("")) {
  2636             if (filename == null || filename.equals("")) {
  2328                 tw.displayErrorDialog(null, new FileNotFoundException
  2637                 tw.displayErrorDialog(null, new FileNotFoundException
  2329                             (PolicyTool.rb.getString("null.filename")));
  2638                             (PolicyTool.getMessage("null.filename")));
  2330             } else {
  2639             } else {
  2331                 tw.displayErrorDialog(null, fnfe);
  2640                 tw.displayErrorDialog(null, fnfe);
  2332             }
  2641             }
  2333         } catch (Exception ee) {
  2642         } catch (Exception ee) {
  2334             tw.displayErrorDialog(null, ee);
  2643             tw.displayErrorDialog(null, ee);
  2342 
  2651 
  2343         if (tool.modified == true) {
  2652         if (tool.modified == true) {
  2344 
  2653 
  2345             // find where the PolicyTool gui is
  2654             // find where the PolicyTool gui is
  2346             Point location = tw.getLocationOnScreen();
  2655             Point location = tw.getLocationOnScreen();
  2347             setBounds(location.x + 75, location.y + 100, 400, 150);
  2656             //setBounds(location.x + 75, location.y + 100, 400, 150);
  2348             setLayout(new GridBagLayout());
  2657             setLayout(new GridBagLayout());
  2349 
  2658 
  2350             Label label = new Label
  2659             JLabel label = new JLabel
  2351                 (PolicyTool.rb.getString("Save.changes."));
  2660                 (PolicyTool.getMessage("Save.changes."));
  2352             tw.addNewComponent(this, label, USC_LABEL,
  2661             tw.addNewComponent(this, label, USC_LABEL,
  2353                                0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2662                                0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
  2354                                ToolWindow.L_TOP_BOTTOM_PADDING);
  2663                                ToolWindow.L_TOP_BOTTOM_PADDING);
  2355 
  2664 
  2356             Panel panel = new Panel();
  2665             JPanel panel = new JPanel();
  2357             panel.setLayout(new GridBagLayout());
  2666             panel.setLayout(new GridBagLayout());
  2358 
  2667 
  2359             Button yesButton = new Button(PolicyTool.rb.getString("Yes"));
  2668             JButton yesButton = new JButton();
       
  2669             ToolWindow.configureButton(yesButton, "Yes");
  2360             yesButton.addActionListener
  2670             yesButton.addActionListener
  2361                         (new UserSaveYesButtonListener(this, tool, tw, select));
  2671                         (new UserSaveYesButtonListener(this, tool, tw, select));
  2362             tw.addNewComponent(panel, yesButton, USC_YES_BUTTON,
  2672             tw.addNewComponent(panel, yesButton, USC_YES_BUTTON,
  2363                                0, 0, 1, 1, 0.0, 0.0,
  2673                                0, 0, 1, 1, 0.0, 0.0,
  2364                                GridBagConstraints.VERTICAL,
  2674                                GridBagConstraints.VERTICAL,
  2365                                ToolWindow.LR_BOTTOM_PADDING);
  2675                                ToolWindow.LR_BOTTOM_PADDING);
  2366             Button noButton = new Button(PolicyTool.rb.getString("No"));
  2676             JButton noButton = new JButton();
       
  2677             ToolWindow.configureButton(noButton, "No");
  2367             noButton.addActionListener
  2678             noButton.addActionListener
  2368                         (new UserSaveNoButtonListener(this, tool, tw, select));
  2679                         (new UserSaveNoButtonListener(this, tool, tw, select));
  2369             tw.addNewComponent(panel, noButton, USC_NO_BUTTON,
  2680             tw.addNewComponent(panel, noButton, USC_NO_BUTTON,
  2370                                1, 0, 1, 1, 0.0, 0.0,
  2681                                1, 0, 1, 1, 0.0, 0.0,
  2371                                GridBagConstraints.VERTICAL,
  2682                                GridBagConstraints.VERTICAL,
  2372                                ToolWindow.LR_BOTTOM_PADDING);
  2683                                ToolWindow.LR_BOTTOM_PADDING);
  2373             Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
  2684             JButton cancelButton = new JButton();
  2374             cancelButton.addActionListener
  2685             ToolWindow.configureButton(cancelButton, "Cancel");
  2375                         (new UserSaveCancelButtonListener(this));
  2686             ActionListener cancelListener = new CancelButtonListener(this);
       
  2687             cancelButton.addActionListener(cancelListener);
  2376             tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON,
  2688             tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON,
  2377                                2, 0, 1, 1, 0.0, 0.0,
  2689                                2, 0, 1, 1, 0.0, 0.0,
  2378                                GridBagConstraints.VERTICAL,
  2690                                GridBagConstraints.VERTICAL,
  2379                                ToolWindow.LR_BOTTOM_PADDING);
  2691                                ToolWindow.LR_BOTTOM_PADDING);
  2380 
  2692 
  2381             tw.addNewComponent(this, panel, USC_PANEL,
  2693             tw.addNewComponent(this, panel, USC_PANEL,
  2382                                0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  2694                                0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
  2383 
  2695 
       
  2696             getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2697 
  2384             pack();
  2698             pack();
       
  2699             setLocationRelativeTo(tw);
  2385             setVisible(true);
  2700             setVisible(true);
  2386         } else {
  2701         } else {
  2387             // just do the original request (QUIT, NEW, or OPEN)
  2702             // just do the original request (QUIT, NEW, or OPEN)
  2388             userSaveContinue(tool, tw, this, select);
  2703             userSaveContinue(tool, tw, this, select);
  2389         }
  2704         }
  2416                 tool.modified = false;
  2731                 tool.modified = false;
  2417                 tw.displayErrorDialog(null, ee);
  2732                 tw.displayErrorDialog(null, ee);
  2418             }
  2733             }
  2419 
  2734 
  2420             // display the policy entries via the policy list textarea
  2735             // display the policy entries via the policy list textarea
  2421             List list = new List(40, false);
  2736             JList list = new JList(new DefaultListModel());
  2422             list.addActionListener(new PolicyListListener(tool, tw));
  2737             list.setVisibleRowCount(15);
       
  2738             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  2739             list.addMouseListener(new PolicyListListener(tool, tw));
  2423             tw.replacePolicyList(list);
  2740             tw.replacePolicyList(list);
  2424 
  2741 
  2425             // display null policy filename and keystore
  2742             // display null policy filename and keystore
  2426             TextField newFilename = (TextField)tw.getComponent(
  2743             JTextField newFilename = (JTextField)tw.getComponent(
  2427                     ToolWindow.MW_FILENAME_TEXTFIELD);
  2744                     ToolWindow.MW_FILENAME_TEXTFIELD);
  2428             newFilename.setText("");
  2745             newFilename.setText("");
  2429             tw.setVisible(true);
  2746             tw.setVisible(true);
  2430             break;
  2747             break;
  2431 
  2748 
  2432         case ToolDialog.OPEN:
  2749         case ToolDialog.OPEN:
  2433 
  2750 
  2434             // pop up a dialog box for the user to enter a filename.
  2751             // pop up a dialog box for the user to enter a filename.
  2435             FileDialog fd = new FileDialog
  2752             FileDialog fd = new FileDialog
  2436                 (tw, PolicyTool.rb.getString("Open"), FileDialog.LOAD);
  2753                 (tw, PolicyTool.getMessage("Open"), FileDialog.LOAD);
  2437             fd.addWindowListener(new WindowAdapter() {
  2754             fd.addWindowListener(new WindowAdapter() {
  2438                 public void windowClosing(WindowEvent e) {
  2755                 public void windowClosing(WindowEvent e) {
  2439                     e.getWindow().setVisible(false);
  2756                     e.getWindow().setVisible(false);
  2440                 }
  2757                 }
  2441             });
  2758             });
  2452             try {
  2769             try {
  2453                 // open the policy file
  2770                 // open the policy file
  2454                 tool.openPolicy(policyFile);
  2771                 tool.openPolicy(policyFile);
  2455 
  2772 
  2456                 // display the policy entries via the policy list textarea
  2773                 // display the policy entries via the policy list textarea
  2457                 list = new List(40, false);
  2774                 DefaultListModel listModel = new DefaultListModel();
  2458                 list.addActionListener(new PolicyListListener(tool, tw));
  2775                 list = new JList(listModel);
       
  2776                 list.setVisibleRowCount(15);
       
  2777                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  2778                 list.addMouseListener(new PolicyListListener(tool, tw));
  2459                 PolicyEntry entries[] = tool.getEntry();
  2779                 PolicyEntry entries[] = tool.getEntry();
  2460                 if (entries != null) {
  2780                 if (entries != null) {
  2461                     for (int i = 0; i < entries.length; i++)
  2781                     for (int i = 0; i < entries.length; i++) {
  2462                         list.add(entries[i].headerToString());
  2782                         listModel.addElement(entries[i].headerToString());
       
  2783                     }
  2463                 }
  2784                 }
  2464                 tw.replacePolicyList(list);
  2785                 tw.replacePolicyList(list);
  2465                 tool.modified = false;
  2786                 tool.modified = false;
  2466 
  2787 
  2467                 // display the new policy filename
  2788                 // display the new policy filename
  2468                 newFilename = (TextField)tw.getComponent(
  2789                 newFilename = (JTextField)tw.getComponent(
  2469                         ToolWindow.MW_FILENAME_TEXTFIELD);
  2790                         ToolWindow.MW_FILENAME_TEXTFIELD);
  2470                 newFilename.setText(policyFile);
  2791                 newFilename.setText(policyFile);
  2471                 tw.setVisible(true);
  2792                 tw.setVisible(true);
  2472 
  2793 
  2473                 // inform user of warnings
  2794                 // inform user of warnings
  2474                 if (tool.newWarning == true) {
  2795                 if (tool.newWarning == true) {
  2475                     tw.displayStatusDialog(null, PolicyTool.rb.getString
  2796                     tw.displayStatusDialog(null, PolicyTool.getMessage
  2476                         ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
  2797                         ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
  2477                 }
  2798                 }
  2478 
  2799 
  2479             } catch (Exception e) {
  2800             } catch (Exception e) {
  2480                 // add blank policy listing
  2801                 // add blank policy listing
  2481                 list = new List(40, false);
  2802                 list = new JList(new DefaultListModel());
  2482                 list.addActionListener(new PolicyListListener(tool, tw));
  2803                 list.setVisibleRowCount(15);
       
  2804                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  2805                 list.addMouseListener(new PolicyListListener(tool, tw));
  2483                 tw.replacePolicyList(list);
  2806                 tw.replacePolicyList(list);
  2484                 tool.setPolicyFileName(null);
  2807                 tool.setPolicyFileName(null);
  2485                 tool.modified = false;
  2808                 tool.modified = false;
  2486 
  2809 
  2487                 // display a null policy filename
  2810                 // display a null policy filename
  2488                 newFilename = (TextField)tw.getComponent(
  2811                 newFilename = (JTextField)tw.getComponent(
  2489                         ToolWindow.MW_FILENAME_TEXTFIELD);
  2812                         ToolWindow.MW_FILENAME_TEXTFIELD);
  2490                 newFilename.setText("");
  2813                 newFilename.setText("");
  2491                 tw.setVisible(true);
  2814                 tw.setVisible(true);
  2492 
  2815 
  2493                 // display the error
  2816                 // display the error
  2494                 MessageFormat form = new MessageFormat(PolicyTool.rb.getString
  2817                 MessageFormat form = new MessageFormat(PolicyTool.getMessage
  2495                     ("Could.not.open.policy.file.policyFile.e.toString."));
  2818                     ("Could.not.open.policy.file.policyFile.e.toString."));
  2496                 Object[] source = {policyFile, e.toString()};
  2819                 Object[] source = {policyFile, e.toString()};
  2497                 tw.displayErrorDialog(null, form.format(source));
  2820                 tw.displayErrorDialog(null, form.format(source));
  2498             }
  2821             }
  2499             break;
  2822             break;
  2509      *
  2832      *
  2510      * If TARGETS are valid but there are no standard ones
  2833      * If TARGETS are valid but there are no standard ones
  2511      * (user must enter them by hand) then the TARGETS array may be empty
  2834      * (user must enter them by hand) then the TARGETS array may be empty
  2512      * (and of course non-null).
  2835      * (and of course non-null).
  2513      */
  2836      */
  2514     void setPermissionNames(Perm inputPerm, Choice names, TextField field) {
  2837     void setPermissionNames(Perm inputPerm, JComboBox names, JTextField field) {
  2515         names.removeAll();
  2838         names.removeAllItems();
  2516         names.add(PERM_NAME);
  2839         names.addItem(PERM_NAME);
  2517 
  2840 
  2518         if (inputPerm == null) {
  2841         if (inputPerm == null) {
  2519             // custom permission
  2842             // custom permission
  2520             field.setEditable(true);
  2843             field.setEditable(true);
  2521         } else if (inputPerm.TARGETS == null) {
  2844         } else if (inputPerm.TARGETS == null) {
  2523             field.setEditable(false);
  2846             field.setEditable(false);
  2524         } else {
  2847         } else {
  2525             // standard permission with standard targets
  2848             // standard permission with standard targets
  2526             field.setEditable(true);
  2849             field.setEditable(true);
  2527             for (int i = 0; i < inputPerm.TARGETS.length; i++) {
  2850             for (int i = 0; i < inputPerm.TARGETS.length; i++) {
  2528                 names.add(inputPerm.TARGETS[i]);
  2851                 names.addItem(inputPerm.TARGETS[i]);
  2529             }
  2852             }
  2530         }
  2853         }
  2531     }
  2854     }
  2532 
  2855 
  2533     /**
  2856     /**
  2539      *
  2862      *
  2540      * If ACTIONS are valid but there are no standard ones
  2863      * If ACTIONS are valid but there are no standard ones
  2541      * (user must enter them by hand) then the ACTIONS array may be empty
  2864      * (user must enter them by hand) then the ACTIONS array may be empty
  2542      * (and of course non-null).
  2865      * (and of course non-null).
  2543      */
  2866      */
  2544     void setPermissionActions(Perm inputPerm, Choice actions, TextField field) {
  2867     void setPermissionActions(Perm inputPerm, JComboBox actions, JTextField field) {
  2545         actions.removeAll();
  2868         actions.removeAllItems();
  2546         actions.add(PERM_ACTIONS);
  2869         actions.addItem(PERM_ACTIONS);
  2547 
  2870 
  2548         if (inputPerm == null) {
  2871         if (inputPerm == null) {
  2549             // custom permission
  2872             // custom permission
  2550             field.setEditable(true);
  2873             field.setEditable(true);
  2551         } else if (inputPerm.ACTIONS == null) {
  2874         } else if (inputPerm.ACTIONS == null) {
  2553             field.setEditable(false);
  2876             field.setEditable(false);
  2554         } else {
  2877         } else {
  2555             // standard permission with standard actions
  2878             // standard permission with standard actions
  2556             field.setEditable(true);
  2879             field.setEditable(true);
  2557             for (int i = 0; i < inputPerm.ACTIONS.length; i++) {
  2880             for (int i = 0; i < inputPerm.ACTIONS.length; i++) {
  2558                 actions.add(inputPerm.ACTIONS[i]);
  2881                 actions.addItem(inputPerm.ACTIONS[i]);
  2559             }
  2882             }
  2560         }
  2883         }
  2561     }
  2884     }
  2562 
  2885 
  2563     static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) {
  2886     static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) {
  2585 /**
  2908 /**
  2586  * Event handler for the PolicyTool window
  2909  * Event handler for the PolicyTool window
  2587  */
  2910  */
  2588 class ToolWindowListener implements WindowListener {
  2911 class ToolWindowListener implements WindowListener {
  2589 
  2912 
       
  2913     private PolicyTool tool;
  2590     private ToolWindow tw;
  2914     private ToolWindow tw;
  2591 
  2915 
  2592     ToolWindowListener(ToolWindow tw) {
  2916     ToolWindowListener(PolicyTool tool, ToolWindow tw) {
       
  2917         this.tool = tool;
  2593         this.tw = tw;
  2918         this.tw = tw;
  2594     }
  2919     }
  2595 
  2920 
  2596     public void windowOpened(WindowEvent we) {
  2921     public void windowOpened(WindowEvent we) {
  2597     }
  2922     }
  2598 
  2923 
  2599     public void windowClosing(WindowEvent we) {
  2924     public void windowClosing(WindowEvent we) {
  2600 
  2925         // Closing the window acts the same as choosing Menu->Exit.
  2601         // XXX
  2926 
  2602         // should we ask user if they want to save changes?
  2927         // ask user if they want to save changes
  2603         // (we do if they choose the Menu->Exit)
  2928         ToolDialog td = new ToolDialog(PolicyTool.getMessage("Save.Changes"), tool, tw, true);
  2604         // seems that if they kill the application by hand,
  2929         td.displayUserSave(ToolDialog.QUIT);
  2605         // we don't have to ask.
  2930 
  2606 
  2931         // the above method will perform the QUIT as long as the
  2607         tw.setVisible(false);
  2932         // user does not CANCEL the request
  2608         tw.dispose();
       
  2609         System.exit(0);
       
  2610     }
  2933     }
  2611 
  2934 
  2612     public void windowClosed(WindowEvent we) {
  2935     public void windowClosed(WindowEvent we) {
  2613         System.exit(0);
  2936         System.exit(0);
  2614     }
  2937     }
  2627 }
  2950 }
  2628 
  2951 
  2629 /**
  2952 /**
  2630  * Event handler for the Policy List
  2953  * Event handler for the Policy List
  2631  */
  2954  */
  2632 class PolicyListListener implements ActionListener {
  2955 class PolicyListListener extends MouseAdapter implements ActionListener {
  2633 
  2956 
  2634     private PolicyTool tool;
  2957     private PolicyTool tool;
  2635     private ToolWindow tw;
  2958     private ToolWindow tw;
  2636 
  2959 
  2637     PolicyListListener(PolicyTool tool, ToolWindow tw) {
  2960     PolicyListListener(PolicyTool tool, ToolWindow tw) {
  2642 
  2965 
  2643     public void actionPerformed(ActionEvent e) {
  2966     public void actionPerformed(ActionEvent e) {
  2644 
  2967 
  2645         // display the permission list for a policy entry
  2968         // display the permission list for a policy entry
  2646         ToolDialog td = new ToolDialog
  2969         ToolDialog td = new ToolDialog
  2647                 (PolicyTool.rb.getString("Policy.Entry"), tool, tw, true);
  2970                 (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
  2648         td.displayPolicyEntryDialog(true);
  2971         td.displayPolicyEntryDialog(true);
       
  2972     }
       
  2973 
       
  2974     public void mouseClicked(MouseEvent evt) {
       
  2975         if (evt.getClickCount() == 2) {
       
  2976             actionPerformed(null);
       
  2977         }
  2649     }
  2978     }
  2650 }
  2979 }
  2651 
  2980 
  2652 /**
  2981 /**
  2653  * Event handler for the File Menu
  2982  * Event handler for the File Menu
  2667         if (PolicyTool.collator.compare(e.getActionCommand(),
  2996         if (PolicyTool.collator.compare(e.getActionCommand(),
  2668                                        ToolWindow.QUIT) == 0) {
  2997                                        ToolWindow.QUIT) == 0) {
  2669 
  2998 
  2670             // ask user if they want to save changes
  2999             // ask user if they want to save changes
  2671             ToolDialog td = new ToolDialog
  3000             ToolDialog td = new ToolDialog
  2672                 (PolicyTool.rb.getString("Save.Changes"), tool, tw, true);
  3001                 (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
  2673             td.displayUserSave(ToolDialog.QUIT);
  3002             td.displayUserSave(ToolDialog.QUIT);
  2674 
  3003 
  2675             // the above method will perform the QUIT as long as the
  3004             // the above method will perform the QUIT as long as the
  2676             // user does not CANCEL the request
  3005             // user does not CANCEL the request
  2677 
  3006 
  2678         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3007         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2679                                    ToolWindow.NEW_POLICY_FILE) == 0) {
  3008                                    ToolWindow.NEW_POLICY_FILE) == 0) {
  2680 
  3009 
  2681             // ask user if they want to save changes
  3010             // ask user if they want to save changes
  2682             ToolDialog td = new ToolDialog
  3011             ToolDialog td = new ToolDialog
  2683                 (PolicyTool.rb.getString("Save.Changes"), tool, tw, true);
  3012                 (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
  2684             td.displayUserSave(ToolDialog.NEW);
  3013             td.displayUserSave(ToolDialog.NEW);
  2685 
  3014 
  2686             // the above method will perform the NEW as long as the
  3015             // the above method will perform the NEW as long as the
  2687             // user does not CANCEL the request
  3016             // user does not CANCEL the request
  2688 
  3017 
  2689         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3018         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2690                                   ToolWindow.OPEN_POLICY_FILE) == 0) {
  3019                                   ToolWindow.OPEN_POLICY_FILE) == 0) {
  2691 
  3020 
  2692             // ask user if they want to save changes
  3021             // ask user if they want to save changes
  2693             ToolDialog td = new ToolDialog
  3022             ToolDialog td = new ToolDialog
  2694                 (PolicyTool.rb.getString("Save.Changes"), tool, tw, true);
  3023                 (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
  2695             td.displayUserSave(ToolDialog.OPEN);
  3024             td.displayUserSave(ToolDialog.OPEN);
  2696 
  3025 
  2697             // the above method will perform the OPEN as long as the
  3026             // the above method will perform the OPEN as long as the
  2698             // user does not CANCEL the request
  3027             // user does not CANCEL the request
  2699 
  3028 
  2700         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3029         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2701                                   ToolWindow.SAVE_POLICY_FILE) == 0) {
  3030                                   ToolWindow.SAVE_POLICY_FILE) == 0) {
  2702 
  3031 
  2703             // get the previously entered filename
  3032             // get the previously entered filename
  2704             String filename = ((TextField)tw.getComponent(
  3033             String filename = ((JTextField)tw.getComponent(
  2705                     ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
  3034                     ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
  2706 
  3035 
  2707             // if there is no filename, do a SAVE_AS
  3036             // if there is no filename, do a SAVE_AS
  2708             if (filename == null || filename.length() == 0) {
  3037             if (filename == null || filename.length() == 0) {
  2709                 // user wants to SAVE AS
  3038                 // user wants to SAVE AS
  2710                 ToolDialog td = new ToolDialog
  3039                 ToolDialog td = new ToolDialog
  2711                         (PolicyTool.rb.getString("Save.As"), tool, tw, true);
  3040                         (PolicyTool.getMessage("Save.As"), tool, tw, true);
  2712                 td.displaySaveAsDialog(ToolDialog.NOACTION);
  3041                 td.displaySaveAsDialog(ToolDialog.NOACTION);
  2713             } else {
  3042             } else {
  2714                 try {
  3043                 try {
  2715                     // save the policy entries to a file
  3044                     // save the policy entries to a file
  2716                     tool.savePolicy(filename);
  3045                     tool.savePolicy(filename);
  2717 
  3046 
  2718                     // display status
  3047                     // display status
  2719                     MessageFormat form = new MessageFormat
  3048                     MessageFormat form = new MessageFormat
  2720                         (PolicyTool.rb.getString
  3049                         (PolicyTool.getMessage
  2721                         ("Policy.successfully.written.to.filename"));
  3050                         ("Policy.successfully.written.to.filename"));
  2722                     Object[] source = {filename};
  3051                     Object[] source = {filename};
  2723                     tw.displayStatusDialog(null, form.format(source));
  3052                     tw.displayStatusDialog(null, form.format(source));
  2724                 } catch (FileNotFoundException fnfe) {
  3053                 } catch (FileNotFoundException fnfe) {
  2725                     if (filename == null || filename.equals("")) {
  3054                     if (filename == null || filename.equals("")) {
  2726                         tw.displayErrorDialog(null, new FileNotFoundException
  3055                         tw.displayErrorDialog(null, new FileNotFoundException
  2727                                 (PolicyTool.rb.getString("null.filename")));
  3056                                 (PolicyTool.getMessage("null.filename")));
  2728                     } else {
  3057                     } else {
  2729                         tw.displayErrorDialog(null, fnfe);
  3058                         tw.displayErrorDialog(null, fnfe);
  2730                     }
  3059                     }
  2731                 } catch (Exception ee) {
  3060                 } catch (Exception ee) {
  2732                     tw.displayErrorDialog(null, ee);
  3061                     tw.displayErrorDialog(null, ee);
  2735         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3064         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2736                                ToolWindow.SAVE_AS_POLICY_FILE) == 0) {
  3065                                ToolWindow.SAVE_AS_POLICY_FILE) == 0) {
  2737 
  3066 
  2738             // user wants to SAVE AS
  3067             // user wants to SAVE AS
  2739             ToolDialog td = new ToolDialog
  3068             ToolDialog td = new ToolDialog
  2740                 (PolicyTool.rb.getString("Save.As"), tool, tw, true);
  3069                 (PolicyTool.getMessage("Save.As"), tool, tw, true);
  2741             td.displaySaveAsDialog(ToolDialog.NOACTION);
  3070             td.displaySaveAsDialog(ToolDialog.NOACTION);
  2742 
  3071 
  2743         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3072         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2744                                      ToolWindow.VIEW_WARNINGS) == 0) {
  3073                                      ToolWindow.VIEW_WARNINGS) == 0) {
  2745             tw.displayWarningLog(null);
  3074             tw.displayWarningLog(null);
  2765         if (PolicyTool.collator.compare(e.getActionCommand(),
  3094         if (PolicyTool.collator.compare(e.getActionCommand(),
  2766                            ToolWindow.ADD_POLICY_ENTRY) == 0) {
  3095                            ToolWindow.ADD_POLICY_ENTRY) == 0) {
  2767 
  3096 
  2768             // display a dialog box for the user to enter policy info
  3097             // display a dialog box for the user to enter policy info
  2769             ToolDialog td = new ToolDialog
  3098             ToolDialog td = new ToolDialog
  2770                 (PolicyTool.rb.getString("Policy.Entry"), tool, tw, true);
  3099                 (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
  2771             td.displayPolicyEntryDialog(false);
  3100             td.displayPolicyEntryDialog(false);
  2772 
  3101 
  2773         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3102         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2774                                ToolWindow.REMOVE_POLICY_ENTRY) == 0) {
  3103                                ToolWindow.REMOVE_POLICY_ENTRY) == 0) {
  2775 
  3104 
  2776             // get the selected entry
  3105             // get the selected entry
  2777             List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3106             JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  2778             int index = list.getSelectedIndex();
  3107             int index = list.getSelectedIndex();
  2779             if (index < 0) {
  3108             if (index < 0) {
  2780                 tw.displayErrorDialog(null, new Exception
  3109                 tw.displayErrorDialog(null, new Exception
  2781                         (PolicyTool.rb.getString("No.Policy.Entry.selected")));
  3110                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
  2782                 return;
  3111                 return;
  2783             }
  3112             }
  2784 
  3113 
  2785             // ask the user if they really want to remove the policy entry
  3114             // ask the user if they really want to remove the policy entry
  2786             ToolDialog td = new ToolDialog(PolicyTool.rb.getString
  3115             ToolDialog td = new ToolDialog(PolicyTool.getMessage
  2787                 ("Remove.Policy.Entry"), tool, tw, true);
  3116                 ("Remove.Policy.Entry"), tool, tw, true);
  2788             td.displayConfirmRemovePolicyEntry();
  3117             td.displayConfirmRemovePolicyEntry();
  2789 
  3118 
  2790         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3119         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2791                                  ToolWindow.EDIT_POLICY_ENTRY) == 0) {
  3120                                  ToolWindow.EDIT_POLICY_ENTRY) == 0) {
  2792 
  3121 
  2793             // get the selected entry
  3122             // get the selected entry
  2794             List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3123             JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  2795             int index = list.getSelectedIndex();
  3124             int index = list.getSelectedIndex();
  2796             if (index < 0) {
  3125             if (index < 0) {
  2797                 tw.displayErrorDialog(null, new Exception
  3126                 tw.displayErrorDialog(null, new Exception
  2798                         (PolicyTool.rb.getString("No.Policy.Entry.selected")));
  3127                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
  2799                 return;
  3128                 return;
  2800             }
  3129             }
  2801 
  3130 
  2802             // display the permission list for a policy entry
  3131             // display the permission list for a policy entry
  2803             ToolDialog td = new ToolDialog
  3132             ToolDialog td = new ToolDialog
  2804                 (PolicyTool.rb.getString("Policy.Entry"), tool, tw, true);
  3133                 (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
  2805             td.displayPolicyEntryDialog(true);
  3134             td.displayPolicyEntryDialog(true);
  2806 
  3135 
  2807         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  3136         } else if (PolicyTool.collator.compare(e.getActionCommand(),
  2808                                      ToolWindow.EDIT_KEYSTORE) == 0) {
  3137                                      ToolWindow.EDIT_KEYSTORE) == 0) {
  2809 
  3138 
  2810             // display a dialog box for the user to enter keystore info
  3139             // display a dialog box for the user to enter keystore info
  2811             ToolDialog td = new ToolDialog
  3140             ToolDialog td = new ToolDialog
  2812                 (PolicyTool.rb.getString("KeyStore"), tool, tw, true);
  3141                 (PolicyTool.getMessage("KeyStore"), tool, tw, true);
  2813             td.keyStoreDialog(ToolDialog.EDIT_KEYSTORE);
  3142             td.keyStoreDialog(ToolDialog.EDIT_KEYSTORE);
  2814         }
  3143         }
  2815     }
  3144     }
  2816 }
  3145 }
  2817 
  3146 
  2850                 String signers[] = tool.parseSigners(newGe.signedBy);
  3179                 String signers[] = tool.parseSigners(newGe.signedBy);
  2851                 for (int i = 0; i < signers.length; i++) {
  3180                 for (int i = 0; i < signers.length; i++) {
  2852                     PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
  3181                     PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
  2853                     if (pubKey == null) {
  3182                     if (pubKey == null) {
  2854                         MessageFormat form = new MessageFormat
  3183                         MessageFormat form = new MessageFormat
  2855                             (PolicyTool.rb.getString
  3184                             (PolicyTool.getMessage
  2856                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
  3185                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
  2857                         Object[] source = {signers[i]};
  3186                         Object[] source = {signers[i]};
  2858                         tool.warnings.addElement(form.format(source));
  3187                         tool.warnings.addElement(form.format(source));
  2859                         tw.displayStatusDialog(td, form.format(source));
  3188                         tw.displayStatusDialog(td, form.format(source));
  2860                     }
  3189                     }
  2861                 }
  3190                 }
  2862             }
  3191             }
  2863 
  3192 
  2864             // add the entry
  3193             // add the entry
  2865             List policyList = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3194             JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  2866             if (edit) {
  3195             if (edit) {
  2867                 int listIndex = policyList.getSelectedIndex();
  3196                 int listIndex = policyList.getSelectedIndex();
  2868                 tool.addEntry(newEntry, listIndex);
  3197                 tool.addEntry(newEntry, listIndex);
  2869                 String newCodeBaseStr = newEntry.headerToString();
  3198                 String newCodeBaseStr = newEntry.headerToString();
  2870                 if (PolicyTool.collator.compare
  3199                 if (PolicyTool.collator.compare
  2871                         (newCodeBaseStr, policyList.getItem(listIndex)) != 0)
  3200                         (newCodeBaseStr, policyList.getModel().getElementAt(listIndex)) != 0)
  2872                     tool.modified = true;
  3201                     tool.modified = true;
  2873                 policyList.replaceItem(newCodeBaseStr, listIndex);
  3202                 ((DefaultListModel)policyList.getModel()).set(listIndex, newCodeBaseStr);
  2874             } else {
  3203             } else {
  2875                 tool.addEntry(newEntry, -1);
  3204                 tool.addEntry(newEntry, -1);
  2876                 policyList.add(newEntry.headerToString());
  3205                 ((DefaultListModel)policyList.getModel()).addElement(newEntry.headerToString());
  2877                 tool.modified = true;
  3206                 tool.modified = true;
  2878             }
  3207             }
  2879             td.setVisible(false);
  3208             td.setVisible(false);
  2880             td.dispose();
  3209             td.dispose();
  2881 
  3210 
  2901         this.td = td;
  3230         this.td = td;
  2902     }
  3231     }
  2903 
  3232 
  2904     public void actionPerformed(ActionEvent e) {
  3233     public void actionPerformed(ActionEvent e) {
  2905 
  3234 
  2906         String URLString = ((TextField)td.getComponent(
  3235         String URLString = ((JTextField)td.getComponent(
  2907                 ToolDialog.KSD_NAME_TEXTFIELD)).getText().trim();
  3236                 ToolDialog.KSD_NAME_TEXTFIELD)).getText().trim();
  2908         String type = ((TextField)td.getComponent(
  3237         String type = ((JTextField)td.getComponent(
  2909                 ToolDialog.KSD_TYPE_TEXTFIELD)).getText().trim();
  3238                 ToolDialog.KSD_TYPE_TEXTFIELD)).getText().trim();
  2910         String provider = ((TextField)td.getComponent(
  3239         String provider = ((JTextField)td.getComponent(
  2911                 ToolDialog.KSD_PROVIDER_TEXTFIELD)).getText().trim();
  3240                 ToolDialog.KSD_PROVIDER_TEXTFIELD)).getText().trim();
  2912         String pwdURL = ((TextField)td.getComponent(
  3241         String pwdURL = ((JTextField)td.getComponent(
  2913                 ToolDialog.KSD_PWD_URL_TEXTFIELD)).getText().trim();
  3242                 ToolDialog.KSD_PWD_URL_TEXTFIELD)).getText().trim();
  2914 
  3243 
  2915         try {
  3244         try {
  2916             tool.openKeyStore
  3245             tool.openKeyStore
  2917                         ((URLString.length() == 0 ? null : URLString),
  3246                         ((URLString.length() == 0 ? null : URLString),
  2918                         (type.length() == 0 ? null : type),
  3247                         (type.length() == 0 ? null : type),
  2919                         (provider.length() == 0 ? null : provider),
  3248                         (provider.length() == 0 ? null : provider),
  2920                         (pwdURL.length() == 0 ? null : pwdURL));
  3249                         (pwdURL.length() == 0 ? null : pwdURL));
  2921             tool.modified = true;
  3250             tool.modified = true;
  2922         } catch (Exception ex) {
  3251         } catch (Exception ex) {
  2923             MessageFormat form = new MessageFormat(PolicyTool.rb.getString
  3252             MessageFormat form = new MessageFormat(PolicyTool.getMessage
  2924                 ("Unable.to.open.KeyStore.ex.toString."));
  3253                 ("Unable.to.open.KeyStore.ex.toString."));
  2925             Object[] source = {ex.toString()};
  3254             Object[] source = {ex.toString()};
  2926             tw.displayErrorDialog(td, form.format(source));
  3255             tw.displayErrorDialog(td, form.format(source));
  2927             return;
  3256             return;
  2928         }
  3257         }
  3014                 try {
  3343                 try {
  3015                     tool.verifyPrincipal(pppe.getPrincipalClass(),
  3344                     tool.verifyPrincipal(pppe.getPrincipalClass(),
  3016                                         pppe.getPrincipalName());
  3345                                         pppe.getPrincipalName());
  3017                 } catch (ClassNotFoundException cnfe) {
  3346                 } catch (ClassNotFoundException cnfe) {
  3018                     MessageFormat form = new MessageFormat
  3347                     MessageFormat form = new MessageFormat
  3019                                 (PolicyTool.rb.getString
  3348                                 (PolicyTool.getMessage
  3020                                 ("Warning.Class.not.found.class"));
  3349                                 ("Warning.Class.not.found.class"));
  3021                     Object[] source = {pppe.getPrincipalClass()};
  3350                     Object[] source = {pppe.getPrincipalClass()};
  3022                     tool.warnings.addElement(form.format(source));
  3351                     tool.warnings.addElement(form.format(source));
  3023                     tw.displayStatusDialog(infoDialog, form.format(source));
  3352                     tw.displayStatusDialog(infoDialog, form.format(source));
  3024                 }
  3353                 }
  3075                         infoDialog.getPermFromDialog();
  3404                         infoDialog.getPermFromDialog();
  3076 
  3405 
  3077             try {
  3406             try {
  3078                 tool.verifyPermission(pppe.permission, pppe.name, pppe.action);
  3407                 tool.verifyPermission(pppe.permission, pppe.name, pppe.action);
  3079             } catch (ClassNotFoundException cnfe) {
  3408             } catch (ClassNotFoundException cnfe) {
  3080                 MessageFormat form = new MessageFormat(PolicyTool.rb.getString
  3409                 MessageFormat form = new MessageFormat(PolicyTool.getMessage
  3081                                 ("Warning.Class.not.found.class"));
  3410                                 ("Warning.Class.not.found.class"));
  3082                 Object[] source = {pppe.permission};
  3411                 Object[] source = {pppe.permission};
  3083                 tool.warnings.addElement(form.format(source));
  3412                 tool.warnings.addElement(form.format(source));
  3084                 tw.displayStatusDialog(infoDialog, form.format(source));
  3413                 tw.displayStatusDialog(infoDialog, form.format(source));
  3085             }
  3414             }
  3132                 ToolDialog.PE_PRIN_LIST);
  3461                 ToolDialog.PE_PRIN_LIST);
  3133         int prinIndex = prinList.getSelectedIndex();
  3462         int prinIndex = prinList.getSelectedIndex();
  3134 
  3463 
  3135         if (prinIndex < 0) {
  3464         if (prinIndex < 0) {
  3136             tw.displayErrorDialog(td, new Exception
  3465             tw.displayErrorDialog(td, new Exception
  3137                 (PolicyTool.rb.getString("No.principal.selected")));
  3466                 (PolicyTool.getMessage("No.principal.selected")));
  3138             return;
  3467             return;
  3139         }
  3468         }
  3140         // remove the principal from the display
  3469         // remove the principal from the display
  3141         prinList.removeTaggedItem(prinIndex);
  3470         prinList.removeTaggedItem(prinIndex);
  3142     }
  3471     }
  3167                 ToolDialog.PE_PERM_LIST);
  3496                 ToolDialog.PE_PERM_LIST);
  3168         int permIndex = permList.getSelectedIndex();
  3497         int permIndex = permList.getSelectedIndex();
  3169 
  3498 
  3170         if (permIndex < 0) {
  3499         if (permIndex < 0) {
  3171             tw.displayErrorDialog(td, new Exception
  3500             tw.displayErrorDialog(td, new Exception
  3172                 (PolicyTool.rb.getString("No.permission.selected")));
  3501                 (PolicyTool.getMessage("No.permission.selected")));
  3173             return;
  3502             return;
  3174         }
  3503         }
  3175         // remove the permission from the display
  3504         // remove the permission from the display
  3176         permList.removeTaggedItem(permIndex);
  3505         permList.removeTaggedItem(permIndex);
  3177 
  3506 
  3185  * adding a new PolicyEntry at this time, or editing an existing entry.
  3514  * adding a new PolicyEntry at this time, or editing an existing entry.
  3186  * If the user is adding a new PolicyEntry, we ONLY update the
  3515  * If the user is adding a new PolicyEntry, we ONLY update the
  3187  * GUI listing.  If the user is editing an existing PolicyEntry, we
  3516  * GUI listing.  If the user is editing an existing PolicyEntry, we
  3188  * update both the GUI listing and the actual PolicyEntry.
  3517  * update both the GUI listing and the actual PolicyEntry.
  3189  */
  3518  */
  3190 class EditPrinButtonListener implements ActionListener {
  3519 class EditPrinButtonListener extends MouseAdapter implements ActionListener {
  3191 
  3520 
  3192     private PolicyTool tool;
  3521     private PolicyTool tool;
  3193     private ToolWindow tw;
  3522     private ToolWindow tw;
  3194     private ToolDialog td;
  3523     private ToolDialog td;
  3195     private boolean editPolicyEntry;
  3524     private boolean editPolicyEntry;
  3209                 ToolDialog.PE_PRIN_LIST);
  3538                 ToolDialog.PE_PRIN_LIST);
  3210         int prinIndex = list.getSelectedIndex();
  3539         int prinIndex = list.getSelectedIndex();
  3211 
  3540 
  3212         if (prinIndex < 0) {
  3541         if (prinIndex < 0) {
  3213             tw.displayErrorDialog(td, new Exception
  3542             tw.displayErrorDialog(td, new Exception
  3214                 (PolicyTool.rb.getString("No.principal.selected")));
  3543                 (PolicyTool.getMessage("No.principal.selected")));
  3215             return;
  3544             return;
  3216         }
  3545         }
  3217         td.displayPrincipalDialog(editPolicyEntry, true);
  3546         td.displayPrincipalDialog(editPolicyEntry, true);
       
  3547     }
       
  3548 
       
  3549     public void mouseClicked(MouseEvent evt) {
       
  3550         if (evt.getClickCount() == 2) {
       
  3551             actionPerformed(null);
       
  3552         }
  3218     }
  3553     }
  3219 }
  3554 }
  3220 
  3555 
  3221 /**
  3556 /**
  3222  * Event handler for Edit Permission button
  3557  * Event handler for Edit Permission button
  3225  * adding a new PolicyEntry at this time, or editing an existing entry.
  3560  * adding a new PolicyEntry at this time, or editing an existing entry.
  3226  * If the user is adding a new PolicyEntry, we ONLY update the
  3561  * If the user is adding a new PolicyEntry, we ONLY update the
  3227  * GUI listing.  If the user is editing an existing PolicyEntry, we
  3562  * GUI listing.  If the user is editing an existing PolicyEntry, we
  3228  * update both the GUI listing and the actual PolicyEntry.
  3563  * update both the GUI listing and the actual PolicyEntry.
  3229  */
  3564  */
  3230 class EditPermButtonListener implements ActionListener {
  3565 class EditPermButtonListener extends MouseAdapter implements ActionListener {
  3231 
  3566 
  3232     private PolicyTool tool;
  3567     private PolicyTool tool;
  3233     private ToolWindow tw;
  3568     private ToolWindow tw;
  3234     private ToolDialog td;
  3569     private ToolDialog td;
  3235     private boolean editPolicyEntry;
  3570     private boolean editPolicyEntry;
  3243     }
  3578     }
  3244 
  3579 
  3245     public void actionPerformed(ActionEvent e) {
  3580     public void actionPerformed(ActionEvent e) {
  3246 
  3581 
  3247         // get the Permission selected from the Permission List
  3582         // get the Permission selected from the Permission List
  3248         List list = (List)td.getComponent(ToolDialog.PE_PERM_LIST);
  3583         JList list = (JList)td.getComponent(ToolDialog.PE_PERM_LIST);
  3249         int permIndex = list.getSelectedIndex();
  3584         int permIndex = list.getSelectedIndex();
  3250 
  3585 
  3251         if (permIndex < 0) {
  3586         if (permIndex < 0) {
  3252             tw.displayErrorDialog(td, new Exception
  3587             tw.displayErrorDialog(td, new Exception
  3253                 (PolicyTool.rb.getString("No.permission.selected")));
  3588                 (PolicyTool.getMessage("No.permission.selected")));
  3254             return;
  3589             return;
  3255         }
  3590         }
  3256         td.displayPermissionDialog(editPolicyEntry, true);
  3591         td.displayPermissionDialog(editPolicyEntry, true);
       
  3592     }
       
  3593 
       
  3594     public void mouseClicked(MouseEvent evt) {
       
  3595         if (evt.getClickCount() == 2) {
       
  3596             actionPerformed(null);
       
  3597         }
  3257     }
  3598     }
  3258 }
  3599 }
  3259 
  3600 
  3260 /**
  3601 /**
  3261  * Event handler for Principal Popup Menu
  3602  * Event handler for Principal Popup Menu
  3267     PrincipalTypeMenuListener(ToolDialog td) {
  3608     PrincipalTypeMenuListener(ToolDialog td) {
  3268         this.td = td;
  3609         this.td = td;
  3269     }
  3610     }
  3270 
  3611 
  3271     public void itemStateChanged(ItemEvent e) {
  3612     public void itemStateChanged(ItemEvent e) {
  3272 
  3613         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3273         Choice prin = (Choice)td.getComponent(ToolDialog.PRD_PRIN_CHOICE);
  3614             // We're only interested in SELECTED events
  3274         TextField prinField = (TextField)td.getComponent(
  3615             return;
       
  3616         }
       
  3617 
       
  3618         JComboBox prin = (JComboBox)td.getComponent(ToolDialog.PRD_PRIN_CHOICE);
       
  3619         JTextField prinField = (JTextField)td.getComponent(
  3275                 ToolDialog.PRD_PRIN_TEXTFIELD);
  3620                 ToolDialog.PRD_PRIN_TEXTFIELD);
  3276         TextField nameField = (TextField)td.getComponent(
  3621         JTextField nameField = (JTextField)td.getComponent(
  3277                 ToolDialog.PRD_NAME_TEXTFIELD);
  3622                 ToolDialog.PRD_NAME_TEXTFIELD);
  3278 
  3623 
  3279         prin.getAccessibleContext().setAccessibleName(
  3624         prin.getAccessibleContext().setAccessibleName(
  3280             PolicyTool.splitToWords((String)e.getItem()));
  3625             PolicyTool.splitToWords((String)e.getItem()));
  3281         if (((String)e.getItem()).equals(ToolDialog.PRIN_TYPE)) {
  3626         if (((String)e.getItem()).equals(ToolDialog.PRIN_TYPE)) {
  3282             // ignore if they choose "Principal Type:" item
  3627             // ignore if they choose "Principal Type:" item
  3283             if (prinField.getText() != null &&
  3628             if (prinField.getText() != null &&
  3284                 prinField.getText().length() > 0) {
  3629                 prinField.getText().length() > 0) {
  3285                 Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true);
  3630                 Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true);
  3286                 prin.select(inputPrin.CLASS);
  3631                 prin.setSelectedItem(inputPrin.CLASS);
  3287             }
  3632             }
  3288             return;
  3633             return;
  3289         }
  3634         }
  3290 
  3635 
  3291         // if you change the principal, clear the name
  3636         // if you change the principal, clear the name
  3313     PermissionMenuListener(ToolDialog td) {
  3658     PermissionMenuListener(ToolDialog td) {
  3314         this.td = td;
  3659         this.td = td;
  3315     }
  3660     }
  3316 
  3661 
  3317     public void itemStateChanged(ItemEvent e) {
  3662     public void itemStateChanged(ItemEvent e) {
  3318 
  3663         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3319         Choice perms = (Choice)td.getComponent(
  3664             // We're only interested in SELECTED events
       
  3665             return;
       
  3666         }
       
  3667 
       
  3668         JComboBox perms = (JComboBox)td.getComponent(
  3320                 ToolDialog.PD_PERM_CHOICE);
  3669                 ToolDialog.PD_PERM_CHOICE);
  3321         Choice names = (Choice)td.getComponent(
  3670         JComboBox names = (JComboBox)td.getComponent(
  3322                 ToolDialog.PD_NAME_CHOICE);
  3671                 ToolDialog.PD_NAME_CHOICE);
  3323         Choice actions = (Choice)td.getComponent(
  3672         JComboBox actions = (JComboBox)td.getComponent(
  3324                 ToolDialog.PD_ACTIONS_CHOICE);
  3673                 ToolDialog.PD_ACTIONS_CHOICE);
  3325         TextField nameField = (TextField)td.getComponent(
  3674         JTextField nameField = (JTextField)td.getComponent(
  3326                 ToolDialog.PD_NAME_TEXTFIELD);
  3675                 ToolDialog.PD_NAME_TEXTFIELD);
  3327         TextField actionsField = (TextField)td.getComponent(
  3676         JTextField actionsField = (JTextField)td.getComponent(
  3328                 ToolDialog.PD_ACTIONS_TEXTFIELD);
  3677                 ToolDialog.PD_ACTIONS_TEXTFIELD);
  3329         TextField permField = (TextField)td.getComponent(
  3678         JTextField permField = (JTextField)td.getComponent(
  3330                 ToolDialog.PD_PERM_TEXTFIELD);
  3679                 ToolDialog.PD_PERM_TEXTFIELD);
  3331         TextField signedbyField = (TextField)td.getComponent(
  3680         JTextField signedbyField = (JTextField)td.getComponent(
  3332                 ToolDialog.PD_SIGNEDBY_TEXTFIELD);
  3681                 ToolDialog.PD_SIGNEDBY_TEXTFIELD);
  3333 
  3682 
  3334         perms.getAccessibleContext().setAccessibleName(
  3683         perms.getAccessibleContext().setAccessibleName(
  3335             PolicyTool.splitToWords((String)e.getItem()));
  3684             PolicyTool.splitToWords((String)e.getItem()));
  3336 
  3685 
  3340             if (permField.getText() != null &&
  3689             if (permField.getText() != null &&
  3341                 permField.getText().length() > 0) {
  3690                 permField.getText().length() > 0) {
  3342 
  3691 
  3343                 Perm inputPerm = ToolDialog.getPerm(permField.getText(), true);
  3692                 Perm inputPerm = ToolDialog.getPerm(permField.getText(), true);
  3344                 if (inputPerm != null) {
  3693                 if (inputPerm != null) {
  3345                     perms.select(inputPerm.CLASS);
  3694                     perms.setSelectedItem(inputPerm.CLASS);
  3346                 }
  3695                 }
  3347             }
  3696             }
  3348             return;
  3697             return;
  3349         }
  3698         }
  3350 
  3699 
  3380     PermissionNameMenuListener(ToolDialog td) {
  3729     PermissionNameMenuListener(ToolDialog td) {
  3381         this.td = td;
  3730         this.td = td;
  3382     }
  3731     }
  3383 
  3732 
  3384     public void itemStateChanged(ItemEvent e) {
  3733     public void itemStateChanged(ItemEvent e) {
  3385 
  3734         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3386         Choice names = (Choice)td.getComponent(ToolDialog.PD_NAME_CHOICE);
  3735             // We're only interested in SELECTED events
       
  3736             return;
       
  3737         }
       
  3738 
       
  3739         JComboBox names = (JComboBox)td.getComponent(ToolDialog.PD_NAME_CHOICE);
  3387         names.getAccessibleContext().setAccessibleName(
  3740         names.getAccessibleContext().setAccessibleName(
  3388             PolicyTool.splitToWords((String)e.getItem()));
  3741             PolicyTool.splitToWords((String)e.getItem()));
  3389 
  3742 
  3390         if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1)
  3743         if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1)
  3391             return;
  3744             return;
  3392 
  3745 
  3393         TextField tf = (TextField)td.getComponent(ToolDialog.PD_NAME_TEXTFIELD);
  3746         JTextField tf = (JTextField)td.getComponent(ToolDialog.PD_NAME_TEXTFIELD);
  3394         tf.setText((String)e.getItem());
  3747         tf.setText((String)e.getItem());
  3395     }
  3748     }
  3396 }
  3749 }
  3397 
  3750 
  3398 /**
  3751 /**
  3405     PermissionActionsMenuListener(ToolDialog td) {
  3758     PermissionActionsMenuListener(ToolDialog td) {
  3406         this.td = td;
  3759         this.td = td;
  3407     }
  3760     }
  3408 
  3761 
  3409     public void itemStateChanged(ItemEvent e) {
  3762     public void itemStateChanged(ItemEvent e) {
  3410 
  3763         if (e.getStateChange() == ItemEvent.DESELECTED) {
  3411         Choice actions = (Choice)td.getComponent(
  3764             // We're only interested in SELECTED events
       
  3765             return;
       
  3766         }
       
  3767 
       
  3768         JComboBox actions = (JComboBox)td.getComponent(
  3412                 ToolDialog.PD_ACTIONS_CHOICE);
  3769                 ToolDialog.PD_ACTIONS_CHOICE);
  3413         actions.getAccessibleContext().setAccessibleName((String)e.getItem());
  3770         actions.getAccessibleContext().setAccessibleName((String)e.getItem());
  3414 
  3771 
  3415         if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1)
  3772         if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1)
  3416             return;
  3773             return;
  3417 
  3774 
  3418         TextField tf = (TextField)td.getComponent(
  3775         JTextField tf = (JTextField)td.getComponent(
  3419                 ToolDialog.PD_ACTIONS_TEXTFIELD);
  3776                 ToolDialog.PD_ACTIONS_TEXTFIELD);
  3420         if (tf.getText() == null || tf.getText().equals("")) {
  3777         if (tf.getText() == null || tf.getText().equals("")) {
  3421             tf.setText((String)e.getItem());
  3778             tf.setText((String)e.getItem());
  3422         } else {
  3779         } else {
  3423             if (tf.getText().indexOf((String)e.getItem()) == -1)
  3780             if (tf.getText().indexOf((String)e.getItem()) == -1)
  3536         // first get rid of the window
  3893         // first get rid of the window
  3537         us.setVisible(false);
  3894         us.setVisible(false);
  3538         us.dispose();
  3895         us.dispose();
  3539 
  3896 
  3540         try {
  3897         try {
  3541             String filename = ((TextField)tw.getComponent(
  3898             String filename = ((JTextField)tw.getComponent(
  3542                     ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
  3899                     ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
  3543             if (filename == null || filename.equals("")) {
  3900             if (filename == null || filename.equals("")) {
  3544                 us.displaySaveAsDialog(select);
  3901                 us.displaySaveAsDialog(select);
  3545 
  3902 
  3546                 // the above dialog will continue with the originally
  3903                 // the above dialog will continue with the originally
  3549                 // save the policy entries to a file
  3906                 // save the policy entries to a file
  3550                 tool.savePolicy(filename);
  3907                 tool.savePolicy(filename);
  3551 
  3908 
  3552                 // display status
  3909                 // display status
  3553                 MessageFormat form = new MessageFormat
  3910                 MessageFormat form = new MessageFormat
  3554                         (PolicyTool.rb.getString
  3911                         (PolicyTool.getMessage
  3555                         ("Policy.successfully.written.to.filename"));
  3912                         ("Policy.successfully.written.to.filename"));
  3556                 Object[] source = {filename};
  3913                 Object[] source = {filename};
  3557                 tw.displayStatusDialog(null, form.format(source));
  3914                 tw.displayStatusDialog(null, form.format(source));
  3558 
  3915 
  3559                 // now continue with the originally requested command
  3916                 // now continue with the originally requested command
  3631         this.us = us;
  3988         this.us = us;
  3632     }
  3989     }
  3633 
  3990 
  3634     public void actionPerformed(ActionEvent e) {
  3991     public void actionPerformed(ActionEvent e) {
  3635         // remove the entry
  3992         // remove the entry
  3636         List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3993         JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
  3637         int index = list.getSelectedIndex();
  3994         int index = list.getSelectedIndex();
  3638         PolicyEntry entries[] = tool.getEntry();
  3995         PolicyEntry entries[] = tool.getEntry();
  3639         tool.removeEntry(entries[index]);
  3996         tool.removeEntry(entries[index]);
  3640 
  3997 
  3641         // redraw the window listing
  3998         // redraw the window listing
  3642         list = new List(40, false);
  3999         DefaultListModel listModel = new DefaultListModel();
  3643         list.addActionListener(new PolicyListListener(tool, tw));
  4000         list = new JList(listModel);
       
  4001         list.setVisibleRowCount(15);
       
  4002         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  4003         list.addMouseListener(new PolicyListListener(tool, tw));
  3644         entries = tool.getEntry();
  4004         entries = tool.getEntry();
  3645         if (entries != null) {
  4005         if (entries != null) {
  3646                 for (int i = 0; i < entries.length; i++)
  4006                 for (int i = 0; i < entries.length; i++) {
  3647                     list.add(entries[i].headerToString());
  4007                     listModel.addElement(entries[i].headerToString());
       
  4008                 }
  3648         }
  4009         }
  3649         tw.replacePolicyList(list);
  4010         tw.replacePolicyList(list);
  3650         us.setVisible(false);
  4011         us.setVisible(false);
  3651         us.dispose();
  4012         us.dispose();
  3652     }
  4013     }
  3661 }
  4022 }
  3662 
  4023 
  3663 /**
  4024 /**
  3664  * This is a java.awt.List that bind an Object to each String it holds.
  4025  * This is a java.awt.List that bind an Object to each String it holds.
  3665  */
  4026  */
  3666 class TaggedList extends List {
  4027 class TaggedList extends JList {
  3667     private static final long serialVersionUID = -5676238110427785853L;
  4028     private static final long serialVersionUID = -5676238110427785853L;
  3668 
  4029 
  3669     private java.util.List<Object> data = new LinkedList<>();
  4030     private java.util.List<Object> data = new LinkedList<>();
  3670     public TaggedList(int i, boolean b) {
  4031     public TaggedList(int i, boolean b) {
  3671         super(i, b);
  4032         super(new DefaultListModel());
       
  4033         setVisibleRowCount(i);
       
  4034         setSelectionMode(b ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION);
  3672     }
  4035     }
  3673 
  4036 
  3674     public Object getObject(int index) {
  4037     public Object getObject(int index) {
  3675         return data.get(index);
  4038         return data.get(index);
  3676     }
  4039     }
  3677 
  4040 
  3678     @Override @Deprecated public void add(String string) {
       
  3679         throw new AssertionError("should not call add in TaggedList");
       
  3680     }
       
  3681     public void addTaggedItem(String string, Object object) {
  4041     public void addTaggedItem(String string, Object object) {
  3682         super.add(string);
  4042         ((DefaultListModel)getModel()).addElement(string);
  3683         data.add(object);
  4043         data.add(object);
  3684     }
  4044     }
  3685 
  4045 
  3686     @Override @Deprecated public void replaceItem(String string, int index) {
       
  3687         throw new AssertionError("should not call replaceItem in TaggedList");
       
  3688     }
       
  3689     public void replaceTaggedItem(String string, Object object, int index) {
  4046     public void replaceTaggedItem(String string, Object object, int index) {
  3690         super.replaceItem(string, index);
  4047         ((DefaultListModel)getModel()).set(index, string);
  3691         data.set(index, object);
  4048         data.set(index, object);
  3692     }
  4049     }
  3693 
  4050 
  3694     @Override @Deprecated public void remove(int index) {
       
  3695         // Cannot throw AssertionError, because replaceItem() call remove() internally
       
  3696         super.remove(index);
       
  3697     }
       
  3698     public void removeTaggedItem(int index) {
  4051     public void removeTaggedItem(int index) {
  3699         super.remove(index);
  4052         ((DefaultListModel)getModel()).remove(index);
  3700         data.remove(index);
  4053         data.remove(index);
  3701     }
  4054     }
  3702 }
  4055 }
  3703 
  4056 
  3704 /**
  4057 /**
  3780                 "modifyPrincipals",
  4133                 "modifyPrincipals",
  3781                 "modifyPublicCredentials",
  4134                 "modifyPublicCredentials",
  3782                 "modifyPrivateCredentials",
  4135                 "modifyPrivateCredentials",
  3783                 "refreshCredential",
  4136                 "refreshCredential",
  3784                 "destroyCredential",
  4137                 "destroyCredential",
  3785                 "createLoginContext.<" + PolicyTool.rb.getString("name") + ">",
  4138                 "createLoginContext.<" + PolicyTool.getMessage("name") + ">",
  3786                 "getLoginConfiguration",
  4139                 "getLoginConfiguration",
  3787                 "setLoginConfiguration",
  4140                 "setLoginConfiguration",
  3788                 "createLoginConfiguration.<" +
  4141                 "createLoginConfiguration.<" +
  3789                         PolicyTool.rb.getString("configuration.type") + ">",
  4142                         PolicyTool.getMessage("configuration.type") + ">",
  3790                 "refreshLoginConfiguration"
  4143                 "refreshLoginConfiguration"
  3791                 },
  4144                 },
  3792         null);
  4145         null);
  3793     }
  4146     }
  3794 }
  4147 }
  3846 class URLPerm extends Perm {
  4199 class URLPerm extends Perm {
  3847     public URLPerm() {
  4200     public URLPerm() {
  3848         super("URLPermission",
  4201         super("URLPermission",
  3849                 "java.net.URLPermission",
  4202                 "java.net.URLPermission",
  3850                 new String[]    {
  4203                 new String[]    {
  3851                     "<"+ PolicyTool.rb.getString("url") + ">",
  4204                     "<"+ PolicyTool.getMessage("url") + ">",
  3852                 },
  4205                 },
  3853                 new String[]    {
  4206                 new String[]    {
  3854                     "<" + PolicyTool.rb.getString("method.list") + ">:<"
  4207                     "<" + PolicyTool.getMessage("method.list") + ">:<"
  3855                         + PolicyTool.rb.getString("request.headers.list") + ">",
  4208                         + PolicyTool.getMessage("request.headers.list") + ">",
  3856                 });
  4209                 });
  3857     }
  4210     }
  3858 }
  4211 }
  3859 
  4212 
  3860 class InqSecContextPerm extends Perm {
  4213 class InqSecContextPerm extends Perm {
  4015                 "setContextClassLoader",
  4368                 "setContextClassLoader",
  4016                 "enableContextClassLoaderOverride",
  4369                 "enableContextClassLoaderOverride",
  4017                 "setSecurityManager",
  4370                 "setSecurityManager",
  4018                 "createSecurityManager",
  4371                 "createSecurityManager",
  4019                 "getenv.<" +
  4372                 "getenv.<" +
  4020                     PolicyTool.rb.getString("environment.variable.name") + ">",
  4373                     PolicyTool.getMessage("environment.variable.name") + ">",
  4021                 "exitVM",
  4374                 "exitVM",
  4022                 "shutdownHooks",
  4375                 "shutdownHooks",
  4023                 "setFactory",
  4376                 "setFactory",
  4024                 "setIO",
  4377                 "setIO",
  4025                 "modifyThread",
  4378                 "modifyThread",
  4027                 "modifyThreadGroup",
  4380                 "modifyThreadGroup",
  4028                 "getProtectionDomain",
  4381                 "getProtectionDomain",
  4029                 "readFileDescriptor",
  4382                 "readFileDescriptor",
  4030                 "writeFileDescriptor",
  4383                 "writeFileDescriptor",
  4031                 "loadLibrary.<" +
  4384                 "loadLibrary.<" +
  4032                     PolicyTool.rb.getString("library.name") + ">",
  4385                     PolicyTool.getMessage("library.name") + ">",
  4033                 "accessClassInPackage.<" +
  4386                 "accessClassInPackage.<" +
  4034                     PolicyTool.rb.getString("package.name")+">",
  4387                     PolicyTool.getMessage("package.name")+">",
  4035                 "defineClassInPackage.<" +
  4388                 "defineClassInPackage.<" +
  4036                     PolicyTool.rb.getString("package.name")+">",
  4389                     PolicyTool.getMessage("package.name")+">",
  4037                 "accessDeclaredMembers",
  4390                 "accessDeclaredMembers",
  4038                 "queuePrintJob",
  4391                 "queuePrintJob",
  4039                 "getStackTrace",
  4392                 "getStackTrace",
  4040                 "setDefaultUncaughtExceptionHandler",
  4393                 "setDefaultUncaughtExceptionHandler",
  4041                 "preferences",
  4394                 "preferences",
  4054                 "createAccessControlContext",
  4407                 "createAccessControlContext",
  4055                 "getDomainCombiner",
  4408                 "getDomainCombiner",
  4056                 "getPolicy",
  4409                 "getPolicy",
  4057                 "setPolicy",
  4410                 "setPolicy",
  4058                 "createPolicy.<" +
  4411                 "createPolicy.<" +
  4059                     PolicyTool.rb.getString("policy.type") + ">",
  4412                     PolicyTool.getMessage("policy.type") + ">",
  4060                 "getProperty.<" +
  4413                 "getProperty.<" +
  4061                     PolicyTool.rb.getString("property.name") + ">",
  4414                     PolicyTool.getMessage("property.name") + ">",
  4062                 "setProperty.<" +
  4415                 "setProperty.<" +
  4063                     PolicyTool.rb.getString("property.name") + ">",
  4416                     PolicyTool.getMessage("property.name") + ">",
  4064                 "insertProvider.<" +
  4417                 "insertProvider.<" +
  4065                     PolicyTool.rb.getString("provider.name") + ">",
  4418                     PolicyTool.getMessage("provider.name") + ">",
  4066                 "removeProvider.<" +
  4419                 "removeProvider.<" +
  4067                     PolicyTool.rb.getString("provider.name") + ">",
  4420                     PolicyTool.getMessage("provider.name") + ">",
  4068                 //"setSystemScope",
  4421                 //"setSystemScope",
  4069                 //"setIdentityPublicKey",
  4422                 //"setIdentityPublicKey",
  4070                 //"setIdentityInfo",
  4423                 //"setIdentityInfo",
  4071                 //"addIdentityCertificate",
  4424                 //"addIdentityCertificate",
  4072                 //"removeIdentityCertificate",
  4425                 //"removeIdentityCertificate",
  4073                 //"printIdentity",
  4426                 //"printIdentity",
  4074                 "clearProviderProperties.<" +
  4427                 "clearProviderProperties.<" +
  4075                     PolicyTool.rb.getString("provider.name") + ">",
  4428                     PolicyTool.getMessage("provider.name") + ">",
  4076                 "putProviderProperty.<" +
  4429                 "putProviderProperty.<" +
  4077                     PolicyTool.rb.getString("provider.name") + ">",
  4430                     PolicyTool.getMessage("provider.name") + ">",
  4078                 "removeProviderProperty.<" +
  4431                 "removeProviderProperty.<" +
  4079                     PolicyTool.rb.getString("provider.name") + ">",
  4432                     PolicyTool.getMessage("provider.name") + ">",
  4080                 //"getSignerPrivateKey",
  4433                 //"getSignerPrivateKey",
  4081                 //"setSignerKeyPair"
  4434                 //"setSignerKeyPair"
  4082                 },
  4435                 },
  4083         null);
  4436         null);
  4084     }
  4437     }