/hg/icedtea-web: PolicyEditor can be made modal.
aazores at icedtea.classpath.org
aazores at icedtea.classpath.org
Wed Mar 26 15:02:11 UTC 2014
changeset fcb9dcf1c83c in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=fcb9dcf1c83c
author: Andrew Azores <aazores at redhat.com>
date: Wed Mar 26 11:02:00 2014 -0400
PolicyEditor can be made modal.
* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java:
(PolicyEditorWindow) new interface to facilitate PolicyEditor as a Window
rather than Panel. (PolicyEditorFrame, PolicyEditorDialog)
PolicyEditorWindow implementations. (getPolicyEditorFrame,
getPolicyEditorWindow) new methods to get frame or dialog implementations.
(setComponentMnemonic) made static. (preparePolicyEditorWindow) common
setup for frame and dialog implementations.
* netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java: refactor to use
PolicyEditorWindow
* netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java:
same
* netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java
same
* netx/net/sourceforge/jnlp/util/FileUtils.java: (showReadOnlyDialog,
showCouldNotOpenFileDialog, showCouldNotOpenFilePathDialog,
showCouldNotOpenDialog) use Component rather than JFrame
diffstat:
ChangeLog | 22 +
netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java | 14 +-
netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java | 17 +-
netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java | 17 +-
netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java | 210 ++++++++-
netx/net/sourceforge/jnlp/util/FileUtils.java | 11 +-
6 files changed, 236 insertions(+), 55 deletions(-)
diffs (truncated from 581 to 500 lines):
diff -r 689447c4d6bd -r fcb9dcf1c83c ChangeLog
--- a/ChangeLog Wed Mar 26 10:45:46 2014 -0400
+++ b/ChangeLog Wed Mar 26 11:02:00 2014 -0400
@@ -1,3 +1,25 @@
+2014-03-26 Andrew Azores <aazores at redhat.com>
+ Jiri Vanek <jvanek at redhat.com>
+
+ PolicyEditor can be made modal.
+ * netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java:
+ (PolicyEditorWindow) new interface to facilitate PolicyEditor as a Window
+ rather than Panel. (PolicyEditorFrame, PolicyEditorDialog)
+ PolicyEditorWindow implementations. (getPolicyEditorFrame,
+ getPolicyEditorWindow) new methods to get frame or dialog implementations.
+ (setComponentMnemonic) made static. (preparePolicyEditorWindow) common
+ setup for frame and dialog implementations.
+ * netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java: refactor to use
+ PolicyEditorWindow
+ * netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java:
+ same
+ * netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java
+ same
+ * netx/net/sourceforge/jnlp/util/FileUtils.java: (showReadOnlyDialog,
+ showCouldNotOpenFileDialog, showCouldNotOpenFilePathDialog,
+ showCouldNotOpenDialog) use Component rather than JFrame
+
+
2014-03-26 Andrew Azores <aazores at redhat.com>
Added many new permissions for PolicyEditor
diff -r 689447c4d6bd -r fcb9dcf1c83c netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java
--- a/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java Wed Mar 26 10:45:46 2014 -0400
+++ b/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java Wed Mar 26 11:02:00 2014 -0400
@@ -54,12 +54,12 @@
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
-import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.security.policyeditor.PolicyEditor;
+import net.sourceforge.jnlp.security.policyeditor.PolicyEditor.PolicyEditorWindow;
import net.sourceforge.jnlp.util.FileUtils;
import net.sourceforge.jnlp.util.FileUtils.OpenFileResult;
import net.sourceforge.jnlp.util.logging.OutputController;
@@ -72,7 +72,7 @@
*/
public class PolicyPanel extends NamedBorderPanel {
- private PolicyEditor policyEditor = null;
+ private PolicyEditorWindow policyEditor = null;
public PolicyPanel(final JFrame frame, final DeploymentConfiguration config) {
super(R("CPHeadPolicy"), new GridBagLayout());
@@ -161,12 +161,12 @@
* @param filePath a {@link String} representing the path to the file to be opened
*/
private void launchSimplePolicyEditor(final String filePath) {
- if (policyEditor == null || policyEditor.isClosed()) {
- policyEditor = PolicyEditor.createInstance(filePath);
- policyEditor.setVisible(true);
+ if (policyEditor == null || policyEditor.getPolicyEditor().isClosed()) {
+ policyEditor = PolicyEditor.getPolicyEditorFrame(filePath);
+ policyEditor.asWindow().setVisible(true);
} else {
- policyEditor.toFront();
- policyEditor.repaint();
+ policyEditor.asWindow().toFront();
+ policyEditor.asWindow().repaint();
}
}
diff -r 689447c4d6bd -r fcb9dcf1c83c netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java
--- a/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java Wed Mar 26 10:45:46 2014 -0400
+++ b/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java Wed Mar 26 11:02:00 2014 -0400
@@ -41,6 +41,7 @@
import java.awt.BorderLayout;
import java.awt.Color;
+import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
@@ -84,6 +85,7 @@
import net.sourceforge.jnlp.security.SecurityDialogs.AccessType;
import net.sourceforge.jnlp.security.SecurityUtil;
import net.sourceforge.jnlp.security.policyeditor.PolicyEditor;
+import net.sourceforge.jnlp.security.policyeditor.PolicyEditor.PolicyEditorWindow;
import net.sourceforge.jnlp.util.FileUtils;
import net.sourceforge.jnlp.util.logging.OutputController;
@@ -109,7 +111,7 @@
private JButton run, sandbox, advancedOptions, cancel, moreInfo;
private boolean alwaysTrustSelected;
private String bottomLabelWarningText;
- private PolicyEditor policyEditor = null;
+ private PolicyEditorWindow policyEditor = null;
public CertWarningPane(SecurityDialog x, CertVerifier certVerifier, SecurityDelegate securityDelegate) {
super(x, certVerifier);
@@ -330,14 +332,15 @@
filepath = null;
}
- if (policyEditor == null || policyEditor.isClosed()) {
- policyEditor = PolicyEditor.createInstance(filepath);
+ if (policyEditor == null || policyEditor.getPolicyEditor().isClosed()) {
+ policyEditor = PolicyEditor.getPolicyEditorDialog(filepath);
} else {
- policyEditor.toFront();
- policyEditor.repaint();
+ policyEditor.asWindow().toFront();
+ policyEditor.asWindow().repaint();
}
- policyEditor.addNewCodebase(file.getCodeBase().toString());
- policyEditor.setVisible(true);
+ policyEditor.setModalityType(ModalityType.DOCUMENT_MODAL);
+ policyEditor.getPolicyEditor().addNewCodebase(file.getCodeBase().toString());
+ policyEditor.asWindow().setVisible(true);
policyMenu.setVisible(false);
}
}
diff -r 689447c4d6bd -r fcb9dcf1c83c netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java
--- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java Wed Mar 26 10:45:46 2014 -0400
+++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java Wed Mar 26 11:02:00 2014 -0400
@@ -2,6 +2,7 @@
import static net.sourceforge.jnlp.runtime.Translator.R;
+import java.awt.Dialog.ModalityType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
@@ -25,6 +26,7 @@
import net.sourceforge.jnlp.security.appletextendedsecurity.ExecuteAppletAction;
import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletTrustConfirmation;
import net.sourceforge.jnlp.security.policyeditor.PolicyEditor;
+import net.sourceforge.jnlp.security.policyeditor.PolicyEditor.PolicyEditorWindow;
import net.sourceforge.jnlp.tools.CertInformation;
import net.sourceforge.jnlp.tools.JarCertVerifier;
@@ -34,7 +36,7 @@
private final JButton sandboxButton;
private final JButton advancedOptionsButton;
private final JPopupMenu policyMenu;
- private PolicyEditor policyEditor = null;
+ private PolicyEditorWindow policyEditor = null;
public PartiallySignedAppTrustWarningPanel(JNLPFile file, ActionChoiceListener actionChoiceListener, SecurityDialog securityDialog) {
super(file, actionChoiceListener);
@@ -175,14 +177,15 @@
filepath = null;
}
- if (policyEditor == null || policyEditor.isClosed()) {
- policyEditor = PolicyEditor.createInstance(filepath);
+ if (policyEditor == null || policyEditor.getPolicyEditor().isClosed()) {
+ policyEditor = PolicyEditor.getPolicyEditorDialog(filepath);
} else {
- policyEditor.toFront();
- policyEditor.repaint();
+ policyEditor.asWindow().toFront();
+ policyEditor.asWindow().repaint();
}
- policyEditor.addNewCodebase(file.getCodeBase().toString());
- policyEditor.setVisible(true);
+ policyEditor.setModalityType(ModalityType.DOCUMENT_MODAL);
+ policyEditor.getPolicyEditor().addNewCodebase(file.getCodeBase().toString());
+ policyEditor.asWindow().setVisible(true);
policyMenu.setVisible(false);
}
}
diff -r 689447c4d6bd -r fcb9dcf1c83c netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Wed Mar 26 10:45:46 2014 -0400
+++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Wed Mar 26 11:02:00 2014 -0400
@@ -36,10 +36,12 @@
package net.sourceforge.jnlp.security.policyeditor;
+import java.awt.Dialog.ModalityType;
import static net.sourceforge.jnlp.runtime.Translator.R;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
+import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
@@ -73,6 +75,7 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
+import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
@@ -81,7 +84,7 @@
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
-import javax.swing.JRootPane;
+import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
@@ -124,7 +127,7 @@
* Comments will *not* be preserved when PolicyEditor next saves to the
* file.
*/
-public class PolicyEditor extends JFrame {
+public class PolicyEditor extends JPanel {
/**
* Command line switch to print a help message.
@@ -161,7 +164,6 @@
private final JList list = new JList(listModel);
private final JButton okButton = new JButton(), closeButton = new JButton(),
addCodebaseButton = new JButton(), removeCodebaseButton = new JButton();
- private final JMenuBar menuBar = new JMenuBar();
private final JFileChooser fileChooser;
private CustomPolicyViewer cpViewer = null;
private final WeakReference<PolicyEditor> weakThis = new WeakReference<PolicyEditor>(this);
@@ -295,19 +297,156 @@
};
setAccelerators();
- setTitle(R("PETitle"));
setupLayout();
list.setSelectedIndex(0);
updateCheckboxes("");
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ }
- addWindowListener(new WindowAdapter() {
+ private static void preparePolicyEditorWindow(final PolicyEditorWindow w, PolicyEditor e) {
+ w.setModalityType(ModalityType.MODELESS); //at least some default
+ w.setPolicyEditor(e);
+ w.setTitle(R("PETitle"));
+ w.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ w.setJMenuBar(createMenuBar(w.asWindow(), w.getPolicyEditor()));
+ setupPolicyEditorWindow(w.asWindow(), w.getPolicyEditor());
+
+ }
+
+ private static void setupPolicyEditorWindow(final Window window, final PolicyEditor editor) {
+ window.add(editor);
+ window.pack();
+ editor.setVisible(true);
+
+ window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
- quit();
+ editor.quit();
+ window.dispose();
}
});
+
+ editor.closeButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ window.dispose();
+ }
+ });
+ }
+
+ public static interface PolicyEditorWindow {
+
+ public void setTitle(String s);
+
+ public void setDefaultCloseOperation(int i);
+
+ public PolicyEditor getPolicyEditor();
+
+ public void setPolicyEditor(PolicyEditor e);
+
+ public void setJMenuBar(JMenuBar menu);
+
+ public Window asWindow();
+
+ public void setModalityType(ModalityType modalityType);
+ }
+
+ private static class PolicyEditorFrame extends JFrame implements PolicyEditorWindow {
+
+ private PolicyEditor editor;
+
+ private PolicyEditorFrame(final PolicyEditor editor) {
+ super();
+ preparePolicyEditorWindow((PolicyEditorWindow)this, editor);
+ }
+
+ @Override
+ public final void setTitle(String title) {
+ super.setTitle(title);
+ }
+
+ @Override
+ public final PolicyEditor getPolicyEditor() {
+ return editor;
+ }
+
+ @Override
+ public final void setPolicyEditor(PolicyEditor e) {
+ editor = e;
+ }
+
+ @Override
+ public final void setDefaultCloseOperation(int operation) {
+ super.setDefaultCloseOperation(operation);
+ }
+
+ @Override
+ public final void setJMenuBar(JMenuBar menu) {
+ super.setJMenuBar(menu);
+ }
+
+ @Override
+ public final Window asWindow() {
+ return this;
+ }
+
+ @Override
+ public void setModalityType(ModalityType type) {
+ //no op for frame
+ }
+ }
+
+ public static PolicyEditorWindow getPolicyEditorFrame(final String filepath) {
+ return new PolicyEditorFrame(new PolicyEditor(filepath));
+ }
+
+ private static class PolicyEditorDialog extends JDialog implements PolicyEditorWindow {
+
+ private PolicyEditor editor;
+
+ private PolicyEditorDialog(final PolicyEditor editor) {
+ super();
+ preparePolicyEditorWindow((PolicyEditorWindow)this, editor);
+ }
+
+ @Override
+ public final void setTitle(String title) {
+ super.setTitle(title);
+ }
+
+ @Override
+ public final PolicyEditor getPolicyEditor() {
+ return editor;
+ }
+
+ @Override
+ public final void setPolicyEditor(PolicyEditor e) {
+ editor = e;
+ }
+
+ @Override
+ public final void setDefaultCloseOperation(int operation) {
+ super.setDefaultCloseOperation(operation);
+ }
+
+ @Override
+ public final void setJMenuBar(JMenuBar menu) {
+ super.setJMenuBar(menu);
+ }
+
+ @Override
+ public final Window asWindow() {
+ return this;
+ }
+
+ @Override
+ public void setModalityType(ModalityType type) {
+ super.setModalityType(type);
+ }
+ }
+
+ public static PolicyEditorWindow getPolicyEditorDialog(final String filepath) {
+ return new PolicyEditorDialog(new PolicyEditor(filepath));
}
private void setClosed() {
@@ -370,9 +509,8 @@
*/
private void setAccelerator(final int trigger, final int modifiers, final Action action, final String identifier) {
final KeyStroke key = KeyStroke.getKeyStroke(trigger, modifiers);
- final JRootPane root = getRootPane();
- root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, identifier);
- root.getActionMap().put(identifier, action);
+ this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(key, identifier);
+ this.getActionMap().put(identifier, action);
}
/**
@@ -454,7 +592,6 @@
}
weakThis.clear();
setClosed();
- dispose();
}
/**
@@ -649,7 +786,7 @@
* @param component the component for which to set a mnemonic
* @param mnemonic the mnemonic to set
*/
- private void setComponentMnemonic(final AbstractButton component, final String mnemonic) {
+ private static void setComponentMnemonic(final AbstractButton component, final String mnemonic) {
final int trig;
try {
trig = Integer.parseInt(mnemonic);
@@ -660,45 +797,61 @@
component.setMnemonic(trig);
}
- /**
- * Lay out all controls, tooltips, etc.
- */
- private void setupLayout() {
+ private static JMenuBar createMenuBar(final Window window, final PolicyEditor editor) {
+ final JMenuBar menuBar = new JMenuBar();
+
final JMenu fileMenu = new JMenu(R("PEFileMenu"));
setComponentMnemonic(fileMenu, R("PEFileMenuMnemonic"));
+
final JMenuItem openItem = new JMenuItem(R("PEOpenMenuItem"));
setComponentMnemonic(openItem, R("PEOpenMenuItemMnemonic"));
openItem.setAccelerator(KeyStroke.getKeyStroke(openItem.getMnemonic(), ActionEvent.CTRL_MASK));
- openItem.addActionListener(openButtonAction);
+ openItem.addActionListener(editor.openButtonAction);
fileMenu.add(openItem);
+
final JMenuItem saveItem = new JMenuItem(R("PESaveMenuItem"));
setComponentMnemonic(saveItem, R("PESaveMenuItemMnemonic"));
saveItem.setAccelerator(KeyStroke.getKeyStroke(saveItem.getMnemonic(), ActionEvent.CTRL_MASK));
- saveItem.addActionListener(okButtonAction);
+ saveItem.addActionListener(editor.okButtonAction);
fileMenu.add(saveItem);
+
final JMenuItem saveAsItem = new JMenuItem(R("PESaveAsMenuItem"));
setComponentMnemonic(saveAsItem, R("PESaveAsMenuItemMnemonic"));
saveAsItem.setAccelerator(KeyStroke.getKeyStroke(saveAsItem.getMnemonic(), ActionEvent.CTRL_MASK));
- saveAsItem.addActionListener(saveAsButtonAction);
+ saveAsItem.addActionListener(editor.saveAsButtonAction);
fileMenu.add(saveAsItem);
+
final JMenuItem exitItem = new JMenuItem(R("PEExitMenuItem"));
setComponentMnemonic(exitItem, R("PEExitMenuItemMnemonic"));
exitItem.setAccelerator(KeyStroke.getKeyStroke(exitItem.getMnemonic(), ActionEvent.CTRL_MASK));
- exitItem.addActionListener(closeButtonAction);
+ exitItem.addActionListener(editor.closeButtonAction);
+ exitItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(final ActionEvent e) {
+ window.dispose();
+ }
+ });
fileMenu.add(exitItem);
menuBar.add(fileMenu);
final JMenu viewMenu = new JMenu(R("PEViewMenu"));
setComponentMnemonic(viewMenu, R("PEViewMenuMnemonic"));
+
final JMenuItem customPermissionsItem = new JMenuItem(R("PECustomPermissionsItem"));
setComponentMnemonic(customPermissionsItem, R("PECustomPermissionsItemMnemonic"));
customPermissionsItem.setAccelerator(KeyStroke.getKeyStroke(customPermissionsItem.getMnemonic(), ActionEvent.ALT_MASK));
- customPermissionsItem.addActionListener(viewCustomButtonAction);
+ customPermissionsItem.addActionListener(editor.viewCustomButtonAction);
viewMenu.add(customPermissionsItem);
menuBar.add(viewMenu);
- this.setJMenuBar(menuBar);
+ return menuBar;
+ }
+
+ /**
+ * Lay out all controls, tooltips, etc.
+ */
+ private void setupLayout() {
final JLabel checkboxLabel = new JLabel();
checkboxLabel.setText(R("PECheckboxLabel"));
checkboxLabel.setBorder(new EmptyBorder(2, 2, 2, 2));
@@ -796,7 +949,6 @@
add(closeButton, cancelButtonConstraints);
setMinimumSize(getPreferredSize());
- pack();
}
/**
@@ -979,10 +1131,10 @@
}
final StringBuilder sb = new StringBuilder();
sb.append(AUTOGENERATED_NOTICE);
- sb.append("\n/* Generated by PolicyEditor at " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
- .format(Calendar.getInstance().getTime()) + " */" + System.getProperty("line.separator"));
+ sb.append("\n/* Generated by PolicyEditor at ").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
More information about the distro-pkg-dev
mailing list