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/] [PRToolGUI.java] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
package edu.byu.cc.plieber.fpgaenet.examples;
2
import java.io.IOException;
3
import java.net.InetAddress;
4
 
5
import com.trolltech.qt.core.Qt.ItemDataRole;
6
import com.trolltech.qt.gui.*;
7
 
8
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
9
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
10
import edu.byu.cc.plieber.fpgaenet.icapif.IcapInterface;
11
 
12
public class PRToolGUI extends QMainWindow {
13
 
14
        private QMenu fileMenu;
15
        private QMenu helpMenu;
16
 
17
        private QAction addPbitAct;
18
        private QAction exitAct;
19
        private QAction aboutAct;
20
        private QAction aboutQtJambiAct;
21
 
22
        private QListWidget prList;
23
        private QPushButton buttonProgram;
24
 
25
        FCPProtocol fcpProtocol;
26
        IcapInterface icapif;
27
 
28
        public static void main(String[] args) {
29
                QApplication.initialize(args);
30
 
31
                PRToolGUI testPRToolGUI = new PRToolGUI(null);
32
                testPRToolGUI.show();
33
 
34
                QApplication.exec();
35
 
36
                testPRToolGUI.tearDown();
37
        }
38
 
39
        private void tearDown() {
40
                fcpProtocol.disconnect();
41
        }
42
 
43
        public PRToolGUI(QWidget parent) {
44
                super(parent);
45
                setupConnections();
46
                createActions();
47
                createMenus();
48
                createWidgets();
49
                connectSignals();
50
        }
51
 
52
        private void setupConnections() {
53
                try {
54
                        fcpProtocol = new FCPProtocol();
55
                        fcpProtocol.connect(InetAddress.getByName("192.168.1.222"), 0x3001);
56
                } catch (IOException e) {
57
                        return;
58
                }
59
                icapif = new IcapInterface(fcpProtocol);
60
        }
61
 
62
        private void createActions() {
63
                addPbitAct = new QAction(tr("&Add PR"), this);
64
                addPbitAct.setShortcut(tr("Ctrl+A"));
65
                addPbitAct.setStatusTip(tr("Add Partial Bitstream"));
66
                addPbitAct.triggered.connect(this, "addPR()");
67
 
68
                exitAct = new QAction(tr("E&xit"), this);
69
                exitAct.setShortcut(tr("Ctrl+Q"));
70
                exitAct.setStatusTip(tr("Exit the application"));
71
                exitAct.triggered.connect(this, "close()");
72
 
73
                aboutAct = new QAction(tr("&About"), this);
74
                aboutAct.setStatusTip(tr("Show the application's About box"));
75
                aboutAct.triggered.connect(this, "about()");
76
 
77
                aboutQtJambiAct = new QAction(tr("About &Qt Jambi"), this);
78
                aboutQtJambiAct.setStatusTip(tr("Show the Qt Jambi's About box"));
79
                aboutQtJambiAct.triggered.connect(QApplication.instance(), "aboutQtJambi()");
80
        }
81
 
82
        private void createMenus() {
83
                fileMenu = menuBar().addMenu(tr("&File"));
84
                fileMenu.addAction(addPbitAct);
85
                fileMenu.addAction(exitAct);
86
 
87
                helpMenu = menuBar().addMenu(tr("&Help"));
88
                helpMenu.addAction(aboutAct);
89
                helpMenu.addAction(aboutQtJambiAct);
90
        }
91
 
92
        private void createWidgets() {
93
                QFrame mainFrame = new QFrame(this);
94
                setCentralWidget(mainFrame);
95
                prList = new QListWidget(mainFrame);
96
                QVBoxLayout mainLayout = new QVBoxLayout(mainFrame);
97
                mainLayout.addWidget(prList);
98
                buttonProgram = new QPushButton(tr("Program"), mainFrame);
99
                mainLayout.addWidget(buttonProgram);
100
                mainFrame.setLayout(mainLayout);
101
        }
102
 
103
        private void connectSignals() {
104
                buttonProgram.clicked.connect(this, "programSelected(boolean)");
105
                prList.itemDoubleClicked.connect(this, "programClicked(QListWidgetItem)");
106
        }
107
 
108
        protected void about() {
109
                QMessageBox.information(this, "Info", "It's your turn now :-)");
110
        }
111
 
112
        protected void addPR() {
113
                String fName = QFileDialog.getOpenFileName(this, tr("Open Partial Bit File"), "", new QFileDialog.Filter(
114
                                tr("Bit Files (*.bit)")));
115
                if (fName == null) return;
116
                String name = QInputDialog.getText(this, "PR Tool GUI", "PR Bitstream Name", QLineEdit.EchoMode.Normal, fName);
117
                if (name == null) return;
118
                QListWidgetItem item = new QListWidgetItem(name, prList);
119
                item.setData(ItemDataRole.UserRole, fName);
120
        }
121
 
122
        protected void programSelected(boolean checked) {
123
                QListWidgetItem item = prList.selectedItems().get(0);
124
                programClicked(item);
125
        }
126
 
127
        protected void programClicked(QListWidgetItem item) {
128
                String fName = (String)item.data(ItemDataRole.UserRole);
129
                try {
130
                        icapif.sendIcapFile(fName);
131
                } catch (FCPException e) {
132
                        statusBar().showMessage(tr("Programming Failed!"));
133
                }
134
                statusBar().showMessage(tr("Programmed: " + fName));
135
        }
136
}

powered by: WebSVN 2.1.0

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