summaryrefslogtreecommitdiff
path: root/src/main/java/com/benburwell/planes/gui/TCPConnectionOptionDialog.java
blob: 609a70a9aa4e10629f2f4588ea78f1154e9b1cf7 (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
package com.benburwell.planes.gui;

import javax.swing.*;

/**
 * Created by ben on 11/17/16.
 */
public class TCPConnectionOptionDialog implements ViewComponent {
    public static final String DEFAULT_HOSTNAME = "10.0.0.111";
    public static final int DEFAULT_TCP_PORT = 30003;

    private JPanel dialog = new JPanel();
    private JTextField hostField = new JTextField(10);
    private JTextField portField = new JTextField(5);
    private JLabel descriptionLabel = new JLabel("Add a network data source that provides data in the SBS-1 format");

    @Override
    public JComponent getComponent() {
        // set properties
        hostField.setText(DEFAULT_HOSTNAME);
        hostField.setToolTipText("Hostname or IP address");

        portField.setText(String.valueOf(DEFAULT_TCP_PORT));
        portField.setToolTipText("Port number");

        // create layout
        dialog.add(descriptionLabel);
        dialog.add(hostField);
        dialog.add(portField);

        return dialog;
    }

    public String getHost() {
        return this.hostField.getText();
    }

    public int getPort() {
        try {
            return Integer.valueOf(this.portField.getText());
        } catch (NumberFormatException e) {
            return DEFAULT_TCP_PORT;
        }
    }
}