OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [modmod/] [ConnectionWidget.java] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
package edu.byu.cc.plieber.fpgaenet.modmod;
2
 
3
import java.io.IOException;
4
import java.net.InetAddress;
5
import java.net.UnknownHostException;
6
 
7
import com.trolltech.qt.core.Qt;
8
import com.trolltech.qt.core.Qt.WindowModality;
9
import com.trolltech.qt.gui.*;
10
 
11
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
12
 
13
public class ConnectionWidget extends QWidget {
14
 
15
        public static void main(String[] args) {
16
                QApplication.initialize(args);
17
 
18
                FCPProtocol fcpprotocol;
19
                try {
20
                        fcpprotocol = new FCPProtocol();
21
                        ConnectionWidget testStaticModulesWidget = new ConnectionWidget(null, fcpprotocol);
22
                        testStaticModulesWidget.show();
23
                        QApplication.exec();
24
                        fcpprotocol.disconnect();
25
                } catch (IOException e) {
26
                        // TODO Auto-generated catch block
27
                        e.printStackTrace();
28
                }
29
        }
30
 
31
        private FCPProtocol fcpprotocol;
32
 
33
        public ConnectionWidget(QWidget parent, FCPProtocol protocol) {
34
                super(parent);
35
                fcpprotocol = protocol;
36
                createWidgets();
37
                createLayout();
38
                connectSignalsAndSlots();
39
                setWindowModality(WindowModality.ApplicationModal);
40
                fillWidgets();
41
        }
42
 
43
        private void fillWidgets() {
44
                if (fcpprotocol != null) {
45
                        spnSourcePort.setValue(fcpprotocol.getSourceUDPPort());
46
                        spnDestPort.setValue(fcpprotocol.getDestUDPPort());
47
                        if (fcpprotocol.getDestIPAddress() != null)
48 7 peteralieb
                                txtFPGAIP.setText(fcpprotocol.getDestIPAddress().getHostAddress());
49 2 peteralieb
                        else
50
                                txtFPGAIP.setText("10.0.1.42");
51
                        textStatus.setText(fcpprotocol.isConnected() ? "Connected" : "Not Connected");
52
                } else {
53
                        textStatus.setText("Not Connected");
54
                }
55
        }
56
 
57
        private QLabel labelSourcePort = new QLabel("Source UDP Port");
58
        private QLabel labelDestPort = new QLabel("Destination UDP Port");
59
        private QLabel labelFPGAIP = new QLabel("FPGA IP Address");
60
        private QLabel labelStatus = new QLabel("Status");
61
 
62
        private QSpinBox spnSourcePort = new QSpinBox();
63
        private QSpinBox spnDestPort = new QSpinBox();
64
        private QLineEdit txtFPGAIP = new QLineEdit();
65
        private QTextEdit textStatus = new QTextEdit();
66
 
67
        private QPushButton btnConnect = new QPushButton("Connect");
68
        private QPushButton btnDisconnect = new QPushButton("Disconnect");
69
 
70
        public Signal0 ConnectionChangedSignal = new Signal0();
71
 
72
        private void createWidgets() {
73
                labelSourcePort.setAlignment(Qt.AlignmentFlag.AlignRight);
74
                labelDestPort.setAlignment(Qt.AlignmentFlag.AlignRight);
75
                labelFPGAIP.setAlignment(Qt.AlignmentFlag.AlignRight);
76
                labelStatus.setAlignment(Qt.AlignmentFlag.AlignCenter);
77
                textStatus.setReadOnly(true);
78
        }
79
 
80
        private void createLayout() {
81
                QVBoxLayout mainLayout = new QVBoxLayout(this);
82
                QHBoxLayout topLayout = new QHBoxLayout();
83
                mainLayout.addLayout(topLayout);
84
                QVBoxLayout statusLayout = new QVBoxLayout();
85
                QHBoxLayout bottomLayout = new QHBoxLayout();
86
                mainLayout.addLayout(bottomLayout);
87
                QGridLayout settingsLayout = new QGridLayout();
88
                topLayout.addLayout(settingsLayout);
89
                topLayout.addLayout(statusLayout);
90
 
91
                settingsLayout.setRowMinimumHeight(0, 20);
92
                settingsLayout.addWidget(labelSourcePort, 1, 0);
93
                spnSourcePort.setMaximum(65535);
94
                spnSourcePort.setMinimum(1);
95
                settingsLayout.addWidget(spnSourcePort, 1, 1);
96
                settingsLayout.addWidget(labelDestPort, 2, 0);
97
                spnDestPort.setMaximum(65535);
98
                spnDestPort.setMinimum(1);
99
                settingsLayout.addWidget(spnDestPort, 2, 1);
100
                settingsLayout.addWidget(labelFPGAIP, 3, 0);
101
                settingsLayout.addWidget(txtFPGAIP, 3, 1);
102
                settingsLayout.setColumnStretch(0, 1);
103
                settingsLayout.setRowStretch(4, 1);
104
 
105
                statusLayout.addWidget(labelStatus);
106
                statusLayout.addWidget(textStatus);
107
 
108
                bottomLayout.addWidget(btnConnect);
109
                bottomLayout.addWidget(btnDisconnect);
110
        }
111
 
112
        private void connectSignalsAndSlots() {
113
                btnConnect.clicked.connect(this, "connect()");
114
                btnDisconnect.clicked.connect(this, "disconnectFCP()");
115
        }
116
 
117
        @SuppressWarnings("unused")
118
        private void connect() {
119
                if (fcpprotocol == null) {
120
                        this.textStatus.setText("Not Connected");
121
                }
122
                else {
123
                        try {
124 7 peteralieb
                                //if (fcpprotocol.isConnected()) fcpprotocol.disconnect();
125 2 peteralieb
                                fcpprotocol.connect(InetAddress.getByName(this.txtFPGAIP.text()), spnDestPort.value());
126
                                while (!fcpprotocol.isConnected());
127
                                this.textStatus.setText("Connected!");
128
                        } catch (UnknownHostException e) {
129
                                this.textStatus.setText("Not Connected");
130
                        }
131
                        this.ConnectionChangedSignal.emit();
132
                }
133
        }
134
 
135
        @SuppressWarnings("unused")
136
        private void disconnectFCP() {
137
                if (fcpprotocol != null) {
138
                        fcpprotocol.disconnect();
139
                }
140
                this.textStatus.setText("Not Connected");
141
        }
142
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.