-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNinjaConsole.java
81 lines (70 loc) · 2.37 KB
/
NinjaConsole.java
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
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.JFrame;
public class NinjaConsole extends JPanel implements ScrollPaneConstants
{
private NinjaTextPane m_textPane;
private NinjaCommandLine m_commandLine;
private JScrollPane m_scrollPane;
public NinjaConsole()
{
m_textPane = new NinjaTextPane();
m_commandLine = new NinjaCommandLine(this);
m_scrollPane = new JScrollPane(m_textPane);
m_scrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
m_scrollPane.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_AS_NEEDED);
setLayout(new BorderLayout());
add(m_scrollPane, BorderLayout.CENTER);
add(m_commandLine, BorderLayout.SOUTH);
}
public void setWordWrap(boolean wrap)
{
int policy = wrap ? HORIZONTAL_SCROLLBAR_NEVER : HORIZONTAL_SCROLLBAR_AS_NEEDED;
m_scrollPane.setHorizontalScrollBarPolicy(policy);
}
public void log(int style, String message)
{
m_textPane.log(style, message);
}
public NinjaTextPane getTextPane()
{
return m_textPane;
}
public NinjaCommandLine getCommandLine()
{
return m_commandLine;
}
public void startProcess(String workingDir, String command)
{
try
{
Runtime r = Runtime.getRuntime();
setProcess(r.exec(command, null, new java.io.File(workingDir)));
}
catch (java.io.IOException e)
{
log(LogConstants.Style_Error, e.toString());
}
}
private void setProcess(Process p)
{
m_textPane.setProcess(p);
m_commandLine.setProcess(p);
}
public static void main(String [] args)
{
JFrame window = new JFrame();
NinjaConsole console = new NinjaConsole();
window.setContentPane(console);
window.setSize(640, 480);
window.setLocation(640, 480);
window.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
window.setTitle("NinjaConsole");
window.setVisible(true);
String workingDir = "/Users/abubics/Development/git_sandbox_mvpss/devices_ember/em35x-ezsp/build/smartmeter";
String command = "./smartmeter -p /dev/cu.SLABtoUART -o 0";
console.startProcess(workingDir, command);
}
}