提交 885bf602 编写于 作者: W weijun

7025699: Policy Tool is not accessible by keyboard

Reviewed-by: alexp, weijun
Contributed-by: NLeif Samuelsson <leif.samuelsson@oracle.com>
上级 e864d64d
...@@ -37,7 +37,16 @@ import java.text.Collator; ...@@ -37,7 +37,16 @@ import java.text.Collator;
import java.text.MessageFormat; import java.text.MessageFormat;
import sun.security.util.PropertyExpander; import sun.security.util.PropertyExpander;
import sun.security.util.PropertyExpander.ExpandException; import sun.security.util.PropertyExpander.ExpandException;
import java.awt.*; import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.*; import java.awt.event.*;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
...@@ -45,6 +54,8 @@ import java.security.*; ...@@ -45,6 +54,8 @@ import java.security.*;
import sun.security.provider.*; import sun.security.provider.*;
import sun.security.util.PolicyUtil; import sun.security.util.PolicyUtil;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
/** /**
* PolicyTool may be used by users and administrators to configure the * PolicyTool may be used by users and administrators to configure the
...@@ -66,7 +77,22 @@ public class PolicyTool { ...@@ -66,7 +77,22 @@ public class PolicyTool {
static { static {
// this is for case insensitive string comparisons // this is for case insensitive string comparisons
collator.setStrength(Collator.PRIMARY); collator.setStrength(Collator.PRIMARY);
};
// Support for Apple menu bar
if (System.getProperty("apple.laf.useScreenMenuBar") == null) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
}
System.setProperty("apple.awt.application.name", getMessage("Policy.Tool"));
// Apply the system L&F if not specified with a system property.
if (System.getProperty("swing.defaultlaf") == null) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
// ignore
}
}
}
// anyone can add warnings // anyone can add warnings
Vector<String> warnings; Vector<String> warnings;
...@@ -228,7 +254,7 @@ public class PolicyTool { ...@@ -228,7 +254,7 @@ public class PolicyTool {
PublicKey pubKey = getPublicKeyAlias(signers[i]); PublicKey pubKey = getPublicKeyAlias(signers[i]);
if (pubKey == null) { if (pubKey == null) {
newWarning = true; newWarning = true;
MessageFormat form = new MessageFormat(rb.getString MessageFormat form = new MessageFormat(getMessage
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
Object[] source = {signers[i]}; Object[] source = {signers[i]};
warnings.addElement(form.format(source)); warnings.addElement(form.format(source));
...@@ -246,7 +272,7 @@ public class PolicyTool { ...@@ -246,7 +272,7 @@ public class PolicyTool {
pe.getPrincipalName()); pe.getPrincipalName());
} catch (ClassNotFoundException fnfe) { } catch (ClassNotFoundException fnfe) {
newWarning = true; newWarning = true;
MessageFormat form = new MessageFormat(rb.getString MessageFormat form = new MessageFormat(getMessage
("Warning.Class.not.found.class")); ("Warning.Class.not.found.class"));
Object[] source = {pe.getPrincipalClass()}; Object[] source = {pe.getPrincipalClass()};
warnings.addElement(form.format(source)); warnings.addElement(form.format(source));
...@@ -262,13 +288,13 @@ public class PolicyTool { ...@@ -262,13 +288,13 @@ public class PolicyTool {
verifyPermission(pe.permission, pe.name, pe.action); verifyPermission(pe.permission, pe.name, pe.action);
} catch (ClassNotFoundException fnfe) { } catch (ClassNotFoundException fnfe) {
newWarning = true; newWarning = true;
MessageFormat form = new MessageFormat(rb.getString MessageFormat form = new MessageFormat(getMessage
("Warning.Class.not.found.class")); ("Warning.Class.not.found.class"));
Object[] source = {pe.permission}; Object[] source = {pe.permission};
warnings.addElement(form.format(source)); warnings.addElement(form.format(source));
} catch (InvocationTargetException ite) { } catch (InvocationTargetException ite) {
newWarning = true; newWarning = true;
MessageFormat form = new MessageFormat(rb.getString MessageFormat form = new MessageFormat(getMessage
("Warning.Invalid.argument.s.for.constructor.arg")); ("Warning.Invalid.argument.s.for.constructor.arg"));
Object[] source = {pe.permission}; Object[] source = {pe.permission};
warnings.addElement(form.format(source)); warnings.addElement(form.format(source));
...@@ -283,7 +309,7 @@ public class PolicyTool { ...@@ -283,7 +309,7 @@ public class PolicyTool {
PublicKey pubKey = getPublicKeyAlias(signers[i]); PublicKey pubKey = getPublicKeyAlias(signers[i]);
if (pubKey == null) { if (pubKey == null) {
newWarning = true; newWarning = true;
MessageFormat form = new MessageFormat(rb.getString MessageFormat form = new MessageFormat(getMessage
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
Object[] source = {signers[i]}; Object[] source = {signers[i]};
warnings.addElement(form.format(source)); warnings.addElement(form.format(source));
...@@ -611,7 +637,7 @@ public class PolicyTool { ...@@ -611,7 +637,7 @@ public class PolicyTool {
Class<?> pc = Class.forName(type, true, Class<?> pc = Class.forName(type, true,
Thread.currentThread().getContextClassLoader()); Thread.currentThread().getContextClassLoader());
if (!PRIN.isAssignableFrom(pc)) { if (!PRIN.isAssignableFrom(pc)) {
MessageFormat form = new MessageFormat(rb.getString MessageFormat form = new MessageFormat(getMessage
("Illegal.Principal.Type.type")); ("Illegal.Principal.Type.type"));
Object[] source = {type}; Object[] source = {type};
throw new InstantiationException(form.format(source)); throw new InstantiationException(form.format(source));
...@@ -690,7 +716,7 @@ public class PolicyTool { ...@@ -690,7 +716,7 @@ public class PolicyTool {
if (++n == args.length) usage(); if (++n == args.length) usage();
policyFileName = args[n]; policyFileName = args[n];
} else { } else {
MessageFormat form = new MessageFormat(rb.getString MessageFormat form = new MessageFormat(getMessage
("Illegal.option.option")); ("Illegal.option.option"));
Object[] source = { flags }; Object[] source = { flags };
System.err.println(form.format(source)); System.err.println(form.format(source));
...@@ -700,9 +726,9 @@ public class PolicyTool { ...@@ -700,9 +726,9 @@ public class PolicyTool {
} }
static void usage() { static void usage() {
System.out.println(rb.getString("Usage.policytool.options.")); System.out.println(getMessage("Usage.policytool.options."));
System.out.println(); System.out.println();
System.out.println(rb.getString System.out.println(getMessage
(".file.file.policy.file.location")); (".file.file.policy.file.location"));
System.out.println(); System.out.println();
...@@ -714,8 +740,12 @@ public class PolicyTool { ...@@ -714,8 +740,12 @@ public class PolicyTool {
*/ */
public static void main(String args[]) { public static void main(String args[]) {
parseArgs(args); parseArgs(args);
ToolWindow tw = new ToolWindow(new PolicyTool()); SwingUtilities.invokeLater(new Runnable() {
tw.displayToolWindow(args); public void run() {
ToolWindow tw = new ToolWindow(new PolicyTool());
tw.displayToolWindow(args);
}
});
} }
// split instr to words according to capitalization, // split instr to words according to capitalization,
...@@ -725,6 +755,108 @@ public class PolicyTool { ...@@ -725,6 +755,108 @@ public class PolicyTool {
return instr.replaceAll("([A-Z])", " $1"); return instr.replaceAll("([A-Z])", " $1");
} }
/**
* Returns the message corresponding to the key in the bundle.
* This is preferred over {@link #getString} because it removes
* any mnemonic '&' character in the string.
*
* @param key the key
*
* @return the message
*/
static String getMessage(String key) {
return removeMnemonicAmpersand(rb.getString(key));
}
/**
* Returns the mnemonic for a message.
*
* @param key the key
*
* @return the mnemonic <code>int</code>
*/
static int getMnemonicInt(String key) {
String message = rb.getString(key);
return (findMnemonicInt(message));
}
/**
* Returns the mnemonic display index for a message.
*
* @param key the key
*
* @return the mnemonic display index
*/
static int getDisplayedMnemonicIndex(String key) {
String message = rb.getString(key);
return (findMnemonicIndex(message));
}
/**
* Finds the mnemonic character in a message.
*
* The mnemonic character is the first character followed by the first
* <code>&</code> that is not followed by another <code>&</code>.
*
* @return the mnemonic as an <code>int</code>, or <code>0</code> if it
* can't be found.
*/
private static int findMnemonicInt(String s) {
for (int i = 0; i < s.length() - 1; i++) {
if (s.charAt(i) == '&') {
if (s.charAt(i + 1) != '&') {
return KeyEvent.getExtendedKeyCodeForChar(s.charAt(i + 1));
} else {
i++;
}
}
}
return 0;
}
/**
* Finds the index of the mnemonic character in a message.
*
* The mnemonic character is the first character followed by the first
* <code>&</code> that is not followed by another <code>&</code>.
*
* @return the mnemonic character index as an <code>int</code>, or <code>-1</code> if it
* can't be found.
*/
private static int findMnemonicIndex(String s) {
for (int i = 0; i < s.length() - 1; i++) {
if (s.charAt(i) == '&') {
if (s.charAt(i + 1) != '&') {
// Return the index of the '&' since it will be removed
return i;
} else {
i++;
}
}
}
return -1;
}
/**
* Removes the mnemonic identifier (<code>&</code>) from a string unless
* it's escaped by <code>&&</code> or placed at the end.
*
* @param message the message
*
* @return a message with the mnemonic identifier removed
*/
private static String removeMnemonicAmpersand(String message) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < message.length(); i++) {
char current = message.charAt(i);
if (current != '&' || i == message.length() - 1
|| message.charAt(i + 1) == '&') {
s.append(current);
}
}
return s.toString();
}
} }
/** /**
...@@ -880,10 +1012,13 @@ class PolicyEntry { ...@@ -880,10 +1012,13 @@ class PolicyEntry {
/** /**
* The main window for the PolicyTool * The main window for the PolicyTool
*/ */
class ToolWindow extends Frame { class ToolWindow extends JFrame {
// use serialVersionUID from JDK 1.2.2 for interoperability // use serialVersionUID from JDK 1.2.2 for interoperability
private static final long serialVersionUID = 5682568601210376777L; private static final long serialVersionUID = 5682568601210376777L;
/* ESCAPE key */
static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
/* external paddings */ /* external paddings */
public static final Insets TOP_PADDING = new Insets(25,0,0,0); public static final Insets TOP_PADDING = new Insets(25,0,0,0);
public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0); public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0);
...@@ -891,35 +1026,25 @@ class ToolWindow extends Frame { ...@@ -891,35 +1026,25 @@ class ToolWindow extends Frame {
public static final Insets LR_PADDING = new Insets(0,10,0,10); public static final Insets LR_PADDING = new Insets(0,10,0,10);
public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0); public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0);
public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0); public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0);
public static final Insets LR_TOP_BOTTOM_PADDING = new Insets(15, 4, 15, 4);
public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10); public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10);
public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0); public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0);
public static final Insets R_BOTTOM_PADDING = new Insets(0,0,5,10); public static final Insets R_BOTTOM_PADDING = new Insets(0, 0, 25, 5);
public static final Insets R_PADDING = new Insets(0, 0, 0, 5);
/* buttons and menus */ /* buttons and menus */
public static final String NEW_POLICY_FILE = public static final String NEW_POLICY_FILE = "New";
PolicyTool.rb.getString("New"); public static final String OPEN_POLICY_FILE = "Open";
public static final String OPEN_POLICY_FILE = public static final String SAVE_POLICY_FILE = "Save";
PolicyTool.rb.getString("Open"); public static final String SAVE_AS_POLICY_FILE = "Save.As";
public static final String SAVE_POLICY_FILE = public static final String VIEW_WARNINGS = "View.Warning.Log";
PolicyTool.rb.getString("Save"); public static final String QUIT = "Exit";
public static final String SAVE_AS_POLICY_FILE = public static final String ADD_POLICY_ENTRY = "Add.Policy.Entry";
PolicyTool.rb.getString("Save.As"); public static final String EDIT_POLICY_ENTRY = "Edit.Policy.Entry";
public static final String VIEW_WARNINGS = public static final String REMOVE_POLICY_ENTRY = "Remove.Policy.Entry";
PolicyTool.rb.getString("View.Warning.Log"); public static final String EDIT_KEYSTORE = "Edit";
public static final String QUIT = public static final String ADD_PUBKEY_ALIAS = "Add.Public.Key.Alias";
PolicyTool.rb.getString("Exit"); public static final String REMOVE_PUBKEY_ALIAS = "Remove.Public.Key.Alias";
public static final String ADD_POLICY_ENTRY =
PolicyTool.rb.getString("Add.Policy.Entry");
public static final String EDIT_POLICY_ENTRY =
PolicyTool.rb.getString("Edit.Policy.Entry");
public static final String REMOVE_POLICY_ENTRY =
PolicyTool.rb.getString("Remove.Policy.Entry");
public static final String EDIT_KEYSTORE =
PolicyTool.rb.getString("Edit");
public static final String ADD_PUBKEY_ALIAS =
PolicyTool.rb.getString("Add.Public.Key.Alias");
public static final String REMOVE_PUBKEY_ALIAS =
PolicyTool.rb.getString("Remove.Public.Key.Alias");
/* gridbag index for components in the main window (MW) */ /* gridbag index for components in the main window (MW) */
public static final int MW_FILENAME_LABEL = 0; public static final int MW_FILENAME_LABEL = 0;
...@@ -930,6 +1055,9 @@ class ToolWindow extends Frame { ...@@ -930,6 +1055,9 @@ class ToolWindow extends Frame {
public static final int MW_REMOVE_BUTTON = 2; public static final int MW_REMOVE_BUTTON = 2;
public static final int MW_POLICY_LIST = 3; // follows MW_PANEL public static final int MW_POLICY_LIST = 3; // follows MW_PANEL
/* The preferred height of JTextField should match JComboBox. */
static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;
private PolicyTool tool; private PolicyTool tool;
/** /**
...@@ -939,65 +1067,85 @@ class ToolWindow extends Frame { ...@@ -939,65 +1067,85 @@ class ToolWindow extends Frame {
this.tool = tool; this.tool = tool;
} }
/**
* Don't call getComponent directly on the window
*/
public Component getComponent(int n) {
Component c = getContentPane().getComponent(n);
if (c instanceof JScrollPane) {
c = ((JScrollPane)c).getViewport().getView();
}
return c;
}
/** /**
* Initialize the PolicyTool window with the necessary components * Initialize the PolicyTool window with the necessary components
*/ */
private void initWindow() { private void initWindow() {
// The ToolWindowListener will handle closing the window.
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
// create the top menu bar // create the top menu bar
MenuBar menuBar = new MenuBar(); JMenuBar menuBar = new JMenuBar();
// create a File menu // create a File menu
Menu menu = new Menu(PolicyTool.rb.getString("File")); JMenu menu = new JMenu();
menu.add(NEW_POLICY_FILE); configureButton(menu, "File");
menu.add(OPEN_POLICY_FILE); ActionListener actionListener = new FileMenuListener(tool, this);
menu.add(SAVE_POLICY_FILE); addMenuItem(menu, NEW_POLICY_FILE, actionListener);
menu.add(SAVE_AS_POLICY_FILE); addMenuItem(menu, OPEN_POLICY_FILE, actionListener);
menu.add(VIEW_WARNINGS); addMenuItem(menu, SAVE_POLICY_FILE, actionListener);
menu.add(QUIT); addMenuItem(menu, SAVE_AS_POLICY_FILE, actionListener);
menu.addActionListener(new FileMenuListener(tool, this)); addMenuItem(menu, VIEW_WARNINGS, actionListener);
addMenuItem(menu, QUIT, actionListener);
menuBar.add(menu); menuBar.add(menu);
setMenuBar(menuBar);
// create a KeyStore menu // create a KeyStore menu
menu = new Menu(PolicyTool.rb.getString("KeyStore")); menu = new JMenu();
menu.add(EDIT_KEYSTORE); configureButton(menu, "KeyStore");
menu.addActionListener(new MainWindowListener(tool, this)); actionListener = new MainWindowListener(tool, this);
addMenuItem(menu, EDIT_KEYSTORE, actionListener);
menuBar.add(menu); menuBar.add(menu);
setMenuBar(menuBar); setJMenuBar(menuBar);
// Create some space around components
((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));
// policy entry listing // policy entry listing
Label label = new Label(PolicyTool.rb.getString("Policy.File.")); JLabel label = new JLabel(PolicyTool.getMessage("Policy.File."));
addNewComponent(this, label, MW_FILENAME_LABEL, addNewComponent(this, label, MW_FILENAME_LABEL,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
TOP_BOTTOM_PADDING); LR_TOP_BOTTOM_PADDING);
TextField tf = new TextField(50); JTextField tf = new JTextField(50);
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("Policy.File.")); PolicyTool.getMessage("Policy.File."));
tf.setEditable(false); tf.setEditable(false);
addNewComponent(this, tf, MW_FILENAME_TEXTFIELD, addNewComponent(this, tf, MW_FILENAME_TEXTFIELD,
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
TOP_BOTTOM_PADDING); LR_TOP_BOTTOM_PADDING);
// add ADD/REMOVE/EDIT buttons in a new panel // add ADD/REMOVE/EDIT buttons in a new panel
Panel panel = new Panel(); JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
Button button = new Button(ADD_POLICY_ENTRY); JButton button = new JButton();
configureButton(button, ADD_POLICY_ENTRY);
button.addActionListener(new MainWindowListener(tool, this)); button.addActionListener(new MainWindowListener(tool, this));
addNewComponent(panel, button, MW_ADD_BUTTON, addNewComponent(panel, button, MW_ADD_BUTTON,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
LR_PADDING); LR_PADDING);
button = new Button(EDIT_POLICY_ENTRY); button = new JButton();
configureButton(button, EDIT_POLICY_ENTRY);
button.addActionListener(new MainWindowListener(tool, this)); button.addActionListener(new MainWindowListener(tool, this));
addNewComponent(panel, button, MW_EDIT_BUTTON, addNewComponent(panel, button, MW_EDIT_BUTTON,
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
LR_PADDING); LR_PADDING);
button = new Button(REMOVE_POLICY_ENTRY); button = new JButton();
configureButton(button, REMOVE_POLICY_ENTRY);
button.addActionListener(new MainWindowListener(tool, this)); button.addActionListener(new MainWindowListener(tool, this));
addNewComponent(panel, button, MW_REMOVE_BUTTON, addNewComponent(panel, button, MW_REMOVE_BUTTON,
2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
...@@ -1021,41 +1169,47 @@ class ToolWindow extends Frame { ...@@ -1021,41 +1169,47 @@ class ToolWindow extends Frame {
tool.openPolicy(policyFile); tool.openPolicy(policyFile);
// display the policy entries via the policy list textarea // display the policy entries via the policy list textarea
List list = new List(40, false); DefaultListModel listModel = new DefaultListModel();
list.addActionListener(new PolicyListListener(tool, this)); JList list = new JList(listModel);
list.setVisibleRowCount(15);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addMouseListener(new PolicyListListener(tool, this));
PolicyEntry entries[] = tool.getEntry(); PolicyEntry entries[] = tool.getEntry();
if (entries != null) { if (entries != null) {
for (int i = 0; i < entries.length; i++) for (int i = 0; i < entries.length; i++) {
list.add(entries[i].headerToString()); listModel.addElement(entries[i].headerToString());
}
} }
TextField newFilename = (TextField) JTextField newFilename = (JTextField)
getComponent(MW_FILENAME_TEXTFIELD); getComponent(MW_FILENAME_TEXTFIELD);
newFilename.setText(policyFile); newFilename.setText(policyFile);
initPolicyList(list); initPolicyList(list);
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException fnfe) {
// add blank policy listing // add blank policy listing
List list = new List(40, false); JList list = new JList(new DefaultListModel());
list.addActionListener(new PolicyListListener(tool, this)); list.setVisibleRowCount(15);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addMouseListener(new PolicyListListener(tool, this));
initPolicyList(list); initPolicyList(list);
tool.setPolicyFileName(null); tool.setPolicyFileName(null);
tool.modified = false; tool.modified = false;
setVisible(true);
// just add warning // just add warning
tool.warnings.addElement(fnfe.toString()); tool.warnings.addElement(fnfe.toString());
} catch (Exception e) { } catch (Exception e) {
// add blank policy listing // add blank policy listing
List list = new List(40, false); JList list = new JList(new DefaultListModel());
list.addActionListener(new PolicyListListener(tool, this)); list.setVisibleRowCount(15);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addMouseListener(new PolicyListListener(tool, this));
initPolicyList(list); initPolicyList(list);
tool.setPolicyFileName(null); tool.setPolicyFileName(null);
tool.modified = false; tool.modified = false;
setVisible(true);
// display the error // display the error
MessageFormat form = new MessageFormat(PolicyTool.rb.getString MessageFormat form = new MessageFormat(PolicyTool.getMessage
("Could.not.open.policy.file.policyFile.e.toString.")); ("Could.not.open.policy.file.policyFile.e.toString."));
Object[] source = {policyFile, e.toString()}; Object[] source = {policyFile, e.toString()};
displayErrorDialog(null, form.format(source)); displayErrorDialog(null, form.format(source));
...@@ -1063,13 +1217,68 @@ class ToolWindow extends Frame { ...@@ -1063,13 +1217,68 @@ class ToolWindow extends Frame {
} }
// Platform specific modifier (control / command).
private int shortCutModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
private void addMenuItem(JMenu menu, String key, ActionListener actionListener) {
JMenuItem menuItem = new JMenuItem();
configureButton(menuItem, key);
if (PolicyTool.rb.containsKey(key + ".accelerator")) {
String accelerator = PolicyTool.getMessage(key + ".accelerator");
if (accelerator != null && !accelerator.isEmpty()) {
KeyStroke keyStroke;
if (accelerator.matches("^control .$")) {
// Map "control" key to "command" on MacOS
keyStroke = KeyStroke.getKeyStroke(KeyEvent.getExtendedKeyCodeForChar(accelerator.charAt(8)),
shortCutModifier);
} else {
keyStroke = KeyStroke.getKeyStroke(accelerator);
}
menuItem.setAccelerator(keyStroke);
}
}
menuItem.addActionListener(actionListener);
menu.add(menuItem);
}
static void configureButton(AbstractButton button, String key) {
button.setText(PolicyTool.getMessage(key));
button.setActionCommand(key);
int mnemonicInt = PolicyTool.getMnemonicInt(key);
if (mnemonicInt > 0) {
button.setMnemonic(mnemonicInt);
button.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));
}
}
static void configureLabelFor(JLabel label, JComponent component, String key) {
label.setText(PolicyTool.getMessage(key));
label.setLabelFor(component);
int mnemonicInt = PolicyTool.getMnemonicInt(key);
if (mnemonicInt > 0) {
label.setDisplayedMnemonic(mnemonicInt);
label.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));
}
}
/** /**
* Add a component to the PolicyTool window * Add a component to the PolicyTool window
*/ */
void addNewComponent(Container container, Component component, void addNewComponent(Container container, JComponent component,
int index, int gridx, int gridy, int gridwidth, int gridheight, int index, int gridx, int gridy, int gridwidth, int gridheight,
double weightx, double weighty, int fill, Insets is) { double weightx, double weighty, int fill, Insets is) {
if (container instanceof JFrame) {
container = ((JFrame)container).getContentPane();
} else if (container instanceof JDialog) {
container = ((JDialog)container).getContentPane();
}
// add the component at the specified gridbag index // add the component at the specified gridbag index
container.add(component, index); container.add(component, index);
...@@ -1091,7 +1300,7 @@ class ToolWindow extends Frame { ...@@ -1091,7 +1300,7 @@ class ToolWindow extends Frame {
/** /**
* Add a component to the PolicyTool window without external padding * Add a component to the PolicyTool window without external padding
*/ */
void addNewComponent(Container container, Component component, void addNewComponent(Container container, JComponent component,
int index, int gridx, int gridy, int gridwidth, int gridheight, int index, int gridx, int gridy, int gridwidth, int gridheight,
double weightx, double weighty, int fill) { double weightx, double weighty, int fill) {
...@@ -1106,10 +1315,12 @@ class ToolWindow extends Frame { ...@@ -1106,10 +1315,12 @@ class ToolWindow extends Frame {
* Init the policy_entry_list TEXTAREA component in the * Init the policy_entry_list TEXTAREA component in the
* PolicyTool window * PolicyTool window
*/ */
void initPolicyList(List policyList) { void initPolicyList(JList policyList) {
// add the policy list to the window // add the policy list to the window
addNewComponent(this, policyList, MW_POLICY_LIST, //policyList.setPreferredSize(new Dimension(500, 350));
JScrollPane scrollPane = new JScrollPane(policyList);
addNewComponent(this, scrollPane, MW_POLICY_LIST,
0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH); 0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH);
} }
...@@ -1117,15 +1328,12 @@ class ToolWindow extends Frame { ...@@ -1117,15 +1328,12 @@ class ToolWindow extends Frame {
* Replace the policy_entry_list TEXTAREA component in the * Replace the policy_entry_list TEXTAREA component in the
* PolicyTool window with an updated one. * PolicyTool window with an updated one.
*/ */
void replacePolicyList(List policyList) { void replacePolicyList(JList policyList) {
// remove the original list of Policy Entries // remove the original list of Policy Entries
// and add the new list of entries // and add the new list of entries
List list = (List)getComponent(MW_POLICY_LIST); JList list = (JList)getComponent(MW_POLICY_LIST);
list.removeAll(); list.setModel(policyList.getModel());
String newItems[] = policyList.getItems();
for (int i = 0; i < newItems.length; i++)
list.add(newItems[i]);
} }
/** /**
...@@ -1133,19 +1341,21 @@ class ToolWindow extends Frame { ...@@ -1133,19 +1341,21 @@ class ToolWindow extends Frame {
*/ */
void displayToolWindow(String args[]) { void displayToolWindow(String args[]) {
setTitle(PolicyTool.rb.getString("Policy.Tool")); setTitle(PolicyTool.getMessage("Policy.Tool"));
setResizable(true); setResizable(true);
addWindowListener(new ToolWindowListener(this)); addWindowListener(new ToolWindowListener(tool, this));
setBounds(135, 80, 500, 500); //setBounds(135, 80, 500, 500);
setLayout(new GridBagLayout()); getContentPane().setLayout(new GridBagLayout());
initWindow(); initWindow();
pack();
setLocationRelativeTo(null);
// display it // display it
setVisible(true); setVisible(true);
if (tool.newWarning == true) { if (tool.newWarning == true) {
displayStatusDialog(this, PolicyTool.rb.getString displayStatusDialog(this, PolicyTool.getMessage
("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information.")); ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
} }
} }
...@@ -1155,24 +1365,29 @@ class ToolWindow extends Frame { ...@@ -1155,24 +1365,29 @@ class ToolWindow extends Frame {
*/ */
void displayErrorDialog(Window w, String error) { void displayErrorDialog(Window w, String error) {
ToolDialog ed = new ToolDialog ToolDialog ed = new ToolDialog
(PolicyTool.rb.getString("Error"), tool, this, true); (PolicyTool.getMessage("Error"), tool, this, true);
// find where the PolicyTool gui is // find where the PolicyTool gui is
Point location = ((w == null) ? Point location = ((w == null) ?
getLocationOnScreen() : w.getLocationOnScreen()); getLocationOnScreen() : w.getLocationOnScreen());
ed.setBounds(location.x + 50, location.y + 50, 600, 100); //ed.setBounds(location.x + 50, location.y + 50, 600, 100);
ed.setLayout(new GridBagLayout()); ed.setLayout(new GridBagLayout());
Label label = new Label(error); JLabel label = new JLabel(error);
addNewComponent(ed, label, 0, addNewComponent(ed, label, 0,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
Button okButton = new Button(PolicyTool.rb.getString("OK")); JButton okButton = new JButton(PolicyTool.getMessage("OK"));
okButton.addActionListener(new ErrorOKButtonListener(ed)); ActionListener okListener = new ErrorOKButtonListener(ed);
okButton.addActionListener(okListener);
addNewComponent(ed, okButton, 1, addNewComponent(ed, okButton, 1,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
ed.getRootPane().setDefaultButton(okButton);
ed.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
ed.pack(); ed.pack();
ed.setLocationRelativeTo(w);
ed.setVisible(true); ed.setVisible(true);
} }
...@@ -1191,23 +1406,29 @@ class ToolWindow extends Frame { ...@@ -1191,23 +1406,29 @@ class ToolWindow extends Frame {
*/ */
void displayStatusDialog(Window w, String status) { void displayStatusDialog(Window w, String status) {
ToolDialog sd = new ToolDialog ToolDialog sd = new ToolDialog
(PolicyTool.rb.getString("Status"), tool, this, true); (PolicyTool.getMessage("Status"), tool, this, true);
// find the location of the PolicyTool gui // find the location of the PolicyTool gui
Point location = ((w == null) ? Point location = ((w == null) ?
getLocationOnScreen() : w.getLocationOnScreen()); getLocationOnScreen() : w.getLocationOnScreen());
sd.setBounds(location.x + 50, location.y + 50, 500, 100); //sd.setBounds(location.x + 50, location.y + 50, 500, 100);
sd.setLayout(new GridBagLayout()); sd.setLayout(new GridBagLayout());
Label label = new Label(status); JLabel label = new JLabel(status);
addNewComponent(sd, label, 0, addNewComponent(sd, label, 0,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
Button okButton = new Button(PolicyTool.rb.getString("OK")); JButton okButton = new JButton(PolicyTool.getMessage("OK"));
okButton.addActionListener(new StatusOKButtonListener(sd)); ActionListener okListener = new StatusOKButtonListener(sd);
okButton.addActionListener(okListener);
addNewComponent(sd, okButton, 1, addNewComponent(sd, okButton, 1,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
sd.getRootPane().setDefaultButton(okButton);
sd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
sd.pack(); sd.pack();
sd.setLocationRelativeTo(w);
sd.setVisible(true); sd.setVisible(true);
} }
...@@ -1217,32 +1438,37 @@ class ToolWindow extends Frame { ...@@ -1217,32 +1438,37 @@ class ToolWindow extends Frame {
void displayWarningLog(Window w) { void displayWarningLog(Window w) {
ToolDialog wd = new ToolDialog ToolDialog wd = new ToolDialog
(PolicyTool.rb.getString("Warning"), tool, this, true); (PolicyTool.getMessage("Warning"), tool, this, true);
// find the location of the PolicyTool gui // find the location of the PolicyTool gui
Point location = ((w == null) ? Point location = ((w == null) ?
getLocationOnScreen() : w.getLocationOnScreen()); getLocationOnScreen() : w.getLocationOnScreen());
wd.setBounds(location.x + 50, location.y + 50, 500, 100); //wd.setBounds(location.x + 50, location.y + 50, 500, 100);
wd.setLayout(new GridBagLayout()); wd.setLayout(new GridBagLayout());
TextArea ta = new TextArea(); JTextArea ta = new JTextArea();
ta.setEditable(false); ta.setEditable(false);
for (int i = 0; i < tool.warnings.size(); i++) { for (int i = 0; i < tool.warnings.size(); i++) {
ta.append(tool.warnings.elementAt(i)); ta.append(tool.warnings.elementAt(i));
ta.append(PolicyTool.rb.getString("NEWLINE")); ta.append(PolicyTool.getMessage("NEWLINE"));
} }
addNewComponent(wd, ta, 0, addNewComponent(wd, ta, 0,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
BOTTOM_PADDING); BOTTOM_PADDING);
ta.setFocusable(false); ta.setFocusable(false);
Button okButton = new Button(PolicyTool.rb.getString("OK")); JButton okButton = new JButton(PolicyTool.getMessage("OK"));
okButton.addActionListener(new CancelButtonListener(wd)); ActionListener okListener = new CancelButtonListener(wd);
okButton.addActionListener(okListener);
addNewComponent(wd, okButton, 1, addNewComponent(wd, okButton, 1,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
LR_PADDING); LR_PADDING);
wd.getRootPane().setDefaultButton(okButton);
wd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
wd.pack(); wd.pack();
wd.setLocationRelativeTo(w);
wd.setVisible(true); wd.setVisible(true);
} }
...@@ -1252,22 +1478,27 @@ class ToolWindow extends Frame { ...@@ -1252,22 +1478,27 @@ class ToolWindow extends Frame {
(title, tool, this, true); (title, tool, this, true);
Point location = ((w == null) ? Point location = ((w == null) ?
getLocationOnScreen() : w.getLocationOnScreen()); getLocationOnScreen() : w.getLocationOnScreen());
tw.setBounds(location.x + 75, location.y + 100, 400, 150); //tw.setBounds(location.x + 75, location.y + 100, 400, 150);
tw.setLayout(new GridBagLayout()); tw.setLayout(new GridBagLayout());
TextArea ta = new TextArea(prompt, 10, 50, TextArea.SCROLLBARS_VERTICAL_ONLY); JTextArea ta = new JTextArea(prompt, 10, 50);
ta.setEditable(false); ta.setEditable(false);
addNewComponent(tw, ta, 0, ta.setLineWrap(true);
ta.setWrapStyleWord(true);
JScrollPane scrollPane = new JScrollPane(ta,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
addNewComponent(tw, scrollPane, 0,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
ta.setFocusable(false); ta.setFocusable(false);
Panel panel = new Panel(); JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
// StringBuffer to store button press. Must be final. // StringBuffer to store button press. Must be final.
final StringBuffer chooseResult = new StringBuffer(); final StringBuffer chooseResult = new StringBuffer();
Button button = new Button(yes); JButton button = new JButton(yes);
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
chooseResult.append('Y'); chooseResult.append('Y');
...@@ -1279,7 +1510,7 @@ class ToolWindow extends Frame { ...@@ -1279,7 +1510,7 @@ class ToolWindow extends Frame {
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
LR_PADDING); LR_PADDING);
button = new Button(no); button = new JButton(no);
button.addActionListener(new ActionListener() { button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
chooseResult.append('N'); chooseResult.append('N');
...@@ -1295,6 +1526,7 @@ class ToolWindow extends Frame { ...@@ -1295,6 +1526,7 @@ class ToolWindow extends Frame {
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
tw.pack(); tw.pack();
tw.setLocationRelativeTo(w);
tw.setVisible(true); tw.setVisible(true);
if (chooseResult.length() > 0) { if (chooseResult.length() > 0) {
return chooseResult.charAt(0); return chooseResult.charAt(0);
...@@ -1309,10 +1541,13 @@ class ToolWindow extends Frame { ...@@ -1309,10 +1541,13 @@ class ToolWindow extends Frame {
/** /**
* General dialog window * General dialog window
*/ */
class ToolDialog extends Dialog { class ToolDialog extends JDialog {
// use serialVersionUID from JDK 1.2.2 for interoperability // use serialVersionUID from JDK 1.2.2 for interoperability
private static final long serialVersionUID = -372244357011301190L; private static final long serialVersionUID = -372244357011301190L;
/* ESCAPE key */
static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
/* necessary constants */ /* necessary constants */
public static final int NOACTION = 0; public static final int NOACTION = 0;
public static final int QUIT = 1; public static final int QUIT = 1;
...@@ -1329,22 +1564,22 @@ class ToolDialog extends Dialog { ...@@ -1329,22 +1564,22 @@ class ToolDialog extends Dialog {
/* popup menus */ /* popup menus */
public static final String PERM = public static final String PERM =
PolicyTool.rb.getString PolicyTool.getMessage
("Permission."); ("Permission.");
public static final String PRIN_TYPE = public static final String PRIN_TYPE =
PolicyTool.rb.getString("Principal.Type."); PolicyTool.getMessage("Principal.Type.");
public static final String PRIN_NAME = public static final String PRIN_NAME =
PolicyTool.rb.getString("Principal.Name."); PolicyTool.getMessage("Principal.Name.");
/* more popu menus */ /* more popu menus */
public static final String PERM_NAME = public static final String PERM_NAME =
PolicyTool.rb.getString PolicyTool.getMessage
("Target.Name."); ("Target.Name.");
/* and more popup menus */ /* and more popup menus */
public static final String PERM_ACTIONS = public static final String PERM_ACTIONS =
PolicyTool.rb.getString PolicyTool.getMessage
("Actions."); ("Actions.");
/* gridbag index for display PolicyEntry (PE) components */ /* gridbag index for display PolicyEntry (PE) components */
...@@ -1431,6 +1666,9 @@ class ToolDialog extends Dialog { ...@@ -1431,6 +1666,9 @@ class ToolDialog extends Dialog {
private static final int PRINCIPAL_TYPE = 4; private static final int PRINCIPAL_TYPE = 4;
private static final int PRINCIPAL_NAME = 5; private static final int PRINCIPAL_NAME = 5;
/* The preferred height of JTextField should match JComboBox. */
static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;
public static java.util.ArrayList<Perm> PERM_ARRAY; public static java.util.ArrayList<Perm> PERM_ARRAY;
public static java.util.ArrayList<Prin> PRIN_ARRAY; public static java.util.ArrayList<Prin> PRIN_ARRAY;
PolicyTool tool; PolicyTool tool;
...@@ -1480,6 +1718,20 @@ class ToolDialog extends Dialog { ...@@ -1480,6 +1718,20 @@ class ToolDialog extends Dialog {
this.tool = tool; this.tool = tool;
this.tw = tw; this.tw = tw;
addWindowListener(new ChildWindowListener(this)); addWindowListener(new ChildWindowListener(this));
// Create some space around components
((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));
}
/**
* Don't call getComponent directly on the window
*/
public Component getComponent(int n) {
Component c = getContentPane().getComponent(n);
if (c instanceof JScrollPane) {
c = ((JScrollPane)c).getViewport().getView();
}
return c;
} }
/** /**
...@@ -1540,25 +1792,25 @@ class ToolDialog extends Dialog { ...@@ -1540,25 +1792,25 @@ class ToolDialog extends Dialog {
PolicyEntry entries[] = null; PolicyEntry entries[] = null;
TaggedList prinList = new TaggedList(3, false); TaggedList prinList = new TaggedList(3, false);
prinList.getAccessibleContext().setAccessibleName( prinList.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("Principal.List")); PolicyTool.getMessage("Principal.List"));
prinList.addActionListener prinList.addMouseListener
(new EditPrinButtonListener(tool, tw, this, edit)); (new EditPrinButtonListener(tool, tw, this, edit));
TaggedList permList = new TaggedList(10, false); TaggedList permList = new TaggedList(10, false);
permList.getAccessibleContext().setAccessibleName( permList.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("Permission.List")); PolicyTool.getMessage("Permission.List"));
permList.addActionListener permList.addMouseListener
(new EditPermButtonListener(tool, tw, this, edit)); (new EditPermButtonListener(tool, tw, this, edit));
// find where the PolicyTool gui is // find where the PolicyTool gui is
Point location = tw.getLocationOnScreen(); Point location = tw.getLocationOnScreen();
setBounds(location.x + 75, location.y + 200, 650, 500); //setBounds(location.x + 75, location.y + 200, 650, 500);
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
setResizable(true); setResizable(true);
if (edit) { if (edit) {
// get the selected item // get the selected item
entries = tool.getEntry(); entries = tool.getEntry();
List policyList = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
listIndex = policyList.getSelectedIndex(); listIndex = policyList.getSelectedIndex();
// get principal list // get principal list
...@@ -1582,82 +1834,97 @@ class ToolDialog extends Dialog { ...@@ -1582,82 +1834,97 @@ class ToolDialog extends Dialog {
} }
// codebase label and textfield // codebase label and textfield
Label label = new Label(PolicyTool.rb.getString("CodeBase.")); JLabel label = new JLabel();
tw.addNewComponent(this, label, PE_CODEBASE_LABEL, tw.addNewComponent(this, label, PE_CODEBASE_LABEL,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
TextField tf; ToolWindow.R_PADDING);
JTextField tf;
tf = (edit ? tf = (edit ?
new TextField(entries[listIndex].getGrantEntry().codeBase, 60) : new JTextField(entries[listIndex].getGrantEntry().codeBase) :
new TextField(60)); new JTextField());
ToolWindow.configureLabelFor(label, tf, "CodeBase.");
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("Code.Base")); PolicyTool.getMessage("Code.Base"));
tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD, tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD,
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);
// signedby label and textfield // signedby label and textfield
label = new Label(PolicyTool.rb.getString("SignedBy.")); label = new JLabel();
tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL, tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.R_PADDING);
tf = (edit ? tf = (edit ?
new TextField(entries[listIndex].getGrantEntry().signedBy, 60) : new JTextField(entries[listIndex].getGrantEntry().signedBy) :
new TextField(60)); new JTextField());
ToolWindow.configureLabelFor(label, tf, "SignedBy.");
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("Signed.By.")); PolicyTool.getMessage("Signed.By."));
tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD, tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD,
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);
// panel for principal buttons // panel for principal buttons
Panel panel = new Panel(); JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
Button button = new Button(PolicyTool.rb.getString("Add.Principal")); JButton button = new JButton();
ToolWindow.configureButton(button, "Add.Principal");
button.addActionListener button.addActionListener
(new AddPrinButtonListener(tool, tw, this, edit)); (new AddPrinButtonListener(tool, tw, this, edit));
tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON, tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON,
0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
button = new Button(PolicyTool.rb.getString("Edit.Principal")); button = new JButton();
ToolWindow.configureButton(button, "Edit.Principal");
button.addActionListener(new EditPrinButtonListener button.addActionListener(new EditPrinButtonListener
(tool, tw, this, edit)); (tool, tw, this, edit));
tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON, tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON,
1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
button = new Button(PolicyTool.rb.getString("Remove.Principal")); button = new JButton();
ToolWindow.configureButton(button, "Remove.Principal");
button.addActionListener(new RemovePrinButtonListener button.addActionListener(new RemovePrinButtonListener
(tool, tw, this, edit)); (tool, tw, this, edit));
tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON, tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON,
2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
tw.addNewComponent(this, panel, PE_PANEL0, tw.addNewComponent(this, panel, PE_PANEL0,
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL); 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,
ToolWindow.LITE_BOTTOM_PADDING);
// principal label and list // principal label and list
label = new Label(PolicyTool.rb.getString("Principals.")); label = new JLabel();
tw.addNewComponent(this, label, PE_PRIN_LABEL, tw.addNewComponent(this, label, PE_PRIN_LABEL,
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.R_BOTTOM_PADDING);
tw.addNewComponent(this, prinList, PE_PRIN_LIST, JScrollPane scrollPane = new JScrollPane(prinList);
1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, ToolWindow.configureLabelFor(label, scrollPane, "Principals.");
tw.addNewComponent(this, scrollPane, PE_PRIN_LIST,
1, 3, 3, 1, 0.0, prinList.getVisibleRowCount(), GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.BOTTOM_PADDING);
// panel for permission buttons // panel for permission buttons
panel = new Panel(); panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
button = new Button(PolicyTool.rb.getString(".Add.Permission")); button = new JButton();
ToolWindow.configureButton(button, ".Add.Permission");
button.addActionListener(new AddPermButtonListener button.addActionListener(new AddPermButtonListener
(tool, tw, this, edit)); (tool, tw, this, edit));
tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON, tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON,
0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
button = new Button(PolicyTool.rb.getString(".Edit.Permission")); button = new JButton();
ToolWindow.configureButton(button, ".Edit.Permission");
button.addActionListener(new EditPermButtonListener button.addActionListener(new EditPermButtonListener
(tool, tw, this, edit)); (tool, tw, this, edit));
tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON, tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON,
1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
button = new Button(PolicyTool.rb.getString("Remove.Permission")); button = new JButton();
ToolWindow.configureButton(button, "Remove.Permission");
button.addActionListener(new RemovePermButtonListener button.addActionListener(new RemovePermButtonListener
(tool, tw, this, edit)); (tool, tw, this, edit));
tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON, tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON,
...@@ -1668,27 +1935,29 @@ class ToolDialog extends Dialog { ...@@ -1668,27 +1935,29 @@ class ToolDialog extends Dialog {
ToolWindow.LITE_BOTTOM_PADDING); ToolWindow.LITE_BOTTOM_PADDING);
// permission list // permission list
tw.addNewComponent(this, permList, PE_PERM_LIST, scrollPane = new JScrollPane(permList);
0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, tw.addNewComponent(this, scrollPane, PE_PERM_LIST,
0, 5, 3, 1, 0.0, permList.getVisibleRowCount(), GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.BOTTOM_PADDING);
// panel for Done and Cancel buttons // panel for Done and Cancel buttons
panel = new Panel(); panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
// Done Button // Done Button
button = new Button(PolicyTool.rb.getString("Done")); JButton okButton = new JButton(PolicyTool.getMessage("Done"));
button.addActionListener okButton.addActionListener
(new AddEntryDoneButtonListener(tool, tw, this, edit)); (new AddEntryDoneButtonListener(tool, tw, this, edit));
tw.addNewComponent(panel, button, PE_DONE_BUTTON, tw.addNewComponent(panel, okButton, PE_DONE_BUTTON,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
ToolWindow.LR_PADDING); ToolWindow.LR_PADDING);
// Cancel Button // Cancel Button
button = new Button(PolicyTool.rb.getString("Cancel")); JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
button.addActionListener(new CancelButtonListener(this)); ActionListener cancelListener = new CancelButtonListener(this);
tw.addNewComponent(panel, button, PE_CANCEL_BUTTON, cancelButton.addActionListener(cancelListener);
tw.addNewComponent(panel, cancelButton, PE_CANCEL_BUTTON,
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
ToolWindow.LR_PADDING); ToolWindow.LR_PADDING);
...@@ -1696,6 +1965,11 @@ class ToolDialog extends Dialog { ...@@ -1696,6 +1965,11 @@ class ToolDialog extends Dialog {
tw.addNewComponent(this, panel, PE_PANEL2, tw.addNewComponent(this, panel, PE_PANEL2,
0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); 0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
getRootPane().setDefaultButton(okButton);
getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
pack();
setLocationRelativeTo(tw);
setVisible(true); setVisible(true);
} }
...@@ -1710,13 +1984,13 @@ class ToolDialog extends Dialog { ...@@ -1710,13 +1984,13 @@ class ToolDialog extends Dialog {
CertificateException, IOException, Exception { CertificateException, IOException, Exception {
// get the Codebase // get the Codebase
TextField tf = (TextField)getComponent(PE_CODEBASE_TEXTFIELD); JTextField tf = (JTextField)getComponent(PE_CODEBASE_TEXTFIELD);
String codebase = null; String codebase = null;
if (tf.getText().trim().equals("") == false) if (tf.getText().trim().equals("") == false)
codebase = new String(tf.getText().trim()); codebase = new String(tf.getText().trim());
// get the SignedBy // get the SignedBy
tf = (TextField)getComponent(PE_SIGNEDBY_TEXTFIELD); tf = (JTextField)getComponent(PE_SIGNEDBY_TEXTFIELD);
String signedby = null; String signedby = null;
if (tf.getText().trim().equals("") == false) if (tf.getText().trim().equals("") == false)
signedby = new String(tf.getText().trim()); signedby = new String(tf.getText().trim());
...@@ -1728,7 +2002,7 @@ class ToolDialog extends Dialog { ...@@ -1728,7 +2002,7 @@ class ToolDialog extends Dialog {
// get the new Principals // get the new Principals
LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>(); LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>();
TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST); TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);
for (int i = 0; i < prinList.getItemCount(); i++) { for (int i = 0; i < prinList.getModel().getSize(); i++) {
prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i)); prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i));
} }
ge.principals = prins; ge.principals = prins;
...@@ -1736,7 +2010,7 @@ class ToolDialog extends Dialog { ...@@ -1736,7 +2010,7 @@ class ToolDialog extends Dialog {
// get the new Permissions // get the new Permissions
Vector<PolicyParser.PermissionEntry> perms = new Vector<>(); Vector<PolicyParser.PermissionEntry> perms = new Vector<>();
TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST); TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);
for (int i = 0; i < permList.getItemCount(); i++) { for (int i = 0; i < permList.getModel().getSize(); i++) {
perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i)); perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i));
} }
ge.permissionEntries = perms; ge.permissionEntries = perms;
...@@ -1754,78 +2028,89 @@ class ToolDialog extends Dialog { ...@@ -1754,78 +2028,89 @@ class ToolDialog extends Dialog {
// find where the PolicyTool gui is // find where the PolicyTool gui is
Point location = tw.getLocationOnScreen(); Point location = tw.getLocationOnScreen();
setBounds(location.x + 25, location.y + 100, 500, 300); //setBounds(location.x + 25, location.y + 100, 500, 300);
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
if (mode == EDIT_KEYSTORE) { if (mode == EDIT_KEYSTORE) {
// KeyStore label and textfield // KeyStore label and textfield
Label label = new Label JLabel label = new JLabel();
(PolicyTool.rb.getString("KeyStore.URL."));
tw.addNewComponent(this, label, KSD_NAME_LABEL, tw.addNewComponent(this, label, KSD_NAME_LABEL,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.R_BOTTOM_PADDING);
TextField tf = new TextField(tool.getKeyStoreName(), 30); JTextField tf = new JTextField(tool.getKeyStoreName(), 30);
ToolWindow.configureLabelFor(label, tf, "KeyStore.URL.");
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
// URL to U R L, so that accessibility reader will pronounce well // URL to U R L, so that accessibility reader will pronounce well
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("KeyStore.U.R.L.")); PolicyTool.getMessage("KeyStore.U.R.L."));
tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD, tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD,
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.BOTTOM_PADDING);
// KeyStore type and textfield // KeyStore type and textfield
label = new Label(PolicyTool.rb.getString("KeyStore.Type.")); label = new JLabel();
tw.addNewComponent(this, label, KSD_TYPE_LABEL, tw.addNewComponent(this, label, KSD_TYPE_LABEL,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.R_BOTTOM_PADDING);
tf = new TextField(tool.getKeyStoreType(), 30); tf = new JTextField(tool.getKeyStoreType(), 30);
ToolWindow.configureLabelFor(label, tf, "KeyStore.Type.");
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("KeyStore.Type.")); PolicyTool.getMessage("KeyStore.Type."));
tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD, tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD,
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.BOTTOM_PADDING);
// KeyStore provider and textfield // KeyStore provider and textfield
label = new Label(PolicyTool.rb.getString label = new JLabel();
("KeyStore.Provider."));
tw.addNewComponent(this, label, KSD_PROVIDER_LABEL, tw.addNewComponent(this, label, KSD_PROVIDER_LABEL,
0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.R_BOTTOM_PADDING);
tf = new TextField(tool.getKeyStoreProvider(), 30); tf = new JTextField(tool.getKeyStoreProvider(), 30);
ToolWindow.configureLabelFor(label, tf, "KeyStore.Provider.");
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("KeyStore.Provider.")); PolicyTool.getMessage("KeyStore.Provider."));
tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD, tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD,
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.BOTTOM_PADDING);
// KeyStore password URL and textfield // KeyStore password URL and textfield
label = new Label(PolicyTool.rb.getString label = new JLabel();
("KeyStore.Password.URL."));
tw.addNewComponent(this, label, KSD_PWD_URL_LABEL, tw.addNewComponent(this, label, KSD_PWD_URL_LABEL,
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.R_BOTTOM_PADDING);
tf = new TextField(tool.getKeyStorePwdURL(), 30); tf = new JTextField(tool.getKeyStorePwdURL(), 30);
ToolWindow.configureLabelFor(label, tf, "KeyStore.Password.URL.");
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("KeyStore.Password.U.R.L.")); PolicyTool.getMessage("KeyStore.Password.U.R.L."));
tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD, tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD,
1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.BOTTOM_PADDING);
// OK button // OK button
Button okButton = new Button(PolicyTool.rb.getString("OK")); JButton okButton = new JButton(PolicyTool.getMessage("OK"));
okButton.addActionListener okButton.addActionListener
(new ChangeKeyStoreOKButtonListener(tool, tw, this)); (new ChangeKeyStoreOKButtonListener(tool, tw, this));
tw.addNewComponent(this, okButton, KSD_OK_BUTTON, tw.addNewComponent(this, okButton, KSD_OK_BUTTON,
0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
// cancel button // cancel button
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
cancelButton.addActionListener(new CancelButtonListener(this)); ActionListener cancelListener = new CancelButtonListener(this);
cancelButton.addActionListener(cancelListener);
tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON, tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON,
1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
getRootPane().setDefaultButton(okButton);
getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
} }
pack();
setLocationRelativeTo(tw);
setVisible(true); setVisible(true);
} }
...@@ -1851,75 +2136,78 @@ class ToolDialog extends Dialog { ...@@ -1851,75 +2136,78 @@ class ToolDialog extends Dialog {
} }
ToolDialog newTD = new ToolDialog ToolDialog newTD = new ToolDialog
(PolicyTool.rb.getString("Principals"), tool, tw, true); (PolicyTool.getMessage("Principals"), tool, tw, true);
newTD.addWindowListener(new ChildWindowListener(newTD)); newTD.addWindowListener(new ChildWindowListener(newTD));
// find where the PolicyTool gui is // find where the PolicyTool gui is
Point location = getLocationOnScreen(); Point location = getLocationOnScreen();
newTD.setBounds(location.x + 50, location.y + 100, 650, 190); //newTD.setBounds(location.x + 50, location.y + 100, 650, 190);
newTD.setLayout(new GridBagLayout()); newTD.setLayout(new GridBagLayout());
newTD.setResizable(true); newTD.setResizable(true);
// description label // description label
Label label = (edit ? JLabel label = (edit ?
new Label(PolicyTool.rb.getString(".Edit.Principal.")) : new JLabel(PolicyTool.getMessage(".Edit.Principal.")) :
new Label(PolicyTool.rb.getString(".Add.New.Principal."))); new JLabel(PolicyTool.getMessage(".Add.New.Principal.")));
tw.addNewComponent(newTD, label, PRD_DESC_LABEL, tw.addNewComponent(newTD, label, PRD_DESC_LABEL,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.TOP_BOTTOM_PADDING); ToolWindow.TOP_BOTTOM_PADDING);
// principal choice // principal choice
Choice choice = new Choice(); JComboBox choice = new JComboBox();
choice.add(PRIN_TYPE); choice.addItem(PRIN_TYPE);
choice.getAccessibleContext().setAccessibleName(PRIN_TYPE); choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
for (int i = 0; i < PRIN_ARRAY.size(); i++) { for (int i = 0; i < PRIN_ARRAY.size(); i++) {
Prin next = PRIN_ARRAY.get(i); Prin next = PRIN_ARRAY.get(i);
choice.add(next.CLASS); choice.addItem(next.CLASS);
} }
choice.addItemListener(new PrincipalTypeMenuListener(newTD));
if (edit) { if (edit) {
if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals
(editMe.getPrincipalClass())) { (editMe.getPrincipalClass())) {
choice.select(PRIN_TYPE); choice.setSelectedItem(PRIN_TYPE);
} else { } else {
Prin inputPrin = getPrin(editMe.getPrincipalClass(), true); Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);
if (inputPrin != null) { if (inputPrin != null) {
choice.select(inputPrin.CLASS); choice.setSelectedItem(inputPrin.CLASS);
} }
} }
} }
// Add listener after selected item is set
choice.addItemListener(new PrincipalTypeMenuListener(newTD));
tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE, tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_PADDING);
// principal textfield // principal textfield
TextField tf; JTextField tf;
tf = (edit ? tf = (edit ?
new TextField(editMe.getDisplayClass(), 30) : new JTextField(editMe.getDisplayClass(), 30) :
new TextField(30)); new JTextField(30));
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName(PRIN_TYPE); tf.getAccessibleContext().setAccessibleName(PRIN_TYPE);
tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD, tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD,
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_PADDING);
// name label and textfield // name label and textfield
label = new Label(PRIN_NAME); label = new JLabel(PRIN_NAME);
tf = (edit ? tf = (edit ?
new TextField(editMe.getDisplayName(), 40) : new JTextField(editMe.getDisplayName(), 40) :
new TextField(40)); new JTextField(40));
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName(PRIN_NAME); tf.getAccessibleContext().setAccessibleName(PRIN_NAME);
tw.addNewComponent(newTD, label, PRD_NAME_LABEL, tw.addNewComponent(newTD, label, PRD_NAME_LABEL,
0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_PADDING);
tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD, tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD,
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_PADDING);
// OK button // OK button
Button okButton = new Button(PolicyTool.rb.getString("OK")); JButton okButton = new JButton(PolicyTool.getMessage("OK"));
okButton.addActionListener( okButton.addActionListener(
new NewPolicyPrinOKButtonListener new NewPolicyPrinOKButtonListener
(tool, tw, this, newTD, edit)); (tool, tw, this, newTD, edit));
...@@ -1927,12 +2215,18 @@ class ToolDialog extends Dialog { ...@@ -1927,12 +2215,18 @@ class ToolDialog extends Dialog {
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
ToolWindow.TOP_BOTTOM_PADDING); ToolWindow.TOP_BOTTOM_PADDING);
// cancel button // cancel button
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
cancelButton.addActionListener(new CancelButtonListener(newTD)); ActionListener cancelListener = new CancelButtonListener(newTD);
cancelButton.addActionListener(cancelListener);
tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON, tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON,
1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
ToolWindow.TOP_BOTTOM_PADDING); ToolWindow.TOP_BOTTOM_PADDING);
newTD.getRootPane().setDefaultButton(okButton);
newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
newTD.pack();
newTD.setLocationRelativeTo(tw);
newTD.setVisible(true); newTD.setVisible(true);
} }
...@@ -1958,98 +2252,102 @@ class ToolDialog extends Dialog { ...@@ -1958,98 +2252,102 @@ class ToolDialog extends Dialog {
} }
ToolDialog newTD = new ToolDialog ToolDialog newTD = new ToolDialog
(PolicyTool.rb.getString("Permissions"), tool, tw, true); (PolicyTool.getMessage("Permissions"), tool, tw, true);
newTD.addWindowListener(new ChildWindowListener(newTD)); newTD.addWindowListener(new ChildWindowListener(newTD));
// find where the PolicyTool gui is // find where the PolicyTool gui is
Point location = getLocationOnScreen(); Point location = getLocationOnScreen();
newTD.setBounds(location.x + 50, location.y + 100, 700, 250); //newTD.setBounds(location.x + 50, location.y + 100, 700, 250);
newTD.setLayout(new GridBagLayout()); newTD.setLayout(new GridBagLayout());
newTD.setResizable(true); newTD.setResizable(true);
// description label // description label
Label label = (edit ? JLabel label = (edit ?
new Label(PolicyTool.rb.getString(".Edit.Permission.")) : new JLabel(PolicyTool.getMessage(".Edit.Permission.")) :
new Label(PolicyTool.rb.getString(".Add.New.Permission."))); new JLabel(PolicyTool.getMessage(".Add.New.Permission.")));
tw.addNewComponent(newTD, label, PD_DESC_LABEL, tw.addNewComponent(newTD, label, PD_DESC_LABEL,
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.TOP_BOTTOM_PADDING); ToolWindow.TOP_BOTTOM_PADDING);
// permission choice (added in alphabetical order) // permission choice (added in alphabetical order)
Choice choice = new Choice(); JComboBox choice = new JComboBox();
choice.add(PERM); choice.addItem(PERM);
choice.getAccessibleContext().setAccessibleName(PERM); choice.getAccessibleContext().setAccessibleName(PERM);
for (int i = 0; i < PERM_ARRAY.size(); i++) { for (int i = 0; i < PERM_ARRAY.size(); i++) {
Perm next = PERM_ARRAY.get(i); Perm next = PERM_ARRAY.get(i);
choice.add(next.CLASS); choice.addItem(next.CLASS);
} }
choice.addItemListener(new PermissionMenuListener(newTD));
tw.addNewComponent(newTD, choice, PD_PERM_CHOICE, tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
// permission textfield // permission textfield
TextField tf; JTextField tf;
tf = (edit ? new TextField(editMe.permission, 30) : new TextField(30)); tf = (edit ? new JTextField(editMe.permission, 30) : new JTextField(30));
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName(PERM); tf.getAccessibleContext().setAccessibleName(PERM);
if (edit) { if (edit) {
Perm inputPerm = getPerm(editMe.permission, true); Perm inputPerm = getPerm(editMe.permission, true);
if (inputPerm != null) { if (inputPerm != null) {
choice.select(inputPerm.CLASS); choice.setSelectedItem(inputPerm.CLASS);
} }
} }
tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD, tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
choice.addItemListener(new PermissionMenuListener(newTD));
// name label and textfield // name label and textfield
choice = new Choice(); choice = new JComboBox();
choice.add(PERM_NAME); choice.addItem(PERM_NAME);
choice.getAccessibleContext().setAccessibleName(PERM_NAME); choice.getAccessibleContext().setAccessibleName(PERM_NAME);
choice.addItemListener(new PermissionNameMenuListener(newTD)); tf = (edit ? new JTextField(editMe.name, 40) : new JTextField(40));
tf = (edit ? new TextField(editMe.name, 40) : new TextField(40)); tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName(PERM_NAME); tf.getAccessibleContext().setAccessibleName(PERM_NAME);
if (edit) { if (edit) {
setPermissionNames(getPerm(editMe.permission, true), choice, tf); setPermissionNames(getPerm(editMe.permission, true), choice, tf);
} }
tw.addNewComponent(newTD, choice, PD_NAME_CHOICE, tw.addNewComponent(newTD, choice, PD_NAME_CHOICE,
0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD, tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD,
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
choice.addItemListener(new PermissionNameMenuListener(newTD));
// actions label and textfield // actions label and textfield
choice = new Choice(); choice = new JComboBox();
choice.add(PERM_ACTIONS); choice.addItem(PERM_ACTIONS);
choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS); choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
choice.addItemListener(new PermissionActionsMenuListener(newTD)); tf = (edit ? new JTextField(editMe.action, 40) : new JTextField(40));
tf = (edit ? new TextField(editMe.action, 40) : new TextField(40)); tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS); tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
if (edit) { if (edit) {
setPermissionActions(getPerm(editMe.permission, true), choice, tf); setPermissionActions(getPerm(editMe.permission, true), choice, tf);
} }
tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE, tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE,
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD, tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD,
1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
choice.addItemListener(new PermissionActionsMenuListener(newTD));
// signedby label and textfield // signedby label and textfield
label = new Label(PolicyTool.rb.getString("Signed.By.")); label = new JLabel(PolicyTool.getMessage("Signed.By."));
tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL, tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL,
0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
tf = (edit ? new TextField(editMe.signedBy, 40) : new TextField(40)); tf = (edit ? new JTextField(editMe.signedBy, 40) : new JTextField(40));
tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
tf.getAccessibleContext().setAccessibleName( tf.getAccessibleContext().setAccessibleName(
PolicyTool.rb.getString("Signed.By.")); PolicyTool.getMessage("Signed.By."));
tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD, tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD,
1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, 1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.LR_PADDING); ToolWindow.LR_BOTTOM_PADDING);
// OK button // OK button
Button okButton = new Button(PolicyTool.rb.getString("OK")); JButton okButton = new JButton(PolicyTool.getMessage("OK"));
okButton.addActionListener( okButton.addActionListener(
new NewPolicyPermOKButtonListener new NewPolicyPermOKButtonListener
(tool, tw, this, newTD, edit)); (tool, tw, this, newTD, edit));
...@@ -2058,12 +2356,18 @@ class ToolDialog extends Dialog { ...@@ -2058,12 +2356,18 @@ class ToolDialog extends Dialog {
ToolWindow.TOP_BOTTOM_PADDING); ToolWindow.TOP_BOTTOM_PADDING);
// cancel button // cancel button
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
cancelButton.addActionListener(new CancelButtonListener(newTD)); ActionListener cancelListener = new CancelButtonListener(newTD);
cancelButton.addActionListener(cancelListener);
tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON, tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON,
1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
ToolWindow.TOP_BOTTOM_PADDING); ToolWindow.TOP_BOTTOM_PADDING);
newTD.getRootPane().setDefaultButton(okButton);
newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
newTD.pack();
newTD.setLocationRelativeTo(tw);
newTD.setVisible(true); newTD.setVisible(true);
} }
...@@ -2072,9 +2376,9 @@ class ToolDialog extends Dialog { ...@@ -2072,9 +2376,9 @@ class ToolDialog extends Dialog {
*/ */
PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception { PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception {
TextField tf = (TextField)getComponent(PRD_PRIN_TEXTFIELD); JTextField tf = (JTextField)getComponent(PRD_PRIN_TEXTFIELD);
String pclass = new String(tf.getText().trim()); String pclass = new String(tf.getText().trim());
tf = (TextField)getComponent(PRD_NAME_TEXTFIELD); tf = (JTextField)getComponent(PRD_NAME_TEXTFIELD);
String pname = new String(tf.getText().trim()); String pname = new String(tf.getText().trim());
if (pclass.equals("*")) { if (pclass.equals("*")) {
pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS; pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS;
...@@ -2088,10 +2392,10 @@ class ToolDialog extends Dialog { ...@@ -2088,10 +2392,10 @@ class ToolDialog extends Dialog {
if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) && if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) &&
(!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) { (!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) {
throw new Exception throw new Exception
(PolicyTool.rb.getString("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name")); (PolicyTool.getMessage("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name"));
} else if (pname.equals("")) { } else if (pname.equals("")) {
throw new Exception throw new Exception
(PolicyTool.rb.getString("Cannot.Specify.Principal.without.a.Name")); (PolicyTool.getMessage("Cannot.Specify.Principal.without.a.Name"));
} else if (pclass.equals("")) { } else if (pclass.equals("")) {
// make this consistent with what PolicyParser does // make this consistent with what PolicyParser does
// when it sees an empty principal class // when it sees an empty principal class
...@@ -2130,15 +2434,15 @@ class ToolDialog extends Dialog { ...@@ -2130,15 +2434,15 @@ class ToolDialog extends Dialog {
*/ */
PolicyParser.PermissionEntry getPermFromDialog() { PolicyParser.PermissionEntry getPermFromDialog() {
TextField tf = (TextField)getComponent(PD_PERM_TEXTFIELD); JTextField tf = (JTextField)getComponent(PD_PERM_TEXTFIELD);
String permission = new String(tf.getText().trim()); String permission = new String(tf.getText().trim());
tf = (TextField)getComponent(PD_NAME_TEXTFIELD); tf = (JTextField)getComponent(PD_NAME_TEXTFIELD);
String name = null; String name = null;
if (tf.getText().trim().equals("") == false) if (tf.getText().trim().equals("") == false)
name = new String(tf.getText().trim()); name = new String(tf.getText().trim());
if (permission.equals("") || if (permission.equals("") ||
(!permission.equals(ALL_PERM_CLASS) && name == null)) { (!permission.equals(ALL_PERM_CLASS) && name == null)) {
throw new InvalidParameterException(PolicyTool.rb.getString throw new InvalidParameterException(PolicyTool.getMessage
("Permission.and.Target.Name.must.have.a.value")); ("Permission.and.Target.Name.must.have.a.value"));
} }
...@@ -2154,11 +2458,11 @@ class ToolDialog extends Dialog { ...@@ -2154,11 +2458,11 @@ class ToolDialog extends Dialog {
if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) { if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {
char result = tw.displayYesNoDialog(this, char result = tw.displayYesNoDialog(this,
PolicyTool.rb.getString("Warning"), PolicyTool.getMessage("Warning"),
PolicyTool.rb.getString( PolicyTool.getMessage(
"Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"), "Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"),
PolicyTool.rb.getString("Retain"), PolicyTool.getMessage("Retain"),
PolicyTool.rb.getString("Edit") PolicyTool.getMessage("Edit")
); );
if (result != 'Y') { if (result != 'Y') {
// an invisible exception // an invisible exception
...@@ -2166,13 +2470,13 @@ class ToolDialog extends Dialog { ...@@ -2166,13 +2470,13 @@ class ToolDialog extends Dialog {
} }
} }
// get the Actions // get the Actions
tf = (TextField)getComponent(PD_ACTIONS_TEXTFIELD); tf = (JTextField)getComponent(PD_ACTIONS_TEXTFIELD);
String actions = null; String actions = null;
if (tf.getText().trim().equals("") == false) if (tf.getText().trim().equals("") == false)
actions = new String(tf.getText().trim()); actions = new String(tf.getText().trim());
// get the Signed By // get the Signed By
tf = (TextField)getComponent(PD_SIGNEDBY_TEXTFIELD); tf = (JTextField)getComponent(PD_SIGNEDBY_TEXTFIELD);
String signedBy = null; String signedBy = null;
if (tf.getText().trim().equals("") == false) if (tf.getText().trim().equals("") == false)
signedBy = new String(tf.getText().trim()); signedBy = new String(tf.getText().trim());
...@@ -2189,7 +2493,7 @@ class ToolDialog extends Dialog { ...@@ -2189,7 +2493,7 @@ class ToolDialog extends Dialog {
PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
if (pubKey == null) { if (pubKey == null) {
MessageFormat form = new MessageFormat MessageFormat form = new MessageFormat
(PolicyTool.rb.getString (PolicyTool.getMessage
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
Object[] source = {signers[i]}; Object[] source = {signers[i]};
tool.warnings.addElement(form.format(source)); tool.warnings.addElement(form.format(source));
...@@ -2209,27 +2513,27 @@ class ToolDialog extends Dialog { ...@@ -2209,27 +2513,27 @@ class ToolDialog extends Dialog {
void displayConfirmRemovePolicyEntry() { void displayConfirmRemovePolicyEntry() {
// find the entry to be removed // find the entry to be removed
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
int index = list.getSelectedIndex(); int index = list.getSelectedIndex();
PolicyEntry entries[] = tool.getEntry(); PolicyEntry entries[] = tool.getEntry();
// find where the PolicyTool gui is // find where the PolicyTool gui is
Point location = tw.getLocationOnScreen(); Point location = tw.getLocationOnScreen();
setBounds(location.x + 25, location.y + 100, 600, 400); //setBounds(location.x + 25, location.y + 100, 600, 400);
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
// ask the user do they really want to do this? // ask the user do they really want to do this?
Label label = new Label JLabel label = new JLabel
(PolicyTool.rb.getString("Remove.this.Policy.Entry.")); (PolicyTool.getMessage("Remove.this.Policy.Entry."));
tw.addNewComponent(this, label, CRPE_LABEL1, tw.addNewComponent(this, label, CRPE_LABEL1,
0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.BOTTOM_PADDING); ToolWindow.BOTTOM_PADDING);
// display the policy entry // display the policy entry
label = new Label(entries[index].codebaseToString()); label = new JLabel(entries[index].codebaseToString());
tw.addNewComponent(this, label, CRPE_LABEL2, tw.addNewComponent(this, label, CRPE_LABEL2,
0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
label = new Label(entries[index].principalsToString().trim()); label = new JLabel(entries[index].principalsToString().trim());
tw.addNewComponent(this, label, CRPE_LABEL2+1, tw.addNewComponent(this, label, CRPE_LABEL2+1,
0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
Vector<PolicyParser.PermissionEntry> perms = Vector<PolicyParser.PermissionEntry> perms =
...@@ -2237,7 +2541,7 @@ class ToolDialog extends Dialog { ...@@ -2237,7 +2541,7 @@ class ToolDialog extends Dialog {
for (int i = 0; i < perms.size(); i++) { for (int i = 0; i < perms.size(); i++) {
PolicyParser.PermissionEntry nextPerm = perms.elementAt(i); PolicyParser.PermissionEntry nextPerm = perms.elementAt(i);
String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm); String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm);
label = new Label(" " + permString); label = new JLabel(" " + permString);
if (i == (perms.size()-1)) { if (i == (perms.size()-1)) {
tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i, tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,
1, 3 + i, 1, 1, 0.0, 0.0, 1, 3 + i, 1, 1, 0.0, 0.0,
...@@ -2252,11 +2556,11 @@ class ToolDialog extends Dialog { ...@@ -2252,11 +2556,11 @@ class ToolDialog extends Dialog {
// add OK/CANCEL buttons in a new panel // add OK/CANCEL buttons in a new panel
Panel panel = new Panel(); JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
// OK button // OK button
Button okButton = new Button(PolicyTool.rb.getString("OK")); JButton okButton = new JButton(PolicyTool.getMessage("OK"));
okButton.addActionListener okButton.addActionListener
(new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this)); (new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this));
tw.addNewComponent(panel, okButton, CRPE_PANEL_OK, tw.addNewComponent(panel, okButton, CRPE_PANEL_OK,
...@@ -2264,8 +2568,9 @@ class ToolDialog extends Dialog { ...@@ -2264,8 +2568,9 @@ class ToolDialog extends Dialog {
GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING); GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
// cancel button // cancel button
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
cancelButton.addActionListener(new CancelButtonListener(this)); ActionListener cancelListener = new CancelButtonListener(this);
cancelButton.addActionListener(cancelListener);
tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL, tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL,
1, 0, 1, 1, 0.0, 0.0, 1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING); GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
...@@ -2274,7 +2579,11 @@ class ToolDialog extends Dialog { ...@@ -2274,7 +2579,11 @@ class ToolDialog extends Dialog {
0, 3 + perms.size(), 2, 1, 0.0, 0.0, 0, 3 + perms.size(), 2, 1, 0.0, 0.0,
GridBagConstraints.VERTICAL, ToolWindow.TOP_BOTTOM_PADDING); GridBagConstraints.VERTICAL, ToolWindow.TOP_BOTTOM_PADDING);
getRootPane().setDefaultButton(okButton);
getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
pack(); pack();
setLocationRelativeTo(tw);
setVisible(true); setVisible(true);
} }
...@@ -2285,7 +2594,7 @@ class ToolDialog extends Dialog { ...@@ -2285,7 +2594,7 @@ class ToolDialog extends Dialog {
// pop up a dialog box for the user to enter a filename. // pop up a dialog box for the user to enter a filename.
FileDialog fd = new FileDialog FileDialog fd = new FileDialog
(tw, PolicyTool.rb.getString("Save.As"), FileDialog.SAVE); (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
fd.addWindowListener(new WindowAdapter() { fd.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
e.getWindow().setVisible(false); e.getWindow().setVisible(false);
...@@ -2308,13 +2617,13 @@ class ToolDialog extends Dialog { ...@@ -2308,13 +2617,13 @@ class ToolDialog extends Dialog {
tool.savePolicy(filename); tool.savePolicy(filename);
// display status // display status
MessageFormat form = new MessageFormat(PolicyTool.rb.getString MessageFormat form = new MessageFormat(PolicyTool.getMessage
("Policy.successfully.written.to.filename")); ("Policy.successfully.written.to.filename"));
Object[] source = {filename}; Object[] source = {filename};
tw.displayStatusDialog(null, form.format(source)); tw.displayStatusDialog(null, form.format(source));
// display the new policy filename // display the new policy filename
TextField newFilename = (TextField)tw.getComponent JTextField newFilename = (JTextField)tw.getComponent
(ToolWindow.MW_FILENAME_TEXTFIELD); (ToolWindow.MW_FILENAME_TEXTFIELD);
newFilename.setText(filename); newFilename.setText(filename);
tw.setVisible(true); tw.setVisible(true);
...@@ -2326,7 +2635,7 @@ class ToolDialog extends Dialog { ...@@ -2326,7 +2635,7 @@ class ToolDialog extends Dialog {
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException fnfe) {
if (filename == null || filename.equals("")) { if (filename == null || filename.equals("")) {
tw.displayErrorDialog(null, new FileNotFoundException tw.displayErrorDialog(null, new FileNotFoundException
(PolicyTool.rb.getString("null.filename"))); (PolicyTool.getMessage("null.filename")));
} else { } else {
tw.displayErrorDialog(null, fnfe); tw.displayErrorDialog(null, fnfe);
} }
...@@ -2344,35 +2653,38 @@ class ToolDialog extends Dialog { ...@@ -2344,35 +2653,38 @@ class ToolDialog extends Dialog {
// find where the PolicyTool gui is // find where the PolicyTool gui is
Point location = tw.getLocationOnScreen(); Point location = tw.getLocationOnScreen();
setBounds(location.x + 75, location.y + 100, 400, 150); //setBounds(location.x + 75, location.y + 100, 400, 150);
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
Label label = new Label JLabel label = new JLabel
(PolicyTool.rb.getString("Save.changes.")); (PolicyTool.getMessage("Save.changes."));
tw.addNewComponent(this, label, USC_LABEL, tw.addNewComponent(this, label, USC_LABEL,
0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, 0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
ToolWindow.L_TOP_BOTTOM_PADDING); ToolWindow.L_TOP_BOTTOM_PADDING);
Panel panel = new Panel(); JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout()); panel.setLayout(new GridBagLayout());
Button yesButton = new Button(PolicyTool.rb.getString("Yes")); JButton yesButton = new JButton();
ToolWindow.configureButton(yesButton, "Yes");
yesButton.addActionListener yesButton.addActionListener
(new UserSaveYesButtonListener(this, tool, tw, select)); (new UserSaveYesButtonListener(this, tool, tw, select));
tw.addNewComponent(panel, yesButton, USC_YES_BUTTON, tw.addNewComponent(panel, yesButton, USC_YES_BUTTON,
0, 0, 1, 1, 0.0, 0.0, 0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.VERTICAL, GridBagConstraints.VERTICAL,
ToolWindow.LR_BOTTOM_PADDING); ToolWindow.LR_BOTTOM_PADDING);
Button noButton = new Button(PolicyTool.rb.getString("No")); JButton noButton = new JButton();
ToolWindow.configureButton(noButton, "No");
noButton.addActionListener noButton.addActionListener
(new UserSaveNoButtonListener(this, tool, tw, select)); (new UserSaveNoButtonListener(this, tool, tw, select));
tw.addNewComponent(panel, noButton, USC_NO_BUTTON, tw.addNewComponent(panel, noButton, USC_NO_BUTTON,
1, 0, 1, 1, 0.0, 0.0, 1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.VERTICAL, GridBagConstraints.VERTICAL,
ToolWindow.LR_BOTTOM_PADDING); ToolWindow.LR_BOTTOM_PADDING);
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); JButton cancelButton = new JButton();
cancelButton.addActionListener ToolWindow.configureButton(cancelButton, "Cancel");
(new UserSaveCancelButtonListener(this)); ActionListener cancelListener = new CancelButtonListener(this);
cancelButton.addActionListener(cancelListener);
tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON, tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON,
2, 0, 1, 1, 0.0, 0.0, 2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.VERTICAL, GridBagConstraints.VERTICAL,
...@@ -2381,7 +2693,10 @@ class ToolDialog extends Dialog { ...@@ -2381,7 +2693,10 @@ class ToolDialog extends Dialog {
tw.addNewComponent(this, panel, USC_PANEL, tw.addNewComponent(this, panel, USC_PANEL,
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
pack(); pack();
setLocationRelativeTo(tw);
setVisible(true); setVisible(true);
} else { } else {
// just do the original request (QUIT, NEW, or OPEN) // just do the original request (QUIT, NEW, or OPEN)
...@@ -2418,12 +2733,14 @@ class ToolDialog extends Dialog { ...@@ -2418,12 +2733,14 @@ class ToolDialog extends Dialog {
} }
// display the policy entries via the policy list textarea // display the policy entries via the policy list textarea
List list = new List(40, false); JList list = new JList(new DefaultListModel());
list.addActionListener(new PolicyListListener(tool, tw)); list.setVisibleRowCount(15);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addMouseListener(new PolicyListListener(tool, tw));
tw.replacePolicyList(list); tw.replacePolicyList(list);
// display null policy filename and keystore // display null policy filename and keystore
TextField newFilename = (TextField)tw.getComponent( JTextField newFilename = (JTextField)tw.getComponent(
ToolWindow.MW_FILENAME_TEXTFIELD); ToolWindow.MW_FILENAME_TEXTFIELD);
newFilename.setText(""); newFilename.setText("");
tw.setVisible(true); tw.setVisible(true);
...@@ -2433,7 +2750,7 @@ class ToolDialog extends Dialog { ...@@ -2433,7 +2750,7 @@ class ToolDialog extends Dialog {
// pop up a dialog box for the user to enter a filename. // pop up a dialog box for the user to enter a filename.
FileDialog fd = new FileDialog FileDialog fd = new FileDialog
(tw, PolicyTool.rb.getString("Open"), FileDialog.LOAD); (tw, PolicyTool.getMessage("Open"), FileDialog.LOAD);
fd.addWindowListener(new WindowAdapter() { fd.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
e.getWindow().setVisible(false); e.getWindow().setVisible(false);
...@@ -2454,44 +2771,50 @@ class ToolDialog extends Dialog { ...@@ -2454,44 +2771,50 @@ class ToolDialog extends Dialog {
tool.openPolicy(policyFile); tool.openPolicy(policyFile);
// display the policy entries via the policy list textarea // display the policy entries via the policy list textarea
list = new List(40, false); DefaultListModel listModel = new DefaultListModel();
list.addActionListener(new PolicyListListener(tool, tw)); list = new JList(listModel);
list.setVisibleRowCount(15);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addMouseListener(new PolicyListListener(tool, tw));
PolicyEntry entries[] = tool.getEntry(); PolicyEntry entries[] = tool.getEntry();
if (entries != null) { if (entries != null) {
for (int i = 0; i < entries.length; i++) for (int i = 0; i < entries.length; i++) {
list.add(entries[i].headerToString()); listModel.addElement(entries[i].headerToString());
}
} }
tw.replacePolicyList(list); tw.replacePolicyList(list);
tool.modified = false; tool.modified = false;
// display the new policy filename // display the new policy filename
newFilename = (TextField)tw.getComponent( newFilename = (JTextField)tw.getComponent(
ToolWindow.MW_FILENAME_TEXTFIELD); ToolWindow.MW_FILENAME_TEXTFIELD);
newFilename.setText(policyFile); newFilename.setText(policyFile);
tw.setVisible(true); tw.setVisible(true);
// inform user of warnings // inform user of warnings
if (tool.newWarning == true) { if (tool.newWarning == true) {
tw.displayStatusDialog(null, PolicyTool.rb.getString tw.displayStatusDialog(null, PolicyTool.getMessage
("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information.")); ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
} }
} catch (Exception e) { } catch (Exception e) {
// add blank policy listing // add blank policy listing
list = new List(40, false); list = new JList(new DefaultListModel());
list.addActionListener(new PolicyListListener(tool, tw)); list.setVisibleRowCount(15);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addMouseListener(new PolicyListListener(tool, tw));
tw.replacePolicyList(list); tw.replacePolicyList(list);
tool.setPolicyFileName(null); tool.setPolicyFileName(null);
tool.modified = false; tool.modified = false;
// display a null policy filename // display a null policy filename
newFilename = (TextField)tw.getComponent( newFilename = (JTextField)tw.getComponent(
ToolWindow.MW_FILENAME_TEXTFIELD); ToolWindow.MW_FILENAME_TEXTFIELD);
newFilename.setText(""); newFilename.setText("");
tw.setVisible(true); tw.setVisible(true);
// display the error // display the error
MessageFormat form = new MessageFormat(PolicyTool.rb.getString MessageFormat form = new MessageFormat(PolicyTool.getMessage
("Could.not.open.policy.file.policyFile.e.toString.")); ("Could.not.open.policy.file.policyFile.e.toString."));
Object[] source = {policyFile, e.toString()}; Object[] source = {policyFile, e.toString()};
tw.displayErrorDialog(null, form.format(source)); tw.displayErrorDialog(null, form.format(source));
...@@ -2511,9 +2834,9 @@ class ToolDialog extends Dialog { ...@@ -2511,9 +2834,9 @@ class ToolDialog extends Dialog {
* (user must enter them by hand) then the TARGETS array may be empty * (user must enter them by hand) then the TARGETS array may be empty
* (and of course non-null). * (and of course non-null).
*/ */
void setPermissionNames(Perm inputPerm, Choice names, TextField field) { void setPermissionNames(Perm inputPerm, JComboBox names, JTextField field) {
names.removeAll(); names.removeAllItems();
names.add(PERM_NAME); names.addItem(PERM_NAME);
if (inputPerm == null) { if (inputPerm == null) {
// custom permission // custom permission
...@@ -2525,7 +2848,7 @@ class ToolDialog extends Dialog { ...@@ -2525,7 +2848,7 @@ class ToolDialog extends Dialog {
// standard permission with standard targets // standard permission with standard targets
field.setEditable(true); field.setEditable(true);
for (int i = 0; i < inputPerm.TARGETS.length; i++) { for (int i = 0; i < inputPerm.TARGETS.length; i++) {
names.add(inputPerm.TARGETS[i]); names.addItem(inputPerm.TARGETS[i]);
} }
} }
} }
...@@ -2541,9 +2864,9 @@ class ToolDialog extends Dialog { ...@@ -2541,9 +2864,9 @@ class ToolDialog extends Dialog {
* (user must enter them by hand) then the ACTIONS array may be empty * (user must enter them by hand) then the ACTIONS array may be empty
* (and of course non-null). * (and of course non-null).
*/ */
void setPermissionActions(Perm inputPerm, Choice actions, TextField field) { void setPermissionActions(Perm inputPerm, JComboBox actions, JTextField field) {
actions.removeAll(); actions.removeAllItems();
actions.add(PERM_ACTIONS); actions.addItem(PERM_ACTIONS);
if (inputPerm == null) { if (inputPerm == null) {
// custom permission // custom permission
...@@ -2555,7 +2878,7 @@ class ToolDialog extends Dialog { ...@@ -2555,7 +2878,7 @@ class ToolDialog extends Dialog {
// standard permission with standard actions // standard permission with standard actions
field.setEditable(true); field.setEditable(true);
for (int i = 0; i < inputPerm.ACTIONS.length; i++) { for (int i = 0; i < inputPerm.ACTIONS.length; i++) {
actions.add(inputPerm.ACTIONS[i]); actions.addItem(inputPerm.ACTIONS[i]);
} }
} }
} }
...@@ -2587,9 +2910,11 @@ class ToolDialog extends Dialog { ...@@ -2587,9 +2910,11 @@ class ToolDialog extends Dialog {
*/ */
class ToolWindowListener implements WindowListener { class ToolWindowListener implements WindowListener {
private PolicyTool tool;
private ToolWindow tw; private ToolWindow tw;
ToolWindowListener(ToolWindow tw) { ToolWindowListener(PolicyTool tool, ToolWindow tw) {
this.tool = tool;
this.tw = tw; this.tw = tw;
} }
...@@ -2597,16 +2922,14 @@ class ToolWindowListener implements WindowListener { ...@@ -2597,16 +2922,14 @@ class ToolWindowListener implements WindowListener {
} }
public void windowClosing(WindowEvent we) { public void windowClosing(WindowEvent we) {
// Closing the window acts the same as choosing Menu->Exit.
// XXX // ask user if they want to save changes
// should we ask user if they want to save changes? ToolDialog td = new ToolDialog(PolicyTool.getMessage("Save.Changes"), tool, tw, true);
// (we do if they choose the Menu->Exit) td.displayUserSave(ToolDialog.QUIT);
// seems that if they kill the application by hand,
// we don't have to ask.
tw.setVisible(false); // the above method will perform the QUIT as long as the
tw.dispose(); // user does not CANCEL the request
System.exit(0);
} }
public void windowClosed(WindowEvent we) { public void windowClosed(WindowEvent we) {
...@@ -2629,7 +2952,7 @@ class ToolWindowListener implements WindowListener { ...@@ -2629,7 +2952,7 @@ class ToolWindowListener implements WindowListener {
/** /**
* Event handler for the Policy List * Event handler for the Policy List
*/ */
class PolicyListListener implements ActionListener { class PolicyListListener extends MouseAdapter implements ActionListener {
private PolicyTool tool; private PolicyTool tool;
private ToolWindow tw; private ToolWindow tw;
...@@ -2644,9 +2967,15 @@ class PolicyListListener implements ActionListener { ...@@ -2644,9 +2967,15 @@ class PolicyListListener implements ActionListener {
// display the permission list for a policy entry // display the permission list for a policy entry
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Policy.Entry"), tool, tw, true); (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
td.displayPolicyEntryDialog(true); td.displayPolicyEntryDialog(true);
} }
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2) {
actionPerformed(null);
}
}
} }
/** /**
...@@ -2669,7 +2998,7 @@ class FileMenuListener implements ActionListener { ...@@ -2669,7 +2998,7 @@ class FileMenuListener implements ActionListener {
// ask user if they want to save changes // ask user if they want to save changes
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Save.Changes"), tool, tw, true); (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
td.displayUserSave(ToolDialog.QUIT); td.displayUserSave(ToolDialog.QUIT);
// the above method will perform the QUIT as long as the // the above method will perform the QUIT as long as the
...@@ -2680,7 +3009,7 @@ class FileMenuListener implements ActionListener { ...@@ -2680,7 +3009,7 @@ class FileMenuListener implements ActionListener {
// ask user if they want to save changes // ask user if they want to save changes
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Save.Changes"), tool, tw, true); (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
td.displayUserSave(ToolDialog.NEW); td.displayUserSave(ToolDialog.NEW);
// the above method will perform the NEW as long as the // the above method will perform the NEW as long as the
...@@ -2691,7 +3020,7 @@ class FileMenuListener implements ActionListener { ...@@ -2691,7 +3020,7 @@ class FileMenuListener implements ActionListener {
// ask user if they want to save changes // ask user if they want to save changes
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Save.Changes"), tool, tw, true); (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
td.displayUserSave(ToolDialog.OPEN); td.displayUserSave(ToolDialog.OPEN);
// the above method will perform the OPEN as long as the // the above method will perform the OPEN as long as the
...@@ -2701,14 +3030,14 @@ class FileMenuListener implements ActionListener { ...@@ -2701,14 +3030,14 @@ class FileMenuListener implements ActionListener {
ToolWindow.SAVE_POLICY_FILE) == 0) { ToolWindow.SAVE_POLICY_FILE) == 0) {
// get the previously entered filename // get the previously entered filename
String filename = ((TextField)tw.getComponent( String filename = ((JTextField)tw.getComponent(
ToolWindow.MW_FILENAME_TEXTFIELD)).getText(); ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
// if there is no filename, do a SAVE_AS // if there is no filename, do a SAVE_AS
if (filename == null || filename.length() == 0) { if (filename == null || filename.length() == 0) {
// user wants to SAVE AS // user wants to SAVE AS
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Save.As"), tool, tw, true); (PolicyTool.getMessage("Save.As"), tool, tw, true);
td.displaySaveAsDialog(ToolDialog.NOACTION); td.displaySaveAsDialog(ToolDialog.NOACTION);
} else { } else {
try { try {
...@@ -2717,14 +3046,14 @@ class FileMenuListener implements ActionListener { ...@@ -2717,14 +3046,14 @@ class FileMenuListener implements ActionListener {
// display status // display status
MessageFormat form = new MessageFormat MessageFormat form = new MessageFormat
(PolicyTool.rb.getString (PolicyTool.getMessage
("Policy.successfully.written.to.filename")); ("Policy.successfully.written.to.filename"));
Object[] source = {filename}; Object[] source = {filename};
tw.displayStatusDialog(null, form.format(source)); tw.displayStatusDialog(null, form.format(source));
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException fnfe) {
if (filename == null || filename.equals("")) { if (filename == null || filename.equals("")) {
tw.displayErrorDialog(null, new FileNotFoundException tw.displayErrorDialog(null, new FileNotFoundException
(PolicyTool.rb.getString("null.filename"))); (PolicyTool.getMessage("null.filename")));
} else { } else {
tw.displayErrorDialog(null, fnfe); tw.displayErrorDialog(null, fnfe);
} }
...@@ -2737,7 +3066,7 @@ class FileMenuListener implements ActionListener { ...@@ -2737,7 +3066,7 @@ class FileMenuListener implements ActionListener {
// user wants to SAVE AS // user wants to SAVE AS
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Save.As"), tool, tw, true); (PolicyTool.getMessage("Save.As"), tool, tw, true);
td.displaySaveAsDialog(ToolDialog.NOACTION); td.displaySaveAsDialog(ToolDialog.NOACTION);
} else if (PolicyTool.collator.compare(e.getActionCommand(), } else if (PolicyTool.collator.compare(e.getActionCommand(),
...@@ -2767,23 +3096,23 @@ class MainWindowListener implements ActionListener { ...@@ -2767,23 +3096,23 @@ class MainWindowListener implements ActionListener {
// display a dialog box for the user to enter policy info // display a dialog box for the user to enter policy info
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Policy.Entry"), tool, tw, true); (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
td.displayPolicyEntryDialog(false); td.displayPolicyEntryDialog(false);
} else if (PolicyTool.collator.compare(e.getActionCommand(), } else if (PolicyTool.collator.compare(e.getActionCommand(),
ToolWindow.REMOVE_POLICY_ENTRY) == 0) { ToolWindow.REMOVE_POLICY_ENTRY) == 0) {
// get the selected entry // get the selected entry
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
int index = list.getSelectedIndex(); int index = list.getSelectedIndex();
if (index < 0) { if (index < 0) {
tw.displayErrorDialog(null, new Exception tw.displayErrorDialog(null, new Exception
(PolicyTool.rb.getString("No.Policy.Entry.selected"))); (PolicyTool.getMessage("No.Policy.Entry.selected")));
return; return;
} }
// ask the user if they really want to remove the policy entry // ask the user if they really want to remove the policy entry
ToolDialog td = new ToolDialog(PolicyTool.rb.getString ToolDialog td = new ToolDialog(PolicyTool.getMessage
("Remove.Policy.Entry"), tool, tw, true); ("Remove.Policy.Entry"), tool, tw, true);
td.displayConfirmRemovePolicyEntry(); td.displayConfirmRemovePolicyEntry();
...@@ -2791,17 +3120,17 @@ class MainWindowListener implements ActionListener { ...@@ -2791,17 +3120,17 @@ class MainWindowListener implements ActionListener {
ToolWindow.EDIT_POLICY_ENTRY) == 0) { ToolWindow.EDIT_POLICY_ENTRY) == 0) {
// get the selected entry // get the selected entry
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
int index = list.getSelectedIndex(); int index = list.getSelectedIndex();
if (index < 0) { if (index < 0) {
tw.displayErrorDialog(null, new Exception tw.displayErrorDialog(null, new Exception
(PolicyTool.rb.getString("No.Policy.Entry.selected"))); (PolicyTool.getMessage("No.Policy.Entry.selected")));
return; return;
} }
// display the permission list for a policy entry // display the permission list for a policy entry
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("Policy.Entry"), tool, tw, true); (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
td.displayPolicyEntryDialog(true); td.displayPolicyEntryDialog(true);
} else if (PolicyTool.collator.compare(e.getActionCommand(), } else if (PolicyTool.collator.compare(e.getActionCommand(),
...@@ -2809,7 +3138,7 @@ class MainWindowListener implements ActionListener { ...@@ -2809,7 +3138,7 @@ class MainWindowListener implements ActionListener {
// display a dialog box for the user to enter keystore info // display a dialog box for the user to enter keystore info
ToolDialog td = new ToolDialog ToolDialog td = new ToolDialog
(PolicyTool.rb.getString("KeyStore"), tool, tw, true); (PolicyTool.getMessage("KeyStore"), tool, tw, true);
td.keyStoreDialog(ToolDialog.EDIT_KEYSTORE); td.keyStoreDialog(ToolDialog.EDIT_KEYSTORE);
} }
} }
...@@ -2852,7 +3181,7 @@ class AddEntryDoneButtonListener implements ActionListener { ...@@ -2852,7 +3181,7 @@ class AddEntryDoneButtonListener implements ActionListener {
PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
if (pubKey == null) { if (pubKey == null) {
MessageFormat form = new MessageFormat MessageFormat form = new MessageFormat
(PolicyTool.rb.getString (PolicyTool.getMessage
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
Object[] source = {signers[i]}; Object[] source = {signers[i]};
tool.warnings.addElement(form.format(source)); tool.warnings.addElement(form.format(source));
...@@ -2862,18 +3191,18 @@ class AddEntryDoneButtonListener implements ActionListener { ...@@ -2862,18 +3191,18 @@ class AddEntryDoneButtonListener implements ActionListener {
} }
// add the entry // add the entry
List policyList = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
if (edit) { if (edit) {
int listIndex = policyList.getSelectedIndex(); int listIndex = policyList.getSelectedIndex();
tool.addEntry(newEntry, listIndex); tool.addEntry(newEntry, listIndex);
String newCodeBaseStr = newEntry.headerToString(); String newCodeBaseStr = newEntry.headerToString();
if (PolicyTool.collator.compare if (PolicyTool.collator.compare
(newCodeBaseStr, policyList.getItem(listIndex)) != 0) (newCodeBaseStr, policyList.getModel().getElementAt(listIndex)) != 0)
tool.modified = true; tool.modified = true;
policyList.replaceItem(newCodeBaseStr, listIndex); ((DefaultListModel)policyList.getModel()).set(listIndex, newCodeBaseStr);
} else { } else {
tool.addEntry(newEntry, -1); tool.addEntry(newEntry, -1);
policyList.add(newEntry.headerToString()); ((DefaultListModel)policyList.getModel()).addElement(newEntry.headerToString());
tool.modified = true; tool.modified = true;
} }
td.setVisible(false); td.setVisible(false);
...@@ -2903,13 +3232,13 @@ class ChangeKeyStoreOKButtonListener implements ActionListener { ...@@ -2903,13 +3232,13 @@ class ChangeKeyStoreOKButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String URLString = ((TextField)td.getComponent( String URLString = ((JTextField)td.getComponent(
ToolDialog.KSD_NAME_TEXTFIELD)).getText().trim(); ToolDialog.KSD_NAME_TEXTFIELD)).getText().trim();
String type = ((TextField)td.getComponent( String type = ((JTextField)td.getComponent(
ToolDialog.KSD_TYPE_TEXTFIELD)).getText().trim(); ToolDialog.KSD_TYPE_TEXTFIELD)).getText().trim();
String provider = ((TextField)td.getComponent( String provider = ((JTextField)td.getComponent(
ToolDialog.KSD_PROVIDER_TEXTFIELD)).getText().trim(); ToolDialog.KSD_PROVIDER_TEXTFIELD)).getText().trim();
String pwdURL = ((TextField)td.getComponent( String pwdURL = ((JTextField)td.getComponent(
ToolDialog.KSD_PWD_URL_TEXTFIELD)).getText().trim(); ToolDialog.KSD_PWD_URL_TEXTFIELD)).getText().trim();
try { try {
...@@ -2920,7 +3249,7 @@ class ChangeKeyStoreOKButtonListener implements ActionListener { ...@@ -2920,7 +3249,7 @@ class ChangeKeyStoreOKButtonListener implements ActionListener {
(pwdURL.length() == 0 ? null : pwdURL)); (pwdURL.length() == 0 ? null : pwdURL));
tool.modified = true; tool.modified = true;
} catch (Exception ex) { } catch (Exception ex) {
MessageFormat form = new MessageFormat(PolicyTool.rb.getString MessageFormat form = new MessageFormat(PolicyTool.getMessage
("Unable.to.open.KeyStore.ex.toString.")); ("Unable.to.open.KeyStore.ex.toString."));
Object[] source = {ex.toString()}; Object[] source = {ex.toString()};
tw.displayErrorDialog(td, form.format(source)); tw.displayErrorDialog(td, form.format(source));
...@@ -3016,7 +3345,7 @@ class NewPolicyPrinOKButtonListener implements ActionListener { ...@@ -3016,7 +3345,7 @@ class NewPolicyPrinOKButtonListener implements ActionListener {
pppe.getPrincipalName()); pppe.getPrincipalName());
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
MessageFormat form = new MessageFormat MessageFormat form = new MessageFormat
(PolicyTool.rb.getString (PolicyTool.getMessage
("Warning.Class.not.found.class")); ("Warning.Class.not.found.class"));
Object[] source = {pppe.getPrincipalClass()}; Object[] source = {pppe.getPrincipalClass()};
tool.warnings.addElement(form.format(source)); tool.warnings.addElement(form.format(source));
...@@ -3077,7 +3406,7 @@ class NewPolicyPermOKButtonListener implements ActionListener { ...@@ -3077,7 +3406,7 @@ class NewPolicyPermOKButtonListener implements ActionListener {
try { try {
tool.verifyPermission(pppe.permission, pppe.name, pppe.action); tool.verifyPermission(pppe.permission, pppe.name, pppe.action);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
MessageFormat form = new MessageFormat(PolicyTool.rb.getString MessageFormat form = new MessageFormat(PolicyTool.getMessage
("Warning.Class.not.found.class")); ("Warning.Class.not.found.class"));
Object[] source = {pppe.permission}; Object[] source = {pppe.permission};
tool.warnings.addElement(form.format(source)); tool.warnings.addElement(form.format(source));
...@@ -3134,7 +3463,7 @@ class RemovePrinButtonListener implements ActionListener { ...@@ -3134,7 +3463,7 @@ class RemovePrinButtonListener implements ActionListener {
if (prinIndex < 0) { if (prinIndex < 0) {
tw.displayErrorDialog(td, new Exception tw.displayErrorDialog(td, new Exception
(PolicyTool.rb.getString("No.principal.selected"))); (PolicyTool.getMessage("No.principal.selected")));
return; return;
} }
// remove the principal from the display // remove the principal from the display
...@@ -3169,7 +3498,7 @@ class RemovePermButtonListener implements ActionListener { ...@@ -3169,7 +3498,7 @@ class RemovePermButtonListener implements ActionListener {
if (permIndex < 0) { if (permIndex < 0) {
tw.displayErrorDialog(td, new Exception tw.displayErrorDialog(td, new Exception
(PolicyTool.rb.getString("No.permission.selected"))); (PolicyTool.getMessage("No.permission.selected")));
return; return;
} }
// remove the permission from the display // remove the permission from the display
...@@ -3187,7 +3516,7 @@ class RemovePermButtonListener implements ActionListener { ...@@ -3187,7 +3516,7 @@ class RemovePermButtonListener implements ActionListener {
* GUI listing. If the user is editing an existing PolicyEntry, we * GUI listing. If the user is editing an existing PolicyEntry, we
* update both the GUI listing and the actual PolicyEntry. * update both the GUI listing and the actual PolicyEntry.
*/ */
class EditPrinButtonListener implements ActionListener { class EditPrinButtonListener extends MouseAdapter implements ActionListener {
private PolicyTool tool; private PolicyTool tool;
private ToolWindow tw; private ToolWindow tw;
...@@ -3211,11 +3540,17 @@ class EditPrinButtonListener implements ActionListener { ...@@ -3211,11 +3540,17 @@ class EditPrinButtonListener implements ActionListener {
if (prinIndex < 0) { if (prinIndex < 0) {
tw.displayErrorDialog(td, new Exception tw.displayErrorDialog(td, new Exception
(PolicyTool.rb.getString("No.principal.selected"))); (PolicyTool.getMessage("No.principal.selected")));
return; return;
} }
td.displayPrincipalDialog(editPolicyEntry, true); td.displayPrincipalDialog(editPolicyEntry, true);
} }
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2) {
actionPerformed(null);
}
}
} }
/** /**
...@@ -3227,7 +3562,7 @@ class EditPrinButtonListener implements ActionListener { ...@@ -3227,7 +3562,7 @@ class EditPrinButtonListener implements ActionListener {
* GUI listing. If the user is editing an existing PolicyEntry, we * GUI listing. If the user is editing an existing PolicyEntry, we
* update both the GUI listing and the actual PolicyEntry. * update both the GUI listing and the actual PolicyEntry.
*/ */
class EditPermButtonListener implements ActionListener { class EditPermButtonListener extends MouseAdapter implements ActionListener {
private PolicyTool tool; private PolicyTool tool;
private ToolWindow tw; private ToolWindow tw;
...@@ -3245,16 +3580,22 @@ class EditPermButtonListener implements ActionListener { ...@@ -3245,16 +3580,22 @@ class EditPermButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// get the Permission selected from the Permission List // get the Permission selected from the Permission List
List list = (List)td.getComponent(ToolDialog.PE_PERM_LIST); JList list = (JList)td.getComponent(ToolDialog.PE_PERM_LIST);
int permIndex = list.getSelectedIndex(); int permIndex = list.getSelectedIndex();
if (permIndex < 0) { if (permIndex < 0) {
tw.displayErrorDialog(td, new Exception tw.displayErrorDialog(td, new Exception
(PolicyTool.rb.getString("No.permission.selected"))); (PolicyTool.getMessage("No.permission.selected")));
return; return;
} }
td.displayPermissionDialog(editPolicyEntry, true); td.displayPermissionDialog(editPolicyEntry, true);
} }
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2) {
actionPerformed(null);
}
}
} }
/** /**
...@@ -3269,11 +3610,15 @@ class PrincipalTypeMenuListener implements ItemListener { ...@@ -3269,11 +3610,15 @@ class PrincipalTypeMenuListener implements ItemListener {
} }
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
// We're only interested in SELECTED events
return;
}
Choice prin = (Choice)td.getComponent(ToolDialog.PRD_PRIN_CHOICE); JComboBox prin = (JComboBox)td.getComponent(ToolDialog.PRD_PRIN_CHOICE);
TextField prinField = (TextField)td.getComponent( JTextField prinField = (JTextField)td.getComponent(
ToolDialog.PRD_PRIN_TEXTFIELD); ToolDialog.PRD_PRIN_TEXTFIELD);
TextField nameField = (TextField)td.getComponent( JTextField nameField = (JTextField)td.getComponent(
ToolDialog.PRD_NAME_TEXTFIELD); ToolDialog.PRD_NAME_TEXTFIELD);
prin.getAccessibleContext().setAccessibleName( prin.getAccessibleContext().setAccessibleName(
...@@ -3283,7 +3628,7 @@ class PrincipalTypeMenuListener implements ItemListener { ...@@ -3283,7 +3628,7 @@ class PrincipalTypeMenuListener implements ItemListener {
if (prinField.getText() != null && if (prinField.getText() != null &&
prinField.getText().length() > 0) { prinField.getText().length() > 0) {
Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true); Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true);
prin.select(inputPrin.CLASS); prin.setSelectedItem(inputPrin.CLASS);
} }
return; return;
} }
...@@ -3315,20 +3660,24 @@ class PermissionMenuListener implements ItemListener { ...@@ -3315,20 +3660,24 @@ class PermissionMenuListener implements ItemListener {
} }
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
// We're only interested in SELECTED events
return;
}
Choice perms = (Choice)td.getComponent( JComboBox perms = (JComboBox)td.getComponent(
ToolDialog.PD_PERM_CHOICE); ToolDialog.PD_PERM_CHOICE);
Choice names = (Choice)td.getComponent( JComboBox names = (JComboBox)td.getComponent(
ToolDialog.PD_NAME_CHOICE); ToolDialog.PD_NAME_CHOICE);
Choice actions = (Choice)td.getComponent( JComboBox actions = (JComboBox)td.getComponent(
ToolDialog.PD_ACTIONS_CHOICE); ToolDialog.PD_ACTIONS_CHOICE);
TextField nameField = (TextField)td.getComponent( JTextField nameField = (JTextField)td.getComponent(
ToolDialog.PD_NAME_TEXTFIELD); ToolDialog.PD_NAME_TEXTFIELD);
TextField actionsField = (TextField)td.getComponent( JTextField actionsField = (JTextField)td.getComponent(
ToolDialog.PD_ACTIONS_TEXTFIELD); ToolDialog.PD_ACTIONS_TEXTFIELD);
TextField permField = (TextField)td.getComponent( JTextField permField = (JTextField)td.getComponent(
ToolDialog.PD_PERM_TEXTFIELD); ToolDialog.PD_PERM_TEXTFIELD);
TextField signedbyField = (TextField)td.getComponent( JTextField signedbyField = (JTextField)td.getComponent(
ToolDialog.PD_SIGNEDBY_TEXTFIELD); ToolDialog.PD_SIGNEDBY_TEXTFIELD);
perms.getAccessibleContext().setAccessibleName( perms.getAccessibleContext().setAccessibleName(
...@@ -3342,7 +3691,7 @@ class PermissionMenuListener implements ItemListener { ...@@ -3342,7 +3691,7 @@ class PermissionMenuListener implements ItemListener {
Perm inputPerm = ToolDialog.getPerm(permField.getText(), true); Perm inputPerm = ToolDialog.getPerm(permField.getText(), true);
if (inputPerm != null) { if (inputPerm != null) {
perms.select(inputPerm.CLASS); perms.setSelectedItem(inputPerm.CLASS);
} }
} }
return; return;
...@@ -3382,15 +3731,19 @@ class PermissionNameMenuListener implements ItemListener { ...@@ -3382,15 +3731,19 @@ class PermissionNameMenuListener implements ItemListener {
} }
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
// We're only interested in SELECTED events
return;
}
Choice names = (Choice)td.getComponent(ToolDialog.PD_NAME_CHOICE); JComboBox names = (JComboBox)td.getComponent(ToolDialog.PD_NAME_CHOICE);
names.getAccessibleContext().setAccessibleName( names.getAccessibleContext().setAccessibleName(
PolicyTool.splitToWords((String)e.getItem())); PolicyTool.splitToWords((String)e.getItem()));
if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1) if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1)
return; return;
TextField tf = (TextField)td.getComponent(ToolDialog.PD_NAME_TEXTFIELD); JTextField tf = (JTextField)td.getComponent(ToolDialog.PD_NAME_TEXTFIELD);
tf.setText((String)e.getItem()); tf.setText((String)e.getItem());
} }
} }
...@@ -3407,15 +3760,19 @@ class PermissionActionsMenuListener implements ItemListener { ...@@ -3407,15 +3760,19 @@ class PermissionActionsMenuListener implements ItemListener {
} }
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
// We're only interested in SELECTED events
return;
}
Choice actions = (Choice)td.getComponent( JComboBox actions = (JComboBox)td.getComponent(
ToolDialog.PD_ACTIONS_CHOICE); ToolDialog.PD_ACTIONS_CHOICE);
actions.getAccessibleContext().setAccessibleName((String)e.getItem()); actions.getAccessibleContext().setAccessibleName((String)e.getItem());
if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1) if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1)
return; return;
TextField tf = (TextField)td.getComponent( JTextField tf = (JTextField)td.getComponent(
ToolDialog.PD_ACTIONS_TEXTFIELD); ToolDialog.PD_ACTIONS_TEXTFIELD);
if (tf.getText() == null || tf.getText().equals("")) { if (tf.getText() == null || tf.getText().equals("")) {
tf.setText((String)e.getItem()); tf.setText((String)e.getItem());
...@@ -3538,7 +3895,7 @@ class UserSaveYesButtonListener implements ActionListener { ...@@ -3538,7 +3895,7 @@ class UserSaveYesButtonListener implements ActionListener {
us.dispose(); us.dispose();
try { try {
String filename = ((TextField)tw.getComponent( String filename = ((JTextField)tw.getComponent(
ToolWindow.MW_FILENAME_TEXTFIELD)).getText(); ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
if (filename == null || filename.equals("")) { if (filename == null || filename.equals("")) {
us.displaySaveAsDialog(select); us.displaySaveAsDialog(select);
...@@ -3551,7 +3908,7 @@ class UserSaveYesButtonListener implements ActionListener { ...@@ -3551,7 +3908,7 @@ class UserSaveYesButtonListener implements ActionListener {
// display status // display status
MessageFormat form = new MessageFormat MessageFormat form = new MessageFormat
(PolicyTool.rb.getString (PolicyTool.getMessage
("Policy.successfully.written.to.filename")); ("Policy.successfully.written.to.filename"));
Object[] source = {filename}; Object[] source = {filename};
tw.displayStatusDialog(null, form.format(source)); tw.displayStatusDialog(null, form.format(source));
...@@ -3633,18 +3990,22 @@ class ConfirmRemovePolicyEntryOKButtonListener implements ActionListener { ...@@ -3633,18 +3990,22 @@ class ConfirmRemovePolicyEntryOKButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// remove the entry // remove the entry
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);
int index = list.getSelectedIndex(); int index = list.getSelectedIndex();
PolicyEntry entries[] = tool.getEntry(); PolicyEntry entries[] = tool.getEntry();
tool.removeEntry(entries[index]); tool.removeEntry(entries[index]);
// redraw the window listing // redraw the window listing
list = new List(40, false); DefaultListModel listModel = new DefaultListModel();
list.addActionListener(new PolicyListListener(tool, tw)); list = new JList(listModel);
list.setVisibleRowCount(15);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addMouseListener(new PolicyListListener(tool, tw));
entries = tool.getEntry(); entries = tool.getEntry();
if (entries != null) { if (entries != null) {
for (int i = 0; i < entries.length; i++) for (int i = 0; i < entries.length; i++) {
list.add(entries[i].headerToString()); listModel.addElement(entries[i].headerToString());
}
} }
tw.replacePolicyList(list); tw.replacePolicyList(list);
us.setVisible(false); us.setVisible(false);
...@@ -3663,40 +4024,32 @@ class NoDisplayException extends RuntimeException { ...@@ -3663,40 +4024,32 @@ class NoDisplayException extends RuntimeException {
/** /**
* This is a java.awt.List that bind an Object to each String it holds. * This is a java.awt.List that bind an Object to each String it holds.
*/ */
class TaggedList extends List { class TaggedList extends JList {
private static final long serialVersionUID = -5676238110427785853L; private static final long serialVersionUID = -5676238110427785853L;
private java.util.List<Object> data = new LinkedList<>(); private java.util.List<Object> data = new LinkedList<>();
public TaggedList(int i, boolean b) { public TaggedList(int i, boolean b) {
super(i, b); super(new DefaultListModel());
setVisibleRowCount(i);
setSelectionMode(b ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION);
} }
public Object getObject(int index) { public Object getObject(int index) {
return data.get(index); return data.get(index);
} }
@Override @Deprecated public void add(String string) {
throw new AssertionError("should not call add in TaggedList");
}
public void addTaggedItem(String string, Object object) { public void addTaggedItem(String string, Object object) {
super.add(string); ((DefaultListModel)getModel()).addElement(string);
data.add(object); data.add(object);
} }
@Override @Deprecated public void replaceItem(String string, int index) {
throw new AssertionError("should not call replaceItem in TaggedList");
}
public void replaceTaggedItem(String string, Object object, int index) { public void replaceTaggedItem(String string, Object object, int index) {
super.replaceItem(string, index); ((DefaultListModel)getModel()).set(index, string);
data.set(index, object); data.set(index, object);
} }
@Override @Deprecated public void remove(int index) {
// Cannot throw AssertionError, because replaceItem() call remove() internally
super.remove(index);
}
public void removeTaggedItem(int index) { public void removeTaggedItem(int index) {
super.remove(index); ((DefaultListModel)getModel()).remove(index);
data.remove(index); data.remove(index);
} }
} }
...@@ -3782,11 +4135,11 @@ class AuthPerm extends Perm { ...@@ -3782,11 +4135,11 @@ class AuthPerm extends Perm {
"modifyPrivateCredentials", "modifyPrivateCredentials",
"refreshCredential", "refreshCredential",
"destroyCredential", "destroyCredential",
"createLoginContext.<" + PolicyTool.rb.getString("name") + ">", "createLoginContext.<" + PolicyTool.getMessage("name") + ">",
"getLoginConfiguration", "getLoginConfiguration",
"setLoginConfiguration", "setLoginConfiguration",
"createLoginConfiguration.<" + "createLoginConfiguration.<" +
PolicyTool.rb.getString("configuration.type") + ">", PolicyTool.getMessage("configuration.type") + ">",
"refreshLoginConfiguration" "refreshLoginConfiguration"
}, },
null); null);
...@@ -3848,11 +4201,11 @@ class URLPerm extends Perm { ...@@ -3848,11 +4201,11 @@ class URLPerm extends Perm {
super("URLPermission", super("URLPermission",
"java.net.URLPermission", "java.net.URLPermission",
new String[] { new String[] {
"<"+ PolicyTool.rb.getString("url") + ">", "<"+ PolicyTool.getMessage("url") + ">",
}, },
new String[] { new String[] {
"<" + PolicyTool.rb.getString("method.list") + ">:<" "<" + PolicyTool.getMessage("method.list") + ">:<"
+ PolicyTool.rb.getString("request.headers.list") + ">", + PolicyTool.getMessage("request.headers.list") + ">",
}); });
} }
} }
...@@ -4017,7 +4370,7 @@ class RuntimePerm extends Perm { ...@@ -4017,7 +4370,7 @@ class RuntimePerm extends Perm {
"setSecurityManager", "setSecurityManager",
"createSecurityManager", "createSecurityManager",
"getenv.<" + "getenv.<" +
PolicyTool.rb.getString("environment.variable.name") + ">", PolicyTool.getMessage("environment.variable.name") + ">",
"exitVM", "exitVM",
"shutdownHooks", "shutdownHooks",
"setFactory", "setFactory",
...@@ -4029,11 +4382,11 @@ class RuntimePerm extends Perm { ...@@ -4029,11 +4382,11 @@ class RuntimePerm extends Perm {
"readFileDescriptor", "readFileDescriptor",
"writeFileDescriptor", "writeFileDescriptor",
"loadLibrary.<" + "loadLibrary.<" +
PolicyTool.rb.getString("library.name") + ">", PolicyTool.getMessage("library.name") + ">",
"accessClassInPackage.<" + "accessClassInPackage.<" +
PolicyTool.rb.getString("package.name")+">", PolicyTool.getMessage("package.name")+">",
"defineClassInPackage.<" + "defineClassInPackage.<" +
PolicyTool.rb.getString("package.name")+">", PolicyTool.getMessage("package.name")+">",
"accessDeclaredMembers", "accessDeclaredMembers",
"queuePrintJob", "queuePrintJob",
"getStackTrace", "getStackTrace",
...@@ -4056,15 +4409,15 @@ class SecurityPerm extends Perm { ...@@ -4056,15 +4409,15 @@ class SecurityPerm extends Perm {
"getPolicy", "getPolicy",
"setPolicy", "setPolicy",
"createPolicy.<" + "createPolicy.<" +
PolicyTool.rb.getString("policy.type") + ">", PolicyTool.getMessage("policy.type") + ">",
"getProperty.<" + "getProperty.<" +
PolicyTool.rb.getString("property.name") + ">", PolicyTool.getMessage("property.name") + ">",
"setProperty.<" + "setProperty.<" +
PolicyTool.rb.getString("property.name") + ">", PolicyTool.getMessage("property.name") + ">",
"insertProvider.<" + "insertProvider.<" +
PolicyTool.rb.getString("provider.name") + ">", PolicyTool.getMessage("provider.name") + ">",
"removeProvider.<" + "removeProvider.<" +
PolicyTool.rb.getString("provider.name") + ">", PolicyTool.getMessage("provider.name") + ">",
//"setSystemScope", //"setSystemScope",
//"setIdentityPublicKey", //"setIdentityPublicKey",
//"setIdentityInfo", //"setIdentityInfo",
...@@ -4072,11 +4425,11 @@ class SecurityPerm extends Perm { ...@@ -4072,11 +4425,11 @@ class SecurityPerm extends Perm {
//"removeIdentityCertificate", //"removeIdentityCertificate",
//"printIdentity", //"printIdentity",
"clearProviderProperties.<" + "clearProviderProperties.<" +
PolicyTool.rb.getString("provider.name") + ">", PolicyTool.getMessage("provider.name") + ">",
"putProviderProperty.<" + "putProviderProperty.<" +
PolicyTool.rb.getString("provider.name") + ">", PolicyTool.getMessage("provider.name") + ">",
"removeProviderProperty.<" + "removeProviderProperty.<" +
PolicyTool.rb.getString("provider.name") + ">", PolicyTool.getMessage("provider.name") + ">",
//"getSignerPrivateKey", //"getSignerPrivateKey",
//"setSignerKeyPair" //"setSignerKeyPair"
}, },
......
...@@ -44,16 +44,19 @@ public class Resources extends java.util.ListResourceBundle { ...@@ -44,16 +44,19 @@ public class Resources extends java.util.ListResourceBundle {
{"Usage.policytool.options.", "Usage: policytool [options]"}, {"Usage.policytool.options.", "Usage: policytool [options]"},
{".file.file.policy.file.location", {".file.file.policy.file.location",
" [-file <file>] policy file location"}, " [-file <file>] policy file location"},
{"New", "New"}, {"New", "&New"},
{"Open", "Open"}, {"New.accelerator", "control N"},
{"Save", "Save"}, {"Open", "&Open..."},
{"Save.As", "Save As"}, {"Open.accelerator", "control O"},
{"View.Warning.Log", "View Warning Log"}, {"Save", "&Save"},
{"Exit", "Exit"}, {"Save.accelerator", "control S"},
{"Add.Policy.Entry", "Add Policy Entry"}, {"Save.As", "Save &As..."},
{"Edit.Policy.Entry", "Edit Policy Entry"}, {"View.Warning.Log", "View &Warning Log"},
{"Remove.Policy.Entry", "Remove Policy Entry"}, {"Exit", "E&xit"},
{"Edit", "Edit"}, {"Add.Policy.Entry", "&Add Policy Entry"},
{"Edit.Policy.Entry", "&Edit Policy Entry"},
{"Remove.Policy.Entry", "&Remove Policy Entry"},
{"Edit", "&Edit"},
{"Retain", "Retain"}, {"Retain", "Retain"},
{"Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes", {"Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes",
...@@ -66,8 +69,8 @@ public class Resources extends java.util.ListResourceBundle { ...@@ -66,8 +69,8 @@ public class Resources extends java.util.ListResourceBundle {
{"Add.Public.Key.Alias", "Add Public Key Alias"}, {"Add.Public.Key.Alias", "Add Public Key Alias"},
{"Remove.Public.Key.Alias", "Remove Public Key Alias"}, {"Remove.Public.Key.Alias", "Remove Public Key Alias"},
{"File", "File"}, {"File", "&File"},
{"KeyStore", "KeyStore"}, {"KeyStore", "&KeyStore"},
{"Policy.File.", "Policy File:"}, {"Policy.File.", "Policy File:"},
{"Could.not.open.policy.file.policyFile.e.toString.", {"Could.not.open.policy.file.policyFile.e.toString.",
"Could not open policy file: {0}: {1}"}, "Could not open policy file: {0}: {1}"},
...@@ -89,20 +92,25 @@ public class Resources extends java.util.ListResourceBundle { ...@@ -89,20 +92,25 @@ public class Resources extends java.util.ListResourceBundle {
{"OK.to.overwrite.existing.file.filename.", {"OK.to.overwrite.existing.file.filename.",
"OK to overwrite existing file {0}?"}, "OK to overwrite existing file {0}?"},
{"Cancel", "Cancel"}, {"Cancel", "Cancel"},
{"CodeBase.", "CodeBase:"},
{"SignedBy.", "SignedBy:"}, // Policy Entry Dialog
{"Add.Principal", "Add Principal"}, {"CodeBase.", "&CodeBase:"},
{"Edit.Principal", "Edit Principal"}, {"SignedBy.", "&SignedBy:"},
{"Remove.Principal", "Remove Principal"}, {"Add.Principal", "&Add Principal"},
{"Principals.", "Principals:"}, {"Edit.Principal", "&Edit Principal"},
{".Add.Permission", " Add Permission"}, {"Remove.Principal", "&Remove Principal"},
{".Edit.Permission", " Edit Permission"}, {"Principals.", "&Principals:"},
{"Remove.Permission", "Remove Permission"}, {".Add.Permission", " A&dd Permission"},
{".Edit.Permission", " Ed&it Permission"},
{"Remove.Permission", "Re&move Permission"},
{"Done", "Done"}, {"Done", "Done"},
{"KeyStore.URL.", "KeyStore URL:"},
{"KeyStore.Type.", "KeyStore Type:"}, // KeyStore Edit Dialog
{"KeyStore.Provider.", "KeyStore Provider:"}, {"KeyStore.URL.", "KeyStore &URL:"},
{"KeyStore.Password.URL.", "KeyStore Password URL:"}, {"KeyStore.Type.", "KeyStore &Type:"},
{"KeyStore.Provider.", "KeyStore &Provider:"},
{"KeyStore.Password.URL.", "KeyStore Pass&word URL:"},
{"Principals", "Principals"}, {"Principals", "Principals"},
{".Edit.Principal.", " Edit Principal:"}, {".Edit.Principal.", " Edit Principal:"},
{".Add.New.Principal.", " Add New Principal:"}, {".Add.New.Principal.", " Add New Principal:"},
...@@ -122,8 +130,8 @@ public class Resources extends java.util.ListResourceBundle { ...@@ -122,8 +130,8 @@ public class Resources extends java.util.ListResourceBundle {
"Policy successfully written to {0}"}, "Policy successfully written to {0}"},
{"null.filename", "null filename"}, {"null.filename", "null filename"},
{"Save.changes.", "Save changes?"}, {"Save.changes.", "Save changes?"},
{"Yes", "Yes"}, {"Yes", "&Yes"},
{"No", "No"}, {"No", "&No"},
{"Policy.Entry", "Policy Entry"}, {"Policy.Entry", "Policy Entry"},
{"Save.Changes", "Save Changes"}, {"Save.Changes", "Save Changes"},
{"No.Policy.Entry.selected", "No Policy Entry selected"}, {"No.Policy.Entry.selected", "No Policy Entry selected"},
......
...@@ -23,12 +23,10 @@ reading these instructions.<br><br> ...@@ -23,12 +23,10 @@ reading these instructions.<br><br>
Warning: Principal name 'myalias' specified without a Principal class. Warning: Principal name 'myalias' specified without a Principal class.
<li> Click on "OK" <li> Click on "OK"
<li> Open the "File" menu, and "Save As" <li> Open the "File" menu, and "Save As"
<li> Enter "p1" as the file name <li> Save using the file name "p1"
<li> Click on "OK" <li> Click on "OK" in the status message window
<li> Click on "OK" in the message window
<li> Open the "File" menu and "Open Policy" <li> Open the "File" menu and "Open Policy"
<li> Enter "p1" as the file name <li> Open the file named "p1"
<li> Click on "OK"
<li> If the file opens successfully, the test passed. <li> If the file opens successfully, the test passed.
Otherwise, the test failed. Otherwise, the test failed.
</ol> </ol>
......
...@@ -9,8 +9,9 @@ reading these instructions.<br><br> ...@@ -9,8 +9,9 @@ reading these instructions.<br><br>
First, policytool will be invoked.<br><br> First, policytool will be invoked.<br><br>
On Windows, if PolicyTool tries to open the default Policy File<br> Pull down 'File' menu and select 'View Warning Log', which shows that
and it has the File separator character pointing the wrong way, like:<br><br> the default Policy File is not found. On Windows, if the file name
has the File separator character pointing the wrong way, like:<br><br>
C:\windows/java.policy<br><br> C:\windows/java.policy<br><br>
......
...@@ -12,6 +12,7 @@ First, policytool will be invoked.<br><br> ...@@ -12,6 +12,7 @@ First, policytool will be invoked.<br><br>
Then, follow these steps:<br> Then, follow these steps:<br>
0) Find (or create) a temporary directory that you have write access to. 0) Find (or create) a temporary directory that you have write access to.
(Example: 'C:\foo\tmp' on Windows or '/tmp' on other systems)<br><br> (Example: 'C:\foo\tmp' on Windows or '/tmp' on other systems)<br><br>
1) Click on the "Add Policy Entry" button in the 1) Click on the "Add Policy Entry" button in the
main policytool window.<br><br> main policytool window.<br><br>
...@@ -31,7 +32,7 @@ select "listenToAllAWTEvents".<br><br> ...@@ -31,7 +32,7 @@ select "listenToAllAWTEvents".<br><br>
select "Save As".<br><br> select "Save As".<br><br>
8) In the SaveAs window, enter "/tmp/ptool.test" as the file name 8) In the SaveAs window, enter "/tmp/ptool.test" as the file name
and click "OK".<br> and save it. If the file already exists, just replace it.<br>
(Or use the temporary directory mentioned in Step 0 if it's not '/tmp'. (Or use the temporary directory mentioned in Step 0 if it's not '/tmp'.
For example, "C:\foo\tmp\ptool.test" on Windows)<br><br> For example, "C:\foo\tmp\ptool.test" on Windows)<br><br>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册