-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandsPanel.java
More file actions
136 lines (109 loc) · 3.77 KB
/
CommandsPanel.java
File metadata and controls
136 lines (109 loc) · 3.77 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
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.SwingConstants;
import java.awt.Font;
import java.awt.Color;
import java.awt.GridLayout;
/*************************************************
* The panel for the user commands.
* Communicates with the GUI to set ActionListeners
* in the controller.
* Displays the LRU victim and memory reference.
* @author Gloire Rubambiza
* @since 11/22/2017
**************************************************/
public class CommandsPanel extends JPanel {
/** Objects of the class are now serializable. */
private static final long serialVersionUID = 1L;
/** The font for user commands the GUI. */
private static final Font NORMAL_FONT =
new Font("Cooper Black", Font.BOLD, 20);
/** The font for user commands the GUI. */
private static final Font VICTIM_FONT =
new Font("Cooper Black", Font.BOLD, 15);
/** The panel for the commands. */
private JPanel command;
/** The buttons for handling user actions. */
private JButton next, runf, runc, exit;
/** The label for the memory reference. */
private JLabel ref;
/** The label for the LRU victim. */
private JLabel victim;
/** The dimensions for the grid. */
private final int col = 1, row = 6;
/*******************************************************
* Instantiates the buttons to be used for user actions.
*******************************************************/
public CommandsPanel () {
super();
command = new JPanel();
victim = new JLabel("Latest LRU Victim:");
ref = new JLabel("Mem References");
next = new JButton("Next Input");
runf = new JButton("Run to Next Fault");
runc = new JButton("Run to Completion");
exit = new JButton("Exit");
setStandards();
// Define the layout to be a grid.
setLayout(new GridLayout(row,col));
// Add the components.
add(victim);
add(ref);
add(next);
add(runf);
add(runc);
add(exit);
setVisible(true);
}
/*******************************************
* Sends the action buttons to the GUI to be
* passed to the controller.
* @return an array of the action buttons.
********************************************/
public JButton [] sendButtons () {
JButton [] actionButtons = new JButton[4];
actionButtons[0] = next;
actionButtons[1] = runf;
actionButtons[2] = runc;
actionButtons[3] = exit;
return actionButtons;
}
/**************************************
* Sets some aesthetics for the panel.
***************************************/
private void setStandards () {
Border line = BorderFactory.createLineBorder(Color.WHITE, 2, true);
victim.setFont(VICTIM_FONT);
victim.setBorder(line);
ref.setFont(NORMAL_FONT);
next.setFont(NORMAL_FONT);
next.setForeground(Color.GREEN);
runf.setFont(NORMAL_FONT);
runc.setFont(NORMAL_FONT);
exit.setFont(NORMAL_FONT);
exit.setForeground(Color.RED);
}
/*******************************************
* Updates the latest LRU victim.
* @param vic is info about the victim that was picked.
********************************************/
public void setVictim( int [] vic ) {
int frame = vic[0];
int pid = vic[1];
int page = vic[2];
victim.setText("LRU Victim:" + " P" + pid + " Page " + page );
victim.setForeground(Color.RED);
}
/**************************************************
* Resets the label for the memory reference
* based on the input.
* @param pid is the process that made a reference.
* @param page is the page that was referenced.
**************************************************/
public void setReference ( int pid, int page ) {
ref.setText("P" + pid + " referenced page " + page);
}
}