aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/desktoputil
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-11 22:15:03 +0100
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-03-11 22:15:03 +0100
commit85901329b0794b136b96bf745f4ab1572806fc89 (patch)
treef23da7e97cae727f39d825f0fef8348cffb238e4 /src/net/java/sip/communicator/plugin/desktoputil
parent3db2e44f186c59429901b2c899e139ea60117a55 (diff)
parentcf5da997da8820b4050f5b87ee9440a0ede36d1f (diff)
downloadjitsi-85901329b0794b136b96bf745f4ab1572806fc89.zip
jitsi-85901329b0794b136b96bf745f4ab1572806fc89.tar.gz
jitsi-85901329b0794b136b96bf745f4ab1572806fc89.tar.bz2
Merge commit 'cf5da99'HEADmaster
Signed-off-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
Diffstat (limited to 'src/net/java/sip/communicator/plugin/desktoputil')
-rw-r--r--src/net/java/sip/communicator/plugin/desktoputil/ColoredDefaultText.java80
-rw-r--r--src/net/java/sip/communicator/plugin/desktoputil/SIPCommCheckBox.java86
-rw-r--r--src/net/java/sip/communicator/plugin/desktoputil/SIPCommRadioButton.java86
-rw-r--r--src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java1032
-rw-r--r--src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomDestroyReasonDialog.java346
-rw-r--r--src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java344
6 files changed, 1015 insertions, 959 deletions
diff --git a/src/net/java/sip/communicator/plugin/desktoputil/ColoredDefaultText.java b/src/net/java/sip/communicator/plugin/desktoputil/ColoredDefaultText.java
index 59dcb5d..e70f57e 100644
--- a/src/net/java/sip/communicator/plugin/desktoputil/ColoredDefaultText.java
+++ b/src/net/java/sip/communicator/plugin/desktoputil/ColoredDefaultText.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,43 +15,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.desktoputil;
-
-import java.awt.*;
-
-/**
- * The purpose of this interface is to allow UI components with a default
- * text value to give the default text its own colour, set independently of
- * the normal text colour.
- * @author Tom Denham
- */
-public interface ColoredDefaultText
-{
- /**
- * Sets the foreground color.
- *
- * @param c the color to set for the text field foreground
- */
- public void setForegroundColor(Color c);
-
- /**
- * Gets the foreground color.
- *
- * @return the color of the text
- */
- public Color getForegroundColor();
-
- /**
- * Sets the foreground color of the default text shown in this text field.
- *
- * @param c the color to set
- */
- public void setDefaultTextColor(Color c);
-
- /**
- * Gets the foreground color of the default text shown in this text field.
- *
- * @return the color of the default text
- */
- public Color getDefaultTextColor();
+package net.java.sip.communicator.plugin.desktoputil;
+
+import java.awt.*;
+
+/**
+ * The purpose of this interface is to allow UI components with a default
+ * text value to give the default text its own colour, set independently of
+ * the normal text colour.
+ * @author Tom Denham
+ */
+public interface ColoredDefaultText
+{
+ /**
+ * Sets the foreground color.
+ *
+ * @param c the color to set for the text field foreground
+ */
+ public void setForegroundColor(Color c);
+
+ /**
+ * Gets the foreground color.
+ *
+ * @return the color of the text
+ */
+ public Color getForegroundColor();
+
+ /**
+ * Sets the foreground color of the default text shown in this text field.
+ *
+ * @param c the color to set
+ */
+ public void setDefaultTextColor(Color c);
+
+ /**
+ * Gets the foreground color of the default text shown in this text field.
+ *
+ * @return the color of the default text
+ */
+ public Color getDefaultTextColor();
}
diff --git a/src/net/java/sip/communicator/plugin/desktoputil/SIPCommCheckBox.java b/src/net/java/sip/communicator/plugin/desktoputil/SIPCommCheckBox.java
index e263415..45c2e69 100644
--- a/src/net/java/sip/communicator/plugin/desktoputil/SIPCommCheckBox.java
+++ b/src/net/java/sip/communicator/plugin/desktoputil/SIPCommCheckBox.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,45 +15,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.desktoputil;
-
-import javax.swing.*;
-
-import org.jitsi.util.*;
-
-/**
- * @author Lubomir Marinov
- */
-public class SIPCommCheckBox
- extends JCheckBox
-{
- private static final long serialVersionUID = 0L;
-
- private static final boolean setContentAreaFilled = (OSUtils.IS_WINDOWS
- || OSUtils.IS_LINUX);
-
- public SIPCommCheckBox()
- {
- init();
- }
-
- public SIPCommCheckBox(String text)
- {
- super(text);
-
- init();
- }
-
- public SIPCommCheckBox(String text, boolean selected)
- {
- super(text, selected);
-
- init();
- }
-
- private void init()
- {
- if (setContentAreaFilled)
- setContentAreaFilled(false);
- }
-}
+package net.java.sip.communicator.plugin.desktoputil;
+
+import javax.swing.*;
+
+import org.jitsi.util.*;
+
+/**
+ * @author Lubomir Marinov
+ */
+public class SIPCommCheckBox
+ extends JCheckBox
+{
+ private static final long serialVersionUID = 0L;
+
+ private static final boolean setContentAreaFilled = (OSUtils.IS_WINDOWS
+ || OSUtils.IS_LINUX);
+
+ public SIPCommCheckBox()
+ {
+ init();
+ }
+
+ public SIPCommCheckBox(String text)
+ {
+ super(text);
+
+ init();
+ }
+
+ public SIPCommCheckBox(String text, boolean selected)
+ {
+ super(text, selected);
+
+ init();
+ }
+
+ private void init()
+ {
+ if (setContentAreaFilled)
+ setContentAreaFilled(false);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/desktoputil/SIPCommRadioButton.java b/src/net/java/sip/communicator/plugin/desktoputil/SIPCommRadioButton.java
index 7089c99..1132c72 100644
--- a/src/net/java/sip/communicator/plugin/desktoputil/SIPCommRadioButton.java
+++ b/src/net/java/sip/communicator/plugin/desktoputil/SIPCommRadioButton.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,45 +15,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.desktoputil;
-
-import javax.swing.*;
-
-import org.jitsi.util.*;
-
-/**
- * @author Ingo Bauersachs
- */
-public class SIPCommRadioButton
- extends JRadioButton
-{
- private static final long serialVersionUID = 0L;
-
- private static final boolean setContentAreaFilled = (OSUtils.IS_WINDOWS
- || OSUtils.IS_LINUX);
-
- public SIPCommRadioButton()
- {
- init();
- }
-
- public SIPCommRadioButton(String text)
- {
- super(text);
-
- init();
- }
-
- public SIPCommRadioButton(String text, boolean selected)
- {
- super(text, selected);
-
- init();
- }
-
- private void init()
- {
- if (setContentAreaFilled)
- setContentAreaFilled(false);
- }
-}
+package net.java.sip.communicator.plugin.desktoputil;
+
+import javax.swing.*;
+
+import org.jitsi.util.*;
+
+/**
+ * @author Ingo Bauersachs
+ */
+public class SIPCommRadioButton
+ extends JRadioButton
+{
+ private static final long serialVersionUID = 0L;
+
+ private static final boolean setContentAreaFilled = (OSUtils.IS_WINDOWS
+ || OSUtils.IS_LINUX);
+
+ public SIPCommRadioButton()
+ {
+ init();
+ }
+
+ public SIPCommRadioButton(String text)
+ {
+ super(text);
+
+ init();
+ }
+
+ public SIPCommRadioButton(String text, boolean selected)
+ {
+ super(text, selected);
+
+ init();
+ }
+
+ private void init()
+ {
+ if (setContentAreaFilled)
+ setContentAreaFilled(false);
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java b/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java
index a1284cd..5358030 100644
--- a/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java
+++ b/src/net/java/sip/communicator/plugin/desktoputil/X509CertificatePanel.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,490 +15,546 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.desktoputil;
-
-import java.awt.*;
-import java.security.*;
-import java.security.cert.*;
-import java.security.cert.Certificate;
-import java.security.interfaces.*;
-import java.util.*;
-
-import javax.naming.*;
-import javax.naming.ldap.*;
-import javax.security.auth.x500.*;
-import javax.swing.*;
-import javax.swing.border.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-import javax.swing.tree.*;
-
-import org.jitsi.service.resources.*;
-
-/**
- * Panel that shows the content of an X509Certificate.
- */
-public class X509CertificatePanel
- extends TransparentPanel
-{
- private static final long serialVersionUID = -8368302061995971947L;
-
- private final JEditorPane infoTextPane = new JEditorPane();
-
- private final ResourceManagementService R
- = DesktopUtilActivator.getResources();
-
- /**
- * Constructs a X509 certificate panel from a single certificate.
- * If a chain is available instead use the second constructor.
- * This constructor is kept for backwards compatibility and for convenience
- * when there is only one certificate of interest.
- *
- * @param certificate <tt>X509Certificate</tt> object
- */
- public X509CertificatePanel(Certificate certificate)
- {
- this(new Certificate[]
- {
- certificate
- });
- }
-
- /**
- * Constructs a X509 certificate panel.
- *
- * @param certificates <tt>X509Certificate</tt> objects
- */
- public X509CertificatePanel(Certificate[] certificates)
- {
- setLayout(new BorderLayout(5, 5));
-
- // Certificate chain list
- TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
- topPanel.add(new JLabel("<html><body><b>"
- + R.getI18NString("service.gui.CERT_INFO_CHAIN")
- + "</b></body></html>"), BorderLayout.NORTH);
-
- DefaultMutableTreeNode top = new DefaultMutableTreeNode();
- DefaultMutableTreeNode previous = top;
- for (int i = certificates.length - 1; i >= 0; i--)
- {
- Certificate cert = certificates[i];
- DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
- previous.add(next);
- previous = next;
- }
- JTree tree = new JTree(top);
- tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
- tree.setRootVisible(false);
- tree.setExpandsSelectedPaths(true);
- tree.getSelectionModel().setSelectionMode(
- TreeSelectionModel.SINGLE_TREE_SELECTION);
- tree.setCellRenderer(new DefaultTreeCellRenderer()
- {
-
- @Override
- public Component getTreeCellRendererComponent(JTree tree,
- Object value, boolean sel, boolean expanded, boolean leaf,
- int row, boolean hasFocus)
- {
- JLabel component = (JLabel) super.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- if (value instanceof DefaultMutableTreeNode)
- {
- Object o = ((DefaultMutableTreeNode) value).getUserObject();
- if (o instanceof X509Certificate)
- {
- component.setText(
- getSimplifiedName((X509Certificate) o));
- }
- else
- {
- // We don't know how to represent this certificate type,
- // let's use the first 20 characters
- String text = o.toString();
- if (text.length() > 20)
- {
- text = text.substring(0, 20);
- }
- component.setText(text);
- }
- }
- return component;
- }
-
- });
- tree.getSelectionModel().addTreeSelectionListener(
- new TreeSelectionListener()
- {
-
- @Override
- public void valueChanged(TreeSelectionEvent e)
- {
- valueChangedPerformed(e);
- }
- });
- tree.setSelectionPath(new TreePath(((
- (DefaultTreeModel)tree.getModel()).getPathToRoot(previous))));
- topPanel.add(tree, BorderLayout.CENTER);
-
- add(topPanel, BorderLayout.NORTH);
-
- // Certificate details pane
- Caret caret = infoTextPane.getCaret();
- if (caret instanceof DefaultCaret)
- {
- ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
- }
-
- /*
- * Make JEditorPane respect our default font because we will be using it
- * to just display text.
- */
- infoTextPane.putClientProperty(
- JEditorPane.HONOR_DISPLAY_PROPERTIES,
- true);
-
- infoTextPane.setOpaque(false);
- infoTextPane.setEditable(false);
- infoTextPane.setContentType("text/html");
- infoTextPane.setText(toString(certificates[0]));
-
- final JScrollPane certScroll = new JScrollPane(infoTextPane);
- certScroll.setPreferredSize(new Dimension(300, 500));
- add(certScroll, BorderLayout.CENTER);
- }
-
- /**
- * Creates a String representation of the given object.
- * @param certificate to print
- * @return the String representation
- */
- private String toString(Object certificate)
- {
- final StringBuilder sb = new StringBuilder();
- sb.append("<html><body>\n");
-
- if (certificate instanceof X509Certificate)
- {
- renderX509(sb, (X509Certificate) certificate);
- }
- else
- {
- sb.append("<pre>\n");
- sb.append(certificate.toString());
- sb.append("</pre>\n");
- }
-
- sb.append("</body></html>");
- return sb.toString();
- }
-
- /**
- * Appends an HTML representation of the given X509Certificate.
- * @param sb StringBuilder to append to
- * @param certificate to print
- */
- private void renderX509(StringBuilder sb, X509Certificate certificate)
- {
- X500Principal issuer = certificate.getIssuerX500Principal();
- X500Principal subject = certificate.getSubjectX500Principal();
-
- sb.append("<table cellspacing='1' cellpadding='1'>\n");
-
- // subject
- addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_TO"));
- try
- {
- for(Rdn name : new LdapName(subject.getName()).getRdns())
- {
- String nameType = name.getType();
- String lblKey = "service.gui.CERT_INFO_" + nameType;
- String lbl = R.getI18NString(lblKey);
-
- if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
- lbl = nameType;
-
- final String value;
- Object nameValue = name.getValue();
-
- if (nameValue instanceof byte[])
- {
- byte[] nameValueAsByteArray = (byte[]) nameValue;
-
- value
- = getHex(nameValueAsByteArray) + " ("
- + new String(nameValueAsByteArray) + ")";
- }
- else
- value = nameValue.toString();
-
- addField(sb, lbl, value);
- }
- }
- catch (InvalidNameException ine)
- {
- addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
- subject.getName());
- }
-
- // issuer
- addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_BY"));
- try
- {
- for(Rdn name : new LdapName(issuer.getName()).getRdns())
- {
- String nameType = name.getType();
- String lblKey = "service.gui.CERT_INFO_" + nameType;
- String lbl = R.getI18NString(lblKey);
-
- if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
- lbl = nameType;
-
- final String value;
- Object nameValue = name.getValue();
-
- if (nameValue instanceof byte[])
- {
- byte[] nameValueAsByteArray = (byte[]) nameValue;
-
- value
- = getHex(nameValueAsByteArray) + " ("
- + new String(nameValueAsByteArray) + ")";
- }
- else
- value = nameValue.toString();
-
- addField(sb, lbl, value);
- }
- }
- catch (InvalidNameException ine)
- {
- addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
- issuer.getName());
- }
-
- // validity
- addTitle(sb, R.getI18NString("service.gui.CERT_INFO_VALIDITY"));
- addField(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_ON"),
- certificate.getNotBefore().toString());
- addField(sb, R.getI18NString("service.gui.CERT_INFO_EXPIRES_ON"),
- certificate.getNotAfter().toString());
-
- addTitle(sb, R.getI18NString("service.gui.CERT_INFO_FINGERPRINTS"));
- try
- {
- String sha1String = getThumbprint(certificate, "SHA1");
- String md5String = getThumbprint(certificate, "MD5");
-
- addField(sb, "SHA1:", sha1String);
- addField(sb, "MD5:", md5String);
- }
- catch (CertificateException e)
- {
- // do nothing as we cannot show this value
- }
-
- addTitle(sb, R.getI18NString("service.gui.CERT_INFO_CERT_DETAILS"));
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_SER_NUM"),
- certificate.getSerialNumber().toString());
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_VER"),
- String.valueOf(certificate.getVersion()));
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN_ALG"),
- String.valueOf(certificate.getSigAlgName()));
-
- addTitle(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY_INFO"));
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_ALG"),
- certificate.getPublicKey().getAlgorithm());
-
- if(certificate.getPublicKey().getAlgorithm().equals("RSA"))
- {
- RSAPublicKey key = (RSAPublicKey)certificate.getPublicKey();
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY"),
- R.getI18NString(
- "service.gui.CERT_INFO_KEY_BYTES_PRINT",
- new String[]{
- String.valueOf(key.getModulus().toByteArray().length-1),
- key.getModulus().toString(16)
- }));
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_EXP"),
- key.getPublicExponent().toString());
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_KEY_SIZE"),
- R.getI18NString(
- "service.gui.CERT_INFO_KEY_BITS_PRINT",
- new String[]{
- String.valueOf(key.getModulus().bitLength())}));
- }
- else if(certificate.getPublicKey().getAlgorithm().equals("DSA"))
- {
- DSAPublicKey key =
- (DSAPublicKey)certificate.getPublicKey();
-
- addField(sb, "Y:", key.getY().toString(16));
- }
-
- addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN"),
- R.getI18NString(
- "service.gui.CERT_INFO_KEY_BYTES_PRINT",
- new String[]{
- String.valueOf(certificate.getSignature().length),
- getHex(certificate.getSignature())
- }));
-
- sb.append("</table>\n");
- }
-
- /**
- * Add a title.
- *
- * @param sb StringBuilder to append to
- * @param title to print
- */
- private void addTitle(StringBuilder sb, String title)
- {
- sb.append("<tr><td colspan='2'")
- .append(" style='margin-top: 5pt; white-space: nowrap'><p><b>")
- .append(title).append("</b></p></td></tr>\n");
- }
-
- /**
- * Add a field.
- * @param sb StringBuilder to append to
- * @param field name of the certificate field
- * @param value to print
- */
- private void addField(StringBuilder sb, String field, String value)
- {
- sb.append("<tr>")
- .append("<td style='margin-left: 5pt; margin-right: 25pt;")
- .append(" white-space: nowrap'>")
- .append(field).append("</td>")
- .append("<td>").append(value).append("</td>")
- .append("</tr>\n");
- }
-
- /**
- * Converts the byte array to hex string.
- * @param raw the data.
- * @return the hex string.
- */
- private String getHex( byte [] raw )
- {
- if (raw == null)
- return null;
-
- StringBuilder hex = new StringBuilder(2 * raw.length);
- Formatter f = new Formatter(hex);
- try
- {
- for (byte b : raw)
- f.format("%02x", b);
- }
- finally
- {
- f.close();
- }
- return hex.toString();
- }
-
- /**
- * Calculates the hash of the certificate known as the "thumbprint"
- * and returns it as a string representation.
- *
- * @param cert The certificate to hash.
- * @param algorithm The hash algorithm to use.
- * @return The SHA-1 hash of the certificate.
- * @throws CertificateException
- */
- private static String getThumbprint(X509Certificate cert, String algorithm)
- throws CertificateException
- {
- MessageDigest digest;
- try
- {
- digest = MessageDigest.getInstance(algorithm);
- }
- catch (NoSuchAlgorithmException e)
- {
- throw new CertificateException(e);
- }
- byte[] encodedCert = cert.getEncoded();
- StringBuilder sb = new StringBuilder(encodedCert.length * 2);
- Formatter f = new Formatter(sb);
- try
- {
- for (byte b : digest.digest(encodedCert))
- f.format("%02x", b);
- }
- finally
- {
- f.close();
- }
- return sb.toString();
- }
-
- /**
- * Construct a "simplified name" based on the subject DN from the
- * certificate. The purpose is to have something shorter to display in the
- * list. The name used is one of the following DN parts, if
- * available, otherwise the complete DN:
- * 'CN', 'OU' or else 'O'.
- * @param cert to read subject DN from
- * @return the simplified name
- */
- private static String getSimplifiedName(X509Certificate cert)
- {
- final HashMap<String, String> parts = new HashMap<String, String>();
- try
- {
- for (Rdn name : new LdapName(
- cert.getSubjectX500Principal().getName()).getRdns())
- {
- if (name.getType() != null && name.getValue() != null)
- {
- parts.put(name.getType(), name.getValue().toString());
- }
- }
- }
- catch (InvalidNameException ignored) // NOPMD
- {
- }
-
- String result = parts.get("CN");
- if (result == null)
- {
- result = parts.get("OU");
- }
- if (result == null)
- {
- result = parts.get("O");
- }
- if (result == null)
- {
- result = cert.getSubjectX500Principal().getName();
- }
- return result;
- }
-
- /**
- * Called when the selection changed in the tree.
- * Loads the selected certificate.
- * @param e the event
- */
- private void valueChangedPerformed(TreeSelectionEvent e)
- {
- Object o = e.getNewLeadSelectionPath().getLastPathComponent();
- if (o instanceof DefaultMutableTreeNode)
- {
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
- infoTextPane.setText(toString(node.getUserObject()));
- }
- }
-}
+package net.java.sip.communicator.plugin.desktoputil;
+
+import java.awt.*;
+import java.security.*;
+import java.security.cert.*;
+import java.security.cert.Certificate;
+import java.security.interfaces.*;
+import java.util.*;
+
+import javax.naming.*;
+import javax.naming.ldap.*;
+import javax.security.auth.x500.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.event.*;
+import javax.swing.text.*;
+import javax.swing.tree.*;
+
+import org.jitsi.service.resources.*;
+
+/**
+ * Panel that shows the content of an X509Certificate.
+ */
+public class X509CertificatePanel
+ extends TransparentPanel
+{
+ private static final long serialVersionUID = -8368302061995971947L;
+
+ private final JEditorPane infoTextPane = new JEditorPane();
+
+ private final ResourceManagementService R
+ = DesktopUtilActivator.getResources();
+
+ /**
+ * Constructs a X509 certificate panel from a single certificate.
+ * If a chain is available instead use the second constructor.
+ * This constructor is kept for backwards compatibility and for convenience
+ * when there is only one certificate of interest.
+ *
+ * @param certificate <tt>X509Certificate</tt> object
+ */
+ public X509CertificatePanel(Certificate certificate)
+ {
+ this(new Certificate[]
+ {
+ certificate
+ });
+ }
+
+ /**
+ * Constructs a X509 certificate panel.
+ *
+ * @param certificates <tt>X509Certificate</tt> objects
+ */
+ public X509CertificatePanel(Certificate[] certificates)
+ {
+ setLayout(new BorderLayout(5, 5));
+
+ // Certificate chain list
+ TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
+ topPanel.add(new JLabel("<html><body><b>"
+ + R.getI18NString("service.gui.CERT_INFO_CHAIN")
+ + "</b></body></html>"), BorderLayout.NORTH);
+
+ DefaultMutableTreeNode top = new DefaultMutableTreeNode();
+ DefaultMutableTreeNode previous = top;
+ for (int i = certificates.length - 1; i >= 0; i--)
+ {
+ Certificate cert = certificates[i];
+ DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
+ previous.add(next);
+ previous = next;
+ }
+ JTree tree = new JTree(top);
+ tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
+ tree.setRootVisible(false);
+ tree.setExpandsSelectedPaths(true);
+ tree.getSelectionModel().setSelectionMode(
+ TreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setCellRenderer(new DefaultTreeCellRenderer()
+ {
+
+ @Override
+ public Component getTreeCellRendererComponent(JTree tree,
+ Object value, boolean sel, boolean expanded, boolean leaf,
+ int row, boolean hasFocus)
+ {
+ JLabel component = (JLabel) super.getTreeCellRendererComponent(
+ tree, value, sel, expanded, leaf, row, hasFocus);
+ if (value instanceof DefaultMutableTreeNode)
+ {
+ Object o = ((DefaultMutableTreeNode) value).getUserObject();
+ if (o instanceof X509Certificate)
+ {
+ component.setText(
+ getSimplifiedName((X509Certificate) o));
+ }
+ else
+ {
+ // We don't know how to represent this certificate type,
+ // let's use the first 20 characters
+ String text = o.toString();
+ if (text.length() > 20)
+ {
+ text = text.substring(0, 20);
+ }
+ component.setText(text);
+ }
+ }
+ return component;
+ }
+
+ });
+ tree.getSelectionModel().addTreeSelectionListener(
+ new TreeSelectionListener()
+ {
+
+ @Override
+ public void valueChanged(TreeSelectionEvent e)
+ {
+ valueChangedPerformed(e);
+ }
+ });
+ tree.setSelectionPath(new TreePath(((
+ (DefaultTreeModel)tree.getModel()).getPathToRoot(previous))));
+ topPanel.add(tree, BorderLayout.CENTER);
+
+ add(topPanel, BorderLayout.NORTH);
+
+ // Certificate details pane
+ Caret caret = infoTextPane.getCaret();
+ if (caret instanceof DefaultCaret)
+ {
+ ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
+ }
+
+ /*
+ * Make JEditorPane respect our default font because we will be using it
+ * to just display text.
+ */
+ infoTextPane.putClientProperty(
+ JEditorPane.HONOR_DISPLAY_PROPERTIES,
+ true);
+
+ infoTextPane.setOpaque(false);
+ infoTextPane.setEditable(false);
+ infoTextPane.setContentType("text/html");
+ infoTextPane.setText(toString(certificates[0]));
+
+ final JScrollPane certScroll = new JScrollPane(infoTextPane);
+ certScroll.setPreferredSize(new Dimension(300, 500));
+ add(certScroll, BorderLayout.CENTER);
+ }
+
+ /**
+ * Creates a String representation of the given object.
+ * @param certificate to print
+ * @return the String representation
+ */
+ private String toString(Object certificate)
+ {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("<html><body>\n");
+
+ if (certificate instanceof X509Certificate)
+ {
+ renderX509(sb, (X509Certificate) certificate);
+ }
+ else
+ {
+ sb.append("<pre>\n");
+ sb.append(certificate.toString());
+ sb.append("</pre>\n");
+ }
+
+ sb.append("</body></html>");
+ return sb.toString();
+ }
+
+ /**
+ * Appends an HTML representation of the given X509Certificate.
+ * @param sb StringBuilder to append to
+ * @param certificate to print
+ */
+ private void renderX509(StringBuilder sb, X509Certificate certificate)
+ {
+ X500Principal issuer = certificate.getIssuerX500Principal();
+ X500Principal subject = certificate.getSubjectX500Principal();
+
+ sb.append("<table cellspacing='1' cellpadding='1'>\n");
+
+ // subject
+ addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_TO"));
+ try
+ {
+ for(Rdn name : new LdapName(subject.getName()).getRdns())
+ {
+ String nameType = name.getType();
+ String lblKey = "service.gui.CERT_INFO_" + nameType;
+ String lbl = R.getI18NString(lblKey);
+
+ if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
+ lbl = nameType;
+
+ final String value;
+ Object nameValue = name.getValue();
+
+ if (nameValue instanceof byte[])
+ {
+ byte[] nameValueAsByteArray = (byte[]) nameValue;
+
+ value
+ = getHex(nameValueAsByteArray) + " ("
+ + new String(nameValueAsByteArray) + ")";
+ }
+ else
+ value = nameValue.toString();
+
+ addField(sb, lbl, value);
+ }
+ }
+ catch (InvalidNameException ine)
+ {
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
+ subject.getName());
+ }
+
+ // issuer
+ addTitle(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_BY"));
+ try
+ {
+ for(Rdn name : new LdapName(issuer.getName()).getRdns())
+ {
+ String nameType = name.getType();
+ String lblKey = "service.gui.CERT_INFO_" + nameType;
+ String lbl = R.getI18NString(lblKey);
+
+ if ((lbl == null) || ("!" + lblKey + "!").equals(lbl))
+ lbl = nameType;
+
+ final String value;
+ Object nameValue = name.getValue();
+
+ if (nameValue instanceof byte[])
+ {
+ byte[] nameValueAsByteArray = (byte[]) nameValue;
+
+ value
+ = getHex(nameValueAsByteArray) + " ("
+ + new String(nameValueAsByteArray) + ")";
+ }
+ else
+ value = nameValue.toString();
+
+ addField(sb, lbl, value);
+ }
+ }
+ catch (InvalidNameException ine)
+ {
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_CN"),
+ issuer.getName());
+ }
+
+ // validity
+ addTitle(sb, R.getI18NString("service.gui.CERT_INFO_VALIDITY"));
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_ISSUED_ON"),
+ certificate.getNotBefore().toString());
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_EXPIRES_ON"),
+ certificate.getNotAfter().toString());
+
+ addTitle(sb, R.getI18NString("service.gui.CERT_INFO_FINGERPRINTS"));
+ try
+ {
+ String sha256String = getThumbprint(certificate, "SHA-256");
+ String sha1String = getThumbprint(certificate, "SHA1");
+
+ addField(sb, "SHA256:", sha256String, 48);
+ addField(sb, "SHA1:", sha1String, 72);
+ }
+ catch (CertificateException e)
+ {
+ // do nothing as we cannot show this value
+ }
+
+ addTitle(sb, R.getI18NString("service.gui.CERT_INFO_CERT_DETAILS"));
+
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_SER_NUM"),
+ certificate.getSerialNumber().toString());
+
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_VER"),
+ String.valueOf(certificate.getVersion()));
+
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN_ALG"),
+ String.valueOf(certificate.getSigAlgName()));
+
+ addTitle(sb, R.getI18NString("service.gui.CERT_INFO_PUB_KEY_INFO"));
+
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_ALG"),
+ certificate.getPublicKey().getAlgorithm());
+
+ if(certificate.getPublicKey().getAlgorithm().equals("RSA"))
+ {
+ RSAPublicKey key = (RSAPublicKey)certificate.getPublicKey();
+
+ addField(sb,
+ R.getI18NString("service.gui.CERT_INFO_PUB_KEY"),
+ R.getI18NString("service.gui.CERT_INFO_KEY_BITS_PRINT",
+ new String[]{
+ String.valueOf(
+ (key.getModulus().toByteArray().length-1)*8)
+ }),
+ getHex(key.getModulus().toByteArray()),
+ 48);
+
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_EXP"),
+ key.getPublicExponent().toString());
+
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_KEY_SIZE"),
+ R.getI18NString(
+ "service.gui.CERT_INFO_KEY_BITS_PRINT",
+ new String[]{
+ String.valueOf(key.getModulus().bitLength())}));
+ }
+ else if(certificate.getPublicKey().getAlgorithm().equals("DSA"))
+ {
+ DSAPublicKey key =
+ (DSAPublicKey)certificate.getPublicKey();
+
+ addField(sb, "Y:", key.getY().toString(16));
+ }
+
+ addField(sb, R.getI18NString("service.gui.CERT_INFO_SIGN"),
+ R.getI18NString(
+ "service.gui.CERT_INFO_KEY_BITS_PRINT",
+ new String[]{
+ String.valueOf(certificate.getSignature().length*8),
+ }),
+ getHex(certificate.getSignature()),
+ 48);
+
+ sb.append("</table>\n");
+ }
+
+ /**
+ * Add a title.
+ *
+ * @param sb StringBuilder to append to
+ * @param title to print
+ */
+ private void addTitle(StringBuilder sb, String title)
+ {
+ sb.append("<tr><td colspan='2'")
+ .append(" style='margin-top: 5pt; white-space: nowrap'><p><b>")
+ .append(title).append("</b></p></td></tr>\n");
+ }
+
+ /**
+ * Add a field.
+ * @param sb StringBuilder to append to
+ * @param field name of the certificate field
+ * @param value to print
+ */
+ private void addField(StringBuilder sb, String field, String value)
+ {
+ addField(sb, field, value, null, 0);
+ }
+
+ /**
+ * Add a field.
+ * @param sb StringBuilder to append to
+ * @param field name of the certificate field
+ * @param value to print
+ * @param wrap force-wrap after number of characters
+ */
+ private void addField(StringBuilder sb, String field, String value,
+ int wrap)
+ {
+ addField(sb, field, value, null, wrap);
+ }
+
+ /**
+ * Add a field.
+ * @param sb StringBuilder to append to
+ * @param field name of the certificate field
+ * @param value to print (not wrapped)
+ * @param otherValue second line of value to print (wrapped)
+ * @param wrap force-wrap after number of characters
+ */
+ private void addField(StringBuilder sb, String field, String value,
+ String otherValue, int wrap)
+ {
+ sb.append("<tr><td style='margin-left: 5pt; margin-right: 25pt;")
+ .append("white-space: nowrap' valign='top'>")
+ .append(field).append("</td><td><span");
+
+ if (otherValue != null)
+ {
+ sb.append('>').append(value).append("</span><br/><span");
+ value = otherValue;
+ }
+
+ if (wrap > 0)
+ {
+ sb.append(" style='font-family:monospace'>");
+ for (int i = 0; i < value.length(); i++)
+ {
+ if (i % wrap == 0 && i > 0)
+ {
+ sb.append("<br/>");
+ }
+
+ sb.append(value.charAt(i));
+ }
+ }
+ else
+ {
+ sb.append(">");
+ sb.append(value);
+ }
+
+ sb.append("</span></td></tr>");
+ }
+
+ /**
+ * Converts the byte array to hex string.
+ * @param raw the data.
+ * @return the hex string.
+ */
+ private String getHex( byte [] raw )
+ {
+ if (raw == null)
+ return null;
+
+ StringBuilder hex = new StringBuilder(2 * raw.length);
+ Formatter f = new Formatter(hex);
+ try
+ {
+ for (byte b : raw)
+ f.format("%02X:", b);
+ }
+ finally
+ {
+ f.close();
+ }
+ return hex.substring(0, hex.length() - 1);
+ }
+
+ /**
+ * Calculates the hash of the certificate known as the "thumbprint"
+ * and returns it as a string representation.
+ *
+ * @param cert The certificate to hash.
+ * @param algorithm The hash algorithm to use.
+ * @return The SHA-1 hash of the certificate.
+ * @throws CertificateException
+ */
+ private static String getThumbprint(X509Certificate cert, String algorithm)
+ throws CertificateException
+ {
+ MessageDigest digest;
+ try
+ {
+ digest = MessageDigest.getInstance(algorithm);
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ throw new CertificateException(e);
+ }
+
+ byte[] encodedCert = cert.getEncoded();
+ StringBuilder sb = new StringBuilder(encodedCert.length * 2);
+ Formatter f = new Formatter(sb);
+ try
+ {
+ for (byte b : digest.digest(encodedCert))
+ f.format("%02X:", b);
+ }
+ finally
+ {
+ f.close();
+ }
+
+ return sb.substring(0, sb.length() - 1);
+ }
+
+ /**
+ * Construct a "simplified name" based on the subject DN from the
+ * certificate. The purpose is to have something shorter to display in the
+ * list. The name used is one of the following DN parts, if
+ * available, otherwise the complete DN:
+ * 'CN', 'OU' or else 'O'.
+ * @param cert to read subject DN from
+ * @return the simplified name
+ */
+ private static String getSimplifiedName(X509Certificate cert)
+ {
+ final HashMap<String, String> parts = new HashMap<String, String>();
+ try
+ {
+ for (Rdn name : new LdapName(
+ cert.getSubjectX500Principal().getName()).getRdns())
+ {
+ if (name.getType() != null && name.getValue() != null)
+ {
+ parts.put(name.getType(), name.getValue().toString());
+ }
+ }
+ }
+ catch (InvalidNameException ignored) // NOPMD
+ {
+ }
+
+ String result = parts.get("CN");
+ if (result == null)
+ {
+ result = parts.get("OU");
+ }
+ if (result == null)
+ {
+ result = parts.get("O");
+ }
+ if (result == null)
+ {
+ result = cert.getSubjectX500Principal().getName();
+ }
+ return result;
+ }
+
+ /**
+ * Called when the selection changed in the tree.
+ * Loads the selected certificate.
+ * @param e the event
+ */
+ private void valueChangedPerformed(TreeSelectionEvent e)
+ {
+ Object o = e.getNewLeadSelectionPath().getLastPathComponent();
+ if (o instanceof DefaultMutableTreeNode)
+ {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
+ infoTextPane.setText(toString(node.getUserObject()));
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomDestroyReasonDialog.java b/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomDestroyReasonDialog.java
index 443171b..ad05797 100644
--- a/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomDestroyReasonDialog.java
+++ b/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomDestroyReasonDialog.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,175 +15,175 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.desktoputil.chat;
-
-import java.awt.*;
-
-import javax.swing.*;
-
-import net.java.sip.communicator.plugin.desktoputil.*;
-import net.java.sip.communicator.util.*;
-
-import org.jitsi.service.resources.*;
-
-/**
- * Dialog with fields for reason and alternate address.
- *
- * @author Hristo Terezov
- */
-public class ChatRoomDestroyReasonDialog extends MessageDialog
-{
- /**
- * The <tt>Logger</tt> used by the <tt>ChatRoomDestroyReasonDialog</tt>
- * class and its instances for logging output.
- */
- private static Logger logger
- = Logger.getLogger(ChatRoomDestroyReasonDialog.class);
-
- /**
- * Serial id.
- */
- private static final long serialVersionUID = -916498752420264164L;
-
- /**
- * Text field for the alternate address.
- */
- private SIPCommTextField alternateAddress
- = new SIPCommTextField("chatroom@example.com");
-
- /**
- * Text field for reason text.
- */
- private JTextField reasonField = new JTextField();
-
- /**
- * Constructs new chat room destroy dialog.
- *
- * @param title the title of the dialog
- * @param message the message shown in this dialog
- */
- public ChatRoomDestroyReasonDialog(String title, String message)
- {
- super(null, title, message,
- DesktopUtilActivator.getResources().getI18NString("service.gui.OK"),
- false);
- this.setIcon((ImageIcon)null);
-
- alternateAddress.setFont(alternateAddress.getFont().deriveFont(12f));
-
- JLabel altAddressLabel
- = new JLabel(DesktopUtilActivator.getResources()
- .getI18NString("service.gui.ALTERNATE_ADDRESS") + ":");
-
- JLabel reasonLabel
- = new JLabel(DesktopUtilActivator.getResources()
- .getI18NString("service.gui.REASON") + ":");
-
- JPanel labelsPanel = new JPanel(new GridLayout(2, 1));
- labelsPanel.add(reasonLabel);
- labelsPanel.add(altAddressLabel);
-
- JPanel valuesPanel = new JPanel(new GridLayout(2, 1));
- valuesPanel.add(reasonField);
- valuesPanel.add(alternateAddress);
-
- JPanel fieldsPanel = new JPanel(new BorderLayout());
- fieldsPanel .add(labelsPanel, BorderLayout.WEST);
-
- fieldsPanel.add(valuesPanel, BorderLayout.CENTER);
- fieldsPanel.add(new JLabel(" "), BorderLayout.EAST);
- fieldsPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
- fieldsPanel.setOpaque(false);
-
-
-
- replaceCheckBoxPanel(fieldsPanel);
- this.pack();
- }
-
- /**
- * Returns the text entered in the alternate address field.
- *
- * @return the text from the alternate address field.
- */
- public String getAlternateAddress()
- {
- return alternateAddress.getText();
- }
-
- /**
- * Returns the text entered in the reason field.
- *
- * @return the text from the reason field.
- */
- public String getReason()
- {
- return reasonField.getText();
- }
-
- /**
- * Opens a dialog with a fields for the reason and alternate address and
- * returns them.
- *
- * @return array with the reason and alternate address values.
- */
- public static String[] getDestroyOptions()
- {
- final ChatRoomDestroyReasonDialog[] res
- = new ChatRoomDestroyReasonDialog[1];
-
- try
- {
- SwingUtilities.invokeAndWait(new Runnable()
- {
- @Override
- public void run()
- {
- ResourceManagementService R
- = DesktopUtilActivator.getResources();
-
- res[0] = new ChatRoomDestroyReasonDialog(
- R.getI18NString("service.gui.DESTROY_CHATROOM"),
- R.getI18NString("service.gui.DESTROY_MESSAGE"));
- }
- });
- }
- catch(Throwable t)
- {
- logger.error("Error creating dialog", t);
- return null;
- }
-
- ChatRoomDestroyReasonDialog reasonDialog = res[0];
-
- int result = reasonDialog.showDialog();
-
- String destroyOptions[] = new String[2];
-
- if (result == MessageDialog.OK_RETURN_CODE)
- {
- destroyOptions[0] = proccessFieldValues(reasonDialog.getReason());
- destroyOptions[1]
- = proccessFieldValues(reasonDialog.getAlternateAddress());
- }
- else
- {
- destroyOptions = null;
- }
-
-
- return destroyOptions;
- }
-
- private static String proccessFieldValues(String value)
- {
- if(value != null)
- {
- value = value.trim();
- if(value.equals(""))
- value = null;
- }
- return value;
- }
-
-}
+package net.java.sip.communicator.plugin.desktoputil.chat;
+
+import java.awt.*;
+
+import javax.swing.*;
+
+import net.java.sip.communicator.plugin.desktoputil.*;
+import net.java.sip.communicator.util.*;
+
+import org.jitsi.service.resources.*;
+
+/**
+ * Dialog with fields for reason and alternate address.
+ *
+ * @author Hristo Terezov
+ */
+public class ChatRoomDestroyReasonDialog extends MessageDialog
+{
+ /**
+ * The <tt>Logger</tt> used by the <tt>ChatRoomDestroyReasonDialog</tt>
+ * class and its instances for logging output.
+ */
+ private static Logger logger
+ = Logger.getLogger(ChatRoomDestroyReasonDialog.class);
+
+ /**
+ * Serial id.
+ */
+ private static final long serialVersionUID = -916498752420264164L;
+
+ /**
+ * Text field for the alternate address.
+ */
+ private SIPCommTextField alternateAddress
+ = new SIPCommTextField("chatroom@example.com");
+
+ /**
+ * Text field for reason text.
+ */
+ private JTextField reasonField = new JTextField();
+
+ /**
+ * Constructs new chat room destroy dialog.
+ *
+ * @param title the title of the dialog
+ * @param message the message shown in this dialog
+ */
+ public ChatRoomDestroyReasonDialog(String title, String message)
+ {
+ super(null, title, message,
+ DesktopUtilActivator.getResources().getI18NString("service.gui.OK"),
+ false);
+ this.setIcon((ImageIcon)null);
+
+ alternateAddress.setFont(alternateAddress.getFont().deriveFont(12f));
+
+ JLabel altAddressLabel
+ = new JLabel(DesktopUtilActivator.getResources()
+ .getI18NString("service.gui.ALTERNATE_ADDRESS") + ":");
+
+ JLabel reasonLabel
+ = new JLabel(DesktopUtilActivator.getResources()
+ .getI18NString("service.gui.REASON") + ":");
+
+ JPanel labelsPanel = new JPanel(new GridLayout(2, 1));
+ labelsPanel.add(reasonLabel);
+ labelsPanel.add(altAddressLabel);
+
+ JPanel valuesPanel = new JPanel(new GridLayout(2, 1));
+ valuesPanel.add(reasonField);
+ valuesPanel.add(alternateAddress);
+
+ JPanel fieldsPanel = new JPanel(new BorderLayout());
+ fieldsPanel .add(labelsPanel, BorderLayout.WEST);
+
+ fieldsPanel.add(valuesPanel, BorderLayout.CENTER);
+ fieldsPanel.add(new JLabel(" "), BorderLayout.EAST);
+ fieldsPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
+ fieldsPanel.setOpaque(false);
+
+
+
+ replaceCheckBoxPanel(fieldsPanel);
+ this.pack();
+ }
+
+ /**
+ * Returns the text entered in the alternate address field.
+ *
+ * @return the text from the alternate address field.
+ */
+ public String getAlternateAddress()
+ {
+ return alternateAddress.getText();
+ }
+
+ /**
+ * Returns the text entered in the reason field.
+ *
+ * @return the text from the reason field.
+ */
+ public String getReason()
+ {
+ return reasonField.getText();
+ }
+
+ /**
+ * Opens a dialog with a fields for the reason and alternate address and
+ * returns them.
+ *
+ * @return array with the reason and alternate address values.
+ */
+ public static String[] getDestroyOptions()
+ {
+ final ChatRoomDestroyReasonDialog[] res
+ = new ChatRoomDestroyReasonDialog[1];
+
+ try
+ {
+ SwingUtilities.invokeAndWait(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ ResourceManagementService R
+ = DesktopUtilActivator.getResources();
+
+ res[0] = new ChatRoomDestroyReasonDialog(
+ R.getI18NString("service.gui.DESTROY_CHATROOM"),
+ R.getI18NString("service.gui.DESTROY_MESSAGE"));
+ }
+ });
+ }
+ catch(Throwable t)
+ {
+ logger.error("Error creating dialog", t);
+ return null;
+ }
+
+ ChatRoomDestroyReasonDialog reasonDialog = res[0];
+
+ int result = reasonDialog.showDialog();
+
+ String destroyOptions[] = new String[2];
+
+ if (result == MessageDialog.OK_RETURN_CODE)
+ {
+ destroyOptions[0] = proccessFieldValues(reasonDialog.getReason());
+ destroyOptions[1]
+ = proccessFieldValues(reasonDialog.getAlternateAddress());
+ }
+ else
+ {
+ destroyOptions = null;
+ }
+
+
+ return destroyOptions;
+ }
+
+ private static String proccessFieldValues(String value)
+ {
+ if(value != null)
+ {
+ value = value.trim();
+ if(value.equals(""))
+ value = null;
+ }
+ return value;
+ }
+
+}
diff --git a/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java b/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java
index 88a5327..db04c56 100644
--- a/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java
+++ b/src/net/java/sip/communicator/plugin/desktoputil/chat/ChatRoomJoinOptionsDialog.java
@@ -1,4 +1,4 @@
-/**
+/**
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,174 +15,174 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.plugin.desktoputil.chat;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import javax.swing.*;
-import javax.swing.border.*;
-
-import net.java.sip.communicator.plugin.desktoputil.*;
-import net.java.sip.communicator.service.protocol.*;
-import net.java.sip.communicator.util.*;
-
-/**
- * Dialog with fields for nickname and subject.
- *
- * @author Hristo Terezov
- */
-public class ChatRoomJoinOptionsDialog extends ChatOperationReasonDialog
-{
- /**
- * Serial id.
- */
- private static final long serialVersionUID = -916498752420264164L;
-
- /**
- * Text field for the subject.
- */
- private SIPCommTextField subject = new SIPCommTextField(DesktopUtilActivator
- .getResources().getI18NString("service.gui.SUBJECT"));
-
- /**
- * Label that hides and shows the subject fields panel on click.
- */
- private JLabel cmdExpandSubjectFields;
-
- /**
- * Panel that holds the subject fields.
- */
- private JPanel subjectFieldsPannel = new JPanel(new BorderLayout());
-
- /**
- * Adds the subject fields to dialog. Sets action listeners.
- *
- * @param title the title of the dialog
- * @param message the message shown in this dialog
- * @param disableOKIfReasonIsEmpty if true the OK button will be
- * disabled if the reason text is empty.
- * @param showReasonLabel specify if we want the "Reason:" label
- * @param dontDisplaySubjectFields if true the sibject fields will be
- * hidden.
- */
- public ChatRoomJoinOptionsDialog(String title, String message,
- boolean showReasonLabel,
- boolean disableOKIfReasonIsEmpty,
- boolean dontDisplaySubjectFields)
- {
- super(title,
- message,
- showReasonLabel,
- disableOKIfReasonIsEmpty);
-
- if(dontDisplaySubjectFields)
- return;
-
- JPanel subjectPanel = new JPanel(new BorderLayout());
- subjectPanel.setOpaque(false);
- subjectPanel.setBorder(
- BorderFactory.createEmptyBorder(10, 0, 0, 0));
-
- subjectFieldsPannel.setBorder(
- BorderFactory.createEmptyBorder(10, 30, 0, 0));
- subjectFieldsPannel.setOpaque(false);
- subjectFieldsPannel.add(subject, BorderLayout.CENTER);
- subjectFieldsPannel.setVisible(false);
- subject.setFont(getFont().deriveFont(12f));
-
- cmdExpandSubjectFields = new JLabel();
- cmdExpandSubjectFields.setBorder(new EmptyBorder(0, 5, 0, 0));
- cmdExpandSubjectFields.setIcon(DesktopUtilActivator.getResources()
- .getImage("service.gui.icons.RIGHT_ARROW_ICON"));
- cmdExpandSubjectFields.setText(DesktopUtilActivator
- .getResources().getI18NString("service.gui.SET_SUBJECT"));
- cmdExpandSubjectFields.addMouseListener(new MouseAdapter()
- {
- @Override
- public void mouseClicked(MouseEvent e)
- {
- cmdExpandSubjectFields.setIcon(
- UtilActivator.getResources().getImage(
- subjectFieldsPannel.isVisible()
- ? "service.gui.icons.RIGHT_ARROW_ICON"
- : "service.gui.icons.DOWN_ARROW_ICON"));
-
- subjectFieldsPannel.setVisible(
- !subjectFieldsPannel.isVisible());
-
- pack();
- }
- });
- subjectPanel.add(cmdExpandSubjectFields,BorderLayout.NORTH);
- subjectPanel.add(subjectFieldsPannel,BorderLayout.CENTER);
- addToReasonFieldPannel(subjectPanel);
- this.pack();
- }
-
- /**
- * Returns the text entered in the subject field.
- *
- * @return the text from the subject field.
- */
- public String getSubject()
- {
- return subject.getText();
- }
-
- /**
- * Opens a dialog with a fields for the nickname and the subject of the room
- * and returns them.
- *
- * @param pps the protocol provider associated with the chat room.
- * @param chatRoomId the id of the chat room.
- * @param defaultNickname the nickname to show if any
- * @return array with the nickname and subject values.
- */
- public static String[] getJoinOptions(ProtocolProviderService pps,
- String chatRoomId, String defaultNickname)
- {
- return getJoinOptions(false, pps, chatRoomId, defaultNickname);
- }
-
- /**
- * Opens a dialog with a fields for the nickname and the subject of the room
- * and returns them.
- *
- * @param dontDisplaySubjectFields if true the subject fields will be hidden
- * @param pps the protocol provider associated with the chat room.
- * @param chatRoomId the id of the chat room.
- * @param defaultNickname the nickname to show if any
- * @return array with the nickname and subject values.
- */
- public static String[] getJoinOptions(boolean dontDisplaySubjectFields,
- ProtocolProviderService pps, String chatRoomId, String defaultNickname)
- {
- String nickName = null;
- ChatRoomJoinOptionsDialog reasonDialog =
- new ChatRoomJoinOptionsDialog(DesktopUtilActivator.getResources()
- .getI18NString("service.gui.CHANGE_NICKNAME"),
- DesktopUtilActivator.getResources().getI18NString(
- "service.gui.CHANGE_NICKNAME_LABEL"), false, true,
- dontDisplaySubjectFields);
- reasonDialog.setIcon(new ImageIcon(DesktopUtilActivator.getImage(
- "service.gui.icons.CHANGE_NICKNAME_16x16")));
-
- if(defaultNickname != null)
- reasonDialog.setReasonFieldText(defaultNickname);
-
- int result = reasonDialog.showDialog();
-
- if (result == MessageDialog.OK_RETURN_CODE)
- {
- nickName = reasonDialog.getReason().trim();
- ConfigurationUtils.updateChatRoomProperty(
- pps,
- chatRoomId, "userNickName", nickName);
-
- }
- String[] joinOptions = {nickName, reasonDialog.getSubject()};
- return joinOptions;
- }
-
-}
+package net.java.sip.communicator.plugin.desktoputil.chat;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import javax.swing.*;
+import javax.swing.border.*;
+
+import net.java.sip.communicator.plugin.desktoputil.*;
+import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * Dialog with fields for nickname and subject.
+ *
+ * @author Hristo Terezov
+ */
+public class ChatRoomJoinOptionsDialog extends ChatOperationReasonDialog
+{
+ /**
+ * Serial id.
+ */
+ private static final long serialVersionUID = -916498752420264164L;
+
+ /**
+ * Text field for the subject.
+ */
+ private SIPCommTextField subject = new SIPCommTextField(DesktopUtilActivator
+ .getResources().getI18NString("service.gui.SUBJECT"));
+
+ /**
+ * Label that hides and shows the subject fields panel on click.
+ */
+ private JLabel cmdExpandSubjectFields;
+
+ /**
+ * Panel that holds the subject fields.
+ */
+ private JPanel subjectFieldsPannel = new JPanel(new BorderLayout());
+
+ /**
+ * Adds the subject fields to dialog. Sets action listeners.
+ *
+ * @param title the title of the dialog
+ * @param message the message shown in this dialog
+ * @param disableOKIfReasonIsEmpty if true the OK button will be
+ * disabled if the reason text is empty.
+ * @param showReasonLabel specify if we want the "Reason:" label
+ * @param dontDisplaySubjectFields if true the sibject fields will be
+ * hidden.
+ */
+ public ChatRoomJoinOptionsDialog(String title, String message,
+ boolean showReasonLabel,
+ boolean disableOKIfReasonIsEmpty,
+ boolean dontDisplaySubjectFields)
+ {
+ super(title,
+ message,
+ showReasonLabel,
+ disableOKIfReasonIsEmpty);
+
+ if(dontDisplaySubjectFields)
+ return;
+
+ JPanel subjectPanel = new JPanel(new BorderLayout());
+ subjectPanel.setOpaque(false);
+ subjectPanel.setBorder(
+ BorderFactory.createEmptyBorder(10, 0, 0, 0));
+
+ subjectFieldsPannel.setBorder(
+ BorderFactory.createEmptyBorder(10, 30, 0, 0));
+ subjectFieldsPannel.setOpaque(false);
+ subjectFieldsPannel.add(subject, BorderLayout.CENTER);
+ subjectFieldsPannel.setVisible(false);
+ subject.setFont(getFont().deriveFont(12f));
+
+ cmdExpandSubjectFields = new JLabel();
+ cmdExpandSubjectFields.setBorder(new EmptyBorder(0, 5, 0, 0));
+ cmdExpandSubjectFields.setIcon(DesktopUtilActivator.getResources()
+ .getImage("service.gui.icons.RIGHT_ARROW_ICON"));
+ cmdExpandSubjectFields.setText(DesktopUtilActivator
+ .getResources().getI18NString("service.gui.SET_SUBJECT"));
+ cmdExpandSubjectFields.addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mouseClicked(MouseEvent e)
+ {
+ cmdExpandSubjectFields.setIcon(
+ UtilActivator.getResources().getImage(
+ subjectFieldsPannel.isVisible()
+ ? "service.gui.icons.RIGHT_ARROW_ICON"
+ : "service.gui.icons.DOWN_ARROW_ICON"));
+
+ subjectFieldsPannel.setVisible(
+ !subjectFieldsPannel.isVisible());
+
+ pack();
+ }
+ });
+ subjectPanel.add(cmdExpandSubjectFields,BorderLayout.NORTH);
+ subjectPanel.add(subjectFieldsPannel,BorderLayout.CENTER);
+ addToReasonFieldPannel(subjectPanel);
+ this.pack();
+ }
+
+ /**
+ * Returns the text entered in the subject field.
+ *
+ * @return the text from the subject field.
+ */
+ public String getSubject()
+ {
+ return subject.getText();
+ }
+
+ /**
+ * Opens a dialog with a fields for the nickname and the subject of the room
+ * and returns them.
+ *
+ * @param pps the protocol provider associated with the chat room.
+ * @param chatRoomId the id of the chat room.
+ * @param defaultNickname the nickname to show if any
+ * @return array with the nickname and subject values.
+ */
+ public static String[] getJoinOptions(ProtocolProviderService pps,
+ String chatRoomId, String defaultNickname)
+ {
+ return getJoinOptions(false, pps, chatRoomId, defaultNickname);
+ }
+
+ /**
+ * Opens a dialog with a fields for the nickname and the subject of the room
+ * and returns them.
+ *
+ * @param dontDisplaySubjectFields if true the subject fields will be hidden
+ * @param pps the protocol provider associated with the chat room.
+ * @param chatRoomId the id of the chat room.
+ * @param defaultNickname the nickname to show if any
+ * @return array with the nickname and subject values.
+ */
+ public static String[] getJoinOptions(boolean dontDisplaySubjectFields,
+ ProtocolProviderService pps, String chatRoomId, String defaultNickname)
+ {
+ String nickName = null;
+ ChatRoomJoinOptionsDialog reasonDialog =
+ new ChatRoomJoinOptionsDialog(DesktopUtilActivator.getResources()
+ .getI18NString("service.gui.CHANGE_NICKNAME"),
+ DesktopUtilActivator.getResources().getI18NString(
+ "service.gui.CHANGE_NICKNAME_LABEL"), false, true,
+ dontDisplaySubjectFields);
+ reasonDialog.setIcon(new ImageIcon(DesktopUtilActivator.getImage(
+ "service.gui.icons.CHANGE_NICKNAME_16x16")));
+
+ if(defaultNickname != null)
+ reasonDialog.setReasonFieldText(defaultNickname);
+
+ int result = reasonDialog.showDialog();
+
+ if (result == MessageDialog.OK_RETURN_CODE)
+ {
+ nickName = reasonDialog.getReason().trim();
+ ConfigurationUtils.updateChatRoomProperty(
+ pps,
+ chatRoomId, "userNickName", nickName);
+
+ }
+ String[] joinOptions = {nickName, reasonDialog.getSubject()};
+ return joinOptions;
+ }
+
+}