-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrontEnd.java
135 lines (117 loc) · 4.69 KB
/
FrontEnd.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
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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class front
{
private JTextArea tarea;
private JComboBox cbox;
private JTextField lineField;
private String[] colourNames = {"RED", "ORANGE", "CYAN"};
private Highlighter.HighlightPainter painter;
private void createAndDisplayGUI()
{
final JFrame frame = new JFrame("STACY - A Static Analysis Tool");
frame.setBounds(15, 15, 50, 35);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEmptyBorder(15, 15, 15, 15), "Enter code here"));
tarea = new JTextArea(30,55);
JScrollPane scrollPane = new JScrollPane(tarea);
contentPane.add(scrollPane);
JButton button = new JButton("Analyze");
button.setBounds(113, 505, 84, 29);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
int selection = JOptionPane.showConfirmDialog(
frame, getOptionPanel(), "Highlighting Options : ", JOptionPane.OK_CANCEL_OPTION
, JOptionPane.PLAIN_MESSAGE);
if (selection == JOptionPane.OK_OPTION)
{
System.out.println("OK Selected");
int lineNumber = Integer.parseInt(lineField.getText().trim());
try
{
int startIndex = tarea.getLineStartOffset(lineNumber);
int endIndex = tarea.getLineEndOffset(lineNumber);
String colour = (String) cbox.getSelectedItem();
if (colour == colourNames[0])
{
System.out.println("RED Colour");
painter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
tarea.getHighlighter().addHighlight(startIndex, endIndex, painter);
}
else if (colour == colourNames[1])
{
System.out.println("ORANGE Colour");
painter = new DefaultHighlighter.DefaultHighlightPainter(Color.ORANGE);
tarea.getHighlighter().addHighlight(startIndex, endIndex, painter);
}
else if (colour == colourNames[2])
{
System.out.println("CYAN Colour");
painter = new DefaultHighlighter.DefaultHighlightPainter(Color.CYAN);
tarea.getHighlighter().addHighlight(startIndex, endIndex, painter);
}
}
catch(BadLocationException ble)
{
ble.printStackTrace();
}
}
else if (selection == JOptionPane.CANCEL_OPTION)
{
System.out.println("CANCEL Selected");
}
else if (selection == JOptionPane.CLOSED_OPTION)
{
System.out.println("JOptionPane closed deliberately.");
}
}
});
frame.getContentPane().add(button);
JButton btnDone = new JButton("Done");
btnDone.setBounds(436, 505, 77, 29);
btnDone.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
});
frame.getContentPane().add(btnDone);
frame.add(contentPane, BorderLayout.CENTER);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
private JPanel getOptionPanel()
{
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(0, 2, 5, 5));
JLabel lineNumberLabel = new JLabel("Enter Line Number : ");
lineField = new JTextField(10);
JLabel colourLabel = new JLabel("Select One Colour : ");
cbox = new JComboBox(colourNames);
panel.add(lineNumberLabel);
panel.add(lineField);
panel.add(colourLabel);
panel.add(cbox);
return panel;
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new AgainTrial().createAndDisplayGUI();
}
});
}
}