1 |
2 |
peteralieb |
package edu.byu.cc.plieber.fpgaenet.modmod;
|
2 |
|
|
|
3 |
|
|
import java.util.ArrayList;
|
4 |
|
|
|
5 |
|
|
import com.trolltech.qt.core.Qt.WindowModality;
|
6 |
|
|
import com.trolltech.qt.gui.*;
|
7 |
|
|
|
8 |
|
|
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
|
9 |
|
|
|
10 |
|
|
public class CreateModuleWidget extends QWidget {
|
11 |
|
|
|
12 |
|
|
public static void main(String[] args) {
|
13 |
|
|
QApplication.initialize(args);
|
14 |
|
|
|
15 |
|
|
CreateModuleWidget testCreateModuleWidget = new CreateModuleWidget(null, null);
|
16 |
|
|
testCreateModuleWidget.show();
|
17 |
|
|
|
18 |
|
|
QApplication.exec();
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
Signal1<AvailableModule> AvailableModuleCreated;
|
22 |
|
|
private FCPProtocol fcpProtocol;
|
23 |
|
|
|
24 |
|
|
public CreateModuleWidget(QWidget parent, FCPProtocol p) {
|
25 |
|
|
super(parent);
|
26 |
|
|
AvailableModuleCreated = new Signal1<AvailableModule>();
|
27 |
|
|
fcpProtocol = p;
|
28 |
|
|
createWidgets();
|
29 |
|
|
populateWidgets();
|
30 |
|
|
createLayout();
|
31 |
|
|
connectSignalsAndSlots();
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
private void createWidgets() {
|
35 |
|
|
txtName = new QLineEdit();
|
36 |
|
|
cmbWidget = new QComboBox();
|
37 |
|
|
txtCh5Bitstream = new QLineEdit();
|
38 |
|
|
btnCh5Bitstream = new QPushButton("Browse");
|
39 |
|
|
txtCh6Bitstream = new QLineEdit();
|
40 |
|
|
btnCh6Bitstream = new QPushButton("Browse");
|
41 |
|
|
btnOk = new QPushButton("Ok");
|
42 |
|
|
btnCancel = new QPushButton("Cancel");
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
private void populateWidgets() {
|
46 |
|
|
cmbWidget.insertItem(0, "MD5 Control", new MD5Widget(null, fcpProtocol));
|
47 |
|
|
cmbWidget.insertItem(1, "SHA1 Control", new SHA1Widget(null, fcpProtocol));
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
private void createLayout() {
|
51 |
|
|
QVBoxLayout layout = new QVBoxLayout();
|
52 |
|
|
this.setLayout(layout);
|
53 |
|
|
QFormLayout formLayout = new QFormLayout();
|
54 |
|
|
formLayout.addRow(tr("Name"), txtName);
|
55 |
|
|
formLayout.addRow(tr("Widget"), cmbWidget);
|
56 |
|
|
QHBoxLayout ch5Layout = new QHBoxLayout();
|
57 |
|
|
ch5Layout.addWidget(txtCh5Bitstream);
|
58 |
|
|
ch5Layout.addWidget(btnCh5Bitstream);
|
59 |
|
|
formLayout.addRow(tr("Channel 5 Bitstream"), ch5Layout);
|
60 |
|
|
QHBoxLayout ch6Layout = new QHBoxLayout();
|
61 |
|
|
ch6Layout.addWidget(txtCh6Bitstream);
|
62 |
|
|
ch6Layout.addWidget(btnCh6Bitstream);
|
63 |
|
|
formLayout.addRow(tr("Channel 6 Bitstream"), ch6Layout);
|
64 |
|
|
layout.addLayout(formLayout);
|
65 |
|
|
layout.addStretch();
|
66 |
|
|
QHBoxLayout buttonLayout = new QHBoxLayout();
|
67 |
|
|
buttonLayout.addStretch();
|
68 |
|
|
buttonLayout.addWidget(btnOk);
|
69 |
|
|
buttonLayout.addWidget(btnCancel);
|
70 |
|
|
layout.addLayout(buttonLayout);
|
71 |
|
|
setWindowModality(WindowModality.ApplicationModal);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
private void connectSignalsAndSlots() {
|
75 |
|
|
btnOk.clicked.connect(this, "ok()");
|
76 |
|
|
btnCancel.clicked.connect(this, "cancel()");
|
77 |
|
|
btnCh5Bitstream.clicked.connect(this, "ch5ButtonPressed()");
|
78 |
|
|
btnCh6Bitstream.clicked.connect(this, "ch6ButtonPressed()");
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
@SuppressWarnings("unused")
|
82 |
|
|
private void ok() {
|
83 |
|
|
ArrayList<String> bitstreams = new ArrayList<String>(6);
|
84 |
|
|
bitstreams.add("");
|
85 |
|
|
bitstreams.add("");
|
86 |
|
|
bitstreams.add("");
|
87 |
|
|
bitstreams.add("");
|
88 |
|
|
bitstreams.add("");
|
89 |
|
|
bitstreams.add(txtCh5Bitstream.text());
|
90 |
|
|
bitstreams.add(txtCh6Bitstream.text());
|
91 |
|
|
this.AvailableModuleCreated.emit(new AvailableModule(this.txtName.text(), null, (ModuleControlWidget) cmbWidget
|
92 |
|
|
.itemData(cmbWidget.currentIndex()), bitstreams));
|
93 |
|
|
this.close();
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
@SuppressWarnings("unused")
|
97 |
|
|
private void cancel() {
|
98 |
|
|
this.close();
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
@SuppressWarnings("unused")
|
102 |
|
|
private void ch5ButtonPressed() {
|
103 |
|
|
String fName = QFileDialog.getOpenFileName(this, tr("Open Channel 5 " + txtName.text() + " Bit File"), "",
|
104 |
|
|
new QFileDialog.Filter(tr("Bit Files (*.bit)")));
|
105 |
|
|
if (fName == null)
|
106 |
|
|
return;
|
107 |
|
|
txtCh5Bitstream.setText(fName);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
@SuppressWarnings("unused")
|
111 |
|
|
private void ch6ButtonPressed() {
|
112 |
|
|
String fName = QFileDialog.getOpenFileName(this, tr("Open Channel 6 " + txtName.text() + " Bit File"), "",
|
113 |
|
|
new QFileDialog.Filter(tr("Bit Files (*.bit)")));
|
114 |
|
|
if (fName == null)
|
115 |
|
|
return;
|
116 |
|
|
txtCh6Bitstream.setText(fName);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
private QLineEdit txtName;
|
120 |
|
|
private QComboBox cmbWidget;
|
121 |
|
|
private QLineEdit txtCh5Bitstream;
|
122 |
|
|
private QPushButton btnCh5Bitstream;
|
123 |
|
|
private QLineEdit txtCh6Bitstream;
|
124 |
|
|
private QPushButton btnCh6Bitstream;
|
125 |
|
|
private QPushButton btnOk;
|
126 |
|
|
private QPushButton btnCancel;
|
127 |
|
|
}
|