-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.java
More file actions
249 lines (197 loc) · 8.31 KB
/
Copy pathgui.java
File metadata and controls
249 lines (197 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import javax.swing.border.Border;
import net.miginfocom.swing.MigLayout;
import org.jfree.chart.ChartPanel;
import java.util.concurrent.*;
import java.lang.Thread;
import java.util.*;
import java.util.concurrent.atomic.*;
import service.*;
import custom.filechooser.*;
import custom.listeners.*;
import custom.threads.*;
import main.*;
public class gui extends JFrame
{
//------------------------ GUI components ------------------------
static JMenuBar menubar = new JMenuBar();
static JMenu menu_m = new JMenu("Process");
static JMenu menu_f = new JMenu("Firmware");
static JMenu menu_h = new JMenu("Help");
static JMenuItem i_mRestart = new JMenuItem("Restart");
static JMenuItem i_fRestart = new JMenuItem("Restart");
static JPanel panel = new JPanel();
static JButton b_exit = new JButton("<html><center>EXIT</center></html>");
static JTextArea ta_shell = new JTextArea("select NIOS");
static JTextArea ta_main = new JTextArea();
static ChartPanel panel_ch = new ChartPanel(null);
static ChartPanel panel_h = new ChartPanel(null); //add H
static BlockingQueue<DataSet> que = new LinkedBlockingQueue<DataSet>();
// ------------------ Main constructor ----------------------------------
public gui()
{
redirectSystemStreams();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200,200,1100,800);
enableEvents(SimpleAWTEvent.EVENT_ID);
b_exit.setBackground(Color.orange);
//--------------------- UI layout ---------------------------------
menubar.add(menu_m);
menubar.add(menu_f);
menubar.add(menu_h);
menu_m.add(i_mRestart);
menu_f.add(i_fRestart);
panel.setLayout(new MigLayout());
panel_ch.setLayout(new MigLayout());
panel_ch.setBackground(Color.WHITE);
panel_ch.setBorder(BorderFactory.createEtchedBorder());
panel_h.setLayout(new MigLayout()); //add H
panel_h.setBackground(Color.WHITE); //add H
panel_h.setBorder(BorderFactory.createEtchedBorder());
//------------------------ processes start here --------------------------------
ChooserDataSet set_home = new ChooserDataSet(panel, ta_main,
"/pingu/gen2dom-fw/ddc2_sockit_nios2/qsys_nios2/software/ddc2_nios2_sw/",
"Chose Process Home Directory");
ChooseFile cdir = new ChooseFile(set_home);
cdir.DirChooser();
if (cdir.getOption() != JFileChooser.APPROVE_OPTION)
{
TAWriter.TAWrite_EDT(ta_main,"Home directory not choosen");
System.exit(0);
}
//create graph panel.it's created separatly since some of it elements
// need to be passed to the threads
GraphSavePanel panel_grsave = new GraphSavePanel(ta_main);
GraphSaveComp grsvcomp = new GraphSaveComp(panel_grsave.getSelectButton(),
panel_grsave.getSaveButton(),
panel_grsave.getTextArea());
ProcessBuilder processbuilder = new ProcessBuilder("/bin/bash");
processbuilder.redirectErrorStream(true);
processbuilder.directory(new File(cdir.getPath()));
cdir = null;//clean up
//main process
MyProcess myprocess = new MyProcess(processbuilder,ta_main);
Boolean flag = myprocess.setProcess();
if (!flag)//if process fails
{
TAWriter.TAWrite_EDT(ta_main,new String("Nios shell: intial process failed"));
}
else
{
myprocess.setOutput();
myprocess.setInput();
ThreadStart reader = new ThreadStart(myprocess,this,que); //start reader thread
ThreadStart hist_grapher = new ThreadStart(myprocess,panel_h,this,que);
ThreadStart grapher = new ThreadStart(myprocess,grsvcomp,panel_ch,this,que);
ThreadStart saver = new ThreadStart(myprocess,grsvcomp,this,que);
}
//firmware process
MyProcess myprocess_firm = new MyProcess(processbuilder,ta_main);
flag = myprocess_firm.setProcess();
if (!flag)
{
TAWriter.TAWrite_EDT(ta_main,new String("Firmware: initial process failed"));
}
else
{
myprocess_firm.setOutput();
myprocess_firm.setInput();
ThreadStart reader_firm = new ThreadStart(myprocess_firm,this);
}
//make a map of componenets to be disabled until file is chosen
Map<Integer, Component> mapDisableMain = new HashMap<Integer, Component> (22);
//create panels
MainTextPanel panel_main = new MainTextPanel(ta_main);
LoadNiosPanel panel_loadN = new LoadNiosPanel(ta_main, myprocess);
FirmwarePanel panel_firm = new FirmwarePanel(this, myprocess_firm, menu_f, ta_shell , ta_main);
ServicePanel panel_ser = new ServicePanel(this, myprocess, myprocess_firm,
menu_h, mapDisableMain);
// add components to the map for disabling
Component[] com = panel_firm.getComponents();
int comlen = com.length;
for (int a = 0; a < comlen; a++)
mapDisableMain.put(a,com[a]);
com = panel_loadN.getComponents();
for (int a = 0; a < com.length; a++)
mapDisableMain.put(com.length+a,com[a]);
comlen = comlen + com.length;
mapDisableMain.put(comlen,menu_f);
mapDisableMain.put(comlen+1,menu_m);
//the last panel, since we need to pass it a map what is already filled with elements
EnterNiosPanel panel_enterN= new EnterNiosPanel(this, myprocess, menu_m, ta_shell,
b_exit, mapDisableMain, ta_main);
//place panels onto the frame
panel.add(panel_main,"cell 0 2 3 1, width 700:2000:2000, height 100:2000:2000, grow");
panel.add(panel_loadN,"cell 2 0 1 2, width 350:800:800, height 190:190:190, growx");
panel.add(panel_enterN,"cell 0 0, width 350:800:800, height 115:115:115, growx");
panel.add(panel_firm,"cell 1 0, width 350:800:800, height 115:115:115, growx");
panel.add(panel_grsave,"cell 0 1 2 1, width 700:1500:2000, height 70:70:70, growx");
panel.add(panel_ch,"cell 0 3 2 1, width 500:1500:2000, height 100:2000:2000, grow"); //change H
panel.add(panel_h,"cell 2 3 1 1, width 200:800:2000, height 100:2000:2000, grow"); //add H
getContentPane().add(panel, BorderLayout.CENTER);
setJMenuBar(menubar);
setVisible(true);
//some actions what cannot be placed into one panel
b_exit.addActionListener(new MyActionListener_exit(myprocess, myprocess_firm, ta_main));
i_fRestart.addActionListener(new MyActionListener_restart_firm(processbuilder, myprocess_firm, ta_main, this));
i_mRestart.addActionListener(new MyActionListener_restart_nios(processbuilder, myprocess, grsvcomp,
panel_ch, panel_h, ta_main, this, que));
}
//---------------------------- METHODS ----------------------------
//------------------- Overvriting Window.processEvent ------------
//to make thread safe way to write into ta_main
protected void processEvent(AWTEvent event)
{
if ( event instanceof SimpleAWTEvent )
{
SimpleAWTEvent ev = (SimpleAWTEvent) event;
ta_main.append(ev.getStr()); // access GUI component
}
else // other events go to the system default process event handler
{
super.processEvent(event);
}
}
// ----------- Redirect console text to main text area (ta_main) -------
private static void updateTextArea(final String text) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ta_main.append(text);
}
});
}
private static void redirectSystemStreams() {
OutputStream out = new OutputStream() {
@Override
public void write(int b) throws IOException {
updateTextArea(String.valueOf((char) b));
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
updateTextArea(new String(b, off, len));
}
@Override
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
};
System.setOut(new PrintStream(out, true));
System.setErr(new PrintStream(out, true));
}
//------------------- Main method ------------------------------
public static void main(String[] args)
{
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
gui gui = new gui();
}
});
}
}