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

Go to most recent revision | 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.util.ArrayList;
6
 
7
import com.trolltech.qt.gui.*;
8
 
9
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
10
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
11
import edu.byu.cc.plieber.fpgaenet.icapif.IcapInterface;
12
 
13
public class ModularModules extends QMainWindow {
14
 
15
        private QMenu fileMenu;
16
        private QMenu helpMenu;
17
 
18
        private QAction addModule;
19
        private QAction connectAct;
20
        private QAction exitAct;
21
        private QAction aboutAct;
22
        private QAction aboutQtJambiAct;
23
 
24
        public static void main(String[] args) {
25
                QApplication.initialize(args);
26
 
27
                ModularModules testModularModules = new ModularModules(null);
28
                testModularModules.show();
29
 
30
                QApplication.exec();
31
 
32
                testModularModules.tearDown();
33
        }
34
 
35
        private FCPProtocol fcpProtocol;
36
        private IcapInterface icapInterface;
37
 
38
        private QFrame mainFrame;
39
 
40
        private MD5Widget md5Widget;
41
        private SHA1Widget sha1Widget;
42
 
43
        private QVBoxLayout mainLayout;
44
        private QHBoxLayout bottomLayout;
45
        private QStackedWidget moduleStack;
46
 
47
        private ConnectionWidget connectWidget;
48
        private StaticModulesWidget staticWidget;
49
        private AvailableModulesWidget availWidget;
50
        private ChannelConfigurationWidget configWidget;
51
 
52
        public ModularModules(QWidget parent) {
53
                super(parent);
54
                this.setWindowTitle("Module Modules");
55
                try {
56
                        fcpProtocol = new FCPProtocol();
57
                        icapInterface = new IcapInterface(fcpProtocol, 3, 4);
58
                } catch (IOException e) {
59
                        // TODO Auto-generated catch block
60
                        e.printStackTrace();
61
                        QMessageBox.critical(this, "Bind Error", "Could not bind socket.");
62
                }
63 7 peteralieb
 
64
                createActions();
65
                createMenus();
66
                // makeConnections();
67
                createWidgets();
68
                createLayout();
69
                connectSignalsAndSlots();
70
 
71 2 peteralieb
                connectionChanged();
72
        }
73
 
74
        @SuppressWarnings("unused")
75
        private void connect() {
76
                ConnectionWidget cw = new ConnectionWidget(null, fcpProtocol);
77
                cw.ConnectionChangedSignal.connect(this, "connectionChanged()");
78
                cw.show();
79
        }
80
 
81
        private void connectionChanged() {
82
                statusBar().showMessage(
83
                                tr("FCP is "
84
                                                + (this.fcpProtocol.isConnected() ? "" : "not ")
85
                                                + "connected"
86
                                                + (this.fcpProtocol.isConnected() ? (" to " + fcpProtocol.getDestIPAddress().getHostAddress()
87
                                                                + " on port " + fcpProtocol.getDestUDPPort() + ".") : ".")));
88
        }
89
 
90
        @SuppressWarnings("unused")
91
        private void addModule() {
92
                CreateModuleWidget cmw = new CreateModuleWidget(null, fcpProtocol);
93
                cmw.AvailableModuleCreated.connect(this, "AvailableModuleCreatedHandler(AvailableModule)");
94
                cmw.show();
95
        }
96
 
97
        @SuppressWarnings("unused")
98
        private void AvailableModuleCreatedHandler(AvailableModule am) {
99
                availWidget.addModule(am);
100
                if (!moduleStack.children().contains(am.getControlWidget())) {
101
                        moduleStack.addWidget(am.getControlWidget());
102
                }
103
        }
104
 
105
        private void createActions() {
106
                addModule = new QAction(tr("&Add Module"), this);
107
                addModule.setShortcut(tr("Ctrl+A"));
108
                addModule.setStatusTip(tr("Add Available Module"));
109
                addModule.triggered.connect(this, "addModule()");
110
 
111
                connectAct = new QAction(tr("&Connect"), this);
112
                connectAct.setShortcut(tr("Ctrl+N"));
113
                connectAct.setStatusTip(tr("Connect to FPGA"));
114
                connectAct.triggered.connect(this, "connect()");
115
 
116
                exitAct = new QAction(tr("E&xit"), this);
117
                exitAct.setShortcut(tr("Ctrl+Q"));
118
                exitAct.setStatusTip(tr("Exit the application"));
119
                exitAct.triggered.connect(this, "close()");
120
 
121
                aboutAct = new QAction(tr("&About"), this);
122
                aboutAct.setStatusTip(tr("Show the application's About box"));
123
                aboutAct.triggered.connect(this, "about()");
124
 
125
                aboutQtJambiAct = new QAction(tr("About &Qt Jambi"), this);
126
                aboutQtJambiAct.setStatusTip(tr("Show the Qt Jambi's About box"));
127
                aboutQtJambiAct.triggered.connect(QApplication.instance(), "aboutQtJambi()");
128
        }
129
 
130
        private void createMenus() {
131
                fileMenu = menuBar().addMenu(tr("&File"));
132
                fileMenu.addAction(addModule);
133
                fileMenu.addAction(connectAct);
134
                fileMenu.addAction(exitAct);
135
 
136
                helpMenu = menuBar().addMenu(tr("&Help"));
137
                helpMenu.addAction(aboutAct);
138
                helpMenu.addAction(aboutQtJambiAct);
139
        }
140
 
141
        private void createWidgets() {
142
                moduleStack = new QStackedWidget(this);
143 7 peteralieb
                staticWidget = new StaticModulesWidget(this, fcpProtocol);
144 2 peteralieb
                availWidget = new AvailableModulesWidget(this);
145
                configWidget = new ChannelConfigurationWidget(this);
146
                md5Widget = new MD5Widget(moduleStack, fcpProtocol);
147
                sha1Widget = new SHA1Widget(moduleStack, fcpProtocol);
148
        }
149
 
150
        private void createLayout() {
151
                mainFrame = new QFrame(this);
152
                this.setCentralWidget(mainFrame);
153
                mainLayout = new QVBoxLayout(mainFrame);
154
                bottomLayout = new QHBoxLayout();
155
                mainLayout.addWidget(configWidget);
156
                mainLayout.addLayout(bottomLayout);
157
                mainLayout.addStretch();
158
                moduleStack.addWidget(new QFrame(moduleStack));
159
                moduleStack.addWidget(md5Widget);
160
                moduleStack.addWidget(sha1Widget);
161
                bottomLayout.addWidget(availWidget);
162
                bottomLayout.addWidget(staticWidget);
163
                bottomLayout.addWidget(moduleStack);
164
                bottomLayout.setStretch(0, 0);
165
                bottomLayout.setStretch(1, 1);
166
                bottomLayout.setStretch(2, 6);
167
        }
168
 
169
        private void connectSignalsAndSlots() {
170
                configWidget.ChannelConfiguredSignal.connect(this, "channelConfiguredHandler(ConfigurationChannel)");
171
                configWidget.ModuleRemovedSignal.connect(this, "moduleRemovedHandler(AvailableModule)");
172
                configWidget.ModuleSelectedSignal.connect(this, "moduleSelectedHandler(AvailableModule)");
173
        }
174
 
175
        protected void about() {
176
                QMessageBox.information(this, "Info",
177
                                "Modular Modules Demo\nv 0.0.1\ncopyright 2010 Peter Lieber\nBrigham Young University");
178
        }
179
 
180
        public void tearDown() {
181
                if (fcpProtocol != null)
182
                        fcpProtocol.disconnect();
183
        }
184
 
185
        @SuppressWarnings("unused")
186
        private void channelConfiguredHandler(ConfigurationChannel cc) {
187
                AvailableModule am = cc.getResident();
188
                try {
189
                        icapInterface.sendIcapFile(am.getBitStreams().get(cc.getChannel()));
190
                        am.getControlWidget().setChannelNumber(cc.getChannel());
191
                } catch (Exception e) {
192
                        cc.removeModule(am);
193
                        QMessageBox.critical(this, "Error", "Error configuring channel!\n" + e.getMessage());
194
                }
195
                // QMessageBox.information(this, "Configuration", "Channel " +
196
                // cc.getChannel() + " configured.");
197
        }
198
 
199
        @SuppressWarnings("unused")
200
        private void moduleRemovedHandler(AvailableModule am) {
201
                availWidget.addModule(new AvailableModule(am));
202
        }
203
 
204
        @SuppressWarnings("unused")
205
        private void moduleSelectedHandler(AvailableModule am) {
206
                if (am != null)
207
                        moduleStack.setCurrentWidget(am.getControlWidget());
208
        }
209
}

powered by: WebSVN 2.1.0

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