diff --git a/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java b/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java --- a/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/PolicyPanel.java @@ -54,12 +54,12 @@ import javax.swing.Box; 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.PolicyEditorFrame; import net.sourceforge.jnlp.util.FileUtils; import net.sourceforge.jnlp.util.FileUtils.OpenFileResult; import net.sourceforge.jnlp.util.logging.OutputController; @@ -72,7 +72,7 @@ import net.sourceforge.jnlp.util.logging */ public class PolicyPanel extends NamedBorderPanel { - private PolicyEditor policyEditor = null; + private PolicyEditorFrame policyEditor = null; public PolicyPanel(final JFrame frame, final DeploymentConfiguration config) { super(R("CPHeadPolicy"), new GridBagLayout()); @@ -161,8 +161,8 @@ public class PolicyPanel extends NamedBo * @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); + if (policyEditor == null || policyEditor.editor.isClosed()) { + policyEditor = PolicyEditor.getPolicyEditorFrame(filePath); policyEditor.setVisible(true); } else { policyEditor.toFront(); diff --git a/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java b/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java --- a/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java +++ b/netx/net/sourceforge/jnlp/security/dialogs/CertWarningPane.java @@ -41,6 +41,7 @@ import static net.sourceforge.jnlp.runti 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.Sec 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.PolicyEditorDialog; import net.sourceforge.jnlp.util.FileUtils; import net.sourceforge.jnlp.util.logging.OutputController; @@ -109,7 +111,7 @@ public class CertWarningPane extends Sec private JButton run, sandbox, advancedOptions, cancel, moreInfo; private boolean alwaysTrustSelected; private String bottomLabelWarningText; - private PolicyEditor policyEditor = null; + private PolicyEditorDialog policyEditor = null; public CertWarningPane(SecurityDialog x, CertVerifier certVerifier, SecurityDelegate securityDelegate) { super(x, certVerifier); @@ -330,13 +332,14 @@ public class CertWarningPane extends Sec filepath = null; } - if (policyEditor == null || policyEditor.isClosed()) { - policyEditor = PolicyEditor.createInstance(filepath); + if (policyEditor == null || policyEditor.editor.isClosed()) { + policyEditor = PolicyEditor.getPolicyEditorDialog(filepath); } else { policyEditor.toFront(); policyEditor.repaint(); } - policyEditor.addNewCodebase(file.getCodeBase().toString()); + policyEditor.setModalityType(ModalityType.DOCUMENT_MODAL); + policyEditor.editor.addNewCodebase(file.getCodeBase().toString()); policyEditor.setVisible(true); policyMenu.setVisible(false); } diff --git a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java --- a/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java +++ b/netx/net/sourceforge/jnlp/security/dialogs/apptrustwarningpanel/PartiallySignedAppTrustWarningPanel.java @@ -2,6 +2,7 @@ package net.sourceforge.jnlp.security.di 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.Sec 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.PolicyEditorDialog; import net.sourceforge.jnlp.tools.CertInformation; import net.sourceforge.jnlp.tools.JarCertVerifier; @@ -34,7 +36,7 @@ public class PartiallySignedAppTrustWarn private final JButton sandboxButton; private final JButton advancedOptionsButton; private final JPopupMenu policyMenu; - private PolicyEditor policyEditor = null; + private PolicyEditorDialog policyEditor = null; public PartiallySignedAppTrustWarningPanel(JNLPFile file, ActionChoiceListener actionChoiceListener, SecurityDialog securityDialog) { super(file, actionChoiceListener); @@ -175,13 +177,14 @@ public class PartiallySignedAppTrustWarn filepath = null; } - if (policyEditor == null || policyEditor.isClosed()) { - policyEditor = PolicyEditor.createInstance(filepath); + if (policyEditor == null || policyEditor.editor.isClosed()) { + policyEditor = PolicyEditor.getPolicyEditorDialog(filepath); } else { policyEditor.toFront(); policyEditor.repaint(); } - policyEditor.addNewCodebase(file.getCodeBase().toString()); + policyEditor.setModalityType(ModalityType.DOCUMENT_MODAL); + policyEditor.editor.addNewCodebase(file.getCodeBase().toString()); policyEditor.setVisible(true); policyMenu.setVisible(false); } diff --git a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java --- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java +++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java @@ -40,6 +40,7 @@ import static net.sourceforge.jnlp.runti 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,15 +74,15 @@ import javax.swing.DefaultListModel; 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; import javax.swing.JList; import javax.swing.JMenu; 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 +125,7 @@ import net.sourceforge.jnlp.util.logging * 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. @@ -150,6 +151,7 @@ public class PolicyEditor extends JFrame private static final String AUTOGENERATED_NOTICE = "/* DO NOT MODIFY! AUTO-GENERATED */"; + private final Window parentWindow; private File file; private boolean changesMade = false; private boolean closed = false; @@ -161,7 +163,6 @@ public class PolicyEditor extends JFrame 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 weakThis = new WeakReference(this); @@ -170,8 +171,9 @@ public class PolicyEditor extends JFrame private final ActionListener okButtonAction, closeButtonAction, addCodebaseButtonAction, removeCodebaseButtonAction, openButtonAction, saveAsButtonAction, viewCustomButtonAction; - public PolicyEditor(final String filepath) { + private PolicyEditor(final String filepath, final Window parentWindow) { super(); + this.parentWindow = parentWindow; setLayout(new GridBagLayout()); for (final PolicyEditorPermissions perm : PolicyEditorPermissions.values()) { @@ -295,19 +297,69 @@ public class PolicyEditor extends JFrame }; setAccelerators(); - setTitle(R("PETitle")); setupLayout(); list.setSelectedIndex(0); updateCheckboxes(""); - setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + } - addWindowListener(new WindowAdapter() { + public PolicyEditor(final String filepath) { + this(filepath, null); + } + + 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 class PolicyEditorFrame extends JDialog { + public final PolicyEditor editor; + + public PolicyEditorFrame(final PolicyEditor editor) { + super(); + this.editor = editor; + setupPolicyEditorWindow(this, editor); + setJMenuBar(createMenuBar(this, editor)); + setTitle(R("PETitle")); + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + } + } + + public static PolicyEditorFrame getPolicyEditorFrame(final String filepath) { + return new PolicyEditorFrame(new PolicyEditor(filepath)); + } + + public static class PolicyEditorDialog extends JDialog { + public final PolicyEditor editor; + + public PolicyEditorDialog(final PolicyEditor editor) { + super(); + this.editor = editor; + setupPolicyEditorWindow(this, editor); + setJMenuBar(createMenuBar(this, editor)); + setTitle(R("PETitle")); + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + } + } + + public static PolicyEditorDialog getPolicyEditorDialog(final String filepath) { + return new PolicyEditorDialog(new PolicyEditor(filepath)); } private void setClosed() { @@ -370,9 +422,8 @@ public class PolicyEditor extends JFrame */ 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 +505,6 @@ public class PolicyEditor extends JFrame } weakThis.clear(); setClosed(); - dispose(); } /** @@ -649,7 +699,7 @@ public class PolicyEditor extends JFrame * @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 +710,61 @@ public class PolicyEditor extends JFrame 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 +862,6 @@ public class PolicyEditor extends JFrame add(closeButton, cancelButtonConstraints); setMinimumSize(getPreferredSize()); - pack(); } /** @@ -829,11 +894,11 @@ public class PolicyEditor extends JFrame } OpenFileResult ofr = FileUtils.testFilePermissions(file); if (ofr == OpenFileResult.FAILURE || ofr == OpenFileResult.NOT_FILE) { - FileUtils.showCouldNotOpenFilepathDialog(weakThis.get(), file.getPath()); + FileUtils.showCouldNotOpenFilepathDialog(parentWindow, file.getPath()); return; } if (ofr == OpenFileResult.CANT_WRITE) { - FileUtils.showReadOnlyDialog(weakThis.get()); + FileUtils.showReadOnlyDialog(parentWindow); } final String contents; try { @@ -845,7 +910,7 @@ public class PolicyEditor extends JFrame } catch (final IOException e) { OutputController.getLogger().log(e); OutputController.getLogger().log(OutputController.Level.ERROR_ALL, R("RCantOpenFile", file.getPath())); - FileUtils.showCouldNotOpenDialog(weakThis.get(), R("PECouldNotOpen")); + FileUtils.showCouldNotOpenDialog(parentWindow, R("PECouldNotOpen")); return; } codebasePermissionsMap.clear(); @@ -858,7 +923,7 @@ public class PolicyEditor extends JFrame fileLock = FileUtils.getFileLock(file.getAbsolutePath(), false, true); } catch (final FileNotFoundException e) { OutputController.getLogger().log(e); - FileUtils.showCouldNotOpenDialog(weakThis.get(), R("PECouldNotOpen")); + FileUtils.showCouldNotOpenDialog(parentWindow, R("PECouldNotOpen")); return; } boolean openBlock = false, commentBlock = false; @@ -1098,12 +1163,12 @@ public class PolicyEditor extends JFrame // maybe the user just forgot the -file flag, so try to open anyway filepath = args[0]; } - final PolicyEditor editor = new PolicyEditor(filepath); - editor.setVisible(true); + final PolicyEditorFrame frame = getPolicyEditorFrame(filepath); + frame.setVisible(true); final String codebaseStr = argsMap.get(CODEBASE_FLAG); if (codebaseStr != null) { final String[] urls = codebaseStr.split(" "); - editor.addNewCodebases(urls); + frame.editor.addNewCodebases(urls); } } }); diff --git a/netx/net/sourceforge/jnlp/util/FileUtils.java b/netx/net/sourceforge/jnlp/util/FileUtils.java --- a/netx/net/sourceforge/jnlp/util/FileUtils.java +++ b/netx/net/sourceforge/jnlp/util/FileUtils.java @@ -18,6 +18,7 @@ package net.sourceforge.jnlp.util; import static net.sourceforge.jnlp.runtime.Translator.R; +import java.awt.Window; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -30,7 +31,6 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.RandomAccessFile; import java.io.Writer; -import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.security.DigestInputStream; @@ -347,7 +347,7 @@ public final class FileUtils { * Show a dialog informing the user that the file is currently read-only * @param frame a {@link JFrame} to act as parent to this dialog */ - public static void showReadOnlyDialog(final JFrame frame) { + public static void showReadOnlyDialog(final Window frame) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -361,7 +361,7 @@ public final class FileUtils { * @param frame a {@link JFrame} to act as parent to this dialog * @param filePath a {@link String} representing the path to the file we failed to open */ - public static void showCouldNotOpenFilepathDialog(final JFrame frame, final String filePath) { + public static void showCouldNotOpenFilepathDialog(final Window frame, final String filePath) { showCouldNotOpenDialog(frame, R("RCantOpenFile", filePath)); } @@ -371,7 +371,7 @@ public final class FileUtils { * @param filePath a {@link String} representing the path to the file we failed to open * @param reason a {@link OpenFileResult} specifying more precisely why we failed to open the file */ - public static void showCouldNotOpenFileDialog(final JFrame frame, final String filePath, final OpenFileResult reason) { + public static void showCouldNotOpenFileDialog(final Window frame, final String filePath, final OpenFileResult reason) { final String message; switch (reason) { case CANT_CREATE: @@ -396,7 +396,7 @@ public final class FileUtils { * @param filePath a {@link String} representing the path to the file we failed to open * @param message a {@link String} giving the specific reason the file could not be opened */ - public static void showCouldNotOpenDialog(final JFrame frame, final String message) { + public static void showCouldNotOpenDialog(final Window frame, final String message) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() {