-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOthersPanel.java
More file actions
102 lines (83 loc) · 2.46 KB
/
OthersPanel.java
File metadata and controls
102 lines (83 loc) · 2.46 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
// OthersPanel.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class OthersPanel extends JPanel
{
MainFrame parent;
JTextArea mainFrameTextArea;
int mainFrameNumRows;
public OthersPanel(MainFrame frame)
{
parent = frame;
mainFrameTextArea = frame.textArea;
mainFrameNumRows = frame.num_rows;
Dimension size = getPreferredSize();
size.width = 1000;
//size.height = 1000;
setPreferredSize(size);
setLayout(new GridBagLayout());
GridBagConstraints gc = new GridBagConstraints();
setBorder(BorderFactory.createLineBorder(Color.WHITE, 1));
JButton deleteLastCommandButton = new JButton("Delete last command");
initializeButton(deleteLastCommandButton, "Click to delete the last command.");
deleteLastCommandButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String text = parent.get_text_of_text_area();
int last_newspace = text.lastIndexOf('\n', text.length() - 2);
if (last_newspace > -1) // If it's not out of bounds (Two or more lines, etc.)
{
text = text.substring(0, last_newspace);
text = text + "\n";
mainFrameTextArea.setText(text);
}
else // If it's out of bounds
{
mainFrameTextArea.setText("");
}
mainFrameNumRows--;
parent.set_num_rows(mainFrameNumRows);
}
});
JButton clearAllButton = new JButton("Clear all");
initializeButton(clearAllButton, "Click to delete all the commands in the text area.");
clearAllButton.setBackground(new Color(40, 101, 243)); // Because I want it blue, instead of red
clearAllButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
mainFrameTextArea.setText("");
mainFrameNumRows = 0;
parent.set_num_rows(mainFrameNumRows);
}
});
gc.weightx = 0.5;
gc.weighty = 0.5;
gc.ipadx = 50;
gc.ipady = 50;
gc.insets = new Insets(5, 5, 5, 5); // top, left, bottom, right
gc.fill = GridBagConstraints.BOTH;
gc.gridx = 0;
gc.gridy = 0;
add(deleteLastCommandButton, gc);
gc.fill = GridBagConstraints.BOTH;
gc.gridx = 0;
gc.gridy = 1;
add(clearAllButton, gc);
}
void initializeButton(JButton button, String text)
{
button.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
button.setBackground(new Color(40, 101, 243));
button.setForeground(Color.WHITE);
button.setToolTipText(text);
}
void setNumRows(int nr)
{
if (nr >= 0)
{
this.mainFrameNumRows = nr;
}
}
}