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/] [examples/] [IcapToolGui.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.examples;
2
 
3
import java.io.IOException;
4
import java.net.InetAddress;
5
 
6
import com.trolltech.qt.core.QModelIndex;
7
import com.trolltech.qt.core.Qt.DockWidgetArea;
8
//import com.trolltech.qt.gui.*;
9
import com.trolltech.qt.gui.QAbstractItemView.SelectionMode;
10
import com.trolltech.qt.gui.QAction;
11
import com.trolltech.qt.gui.QApplication;
12
import com.trolltech.qt.gui.QBoxLayout;
13
import com.trolltech.qt.gui.QBoxLayout.Direction;
14
import com.trolltech.qt.gui.QDockWidget;
15
import com.trolltech.qt.gui.QFileDialog;
16
import com.trolltech.qt.gui.QFrame;
17
import com.trolltech.qt.gui.QHBoxLayout;
18
import com.trolltech.qt.gui.QItemSelection;
19
import com.trolltech.qt.gui.QLabel;
20
import com.trolltech.qt.gui.QLayout;
21
import com.trolltech.qt.gui.QLineEdit;
22
import com.trolltech.qt.gui.QListView;
23
import com.trolltech.qt.gui.QMainWindow;
24
import com.trolltech.qt.gui.QMenu;
25
import com.trolltech.qt.gui.QMessageBox;
26
import com.trolltech.qt.gui.QPushButton;
27
import com.trolltech.qt.gui.QSortFilterProxyModel;
28
import com.trolltech.qt.gui.QTableView;
29
import com.trolltech.qt.gui.QVBoxLayout;
30
import com.trolltech.qt.gui.QWidget;
31
 
32
import edu.byu.cc.plieber.fpgaenet.debug.IcapReadback;
33
import edu.byu.cc.plieber.fpgaenet.debug.LogicalMapping;
34
import edu.byu.cc.plieber.fpgaenet.debug.llparse.LatchRBEntry;
35
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
36
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
37
import edu.byu.cc.plieber.fpgaenet.icapif.IcapInterface;
38
import edu.byu.cc.plieber.fpgaenet.icapif.IcapTools;
39
 
40
public class IcapToolGui extends QMainWindow {
41
 
42
        private QMenu fileMenu;
43
        private QMenu helpMenu;
44
 
45
        private QAction openLL;
46
        private QAction exitAct;
47
        private QAction aboutAct;
48
        private QAction aboutQtJambiAct;
49
 
50
        // Widgets
51
        private QLabel netLabel;
52
        private QLineEdit netValue;
53
        private QPushButton buttonGetValue;
54
 
55
        // Model/Views
56
        private QListView netListView;
57
        private QTableView netTableView;
58
        private NetListModel netListModel;
59
        QSortFilterProxyModel tableProxyModel;
60
        QSortFilterProxyModel listProxyModel;
61
 
62
        // Connections
63
        FCPProtocol fcpProtocol;
64
        IcapInterface icapif;
65
        IcapTools icapTools;
66
        IcapReadback icapReadback;
67
        LatchRBEntry currentEntry;
68
 
69
        public static void main(String[] args) {
70
                QApplication.initialize(args);
71
 
72
                IcapToolGui testIcapToolGui = new IcapToolGui(null);
73
                testIcapToolGui.show();
74
 
75
                QApplication.exec();
76
 
77
                testIcapToolGui.tearDown();
78
        }
79
 
80
        public  void tearDown() {
81
                fcpProtocol.disconnect();
82
        }
83
 
84
        public IcapToolGui(QWidget parent) {
85
                super(parent);
86
                setWindowTitle("ICAP Tool GUI");
87
                createActions();
88
                createMenus();
89
                createWidgets();
90
                setupConnections();
91
                connectSignals();
92
        }
93
 
94
        private void setupConnections() {
95
                try {
96
                        fcpProtocol = new FCPProtocol();
97
                        fcpProtocol.connect(InetAddress.getByName("192.168.1.222"), 0x3001);
98
                } catch (IOException e) {
99
                        return;
100
                }
101
                icapif = new IcapInterface(fcpProtocol);
102
                icapTools = new IcapTools(icapif);
103
                icapReadback = new IcapReadback(icapTools);
104
                while(!fcpProtocol.isConnected());
105 7 peteralieb
                try {
106
                        icapTools.synchIcap();
107
                } catch (FCPException e) {
108
                        // TODO Auto-generated catch block
109
                        e.printStackTrace();
110
                }
111 2 peteralieb
        }
112
 
113
        private void createActions() {
114
                openLL = new QAction(tr("&Open LL File"), this);
115
                openLL.setShortcut(tr("Ctrl+O"));
116
                openLL.setStatusTip(tr("Open new LL file"));
117
                openLL.triggered.connect(this, "openLL()");
118
 
119
                exitAct = new QAction(tr("E&xit"), this);
120
                exitAct.setShortcut(tr("Ctrl+Q"));
121
                exitAct.setStatusTip(tr("Exit the application"));
122
                exitAct.triggered.connect(this, "close()");
123
 
124
                aboutAct = new QAction(tr("&About"), this);
125
                aboutAct.setStatusTip(tr("Show the application's About box"));
126
                aboutAct.triggered.connect(this, "about()");
127
 
128
                aboutQtJambiAct = new QAction(tr("About &Qt Jambi"), this);
129
                aboutQtJambiAct.setStatusTip(tr("Show the Qt Jambi's About box"));
130
                aboutQtJambiAct.triggered.connect(QApplication.instance(), "aboutQtJambi()");
131
        }
132
 
133
        private void createMenus() {
134
                fileMenu = menuBar().addMenu(tr("&File"));
135
                fileMenu.addAction(openLL);
136
                fileMenu.addAction(exitAct);
137
 
138
                helpMenu = menuBar().addMenu(tr("&Help"));
139
                helpMenu.addAction(aboutAct);
140
                helpMenu.addAction(aboutQtJambiAct);
141
        }
142
 
143
        private void createWidgets() {
144
                // Left Dock Net List
145
                netListView = new QListView(this);
146
                netListView.setSelectionMode(SelectionMode.ExtendedSelection);
147
                QDockWidget dockWidget = new QDockWidget(tr("Net List"), this);
148
                dockWidget.setAllowedAreas(DockWidgetArea.LeftDockWidgetArea);
149
                dockWidget.setWidget(netListView);
150
                addDockWidget(DockWidgetArea.LeftDockWidgetArea, dockWidget);
151
 
152
                // Main area Frame -------------------------------------------------
153
                QFrame mainFrame = new QFrame(this);
154
                setCentralWidget(mainFrame);
155
                netTableView = new QTableView(mainFrame);
156
                QVBoxLayout mainLayout = new QVBoxLayout(mainFrame);
157
                mainLayout.addWidget(netTableView);
158
                QHBoxLayout netValueLayout = new QHBoxLayout();
159
                netLabel = new QLabel(tr("Net Value"));
160
                netValue = new QLineEdit(tr("<net value>"));
161
                buttonGetValue = new QPushButton(tr("Get Value"));
162
                buttonGetValue.clicked.connect(this, "getNetValue()");
163
                netValueLayout.addWidget(netLabel);
164
                netValueLayout.addWidget(netValue);
165
                netValueLayout.addWidget(buttonGetValue);
166
                mainLayout.addLayout(netValueLayout);
167
                mainFrame.setLayout(mainLayout);
168
        }
169
 
170
        private void connectSignals() {
171
                netListView.doubleClicked.connect(this, "openStatusWidget(QModelIndex)");
172
        }
173
 
174
        protected void openLL() {
175
                String fName = QFileDialog.getOpenFileName(this, tr("Open LL File"), "", new QFileDialog.Filter(
176
                                tr("LL Files (*.ll *.LL)")));
177
                LogicalMapping llMapping = new LogicalMapping(fName);
178
                netListModel = new NetListModel(llMapping);
179
                listProxyModel = new QSortFilterProxyModel(this);
180
                listProxyModel.setSourceModel(netListModel);
181
                listProxyModel.sort(0);
182
                netListView.setModel(listProxyModel);
183
                tableProxyModel = new QSortFilterProxyModel(this);
184
                tableProxyModel.setSourceModel(netListModel);
185
                tableProxyModel.setFilterFixedString("");
186
                netTableView.setModel(tableProxyModel);
187
                netTableView.setSelectionMode(SelectionMode.SingleSelection);
188
                netListView.selectionModel().selectionChanged.connect(this,
189
                                "netSelectionChanged(QItemSelection,QItemSelection)");
190
                netTableView.clicked.connect(this, "netDetailClicked(QModelIndex)");
191
        }
192
 
193
        protected void about() {
194
                QMessageBox.information(this, "Info", "It's your turn now :-)");
195
        }
196
 
197
        protected void openStatusWidget(QModelIndex index) {
198
                QWidget statusWidget = new QWidget();
199
                QLayout layout = new QBoxLayout(Direction.LeftToRight);
200
                layout.addWidget(new QLabel(tr(listProxyModel.data(index).toString()), statusWidget));
201
                statusWidget.setLayout(layout);
202
                statusWidget.setWindowTitle(tr("Net Status"));
203
                statusWidget.show();
204
        }
205
 
206
        protected void filterTableView(QModelIndex index) {
207
                //tableProxyModel.setFilterFixedString(listProxyModel.data(index).toString());
208
        }
209
 
210
        protected void netSelectionChanged(QItemSelection deselected, QItemSelection selected) {
211
                String regexStr = "^(";
212
                for (QModelIndex index : netListView.selectionModel().selection().indexes()) {
213
                        regexStr += listProxyModel.data(index).toString() + "|";
214
                }
215
                regexStr = regexStr.substring(0, regexStr.length()-1);
216
                regexStr += ")$";
217
                tableProxyModel.setFilterRegExp(regexStr);
218
                tableProxyModel.sort(0);
219
        }
220
 
221
        protected void netDetailClicked(QModelIndex index) {
222
                currentEntry = netListModel.getEntry(tableProxyModel.mapToSource(index));
223
                netLabel.setText(currentEntry.getFullName());
224
                netValue.setText("<Invalid>");
225
        }
226
 
227
        protected void getNetValue() {
228
                try {
229
                        if (currentEntry != null) {
230
                                 netValue.setText(String.valueOf(icapReadback.readState(currentEntry)));
231
                        }
232
                } catch (FCPException e) {
233
                        QMessageBox.critical(this, "FCP Error", "Error during FCP communication, connection closed");
234
                        this.fcpProtocol.disconnect();
235
                        this.close();
236
                }
237
        }
238
}

powered by: WebSVN 2.1.0

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