-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageTableStatePanel.java
More file actions
114 lines (94 loc) · 3.36 KB
/
PageTableStatePanel.java
File metadata and controls
114 lines (94 loc) · 3.36 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
import java.util.Hashtable;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.SwingConstants;
import javax.swing.BoxLayout;
/*************************************************
* The panel for the page table of a process.
* Displays the current state of the page table.
* @author Gloire Rubambiza
* @since 11/22/2017
**************************************************/
public class PageTableStatePanel extends JPanel {
/** Objects of the class are now serializable. */
private static final long serialVersionUID = 1L;
/** The font for the labels. */
private static final Font NORMAL_FONT =
new Font("Cooper Black", Font.PLAIN, 18);
/** The font for the header. */
private static final Font HEADER_FONT =
new Font("Cooper Black", Font.BOLD, 20);
/** The GV blue color. */
private static final java.awt.Color LAKER_BLUE =
new java.awt.Color(0, 101, 164);
/** The panel for the current page table state. */
private JPanel pageTableStatePanel;
/** The array of page/frame pairs. */
private JLabel [] pairs;
/** The label for the page table. **/
private static JLabel pidLabel;
/** The max size of a page table. **/
private final static int max = 64;
/***************************************
* Instantiates the page table state panel.
****************************************/
public PageTableStatePanel () {
super();
// Create the main components
int i;
pageTableStatePanel = new JPanel();
pidLabel = new JLabel("<html>Process Table: P<br>", SwingConstants.CENTER);
pairs = new JLabel[max];
// Add and customize the components
add(pidLabel);
pidLabel.setFont(HEADER_FONT);
pidLabel.setBackground(LAKER_BLUE);
for ( i = 0 ; i < max ; i++ ) {
pairs[i] = new JLabel("", SwingConstants.CENTER);
setStandards(pairs[i]);
add(pairs[i]);
}
// Define the layout i.e. everything will be dropped into a box.
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setVisible(true);
}
/****************************************************
* Builds a page table based on the size of the table.
* @param table is the page table for the process.
* @param pid is the PID of the process.
****************************************************/
public void redrawTable ( Hashtable<Integer,Integer> table, int pid ) {
// Relabel the page table
pidLabel.setText("Process Table: P" + pid );
// Reset the text
resetText();
// Build the table based on size
int counter = 0;
for ( Integer key : table.keySet() ) {
String onePair = "Page " + key + " -----> " + "Frame " + table.get(key);
pairs[counter].setText(onePair);
counter++;
}
}
/****************************************************
* Resets the text in all the labels of the table.
* This ensures any changes made by a page table that
* was bigger than the current one are not kept on the
* panel.
****************************************************/
private void resetText () {
int i;
for ( i = 0; i < max; i++ ) {
pairs[i].setText("");
}
}
/********************************************
* Sets some aesthetics for the panel.
* @param field is the label to be customized
********************************************/
private void setStandards ( JLabel field) {
field.setFont(NORMAL_FONT);
}
}