/
VisualConsole.java
81 lines (68 loc) · 2.21 KB
/
VisualConsole.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.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class VisualConsole{
private JFrame mainFrame;
private JTextArea textOutput;
private JScrollPane outputPane;
private JTextField input;
private Container pane;
private VisualBackend handler;
void VisualConsole(){
prepareConsoleWindow();
}
//Prepare management console
private void prepareConsoleWindow(){
mainFrame = new JFrame("Proxy Server Console");
mainFrame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent windowEvent){
int confirmed = JOptionPane.showConfirmDialog(null, "Are you sure you want to close the proxy server?", "Exit Proxy Server", JOptionPane.YES_NO_OPTION);
if(confirmed == JOptionPane.YES_OPTION){
mainFrame.dispose();
}
System.exit(0);
}
});
//Create a backend Handler
handler = new VisualBackend();
//Begin graphing the UI
pane = mainFrame.getContentPane();
pane.setLayout(new GridBagLayout());
pane.setSize(400, 400);
GridBagConstraints constraints = new GridBagConstraints();
textOutput = new JTextArea("");
outputPane = new JScrollPane(textOutput);
input = new JTextField("");
//Add event handler to allow commands to be input
input.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
handleInput(input.getText());
}
});
//Specify parameters to place UI widgets
constraints.fill = GridBagConstraints.BOTH;
constraints.gridx = 0;
constraints.ipadx = 400;
constraints.ipady = 350;
constraints.weightx = 1;
constraints.gridy = 0;
pane.add(outputPane, constraints);
constraints.gridy = 1;
constraints.ipady = 20;
pane.add(input, constraints);
pane.setSize(400, 400);
mainFrame.pack();
mainFrame.setVisible(true);
}
//Handle input from the user in the management console
private void handleInput(String command){
String response = handler.parseInput(command);
textOutput.append(response);
input.setText("");
}
public static void main(String [] args){
VisualConsole temp = new VisualConsole();
temp.prepareConsoleWindow();
}
}