[RFC] netx: stop using Look and Feel related methods (PR372)
Deepak Bhole
dbhole at redhat.com
Fri Jul 16 13:40:18 PDT 2010
* Omair Majid <omajid at redhat.com> [2010-07-06 11:29]:
> Hi,
>
> Netx (incorrectly) uses Look and Feel related hooks and methods to
> create the security-related dialogs it shows to the user [1]. While
> most of the time it has no consequences, a few JNLP applications
> that modify the Look and Feel demonstrate incorrect behaviour [2].
> The attached patch uses the standard Swing methods to create and
> display GUIs. It is a somewhat large patch, even though most of it
> is fairly mundane - creating JDialogs, setting a JPanel in the
> center depending on the type of dialog and then adding the
> appropriate controls to the JPanel. I have tried to avoid changing
> anything that goes inside the JPanel - it should behave exactly as
> before. I have done some testing and it seems to work just as well
> as before, but I would appreciate it if others could look it over
> and try it out too.
>
> Cheers,
> Omair
>
> [1] http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=372
> [2] https://substance.dev.java.net/webstart/test.jnlp
Doh! I thought I went through this one when I approved the rest.
A lot of these changes do look mechanical as you stated.
I am fine with committing this to head, but please make sure you have
THOROUGHLY tested this.. breakages in things like security dialog would
make netx/plugin unusable for signed applications, so we need to make
sure it works well.
Cheers,
Deepak
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/AccessWarningPane.java
> --- a/netx/net/sourceforge/jnlp/security/AccessWarningPane.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/AccessWarningPane.java Mon Jul 05 11:59:03 2010 -0400
> @@ -51,13 +51,11 @@
> import javax.swing.ImageIcon;
> import javax.swing.JButton;
> import javax.swing.JCheckBox;
> -import javax.swing.JComponent;
> import javax.swing.JLabel;
> import javax.swing.JPanel;
> import javax.swing.SwingConstants;
>
> import net.sourceforge.jnlp.JNLPFile;
> -import net.sourceforge.jnlp.runtime.JNLPRuntime;
>
> /**
> * Provides the look and feel for a SecurityWarningDialog. These dialogs are
> @@ -67,28 +65,29 @@
> *
> * @author <a href="mailto:jsumali at redhat.com">Joshua Sumali</a>
> */
> -public class AccessWarningPane extends SecurityDialogUI {
> +public class AccessWarningPane extends SecurityDialogPanel {
>
> JCheckBox alwaysAllow;
> Object[] extras;
>
> - public AccessWarningPane(JComponent x, CertVerifier certVerifier) {
> + public AccessWarningPane(SecurityWarningDialog x, CertVerifier certVerifier) {
> super(x, certVerifier);
> + addComponents();
> }
> +
>
> - public AccessWarningPane(JComponent x, Object[] extras, CertVerifier certVerifier) {
> + public AccessWarningPane(SecurityWarningDialog x, Object[] extras, CertVerifier certVerifier) {
> super(x, certVerifier);
> this.extras = extras;
> + addComponents();
> }
>
> /**
> * Creates the actual GUI components, and adds it to <code>optionPane</code>
> */
> - protected void installComponents() {
> - SecurityWarningDialog.AccessType type =
> - ((SecurityWarningDialog)optionPane).getType();
> - JNLPFile file =
> - ((SecurityWarningDialog)optionPane).getFile();
> + private void addComponents() {
> + SecurityWarningDialog.AccessType type = parent.getType();
> + JNLPFile file = parent.getFile();
>
> String name = "";
> String publisher = "";
> @@ -173,35 +172,22 @@
>
> JButton run = new JButton("Allow");
> JButton cancel = new JButton("Cancel");
> - run.addActionListener(createButtonActionListener(0));
> + run.addActionListener(createButtonToSetValueListener(parent,0));
> run.addActionListener(new CheckBoxListener());
> - cancel.addActionListener(createButtonActionListener(1));
> + cancel.addActionListener(createButtonToSetValueListener(parent, 1));
> initialFocusComponent = cancel;
> buttonPanel.add(run);
> buttonPanel.add(cancel);
> buttonPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
>
> //all of the above
> - JPanel main = new JPanel();
> - main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
> - main.add(topPanel);
> - main.add(infoPanel);
> - main.add(buttonPanel);
> + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
> + add(topPanel);
> + add(infoPanel);
> + add(buttonPanel);
>
> - optionPane.add(main, BorderLayout.CENTER);
> }
>
> - private static String R(String key) {
> - return JNLPRuntime.getMessage(key);
> - }
> -
> - private static String R(String key, Object param) {
> - return JNLPRuntime.getMessage(key, new Object[] {param});
> - }
> -
> - protected String htmlWrap (String s) {
> - return "<html>"+s+"</html>";
> - }
>
> private class CheckBoxListener implements ActionListener {
> public void actionPerformed(ActionEvent e) {
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/AppletWarningPane.java
> --- a/netx/net/sourceforge/jnlp/security/AppletWarningPane.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/AppletWarningPane.java Mon Jul 05 11:59:03 2010 -0400
> @@ -46,18 +46,18 @@
> import javax.swing.BorderFactory;
> import javax.swing.BoxLayout;
> import javax.swing.JButton;
> -import javax.swing.JComponent;
> import javax.swing.JLabel;
> import javax.swing.JPanel;
>
>
> -public class AppletWarningPane extends SecurityDialogUI {
> +public class AppletWarningPane extends SecurityDialogPanel {
>
> - public AppletWarningPane(JComponent x, CertVerifier certVerifier) {
> + public AppletWarningPane(SecurityWarningDialog x, CertVerifier certVerifier) {
> super(x, certVerifier);
> + addComponents();
> }
>
> - protected void installComponents() {
> + protected void addComponents() {
>
> //Top label
> String topLabelText = "While support for verifying signed code" +
> @@ -95,9 +95,9 @@
> yes.setPreferredSize(d);
> no.setPreferredSize(d);
> cancel.setPreferredSize(d);
> - yes.addActionListener(createButtonActionListener(0));
> - no.addActionListener(createButtonActionListener(1));
> - cancel.addActionListener(createButtonActionListener(2));
> + yes.addActionListener(createButtonToSetValueListener(parent, 0));
> + no.addActionListener(createButtonToSetValueListener(parent, 1));
> + cancel.addActionListener(createButtonToSetValueListener(parent, 2));
> initialFocusComponent = cancel;
> buttonPanel.add(yes);
> buttonPanel.add(no);
> @@ -105,17 +105,12 @@
> buttonPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
>
> //all of the above
> - JPanel main = new JPanel();
> - main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
> - main.add(topPanel);
> - main.add(infoPanel);
> - main.add(buttonPanel);
> + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
> + add(topPanel);
> + add(infoPanel);
> + add(buttonPanel);
>
> - optionPane.add(main, BorderLayout.CENTER);
> }
>
> - protected String htmlWrap (String s) {
> - return "<html>"+s+"</html>";
> - }
> }
>
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/CertWarningPane.java
> --- a/netx/net/sourceforge/jnlp/security/CertWarningPane.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/CertWarningPane.java Mon Jul 05 11:59:03 2010 -0400
> @@ -53,7 +53,6 @@
> import javax.swing.ImageIcon;
> import javax.swing.JButton;
> import javax.swing.JCheckBox;
> -import javax.swing.JComponent;
> import javax.swing.JLabel;
> import javax.swing.JPanel;
> import javax.swing.SwingConstants;
> @@ -71,26 +70,24 @@
> *
> * @author <a href="mailto:jsumali at redhat.com">Joshua Sumali</a>
> */
> -public class CertWarningPane extends SecurityDialogUI {
> +public class CertWarningPane extends SecurityDialogPanel {
>
> JCheckBox alwaysTrust;
> CertVerifier certVerifier;
>
> - public CertWarningPane(JComponent x, CertVerifier certVerifier) {
> + public CertWarningPane(SecurityWarningDialog x, CertVerifier certVerifier) {
> super(x, certVerifier);
> this.certVerifier = certVerifier;
> + addComponents();
> }
>
> /**
> - * Creates the actual GUI components, and adds it to <code>optionPane</code>
> + * Creates the actual GUI components, and adds it to the parent
> */
> - protected void installComponents() {
> - SecurityWarningDialog.AccessType type =
> - ((SecurityWarningDialog)optionPane).getType();
> - JNLPFile file =
> - ((SecurityWarningDialog)optionPane).getFile();
> - Certificate c = ((SecurityWarningDialog)optionPane)
> - .getJarSigner().getPublisher();
> + private void addComponents() {
> + SecurityWarningDialog.AccessType type = parent.getType();
> + JNLPFile file = parent.getFile();
> + Certificate c = parent.getJarSigner().getPublisher();
>
> String name = "";
> String publisher = "";
> @@ -193,26 +190,25 @@
> Dimension d = new Dimension(buttonWidth, buttonHeight);
> run.setPreferredSize(d);
> cancel.setPreferredSize(d);
> - run.addActionListener(createButtonActionListener(0));
> + run.addActionListener(createButtonToSetValueListener(parent, 0));
> run.addActionListener(new CheckBoxListener());
> - cancel.addActionListener(createButtonActionListener(1));
> + cancel.addActionListener(createButtonToSetValueListener(parent, 1));
> initialFocusComponent = cancel;
> buttonPanel.add(run);
> buttonPanel.add(cancel);
> buttonPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
>
> //all of the above
> - JPanel main = new JPanel();
> - main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
> - main.add(topPanel);
> - main.add(infoPanel);
> - main.add(buttonPanel);
> + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
> + add(topPanel);
> + add(infoPanel);
> + add(buttonPanel);
>
> JLabel bottomLabel;
> JButton moreInfo = new JButton("More information...");
> moreInfo.addActionListener(new MoreInfoButtonListener());
>
> - if (((SecurityWarningDialog)optionPane).getJarSigner().getRootInCacerts())
> + if (parent.getJarSigner().getRootInCacerts())
> bottomLabel = new JLabel(htmlWrap(R("STrustedSource")));
> else
> bottomLabel = new JLabel(htmlWrap(R("SUntrustedSource")));
> @@ -223,27 +219,14 @@
> bottomPanel.add(moreInfo);
> bottomPanel.setPreferredSize(new Dimension(500,100));
> bottomPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
> - main.add(bottomPanel);
> + add(bottomPanel);
>
> - optionPane.add(main, BorderLayout.CENTER);
> }
>
> - private static String R(String key) {
> - return JNLPRuntime.getMessage(key);
> - }
> -
> - protected String htmlWrap (String s) {
> - return "<html>"+s+"</html>";
> - }
> -
> private class MoreInfoButtonListener implements ActionListener {
> public void actionPerformed(ActionEvent e) {
> -
> - // TODO: Can we change this to just
> - // optionPane.showMoreInfo(); ?
> - SecurityWarningDialog.showMoreInfoDialog(
> - ((SecurityWarningDialog)optionPane).getJarSigner(),
> - optionPane);
> + SecurityWarningDialog.showMoreInfoDialog(parent.getJarSigner(),
> + parent);
> }
> }
>
> @@ -255,9 +238,11 @@
> if (alwaysTrust != null && alwaysTrust.isSelected()) {
> try {
> KeyTool kt = new KeyTool();
> - Certificate c =
> - ((SecurityWarningDialog)optionPane).getJarSigner().getPublisher();
> + Certificate c = parent.getJarSigner().getPublisher();
> kt.importCert(c);
> + if (JNLPRuntime.isDebug()) {
> + System.out.println("certificate is now permanently trusted");
> + }
> } catch (Exception ex) {
> //TODO: Let NetX show a dialog here notifying user
> //about being unable to add cert to keystore
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/CertsInfoPane.java
> --- a/netx/net/sourceforge/jnlp/security/CertsInfoPane.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/CertsInfoPane.java Mon Jul 05 11:59:03 2010 -0400
> @@ -63,7 +63,7 @@
> *
> * @author <a href="mailto:jsumali at redhat.com">Joshua Sumali</a>
> */
> -public class CertsInfoPane extends SecurityDialogUI {
> +public class CertsInfoPane extends SecurityDialogPanel {
>
> private ArrayList<CertPath> certs;
> private JList list;
> @@ -76,15 +76,16 @@
> private String[] columnNames = { "Field", "Value" };
> protected ArrayList<String[][]> certsData;
>
> - public CertsInfoPane(JComponent x, CertVerifier certVerifier) {
> + public CertsInfoPane(SecurityWarningDialog x, CertVerifier certVerifier) {
> super(x, certVerifier);
> + addComponents();
> }
>
> /**
> * Builds the JTree out of CertPaths.
> */
> void buildTree() {
> - certs = ((SecurityWarningDialog)optionPane).getJarSigner().getCerts();
> + certs = parent.getJarSigner().getCerts();
> //for now, we're only going to display the first signer, even though
> //jars can be signed by multiple people.
> CertPath firstPath = certs.get(0);
> @@ -178,7 +179,7 @@
> /**
> * Constructs the GUI components of this UI
> */
> - protected void installComponents() {
> + protected void addComponents() {
> buildTree();
> populateTable();
> /**
> @@ -224,14 +225,14 @@
> JPanel buttonPane = new JPanel(new BorderLayout());
> JButton close = new JButton("Close");
> JButton copyToClipboard = new JButton("Copy to Clipboard");
> - close.addActionListener(createButtonActionListener(0));
> + close.addActionListener(createButtonToSetValueListener(parent, 0));
> copyToClipboard.addActionListener(new CopyToClipboardHandler());
> buttonPane.add(close, BorderLayout.EAST);
> buttonPane.add(copyToClipboard, BorderLayout.WEST);
> buttonPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
>
> - optionPane.add(mainPane, BorderLayout.CENTER);
> - optionPane.add(buttonPane, BorderLayout.SOUTH);
> + add(mainPane, BorderLayout.CENTER);
> + add(buttonPane, BorderLayout.SOUTH);
> }
>
> /**
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/MoreInfoPane.java
> --- a/netx/net/sourceforge/jnlp/security/MoreInfoPane.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/MoreInfoPane.java Mon Jul 05 11:59:03 2010 -0400
> @@ -47,29 +47,27 @@
> import javax.swing.BorderFactory;
> import javax.swing.ImageIcon;
> import javax.swing.JButton;
> -import javax.swing.JComponent;
> import javax.swing.JLabel;
> import javax.swing.JPanel;
> import javax.swing.SwingConstants;
>
> -import net.sourceforge.jnlp.runtime.JNLPRuntime;
> -
> /**
> * Provides the UI for the More Info dialog. This dialog shows details about an
> * application's signing status.
> *
> * @author <a href="mailto:jsumali at redhat.com">Joshua Sumali</a>
> */
> -public class MoreInfoPane extends SecurityDialogUI {
> +public class MoreInfoPane extends SecurityDialogPanel {
>
> - public MoreInfoPane(JComponent x, CertVerifier certVerifier) {
> + public MoreInfoPane(SecurityWarningDialog x, CertVerifier certVerifier) {
> super(x, certVerifier);
> + addComponents();
> }
>
> /**
> * Constructs the GUI components of this UI
> */
> - protected void installComponents() {
> + private void addComponents() {
> ArrayList<String> details = certVerifier.getDetails();
>
> int numLabels = details.size();
> @@ -93,35 +91,21 @@
> JButton certDetails = new JButton("Certificate Details");
> certDetails.addActionListener(new CertInfoButtonListener());
> JButton close = new JButton("Close");
> - close.addActionListener(createButtonActionListener(0));
> + close.addActionListener(createButtonToSetValueListener(parent, 0));
> buttonsPanel.add(certDetails, BorderLayout.WEST);
> buttonsPanel.add(close, BorderLayout.EAST);
> buttonsPanel.setBorder(BorderFactory.createEmptyBorder(15,15,15,15));
>
> - JPanel main = new JPanel(new BorderLayout());
> - main.add(errorPanel, BorderLayout.NORTH);
> - main.add(buttonsPanel, BorderLayout.SOUTH);
> + add(errorPanel, BorderLayout.NORTH);
> + add(buttonsPanel, BorderLayout.SOUTH);
>
> - optionPane.add(main);
> }
>
> - private static String R(String key) {
> - return JNLPRuntime.getMessage(key);
> - }
> -
> - /**
> - * Needed to get word-wrap working in JLabels.
> - */
> - private String htmlWrap (String s) {
> - return "<html>"+s+"</html>";
> - }
> -
> private class CertInfoButtonListener implements ActionListener {
> public void actionPerformed(ActionEvent e) {
> //TODO: Change to ((SecurityWarningDialog) optionPane).showCertInfoDialog()
> - SecurityWarningDialog.showCertInfoDialog(
> - ((SecurityWarningDialog)optionPane).getJarSigner(),
> - optionPane);
> + SecurityWarningDialog.showCertInfoDialog(parent.getJarSigner(),
> + parent);
> }
> }
> }
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/SecurityDialogPanel.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++ b/netx/net/sourceforge/jnlp/security/SecurityDialogPanel.java Mon Jul 05 11:59:03 2010 -0400
> @@ -0,0 +1,129 @@
> + /* SecurityDialogUI.java
> + Copyright (C) 2008-2010 Red Hat, Inc.
> +
> +This file is part of IcedTea.
> +
> +IcedTea is free software; you can redistribute it and/or
> +modify it under the terms of the GNU General Public License as published by
> +the Free Software Foundation, version 2.
> +
> +IcedTea is distributed in the hope that it will be useful,
> +but WITHOUT ANY WARRANTY; without even the implied warranty of
> +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +General Public License for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with IcedTea; see the file COPYING. If not, write to
> +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +02110-1301 USA.
> +
> +Linking this library statically or dynamically with other modules is
> +making a combined work based on this library. Thus, the terms and
> +conditions of the GNU General Public License cover the whole
> +combination.
> +
> +As a special exception, the copyright holders of this library give you
> +permission to link this library with independent modules to produce an
> +executable, regardless of the license terms of these independent
> +modules, and to copy and distribute the resulting executable under
> +terms of your choice, provided that you also meet, for each linked
> +independent module, the terms and conditions of the license of that
> +module. An independent module is a module which is not derived from
> +or based on this library. If you modify this library, you may extend
> +this exception to your version of the library, but you are not
> +obligated to do so. If you do not wish to do so, delete this
> +exception statement from your version.
> +*/
> +
> +package net.sourceforge.jnlp.security;
> +
> +import java.awt.BorderLayout;
> +import java.awt.event.ActionEvent;
> +import java.awt.event.ActionListener;
> +
> +import javax.swing.JComponent;
> +import javax.swing.JPanel;
> +
> +
> +import net.sourceforge.jnlp.runtime.JNLPRuntime;
> +
> +/**
> + * Provides a JPanel for use in JNLP warning dialogs.
> + */
> +public abstract class SecurityDialogPanel extends JPanel {
> +
> + protected SecurityWarningDialog parent;
> +
> + JComponent initialFocusComponent = null;
> +
> + CertVerifier certVerifier;
> +
> + public SecurityDialogPanel(SecurityWarningDialog dialog, CertVerifier certVerifier){
> + this.parent = dialog;
> + this.certVerifier = certVerifier;
> + this.setLayout(new BorderLayout());
> + }
> +
> + /*
> + * String translation functions
> + */
> +
> + protected static String R(String key) {
> + return JNLPRuntime.getMessage(key);
> + }
> +
> + protected static String R(String key, Object param) {
> + return JNLPRuntime.getMessage(key, new Object[] {param});
> + }
> +
> + /**
> + * Needed to get word wrap working in JLabels.
> + */
> + protected String htmlWrap (String s) {
> + return "<html>"+s+"</html>";
> + }
> +
> + /**
> + * Create an ActionListener suitable for use with buttons. When this {@link ActionListener}
> + * is invoked, it will set the value of the {@link SecurityWarningDialog} and then dispossed.
> + *
> + * @param buttonIndex the index of the button. By convention 0 = Yes. 1 = No, 2 = Cancel
> + * @return
> + */
> + protected ActionListener createButtonToSetValueListener(SecurityWarningDialog dialog, int buttonIndex) {
> + return new ButtonActionHandler(dialog, buttonIndex);
> + }
> +
> + @Override
> + public void setVisible(boolean aFlag) {
> + super.setVisible(aFlag);
> + requestFocusOnDefaultButton();
> + }
> +
> + public void requestFocusOnDefaultButton() {
> + if (initialFocusComponent != null) {
> + initialFocusComponent.requestFocusInWindow();
> + }
> + }
> +
> + /**
> + * Creates a handler that sets a dialog's value and then disposes it when activated
> + *
> + */
> + private class ButtonActionHandler implements ActionListener {
> +
> + Integer buttonIndex;
> + SecurityWarningDialog dialog;
> +
> + public ButtonActionHandler(SecurityWarningDialog dialog, int buttonIndex) {
> + this.dialog = dialog;
> + this.buttonIndex = buttonIndex;
> + }
> +
> + @Override
> + public void actionPerformed(ActionEvent e) {
> + dialog.setValue(buttonIndex);
> + dialog.dispose();
> + }
> + }
> +}
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/SecurityDialogUI.java
> --- a/netx/net/sourceforge/jnlp/security/SecurityDialogUI.java Wed Jun 30 19:15:49 2010 -0400
> +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
> @@ -1,204 +0,0 @@
> -/* SecurityDialogUI.java
> - Copyright (C) 2008 Red Hat, Inc.
> -
> -This file is part of IcedTea.
> -
> -IcedTea is free software; you can redistribute it and/or
> -modify it under the terms of the GNU General Public License as published by
> -the Free Software Foundation, version 2.
> -
> -IcedTea is distributed in the hope that it will be useful,
> -but WITHOUT ANY WARRANTY; without even the implied warranty of
> -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> -General Public License for more details.
> -
> -You should have received a copy of the GNU General Public License
> -along with IcedTea; see the file COPYING. If not, write to
> -the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> -02110-1301 USA.
> -
> -Linking this library statically or dynamically with other modules is
> -making a combined work based on this library. Thus, the terms and
> -conditions of the GNU General Public License cover the whole
> -combination.
> -
> -As a special exception, the copyright holders of this library give you
> -permission to link this library with independent modules to produce an
> -executable, regardless of the license terms of these independent
> -modules, and to copy and distribute the resulting executable under
> -terms of your choice, provided that you also meet, for each linked
> -independent module, the terms and conditions of the license of that
> -module. An independent module is a module which is not derived from
> -or based on this library. If you modify this library, you may extend
> -this exception to your version of the library, but you are not
> -obligated to do so. If you do not wish to do so, delete this
> -exception statement from your version.
> -*/
> -
> -package net.sourceforge.jnlp.security;
> -
> -import java.awt.BorderLayout;
> -import java.awt.Component;
> -import java.awt.ComponentOrientation;
> -import java.awt.event.ActionEvent;
> -import java.awt.event.ActionListener;
> -import java.beans.PropertyChangeEvent;
> -import java.beans.PropertyChangeListener;
> -
> -import javax.swing.JButton;
> -import javax.swing.JComponent;
> -import javax.swing.JOptionPane;
> -import javax.swing.JRootPane;
> -import javax.swing.SwingUtilities;
> -import javax.swing.UIManager;
> -import javax.swing.plaf.OptionPaneUI;
> -
> -import net.sourceforge.jnlp.runtime.JNLPRuntime;
> -
> -/**
> - * Provides a base for JNLP warning dialogs.
> - *
> - * @author <a href="mailto:jsumali at redhat.com">Joshua Sumali</a>
> - */
> -public abstract class SecurityDialogUI extends OptionPaneUI {
> -
> - /** The JOptionPane that we're providing the L&F for */
> - protected JOptionPane optionPane;
> -
> - /** Component to receive focus when messaged with selectInitialValue. */
> - Component initialFocusComponent;
> -
> - CertVerifier certVerifier;
> -
> - /** PropertyChangeListener for <code>optionPane</code> */
> - private PropertyChangeListener propertyChangeListener;
> - private Handler handler;
> -
> - public SecurityDialogUI(JComponent x, CertVerifier certVerifier){
> - optionPane = (JOptionPane)x;
> - this.certVerifier = certVerifier;
> - }
> -
> - /**
> - * Installs the user interface for the SecurityWarningDialog.
> - */
> - public void installUI(JComponent c) {
> -
> - //Only install the UI when type and file in SecurityWarningDialog
> - //have been set.
> - if (((SecurityWarningDialog)c).isInitialized()) {
> - setSystemLookAndFeel();
> - optionPane = (JOptionPane)c;
> - optionPane.setLayout(new BorderLayout());
> - installComponents();
> - installListeners();
> - }
> - }
> -
> - //Taken from javax.swing.plaf.basic.BasicOptionPaneUI
> - protected void installListeners() {
> - if ((propertyChangeListener = getHandler()) != null)
> - optionPane.addPropertyChangeListener(propertyChangeListener);
> - }
> -
> - //Taken from javax.swing.plaf.basic.BasicOptionPaneUI
> - protected void uninstallComponents() {
> - initialFocusComponent = null;
> - optionPane.removeAll();
> - }
> -
> - //Taken from javax.swing.plaf.basic.BasicOptionPaneUI
> - private Handler getHandler() {
> - if (handler == null)
> - handler = new Handler();
> - return handler;
> - }
> -
> - //Inherited from OptionPaneUI
> - //Modified from javax.swing.plaf.basic.BasicOptionPaneUI
> - public void selectInitialValue(JOptionPane op) {
> - if (initialFocusComponent != null)
> - initialFocusComponent.requestFocus();
> -
> - if (initialFocusComponent instanceof JButton) {
> - JRootPane root = SwingUtilities.getRootPane(initialFocusComponent);
> - if (root != null)
> - root.setDefaultButton((JButton) initialFocusComponent);
> - }
> - }
> -
> - //Inherited from OptionPaneUI
> - public boolean containsCustomComponents(JOptionPane op) {
> - return false;
> - }
> -
> - //Taken from javax.swing.plaf.basic.BasicOptionPaneUI
> - protected ActionListener createButtonActionListener(int buttonIndex) {
> - return new ButtonActionListener(buttonIndex);
> - }
> -
> - private static String R(String key) {
> - return JNLPRuntime.getMessage(key);
> - }
> -
> - /**
> - * Needed to get word wrap working in JLabels.
> - */
> - private String htmlWrap (String s) {
> - return "<html>"+s+"</html>";
> - }
> -
> - //Taken from javax.swing.plaf.basic.BasicOptionPaneUI
> - private class Handler implements PropertyChangeListener {
> - public void propertyChange(PropertyChangeEvent e) {
> - if (e.getSource() == optionPane) {
> - String changeName = e.getPropertyName();
> - if (changeName == JOptionPane.OPTIONS_PROPERTY ||
> - changeName == JOptionPane.INITIAL_VALUE_PROPERTY ||
> - changeName == JOptionPane.ICON_PROPERTY ||
> - changeName == JOptionPane.MESSAGE_TYPE_PROPERTY ||
> - changeName == JOptionPane.OPTION_TYPE_PROPERTY ||
> - changeName == JOptionPane.MESSAGE_PROPERTY ||
> - changeName == JOptionPane.SELECTION_VALUES_PROPERTY ||
> - changeName == JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY ||
> - changeName == JOptionPane.WANTS_INPUT_PROPERTY) {
> - uninstallComponents();
> - installComponents();
> - optionPane.validate();
> - } else if (changeName == "componentOrientation") {
> - ComponentOrientation o = (ComponentOrientation)e.getNewValue();
> - JOptionPane op = (JOptionPane)e.getSource();
> - if (o != (ComponentOrientation)e.getOldValue()) {
> - op.applyComponentOrientation(o);
> - }
> - }
> - }
> - }
> - }
> -
> - //Taken from javax.swing.plaf.basic.BasicOptionPaneUI
> - public class ButtonActionListener implements ActionListener {
> - protected int buttonIndex;
> -
> - public ButtonActionListener(int buttonIndex) {
> - this.buttonIndex = buttonIndex;
> - }
> -
> - public void actionPerformed(ActionEvent e) {
> - if (optionPane != null) {
> - optionPane.setValue(new Integer(buttonIndex));
> - }
> - }
> - }
> -
> - private void setSystemLookAndFeel() {
> - try {
> - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
> - } catch (Exception e) {
> - //don't worry if we can't.
> - }
> - }
> -
> - //this is for the different dialogs to fill in.
> - protected abstract void installComponents();
> -}
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/SecurityWarningDialog.java
> --- a/netx/net/sourceforge/jnlp/security/SecurityWarningDialog.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/SecurityWarningDialog.java Mon Jul 05 11:59:03 2010 -0400
> @@ -40,12 +40,11 @@
> import net.sourceforge.jnlp.JNLPFile;
>
> import java.awt.*;
> +
> import javax.swing.*;
> +
> import java.awt.event.*;
> -import javax.swing.plaf.OptionPaneUI;
>
> -import java.beans.PropertyChangeListener;
> -import java.beans.PropertyChangeEvent;
> import java.security.cert.X509Certificate;
>
> /**
> @@ -54,7 +53,7 @@
> *
> * @author <a href="mailto:jsumali at redhat.com">Joshua Sumali</a>
> */
> -public class SecurityWarningDialog extends JOptionPane {
> +public class SecurityWarningDialog extends JDialog {
>
> /** Types of dialogs we can create */
> public static enum DialogType {
> @@ -86,6 +85,8 @@
> /** The type of access that this dialog is for */
> private AccessType accessType;
>
> + private SecurityDialogPanel panel;
> +
> /** The application file associated with this security warning */
> private JNLPFile file;
>
> @@ -102,6 +103,10 @@
> /** Whether or not this object has been fully initialized */
> private boolean initialized = false;
>
> + private Object value;
> +
> + // FIXME we never call super()... is that a problem?
> +
> public SecurityWarningDialog(DialogType dialogType, AccessType accessType,
> JNLPFile file) {
> this.dialogType = dialogType;
> @@ -109,7 +114,7 @@
> this.file = file;
> this.certVerifier = null;
> initialized = true;
> - updateUI();
> + initDialog();
> }
>
> public SecurityWarningDialog(DialogType dialogType, AccessType accessType,
> @@ -119,7 +124,7 @@
> this.file = file;
> this.certVerifier = jarSigner;
> initialized = true;
> - updateUI();
> + initDialog();
> }
>
> public SecurityWarningDialog(DialogType dialogType, AccessType accessType,
> @@ -129,7 +134,7 @@
> this.file = null;
> this.certVerifier = certVerifier;
> initialized = true;
> - updateUI();
> + initDialog();
> }
>
> public SecurityWarningDialog(DialogType dialogType, AccessType accessType,
> @@ -140,7 +145,7 @@
> this.certVerifier = null;
> initialized = true;
> this.extras = extras;
> - updateUI();
> + initDialog();
> }
>
> //for displaying a single certificate
> @@ -151,7 +156,7 @@
> this.certVerifier = null;
> this.cert = c;
> initialized = true;
> - updateUI();
> + initDialog();
> }
>
> /**
> @@ -187,16 +192,12 @@
> */
> public static boolean showAccessWarningDialog(AccessType accessType,
> JNLPFile file, Object[] extras) {
> - SecurityWarningDialog swd = new SecurityWarningDialog(
> + SecurityWarningDialog dialog = new SecurityWarningDialog(
> DialogType.ACCESS_WARNING, accessType, file, extras);
> - JDialog dialog = swd.createDialog();
> - swd.selectInitialValue();
> - dialog.setResizable(true);
> - centerDialog(dialog);
> dialog.setVisible(true);
> dialog.dispose();
>
> - Object selectedValue = swd.getValue();
> + Object selectedValue = dialog.getValue();
> if (selectedValue == null) {
> return false;
> } else if (selectedValue instanceof Integer) {
> @@ -221,17 +222,13 @@
> */
> public static boolean showCertWarningDialog(AccessType accessType,
> JNLPFile file, CertVerifier jarSigner) {
> - SecurityWarningDialog swd =
> + SecurityWarningDialog dialog =
> new SecurityWarningDialog(DialogType.CERT_WARNING, accessType, file,
> jarSigner);
> - JDialog dialog = swd.createDialog();
> - swd.selectInitialValue();
> - dialog.setResizable(true);
> - centerDialog(dialog);
> dialog.setVisible(true);
> dialog.dispose();
>
> - Object selectedValue = swd.getValue();
> + Object selectedValue = dialog.getValue();
> if (selectedValue == null) {
> return false;
> } else if (selectedValue instanceof Integer) {
> @@ -251,15 +248,11 @@
> * @param parent the parent option pane
> */
> public static void showMoreInfoDialog(
> - CertVerifier jarSigner, JOptionPane parent) {
> + CertVerifier jarSigner, SecurityWarningDialog parent) {
>
> - SecurityWarningDialog swd =
> + SecurityWarningDialog dialog =
> new SecurityWarningDialog(DialogType.MORE_INFO, null, null,
> jarSigner);
> - JDialog dialog = swd.createDialog();
> - dialog.setLocationRelativeTo(parent);
> - swd.selectInitialValue();
> - dialog.setResizable(true);
> dialog.setVisible(true);
> dialog.dispose();
> }
> @@ -270,13 +263,10 @@
> * @param certs the certificates used in signing.
> */
> public static void showCertInfoDialog(CertVerifier jarSigner,
> - JOptionPane parent) {
> - SecurityWarningDialog swd = new SecurityWarningDialog(DialogType.CERT_INFO,
> + SecurityWarningDialog parent) {
> + SecurityWarningDialog dialog = new SecurityWarningDialog(DialogType.CERT_INFO,
> null, null, jarSigner);
> - JDialog dialog = swd.createDialog();
> dialog.setLocationRelativeTo(parent);
> - swd.selectInitialValue();
> - dialog.setResizable(true);
> dialog.setVisible(true);
> dialog.dispose();
> }
> @@ -288,28 +278,20 @@
> * @param optionPane
> */
> public static void showSingleCertInfoDialog(X509Certificate c,
> - JOptionPane parent) {
> -
> - SecurityWarningDialog swd = new SecurityWarningDialog(DialogType.SINGLE_CERT_INFO, c);
> - JDialog dialog = swd.createDialog();
> + JDialog parent) {
> + SecurityWarningDialog dialog = new SecurityWarningDialog(DialogType.SINGLE_CERT_INFO, c);
> dialog.setLocationRelativeTo(parent);
> - swd.selectInitialValue();
> - dialog.setResizable(true);
> dialog.setVisible(true);
> dialog.dispose();
> }
>
> public static int showAppletWarning() {
> - SecurityWarningDialog swd = new SecurityWarningDialog(DialogType.APPLET_WARNING,
> + SecurityWarningDialog dialog = new SecurityWarningDialog(DialogType.APPLET_WARNING,
> null, null, (CertVerifier) null);
> - JDialog dialog = swd.createDialog();
> - centerDialog(dialog);
> - swd.selectInitialValue();
> - dialog.setResizable(true);
> dialog.setVisible(true);
> dialog.dispose();
>
> - Object selectedValue = swd.getValue();
> + Object selectedValue = dialog.getValue();
>
> //result 0 = Yes, 1 = No, 2 = Cancel
> if (selectedValue == null) {
> @@ -321,8 +303,11 @@
> }
> }
>
> - //Modified from javax.swing.JOptionPane
> - private JDialog createDialog() {
> +
> + private void initDialog() {
> + setSystemLookAndFeel();
> +
> +
> String dialogTitle = "";
> if (dialogType == DialogType.CERT_WARNING)
> dialogTitle = "Warning - Security";
> @@ -335,53 +320,41 @@
> else if (dialogType == DialogType.APPLET_WARNING)
> dialogTitle = "Applet Warning";
>
> - final JDialog dialog = new JDialog((Frame)null, dialogTitle, true);
> + setTitle(dialogTitle);
> + setModal(true);
>
> - Container contentPane = dialog.getContentPane();
> - contentPane.setLayout(new BorderLayout());
> - contentPane.add(this, BorderLayout.CENTER);
> - dialog.pack();
> + setDefaultCloseOperation(DISPOSE_ON_CLOSE);
> +
> + installPanel();
> +
> + pack();
>
> WindowAdapter adapter = new WindowAdapter() {
> private boolean gotFocus = false;
> + @Override
> public void windowClosing(WindowEvent we) {
> setValue(null);
> }
> + @Override
> public void windowGainedFocus(WindowEvent we) {
> // Once window gets focus, set initial focus
> if (!gotFocus) {
> - selectInitialValue();
> + selectDefaultButton();
> gotFocus = true;
> }
> }
> - };
> - dialog.addWindowListener(adapter);
> - dialog.addWindowFocusListener(adapter);
> -
> - dialog.addComponentListener(new ComponentAdapter() {
> - public void componentShown(ComponentEvent ce) {
> - // reset value to ensure closing works properly
> - setValue(JOptionPane.UNINITIALIZED_VALUE);
> - }
> - });
> -
> - addPropertyChangeListener( new PropertyChangeListener() {
> - public void propertyChange(PropertyChangeEvent event) {
> - // Let the defaultCloseOperation handle the closing
> - // if the user closed the window without selecting a button
> - // (newValue = null in that case). Otherwise, close the dialog.
> - if (dialog.isVisible() &&
> - event.getSource() == SecurityWarningDialog.this &&
> - (event.getPropertyName().equals(VALUE_PROPERTY) ||
> - event.getPropertyName().equals(INPUT_VALUE_PROPERTY)) &&
> - event.getNewValue() != null &&
> - event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
> - dialog.setVisible(false);
> + @Override
> + public void windowOpened(WindowEvent e) {
> + if (e.getSource() instanceof SecurityWarningDialog) {
> + SecurityWarningDialog dialog = (SecurityWarningDialog) e.getSource();
> + dialog.setResizable(true);
> + centerDialog(dialog);
> }
> }
> - });
> + };
> + addWindowListener(adapter);
> + addWindowFocusListener(adapter);
>
> - return dialog;
> }
>
> public AccessType getType() {
> @@ -401,23 +374,24 @@
> }
>
> /**
> - * Updates the UI using SecurityWarningOptionPane, instead of the
> - * basic dialog box.
> + * Adds the appropriate JPanel to this Dialog, based on {@link DialogType}.
> */
> - public void updateUI() {
> + private void installPanel() {
>
> if (dialogType == DialogType.CERT_WARNING)
> - setUI((OptionPaneUI) new CertWarningPane(this, this.certVerifier));
> + panel = new CertWarningPane(this, this.certVerifier);
> else if (dialogType == DialogType.MORE_INFO)
> - setUI((OptionPaneUI) new MoreInfoPane(this, this.certVerifier));
> + panel = new MoreInfoPane(this, this.certVerifier);
> else if (dialogType == DialogType.CERT_INFO)
> - setUI((OptionPaneUI) new CertsInfoPane(this, this.certVerifier));
> + panel = new CertsInfoPane(this, this.certVerifier);
> else if (dialogType == DialogType.SINGLE_CERT_INFO)
> - setUI((OptionPaneUI) new SingleCertInfoPane(this, this.certVerifier));
> + panel = new SingleCertInfoPane(this, this.certVerifier);
> else if (dialogType == DialogType.ACCESS_WARNING)
> - setUI((OptionPaneUI) new AccessWarningPane(this, extras, this.certVerifier));
> + panel = new AccessWarningPane(this, extras, this.certVerifier);
> else if (dialogType == DialogType.APPLET_WARNING)
> - setUI((OptionPaneUI) new AppletWarningPane(this, this.certVerifier));
> + panel = new AppletWarningPane(this, this.certVerifier);
> +
> + add(panel);
> }
>
> private static void centerDialog(JDialog dialog) {
> @@ -427,4 +401,35 @@
> dialog.setLocation((screen.width - dialogSize.width)/2,
> (screen.height - dialogSize.height)/2);
> }
> +
> +
> + private void selectDefaultButton() {
> + if (panel == null) {
> + System.out.println("initial value panel is null");
> + }
> + panel.requestFocusOnDefaultButton();
> + }
> +
> + protected void setValue(Object value) {
> + // FIXME remove
> + System.out.println("Setting value:" + value);
> + this.value = value;
> + }
> +
> + protected Object getValue() {
> + // FIXME remove
> + System.out.println("returnign value:" + value);
> + return value;
> + }
> +
> + /**
> + * Updates the look and feel of the window to be the system look and feel
> + */
> + protected void setSystemLookAndFeel() {
> + try {
> + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
> + } catch (Exception e) {
> + //don't worry if we can't.
> + }
> + }
> }
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/SingleCertInfoPane.java
> --- a/netx/net/sourceforge/jnlp/security/SingleCertInfoPane.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/SingleCertInfoPane.java Mon Jul 05 11:59:03 2010 -0400
> @@ -40,7 +40,6 @@
> import java.security.cert.X509Certificate;
> import java.util.ArrayList;
>
> -import javax.swing.JComponent;
> import javax.swing.JTree;
> import javax.swing.tree.DefaultMutableTreeNode;
> import javax.swing.tree.TreeSelectionModel;
> @@ -48,12 +47,12 @@
>
> public class SingleCertInfoPane extends CertsInfoPane {
>
> - public SingleCertInfoPane(JComponent x, CertVerifier certVerifier) {
> + public SingleCertInfoPane(SecurityWarningDialog x, CertVerifier certVerifier) {
> super(x, certVerifier);
> }
>
> protected void buildTree() {
> - X509Certificate cert = ((SecurityWarningDialog)optionPane).getCert();
> + X509Certificate cert = parent.getCert();
> String subjectString =
> SecurityUtil.getCN(cert.getSubjectX500Principal().getName());
> String issuerString =
> @@ -68,7 +67,7 @@
> }
>
> protected void populateTable() {
> - X509Certificate c = ((SecurityWarningDialog)optionPane).getCert();
> + X509Certificate c = parent.getCert();
> certNames = new String[1];
> certsData = new ArrayList<String[][]>();
> certsData.add(parseCert(c));
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java
> --- a/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/viewer/CertificatePane.java Mon Jul 05 11:59:03 2010 -0400
> @@ -54,30 +54,20 @@
> import javax.swing.BorderFactory;
> import javax.swing.JButton;
> import javax.swing.JComponent;
> +import javax.swing.JDialog;
> import javax.swing.JFileChooser;
> import javax.swing.JOptionPane;
> import javax.swing.JPanel;
> import javax.swing.JScrollPane;
> import javax.swing.JTabbedPane;
> import javax.swing.JTable;
> -import javax.swing.UIManager;
> import javax.swing.table.DefaultTableModel;
>
> -import net.sourceforge.jnlp.security.CertVerifier;
> -import net.sourceforge.jnlp.security.SecurityDialogUI;
> import net.sourceforge.jnlp.security.SecurityUtil;
> import net.sourceforge.jnlp.security.SecurityWarningDialog;
> import net.sourceforge.jnlp.tools.KeyTool;
>
> -//import java.security.KeyStoreException;
> -//import java.security.NoSuchAlgorithmException;
> -//import java.security.cert.CertificateException;
> -//import java.io.FileNotFoundException;
> -//import java.io.IOException;
> -
> -
> -// note: We might want to extend OptionPaneUI instead
> -public class CertificatePane extends SecurityDialogUI {
> +public class CertificatePane extends JPanel {
>
> /**
> * The certificates stored in the user's trusted.certs file.
> @@ -92,14 +82,20 @@
>
> private JTable table;
>
> + private JDialog parent;
> +
> + private JComponent defaultFocusComponent = null;
> +
> /**
> * The KeyStore associated with the user's trusted.certs file.
> */
> private KeyStore keyStore = null;
>
> - public CertificatePane(JComponent x) {
> - super(x, null);
> + public CertificatePane(JDialog parent) {
> + super();
> + this.parent = parent;
> initializeKeyStore();
> + addComponents();
> }
>
> /**
> @@ -114,32 +110,8 @@
> }
> }
>
> - /**
> - * Installs the user interface for the SecurityWarningDialog.
> - */
> - public void installUI(JComponent c) {
> -
> - //Only install the UI when type and file in SecurityWarningDialog
> - //have been set.
> - if (((CertificateViewer)c).isInitialized()) {
> - setSystemLookAndFeel();
> - optionPane = (JOptionPane)c;
> - optionPane.setLayout(new BorderLayout());
> - installComponents();
> - installListeners();
> - }
> - }
> -
> - private void setSystemLookAndFeel() {
> - try {
> - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
> - } catch (Exception e) {
> - //don't worry if we can't.
> - }
> - }
> -
> //create the GUI here.
> - protected void installComponents() {
> + protected void addComponents() {
> readKeyStore();
>
> JPanel main = new JPanel(new BorderLayout());
> @@ -193,13 +165,14 @@
> JPanel closePanel = new JPanel(new BorderLayout());
> closePanel.setBorder(BorderFactory.createEmptyBorder(7,7,7,7));
> JButton closeButton = new JButton("Close");
> - closeButton.addActionListener(createButtonActionListener(0));
> + closeButton.addActionListener(new CloseButtonListener());
> + defaultFocusComponent = closeButton;
> closePanel.add(closeButton, BorderLayout.EAST);
>
> main.add(tablePanel, BorderLayout.CENTER);
> main.add(closePanel, BorderLayout.SOUTH);
>
> - optionPane.add(main);
> + add(main);
>
> }
>
> @@ -245,14 +218,20 @@
> = new DefaultTableModel(issuedToAndBy, columnNames);
>
> table.setModel(tableModel);
> - optionPane.repaint();
> + repaint();
> + }
> +
> + public void focusOnDefaultButton() {
> + if (defaultFocusComponent != null) {
> + defaultFocusComponent.requestFocusInWindow();
> + }
> }
>
> private class ImportButtonListener implements ActionListener {
> public void actionPerformed(ActionEvent e) {
>
> JFileChooser chooser = new JFileChooser();
> - int returnVal = chooser.showOpenDialog(optionPane);
> + int returnVal = chooser.showOpenDialog(parent);
> if(returnVal == JFileChooser.APPROVE_OPTION) {
> try {
> KeyTool kt = new KeyTool();
> @@ -276,7 +255,7 @@
> int selectedRow = table.getSelectedRow();
> if (selectedRow != -1) {
> JFileChooser chooser = new JFileChooser();
> - int returnVal = chooser.showOpenDialog(optionPane);
> + int returnVal = chooser.showOpenDialog(parent);
> if(returnVal == JFileChooser.APPROVE_OPTION) {
> String alias = keyStore.getCertificateAlias(certs
> .get(selectedRow));
> @@ -309,7 +288,7 @@
> String alias = keyStore.getCertificateAlias(certs.get(selectedRow));
> if (alias != null) {
>
> - int i = JOptionPane.showConfirmDialog(optionPane,
> + int i = JOptionPane.showConfirmDialog(parent,
> "Are you sure you want to remove the selected certificate?",
> "Confirmation - Remove Certificate?",
> JOptionPane.YES_NO_OPTION);
> @@ -341,10 +320,17 @@
> int selectedRow = table.getSelectedRow();
> if (selectedRow != -1 && selectedRow >= 0) {
> X509Certificate c = certs.get(selectedRow);
> - SecurityWarningDialog.showSingleCertInfoDialog(c, optionPane);
> + SecurityWarningDialog.showSingleCertInfoDialog(c, parent);
> }
> }
> }
> +
> + private class CloseButtonListener implements ActionListener {
> + @Override
> + public void actionPerformed(ActionEvent e) {
> + parent.dispose();
> + }
> + }
>
> }
>
> diff -r 7649271c60ab netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java
> --- a/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java Wed Jun 30 19:15:49 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java Mon Jul 05 11:59:03 2010 -0400
> @@ -51,96 +51,75 @@
>
> import javax.swing.JDialog;
> import javax.swing.JOptionPane;
> +import javax.swing.UIManager;
> import javax.swing.plaf.OptionPaneUI;
>
> -public class CertificateViewer extends JOptionPane {
> +public class CertificateViewer extends JDialog {
>
> - private boolean initialized = false;
> -
> - public CertificateViewer() throws Exception {
> + private boolean initialized = false;
> + private static final String dialogTitle = "Certificates";
>
> + CertificatePane panel;
> +
> + public CertificateViewer() {
> + super((Frame)null, dialogTitle, true);
> +
> + Container contentPane = getContentPane();
> + contentPane.setLayout(new BorderLayout());
> +
> + panel = new CertificatePane(this);
> +
> + add(panel);
> +
> + pack();
> +
> + WindowAdapter adapter = new WindowAdapter() {
> + private boolean gotFocus = false;
> +
> + public void windowGainedFocus(WindowEvent we) {
> + // Once window gets focus, set initial focus
> + if (!gotFocus) {
> + panel.focusOnDefaultButton();
> + gotFocus = true;
> + }
> + }
> + };
> + addWindowFocusListener(adapter);
> +
> initialized = true;
> - updateUI();
> }
>
> public boolean isInitialized(){
> return initialized;
> }
>
> - public void updateUI() {
> - setUI((OptionPaneUI) new CertificatePane(this));
> - }
> -
> - private static void centerDialog(JDialog dialog) {
> + private void centerDialog() {
> Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
> - Dimension dialogSize = dialog.getSize();
> + Dimension dialogSize = getSize();
>
> - dialog.setLocation((screen.width - dialogSize.width)/2,
> + setLocation((screen.width - dialogSize.width)/2,
> (screen.height - dialogSize.height)/2);
> }
>
> - //Modified from javax.swing.JOptionPane
> - private JDialog createDialog() {
> - String dialogTitle = "Certificates";
> - final JDialog dialog = new JDialog((Frame)null, dialogTitle, true);
> -
> - Container contentPane = dialog.getContentPane();
> - contentPane.setLayout(new BorderLayout());
> - contentPane.add(this, BorderLayout.CENTER);
> - dialog.pack();
> -
> - WindowAdapter adapter = new WindowAdapter() {
> - private boolean gotFocus = false;
> - public void windowClosing(WindowEvent we) {
> - setValue(null);
> - }
> - public void windowGainedFocus(WindowEvent we) {
> - // Once window gets focus, set initial focus
> - if (!gotFocus) {
> - selectInitialValue();
> - gotFocus = true;
> - }
> - }
> - };
> - dialog.addWindowListener(adapter);
> - dialog.addWindowFocusListener(adapter);
> -
> - dialog.addComponentListener(new ComponentAdapter() {
> - public void componentShown(ComponentEvent ce) {
> - // reset value to ensure closing works properly
> - setValue(JOptionPane.UNINITIALIZED_VALUE);
> - }
> - });
> -
> - addPropertyChangeListener( new PropertyChangeListener() {
> - public void propertyChange(PropertyChangeEvent event) {
> - // Let the defaultCloseOperation handle the closing
> - // if the user closed the window without selecting a button
> - // (newValue = null in that case). Otherwise, close the dialog.
> - if (dialog.isVisible() &&
> - event.getSource() == CertificateViewer.this &&
> - (event.getPropertyName().equals(VALUE_PROPERTY) ||
> - event.getPropertyName().equals(INPUT_VALUE_PROPERTY)) &&
> - event.getNewValue() != null &&
> - event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
> - dialog.setVisible(false);
> - }
> - }
> - });
> -
> - return dialog;
> +
> + public static void showCertificateViewer() throws Exception {
> + setSystemLookAndFeel();
> +
> + CertificateViewer cv = new CertificateViewer();
> + cv.setResizable(true);
> + cv.centerDialog();
> + cv.setVisible(true);
> + cv.dispose();
> }
>
> - public static void showCertificateViewer() throws Exception {
> - CertificateViewer cv = new CertificateViewer();
> - JDialog dialog = cv.createDialog();
> - cv.selectInitialValue();
> - dialog.setResizable(true);
> - centerDialog(dialog);
> - dialog.setVisible(true);
> - dialog.dispose();
> - }
> -
> + private static void setSystemLookAndFeel() {
> + try {
> + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
> + } catch (Exception e) {
> + // don't worry if we can't.
> + }
> + }
> +
> public static void main(String[] args) throws Exception {
> CertificateViewer.showCertificateViewer();
> }
More information about the distro-pkg-dev
mailing list