aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/otr/OtrBuddyAuthenticationDialog.java
blob: c8fa0c5de17e352e2ba3e6c49b7c0a89f79e1c64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * SIP Communicator, 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;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import net.java.sip.communicator.service.protocol.*;

/**
 * 
 * @author George Politis
 * 
 */
@SuppressWarnings("serial")
public class OtrBuddyAuthenticationDialog
    extends JDialog
{
    private Contact contact;

    public OtrBuddyAuthenticationDialog(Contact contact)
    {
        this.contact = contact;

        initComponents();
        loadContact();
    }

    JTextArea txtLocalFingerprint;

    JTextArea txtRemoteFingerprint;

    private void loadContact()
    {
        // Local fingerprint.
        String account =
            contact.getProtocolProvider().getAccountID().getDisplayName();
        String localFingerprint =
            OtrActivator.scOtrEngine.getLocalFingerprint(contact
                .getProtocolProvider().getAccountID());
        txtLocalFingerprint.setText(OtrActivator.resourceService.getI18NString(
            "plugin.otr.authbuddydialog.LOCAL_FINGERPRINT", new String[]
            { account, localFingerprint }));

        // Remote fingerprint.
        String user = contact.getDisplayName();
        String remoteFingerprint =
            OtrActivator.scOtrEngine.getRemoteFingerprint(contact);
        txtRemoteFingerprint.setText(OtrActivator.resourceService
            .getI18NString("plugin.otr.authbuddydialog.REMOTE_FINGERPRINT",
                new String[]
                { user, remoteFingerprint }));
    }

    private void initComponents()
    {
        this.setTitle(OtrActivator.resourceService
            .getI18NString("plugin.otr.authbuddydialog.TITLE"));

        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
        mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        mainPanel.setPreferredSize(new Dimension(400, 300));

        JTextArea generalInformation = new JTextArea();
        generalInformation.setBackground(new java.awt.Color(212, 208, 200));
        generalInformation.setColumns(20);
        generalInformation.setEditable(false);
        generalInformation.setLineWrap(true);
        generalInformation.setWrapStyleWord(true);
        generalInformation.setText(OtrActivator.resourceService
            .getI18NString("plugin.otr.authbuddydialog.AUTHENTICATION_INFO"));
        mainPanel.add(generalInformation);

        txtLocalFingerprint = new JTextArea();
        txtLocalFingerprint.setBackground(new java.awt.Color(212, 208, 200));
        txtLocalFingerprint.setColumns(20);
        txtLocalFingerprint.setEditable(false);
        txtLocalFingerprint.setLineWrap(true);
        generalInformation.setWrapStyleWord(true);

        mainPanel.add(txtLocalFingerprint);

        txtRemoteFingerprint = new JTextArea();
        txtRemoteFingerprint.setBackground(new java.awt.Color(212, 208, 200));
        txtRemoteFingerprint.setColumns(20);
        txtRemoteFingerprint.setEditable(false);
        txtRemoteFingerprint.setLineWrap(true);
        generalInformation.setWrapStyleWord(true);

        mainPanel.add(txtRemoteFingerprint);

        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

        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);

        JButton cancelButton =
            new JButton(OtrActivator.resourceService
                .getI18NString("plugin.otr.authbuddydialog.CANCEL"));
        cancelButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                dispose();
            }
        });
        buttonPanel.add(cancelButton);

        JButton authenticateButton =
            new JButton(OtrActivator.resourceService
                .getI18NString("plugin.otr.authbuddydialog.AUTHENTICATE_BUDDY"));
        authenticateButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                OtrActivator.scOtrEngine.verifyContactFingerprint(contact);
                dispose();
            }
        });
        buttonPanel.add(authenticateButton);

        mainPanel.add(buttonPanel);

        this.getContentPane().add(mainPanel);
        this.pack();
    }
}