mirror of https://github.com/sipwise/jitsi.git
Merge pull request #12 from mdzhigarov/otrJitsi
Integrates the latest otr4j library and exposes the Socialist Millionaire Protocol (SMP) functionality in Jitsi.cusax-fix 4904
commit
fa69d4d2e7
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
package net.java.sip.communicator.plugin.otr.authdialog;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* A special {@link JTextArea} for use in the OTR authentication panels.
|
||||
* It is meant to be used for fingerprint representation and general
|
||||
* information display.
|
||||
*
|
||||
* @author George Politis
|
||||
*/
|
||||
public class CustomTextArea
|
||||
extends JTextArea
|
||||
{
|
||||
public CustomTextArea()
|
||||
{
|
||||
this.setBackground(new Color(0,0,0,0));
|
||||
this.setOpaque(false);
|
||||
this.setColumns(20);
|
||||
this.setEditable(false);
|
||||
this.setLineWrap(true);
|
||||
this.setWrapStyleWord(true);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.otr.authdialog;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
import net.java.sip.communicator.plugin.otr.*;
|
||||
import net.java.sip.communicator.plugin.otr.authdialog.FingerprintAuthenticationPanel.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* @author George Politis
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class OtrBuddyAuthenticationDialog
|
||||
extends SIPCommDialog
|
||||
{
|
||||
private final Contact contact;
|
||||
|
||||
/**
|
||||
* The {@link OtrBuddyAuthenticationDialog} ctor.
|
||||
*
|
||||
* @param contact The {@link Contact} this
|
||||
* {@link OtrBuddyAuthenticationDialog} refers to.
|
||||
*/
|
||||
public OtrBuddyAuthenticationDialog(Contact contact)
|
||||
{
|
||||
super(false);
|
||||
this.contact = contact;
|
||||
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the {@link OtrBuddyAuthenticationDialog} components.
|
||||
*/
|
||||
private void initComponents()
|
||||
{
|
||||
this.setTitle(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.TITLE"));
|
||||
|
||||
TransparentPanel mainPanel = new TransparentPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
mainPanel.setPreferredSize(new Dimension(350, 400));
|
||||
|
||||
JTextArea generalInformation = new CustomTextArea();
|
||||
generalInformation.setText(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.AUTHENTICATION_INFO"));
|
||||
mainPanel.add(generalInformation);
|
||||
|
||||
mainPanel.add(Box.createVerticalStrut(10));
|
||||
|
||||
// Add authentication method label and combo box.
|
||||
final String am[] = new String[]{
|
||||
OtrActivator.resourceService.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATION_METHOD_QUESTION"),
|
||||
OtrActivator.resourceService.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATION_METHOD_SECRET"),
|
||||
OtrActivator.resourceService.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATION_METHOD_FINGERPRINT")};
|
||||
final JComboBox authenticationMethodComboBox =
|
||||
new JComboBox(am);
|
||||
JTextArea authMethodLabel = new CustomTextArea();
|
||||
authMethodLabel.setText(
|
||||
OtrActivator.resourceService.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATION_METHOD"));
|
||||
mainPanel.add(authMethodLabel);
|
||||
mainPanel.add(authenticationMethodComboBox);
|
||||
mainPanel.add(Box.createVerticalStrut(10));
|
||||
|
||||
// Add authentication panels in a card layout so that the user can
|
||||
// use the combo box to switch between authentication methods.
|
||||
final JPanel authenticationPanel =
|
||||
new TransparentPanel(new CardLayout());
|
||||
final FingerprintAuthenticationPanel fingerprintPanel =
|
||||
new FingerprintAuthenticationPanel(contact);
|
||||
final SecretQuestionAuthenticationPanel secretQuestionPanel =
|
||||
new SecretQuestionAuthenticationPanel();
|
||||
final SharedSecretAuthenticationPanel sharedSecretPanel =
|
||||
new SharedSecretAuthenticationPanel();
|
||||
authenticationPanel.add(secretQuestionPanel, am[0]);
|
||||
authenticationPanel.add(sharedSecretPanel, am[1]);
|
||||
authenticationPanel.add(fingerprintPanel, am[2]);
|
||||
|
||||
authenticationMethodComboBox.addItemListener(new ItemListener()
|
||||
{
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e)
|
||||
{
|
||||
if (e.getStateChange() == ItemEvent.SELECTED)
|
||||
{
|
||||
CardLayout cl =
|
||||
(CardLayout) (authenticationPanel.getLayout());
|
||||
cl.show(authenticationPanel, (String)e.getItem());
|
||||
}
|
||||
}
|
||||
});
|
||||
authenticationMethodComboBox.setSelectedIndex(0);
|
||||
mainPanel.add(authenticationPanel);
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.insets = new Insets(5, 5, 5, 5);
|
||||
c.weightx = 1.0;
|
||||
c.gridwidth = 1;
|
||||
|
||||
// Buttons panel.
|
||||
JPanel buttonPanel = new TransparentPanel(new GridBagLayout());
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
|
||||
|
||||
JButton helpButton =
|
||||
new JButton(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.HELP"));
|
||||
helpButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent arg0)
|
||||
{
|
||||
OtrActivator.scOtrEngine.launchHelp();
|
||||
}
|
||||
});
|
||||
|
||||
buttonPanel.add(helpButton, c);
|
||||
|
||||
// Provide space between help and the other two button, not sure if this
|
||||
// is optimal..
|
||||
c.weightx = 1.0;
|
||||
buttonPanel.add(new JLabel(), c);
|
||||
c.weightx = 0.0;
|
||||
|
||||
JButton cancelButton =
|
||||
new JButton(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.CANCEL"));
|
||||
cancelButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
buttonPanel.add(cancelButton, c);
|
||||
|
||||
JButton authenticateButton =
|
||||
new JButton(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.AUTHENTICATE_BUDDY"));
|
||||
authenticateButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
String authenticationMethod =
|
||||
(String)authenticationMethodComboBox.getSelectedItem();
|
||||
if (authenticationMethod.equals(am[0]))
|
||||
{
|
||||
String secret = secretQuestionPanel.getSecret();
|
||||
String question = secretQuestionPanel.getQuestion();
|
||||
|
||||
OtrActivator.scOtrEngine.initSmp(contact, question, secret);
|
||||
dispose();
|
||||
}
|
||||
else if (authenticationMethod.equals(am[1]))
|
||||
{
|
||||
String secret = secretQuestionPanel.getSecret();
|
||||
String question = null;
|
||||
|
||||
OtrActivator.scOtrEngine.initSmp(contact, question, secret);
|
||||
dispose();
|
||||
}
|
||||
else if (authenticationMethod.equals(am[2]))
|
||||
{
|
||||
ActionComboBoxItem actionItem =
|
||||
(ActionComboBoxItem) fingerprintPanel.
|
||||
getCbAction().getSelectedItem();
|
||||
switch (actionItem.action)
|
||||
{
|
||||
case I_HAVE:
|
||||
OtrActivator.scOtrKeyManager.verify(contact);
|
||||
break;
|
||||
case I_HAVE_NOT:
|
||||
OtrActivator.scOtrKeyManager.unverify(contact);
|
||||
break;
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonPanel.add(authenticateButton, c);
|
||||
|
||||
this.getContentPane().add(mainPanel, BorderLayout.NORTH);
|
||||
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
|
||||
this.pack();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.otr.authdialog;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
import net.java.sip.communicator.plugin.otr.*;
|
||||
|
||||
/**
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SecretQuestionAuthenticationPanel
|
||||
extends TransparentPanel
|
||||
{
|
||||
/**
|
||||
* The text field where the authentication initiator will type his question.
|
||||
*/
|
||||
private final JTextField question = new JTextField();
|
||||
|
||||
/**
|
||||
* The text field where the authentication initiator will type his answer.
|
||||
*/
|
||||
private final JTextField answer = new JTextField();
|
||||
|
||||
|
||||
/**
|
||||
* Creates an instance SecretQuestionAuthenticationPanel.
|
||||
*/
|
||||
SecretQuestionAuthenticationPanel()
|
||||
{
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the {@link SecretQuestionAuthenticationPanel} components.
|
||||
*/
|
||||
private void initComponents()
|
||||
{
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
|
||||
JTextArea generalInformation = new CustomTextArea();
|
||||
generalInformation.setText(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTH_BY_QUESTION_INFO_INIT"));
|
||||
this.add(generalInformation);
|
||||
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
|
||||
JPanel questionAnswerPanel = new JPanel(new GridBagLayout());
|
||||
questionAnswerPanel.setBorder(BorderFactory.createEtchedBorder());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.insets = new Insets(5, 5, 0, 5);
|
||||
c.weightx = 1;
|
||||
|
||||
JLabel questionLabel =
|
||||
new JLabel(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.QUESTION_INIT"));
|
||||
questionAnswerPanel.add(questionLabel, c);
|
||||
|
||||
c.gridy = 1;
|
||||
c.insets = new Insets(0, 5, 5, 5);
|
||||
questionAnswerPanel.add(question, c);
|
||||
|
||||
c.gridy = 2;
|
||||
c.insets = new Insets(5, 5, 0, 5);
|
||||
JLabel answerLabel =
|
||||
new JLabel(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.ANSWER"));
|
||||
questionAnswerPanel.add(answerLabel, c);
|
||||
|
||||
c.gridy = 3;
|
||||
c.insets = new Insets(0, 5, 5, 5);
|
||||
questionAnswerPanel.add(answer, c);
|
||||
|
||||
this.add(questionAnswerPanel);
|
||||
this.add(new Box.Filler(
|
||||
new Dimension(300, 100),
|
||||
new Dimension(300, 100),
|
||||
new Dimension(300, 100)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the secret answer text.
|
||||
*
|
||||
* @return The secret answer text.
|
||||
*/
|
||||
String getSecret()
|
||||
{
|
||||
return answer.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the secret question text.
|
||||
*
|
||||
* @return The secret question text.
|
||||
*/
|
||||
String getQuestion()
|
||||
{
|
||||
return question.getText();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.otr.authdialog;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
import net.java.sip.communicator.plugin.otr.*;
|
||||
|
||||
/**
|
||||
* @author Marin Dzhigarov
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SharedSecretAuthenticationPanel
|
||||
extends TransparentPanel
|
||||
{
|
||||
/**
|
||||
* The text field where the authentication initiator will type his answer.
|
||||
*/
|
||||
private final JTextField secret = new JTextField();
|
||||
|
||||
/**
|
||||
* Creates an instance SecretQuestionAuthenticationPanel.
|
||||
*/
|
||||
SharedSecretAuthenticationPanel()
|
||||
{
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the {@link SecretQuestionAuthenticationPanel} components.
|
||||
*/
|
||||
private void initComponents()
|
||||
{
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
|
||||
JTextArea generalInformation = new CustomTextArea();
|
||||
generalInformation.setText(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTH_BY_SECRET_INFO_INIT"));
|
||||
this.add(generalInformation);
|
||||
|
||||
this.add(Box.createVerticalStrut(10));
|
||||
|
||||
JPanel questionAnswerPanel = new JPanel(new GridBagLayout());
|
||||
questionAnswerPanel.setBorder(BorderFactory.createEtchedBorder());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.insets = new Insets(5, 5, 0, 5);
|
||||
c.weightx = 1;
|
||||
|
||||
JLabel questionLabel =
|
||||
new JLabel(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.SHARED_SECRET"));
|
||||
questionAnswerPanel.add(questionLabel, c);
|
||||
|
||||
c.gridy = 1;
|
||||
c.insets = new Insets(0, 5, 5, 5);
|
||||
questionAnswerPanel.add(secret, c);
|
||||
|
||||
this.add(questionAnswerPanel);
|
||||
this.add(new Box.Filler(
|
||||
new Dimension(300, 150),
|
||||
new Dimension(300, 150),
|
||||
new Dimension(300, 150)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared secret text.
|
||||
*
|
||||
* @return The shared secret text.
|
||||
*/
|
||||
String getSecret()
|
||||
{
|
||||
return secret.getText();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.otr.authdialog;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
import net.java.sip.communicator.plugin.otr.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
/**
|
||||
* The dialog that pops up when the remote party send us SMP
|
||||
* request. It contains detailed information for the user about
|
||||
* the authentication process and allows him to authenticate.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SmpAuthenticateBuddyDialog
|
||||
extends SIPCommDialog
|
||||
{
|
||||
private final Contact contact;
|
||||
|
||||
private final String question;
|
||||
|
||||
public SmpAuthenticateBuddyDialog(Contact contact, String question)
|
||||
{
|
||||
this.contact = contact;
|
||||
this.question = question;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initComponents()
|
||||
{
|
||||
this.setTitle(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.TITLE"));
|
||||
|
||||
// The main panel that contains all components.
|
||||
JPanel mainPanel = new TransparentPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
mainPanel.setBorder(
|
||||
BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
mainPanel.setPreferredSize(new Dimension(300, 350));
|
||||
|
||||
// Add "authentication from contact" to the main panel.
|
||||
JTextArea authenticationFrom = new CustomTextArea();
|
||||
Font newFont =
|
||||
new Font(
|
||||
UIManager.getDefaults().getFont("TextArea.font").
|
||||
getFontName()
|
||||
, Font.BOLD
|
||||
, 14);
|
||||
authenticationFrom.setFont(newFont);
|
||||
String authFromText =
|
||||
String.format(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATION_FROM",
|
||||
new String[] {contact.getDisplayName()}));
|
||||
authenticationFrom.setText(authFromText);
|
||||
mainPanel.add(authenticationFrom);
|
||||
|
||||
// Add "general info" text to the main panel.
|
||||
JTextArea generalInfo = new CustomTextArea();
|
||||
generalInfo.setText(OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATION_INFO"));
|
||||
mainPanel.add(generalInfo);
|
||||
|
||||
// Add "authentication-by-secret" info text to the main panel.
|
||||
JTextArea authBySecretInfo = new CustomTextArea();
|
||||
newFont =
|
||||
new Font(
|
||||
UIManager.getDefaults().getFont("TextArea.font").
|
||||
getFontName()
|
||||
, Font.ITALIC
|
||||
, 10);
|
||||
authBySecretInfo.setText(OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTH_BY_SECRET_INFO_RESPOND"));
|
||||
authBySecretInfo.setFont(newFont);
|
||||
mainPanel.add(authBySecretInfo);
|
||||
|
||||
// Create a panel to add question/answer related components
|
||||
JPanel questionAnswerPanel = new JPanel(new GridBagLayout());
|
||||
questionAnswerPanel.setBorder(BorderFactory.createEtchedBorder());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.insets = new Insets(5, 5, 0, 5);
|
||||
c.weightx = 0;
|
||||
|
||||
// Add question label.
|
||||
JLabel questionLabel =
|
||||
new JLabel(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.QUESTION_RESPOND"));
|
||||
questionAnswerPanel.add(questionLabel, c);
|
||||
|
||||
// Add the question.
|
||||
c.insets = new Insets(0, 5, 5, 5);
|
||||
c.gridy = 1;
|
||||
JTextArea questionArea =
|
||||
new CustomTextArea();
|
||||
newFont =
|
||||
new Font(
|
||||
UIManager.getDefaults().getFont("TextArea.font").
|
||||
getFontName()
|
||||
, Font.BOLD
|
||||
, UIManager.getDefaults().getFont("TextArea.font")
|
||||
.getSize());
|
||||
questionArea.setFont(newFont);
|
||||
questionArea.setText(question);
|
||||
questionAnswerPanel.add(questionArea, c);
|
||||
|
||||
// Add answer label.
|
||||
c.insets = new Insets(5, 5, 5, 5);
|
||||
c.gridy = 2;
|
||||
JLabel answerLabel =
|
||||
new JLabel(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.ANSWER"));
|
||||
questionAnswerPanel.add(answerLabel, c);
|
||||
|
||||
// Add the answer text field.
|
||||
c.gridy = 3;
|
||||
final JTextField answerTextBox = new JTextField();
|
||||
questionAnswerPanel.add(answerTextBox, c);
|
||||
|
||||
// Add the question/answer panel to the main panel.
|
||||
mainPanel.add(questionAnswerPanel);
|
||||
|
||||
// Buttons panel.
|
||||
JPanel buttonPanel = new TransparentPanel(new GridBagLayout());
|
||||
buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
|
||||
|
||||
JButton helpButton =
|
||||
new JButton(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.HELP"));
|
||||
helpButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent arg0)
|
||||
{
|
||||
OtrActivator.scOtrEngine.launchHelp();
|
||||
}
|
||||
});
|
||||
|
||||
c.gridwidth = 1;
|
||||
c.gridy = 0;
|
||||
c.gridx = 0;
|
||||
c.weightx = 0;
|
||||
c.insets = new Insets(5, 5, 5, 20);
|
||||
buttonPanel.add(helpButton, c);
|
||||
|
||||
JButton cancelButton =
|
||||
new JButton(OtrActivator.resourceService
|
||||
.getI18NString("plugin.otr.authbuddydialog.CANCEL"));
|
||||
cancelButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
OtrActivator.scOtrEngine.abortSmp(contact);
|
||||
SmpAuthenticateBuddyDialog.this.dispose();
|
||||
}
|
||||
});
|
||||
c.insets = new Insets(5, 5, 5, 5);
|
||||
c.gridx = 1;
|
||||
buttonPanel.add(cancelButton, c);
|
||||
|
||||
c.gridx = 2;
|
||||
JButton authenticateButton =
|
||||
new JButton(OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATE_BUDDY"));
|
||||
authenticateButton.addActionListener(new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
OtrActivator.scOtrEngine.respondSmp(
|
||||
contact, question, answerTextBox.getText());
|
||||
SmpAuthenticateBuddyDialog.this.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
buttonPanel.add(authenticateButton, c);
|
||||
|
||||
this.getContentPane().add(mainPanel, BorderLayout.NORTH);
|
||||
this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
|
||||
this.pack();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
|
||||
*
|
||||
* Distributable under LGPL license.
|
||||
* See terms of license at gnu.org.
|
||||
*/
|
||||
package net.java.sip.communicator.plugin.otr.authdialog;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
import net.java.sip.communicator.plugin.desktoputil.*;
|
||||
import net.java.sip.communicator.plugin.otr.*;
|
||||
import net.java.sip.communicator.service.protocol.*;
|
||||
|
||||
|
||||
/**
|
||||
* The dialog that pops up when SMP negotiation starts.
|
||||
* It contains a progress bar that indicates the status of the SMP
|
||||
* authentication process.
|
||||
*
|
||||
* @author Marin Dzhigarov
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SmpProgressDialog
|
||||
extends SIPCommDialog
|
||||
{
|
||||
private final JProgressBar progressBar = new JProgressBar(0, 100);
|
||||
|
||||
private final Color successColor = new Color(86, 140, 2);
|
||||
|
||||
private final Color failColor = new Color(204, 0, 0);
|
||||
|
||||
private final JLabel iconLabel = new JLabel();
|
||||
|
||||
/**
|
||||
* Instantiates SmpProgressDialog.
|
||||
*
|
||||
* @param contact The contact that this dialog is associated with.
|
||||
*/
|
||||
public SmpProgressDialog(Contact contact)
|
||||
{
|
||||
setTitle(
|
||||
OtrActivator.resourceService.getI18NString(
|
||||
"plugin.otr.smpprogressdialog.TITLE"));
|
||||
|
||||
JPanel mainPanel = new TransparentPanel();
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
mainPanel.setBorder(
|
||||
BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
mainPanel.setPreferredSize(new Dimension(300, 70));
|
||||
|
||||
String authFromText =
|
||||
String.format(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.authbuddydialog.AUTHENTICATION_FROM",
|
||||
new String[] {contact.getDisplayName()}));
|
||||
|
||||
JPanel labelsPanel = new TransparentPanel();
|
||||
labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.X_AXIS));
|
||||
|
||||
labelsPanel.add(iconLabel);
|
||||
labelsPanel.add(Box.createRigidArea(new Dimension(5,0)));
|
||||
labelsPanel.add(new JLabel(authFromText));
|
||||
|
||||
mainPanel.add(labelsPanel);
|
||||
mainPanel.add(progressBar);
|
||||
|
||||
init();
|
||||
|
||||
this.getContentPane().add(mainPanel);
|
||||
this.pack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the progress bar and sets it's progression to 1/3.
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
progressBar.setUI(new BasicProgressBarUI() {
|
||||
private Rectangle r = new Rectangle();
|
||||
|
||||
@Override
|
||||
protected void paintIndeterminate(Graphics g, JComponent c) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setRenderingHint(
|
||||
RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
r = getBox(r);
|
||||
g.setColor(progressBar.getForeground());
|
||||
g.fillOval(r.x, r.y, r.width, r.height);
|
||||
}
|
||||
});
|
||||
progressBar.setValue(33);
|
||||
progressBar.setForeground(successColor);
|
||||
progressBar.setStringPainted(false);
|
||||
iconLabel.setIcon(
|
||||
OtrActivator.resourceService.getImage(
|
||||
"plugin.otr.ENCRYPTED_UNVERIFIED_ICON_22x22"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the progress bar to 2/3 of completion.
|
||||
*/
|
||||
public void incrementProgress()
|
||||
{
|
||||
progressBar.setValue(66);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the progress bar to green.
|
||||
*/
|
||||
public void setProgressSuccess()
|
||||
{
|
||||
progressBar.setValue(100);
|
||||
progressBar.setForeground(successColor);
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setString(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.smpprogressdialog.AUTHENTICATION_SUCCESS"));
|
||||
iconLabel.setIcon(
|
||||
OtrActivator.resourceService.getImage(
|
||||
"plugin.otr.ENCRYPTED_ICON_22x22"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the progress bar to red.
|
||||
*/
|
||||
public void setProgressFail()
|
||||
{
|
||||
progressBar.setValue(100);
|
||||
progressBar.setForeground(failColor);
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setString(
|
||||
OtrActivator.resourceService
|
||||
.getI18NString(
|
||||
"plugin.otr.smpprogressdialog.AUTHENTICATION_FAIL"));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue