aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/protocol/ssh/SSHContactInfo.java
blob: 47bb48400d1bbeae3866d933b46b320844e84539 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.impl.protocol.ssh;

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

import javax.swing.*;
import javax.swing.text.*;

import net.java.sip.communicator.plugin.desktoputil.*;

/**
 * @author Shobhit Jindal
 */
class SSHContactInfo
    extends SIPCommDialog
{
    /**
     * Serial version UID.
     */
    private static final long serialVersionUID = 0L;

    private ContactSSH sshContact;

    private JPanel mainPanel = new TransparentPanel();
    private JPanel machinePanel = new TransparentPanel();
    private JPanel detailNamesPanel = new TransparentPanel();
    private JPanel detailFieldsPanel = new TransparentPanel();
    private JPanel detailsPanel = new TransparentPanel();

    private JCheckBox addDetailsCheckBox = new SIPCommCheckBox("Add Details");

    private JButton doneButton = new JButton("Done");
    private JLabel machineID = new JLabel("Hostname / IP: ");
    private JTextField machineIDField = new JTextField();
    private JLabel userName = new JLabel("User Name: ");
    private JTextField userNameField = new JTextField();
    private JLabel password = new JLabel("Password: ");
    private JTextField passwordField = new JPasswordField();
    private JLabel port = new JLabel("Port: ");

    private JFormattedTextField portField;
    private JLabel secs = new JLabel("secs");
    private JLabel statusUpdate = new JLabel("Update Interval: ");
    private JLabel terminalType = new JLabel("Terminal Type: ");
    private JTextField terminalTypeField = new JTextField("SIP Communicator");
    private JSpinner updateTimer = new JSpinner();

    private JPanel emptyPanel1 = new TransparentPanel();

    private JPanel emptyPanel2 = new TransparentPanel();

    private JPanel emptyPanel3 = new TransparentPanel();

    private JPanel emptyPanel4 = new TransparentPanel();

    private JPanel emptyPanel5 = new TransparentPanel();

    private JPanel emptyPanel6 = new TransparentPanel();

    private JPanel emptyPanel7 = new TransparentPanel();

    private JPanel emptyPanel8 = new TransparentPanel();

    private JPanel emptyPanel9 = new TransparentPanel();

    private JPanel emptyPanel10 = new TransparentPanel();

    private JPanel emptyPanel11 = new TransparentPanel();

//    private ContactGroup contactGroup = null;

    /**
     * Creates a new instance of SSHContactInfo
     *
     * @param sshContact the concerned contact
     */
    public SSHContactInfo(ContactSSH sshContact) {
        super(true);

        this.sshContact = sshContact;
        initForm();

        this.getContentPane().add(mainPanel);

        this.setSize(370, 325);

        this.setResizable(false);

        this.setTitle("SSH: Account Details of " + sshContact.getDisplayName());

        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();

        int x = (screenSize.width - this.getWidth()) / 2;
        int y = (screenSize.height - this.getHeight()) / 2;

        this.setLocation(x,y);

//        ProtocolProviderServiceSSHImpl.getUIService().getConfigurationWindow().
//                addConfigurationForm(this);
    }

    /**
     * initialize the form.
     */
    public void initForm() {
        updateTimer.setValue(30);
        MaskFormatter maskFormatter = new MaskFormatter();
        try {
            maskFormatter.setMask("#####");
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        maskFormatter.setAllowsInvalid(false);
        portField = new JFormattedTextField(maskFormatter);
        portField.setValue(22);

        userNameField.setEnabled(false);
        passwordField.setEditable(false);
        portField.setEnabled(false);
        terminalTypeField.setEnabled(false);
        updateTimer.setEnabled(false);

        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
        machinePanel.setLayout(new BoxLayout(machinePanel, BoxLayout.X_AXIS));
        detailNamesPanel.setLayout(new BoxLayout(detailNamesPanel,
                BoxLayout.Y_AXIS));
        detailFieldsPanel.setLayout(new BoxLayout(detailFieldsPanel,
                BoxLayout.Y_AXIS));
        detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.X_AXIS));

        machinePanel.add(machineID);
        machinePanel.add(machineIDField);

        detailNamesPanel.add(userName);
        detailNamesPanel.add(emptyPanel1);
        detailNamesPanel.add(password);
        detailNamesPanel.add(emptyPanel2);
        detailNamesPanel.add(port);
        detailNamesPanel.add(emptyPanel3);
        detailNamesPanel.add(statusUpdate);
        detailNamesPanel.add(emptyPanel4);
        detailNamesPanel.add(terminalType);

        detailFieldsPanel.add(userNameField);
        detailFieldsPanel.add(emptyPanel5);
        detailFieldsPanel.add(passwordField);
        detailFieldsPanel.add(emptyPanel6);
        detailFieldsPanel.add(portField);
        detailFieldsPanel.add(emptyPanel7);
        detailFieldsPanel.add(updateTimer);
        detailFieldsPanel.add(emptyPanel8);
        detailFieldsPanel.add(terminalTypeField);

        detailsPanel.add(detailNamesPanel);
        detailsPanel.add(detailFieldsPanel);

        detailsPanel.setBorder(BorderFactory.createTitledBorder("Details"));

        mainPanel.add(emptyPanel9);
        mainPanel.add(machinePanel);
        mainPanel.add(addDetailsCheckBox);
        mainPanel.add(detailsPanel);
        mainPanel.add(emptyPanel10);
        mainPanel.add(doneButton);
        mainPanel.add(emptyPanel11);

        addDetailsCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                addDetailsCheckBox.setEnabled(false);
                userNameField.setEnabled(true);
                passwordField.setEditable(true);
                portField.setEnabled(true);
                terminalTypeField.setEnabled(true);
                updateTimer.setEnabled(true);

                userNameField.grabFocus();
            }
        });

        doneButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                if(machineIDField.getText().equals("")) {
                    machineIDField.setText("Field needed");
                    return;
                }

                sshContact.savePersistentDetails();

                //add contact to contact list
                ((OperationSetPersistentPresenceSSHImpl)sshContact
                    .getParentPresenceOperationSet())
                        .addContactToList(
                            sshContact.getParentContactGroup(),
                            sshContact);

                setVisible(false);
            }
        });
    }

    /**
     * Return the ssh icon
     *
     * @return the ssh icon
     */
    public byte[] getIcon() {
        return Resources.getImage(Resources.SSH_LOGO);
    }

//
//    public void setContactGroup(ContactGroup contactGroup)
//    {
//        this.contactGroup = contactGroup;
//    }
//
//    public ContactGroup getContactGroup()
//    {
//        return this.contactGroup;
//    }

    /**
     * Sets the UserName of the dialog
     *
     * @param userName to be associated
     */
    public void setUserNameField(String userName) {
        this.userNameField.setText(userName);
    }

    /**
     * Sets the Password of the dialog
     *
     * @param password to be associated
     */
    public void setPasswordField(String password) {
        this.passwordField.setText(password);
    }

    /**
     * Return the hostname
     *
     * @return the hostname
     */
    public String getHostName() {
        return this.machineIDField.getText();
    }

    /**
     * Return the username
     *
     * @return the username
     */
    public String getUserName() {
        return this.userNameField.getText();
    }

    /**
     * Return the password
     *
     * @return the password in a clear form
     */
    public String getPassword() {
        return this.passwordField.getText();
    }

    /**
     * Return the terminal type
     *
     * @return the terminal type
     */
    public String getTerminalType() {
        return this.terminalTypeField.getText();
    }

    /**
     * Return the port
     *
     * @return the port value
     */
    public int getPort() {
        return Integer.parseInt(this.portField.getText().trim());
    }

    /**
     * Return the update interval
     *
     * @return the update interval
     */
    public int getUpdateInterval() {
        return Integer.parseInt(String.valueOf(this.updateTimer.getValue()));
    }

    /**
     * Sets the HostName of the dialog
     *
     * @param hostName to be associated
     */
    public void setHostNameField(String hostName) {
        this.machineIDField.setText(hostName);
    }

    /**
     * Sets the Terminal Type of the dialog
     *
     * @param termType to be associated
     */
    public void setTerminalType(String termType) {
        this.terminalTypeField.setText(termType);
    }

    /**
     * Sets the Update Interval of the dialog
     *
     * @param interval to be associated
     */
    public void setUpdateInterval(int interval) {
        this.updateTimer.setValue(interval);
    }

    /**
     * Sets the Port of the dialog
     *
     * @param port to be associated
     */
    public void setPort(String port) {
        this.portField.setText(port);
    }

    @Override
    protected void close(boolean isEscaped)
    {
    }
}