-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysicalStatePanel.java
More file actions
166 lines (141 loc) · 4.81 KB
/
PhysicalStatePanel.java
File metadata and controls
166 lines (141 loc) · 4.81 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import java.awt.Color;
import java.awt.Font;
import java.awt.BorderLayout;
/*************************************************
* The panel for the current physical memory state.
* Displays the current state of the frame table.
* @author Gloire Rubambiza
* @since 11/20/2017
**************************************************/
public class PhysicalStatePanel extends JPanel {
/** Objects of the class are now serializable. */
private static final long serialVersionUID = 1L;
/** A panel for the current physical state. */
private JPanel physicalStatePanel;
/** An array of PID/page pairs. */
private JLabel [] pairs;
/** The label for the frame table **/
private JLabel pageState;
/** The number of rows in the frame table. */
private int rowMax = 16;
/** The font for most text in the GUI. */
private static final Font NORMAL_FONT =
new Font("Cooper Black", Font.PLAIN, 14);
/** The font for most text in the GUI. */
private static final Font HEADER_FONT =
new Font("Cooper Black", Font.BOLD, 20);
/** Creates a border constant. */
private static final Border CREATE_EMPTY_BORDER =
BorderFactory.createEmptyBorder(3, 3, 3, 3);
/** The GV blue color. */
private static final java.awt.Color LAKER_BLUE =
new java.awt.Color(0, 101, 164);
/** LIGHT_GOLD color. */
private static final java.awt.Color LIGHT_GOLD =
new java.awt.Color(255, 153, 51);
/** LIGHT_GOLD color. */
private static final java.awt.Color CAMO_GREEN =
new java.awt.Color(153, 153, 0);
/***************************************
* Instantiates the physical state panel.
****************************************/
public PhysicalStatePanel () {
super();
// Create the objects.
physicalStatePanel = new JPanel();
String title = "<html>Physical Memory State<br>";
pageState = new JLabel(title, SwingConstants.CENTER);
// Set the layout to drop everything into a box.
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
// Customize the header.
add(pageState);
pageState.setBackground(LAKER_BLUE);
pageState.setFont(HEADER_FONT);
pairs = new JLabel[rowMax];
int i;
for ( i = 0; i < rowMax; i++ ) {
pairs[i] = new JLabel("", SwingConstants.CENTER);
setStandards(pairs[i]);
add(pairs[i]);
}
setVisible(true);
}
/***********************************************
* Repaints the frame table as new changes occur.
* @param table is the frame table.
* @param fault is the kind of fault.
* @param frame is frame that potentiall needs to be
* colored for the user.
************************************************/
public void redrawTable ( Frame[] table, boolean fault, int frame ) {
// Repaint the frame table
resetFont(pairs);
int i;
for ( i = 0; i < rowMax; i++ ) {
int pid = table[i].getPID();
int page = table[i].getPage();
String display = "Frame " + i + " P" + pid + " Page " + page;
pairs[i].setText(display);
//Set the color based on the process number.
pairs[i].setForeground( customizeFont(pid) );
}
if ( fault ) { // A hard fault occured
pairs[frame].setForeground(Color.RED);
}
}
/********************************************
* Sets some aesthetics for the panel.
* @param field is the label to be customized
********************************************/
private void setStandards ( JLabel field) {
field.setFont(NORMAL_FONT);
field.setBorder(CREATE_EMPTY_BORDER);
}
/*******************************************
* Resets the font all the frames.
* @param fArray is the array of frame labels.
********************************************/
private void resetFont ( JLabel [] fArray ) {
int i;
for ( i = 0; i < rowMax; i++ ) {
fArray[i].setForeground(Color.BLACK);
}
}
/**************************************
* Customizes the font of the label based
* on the process number.
* @param pid is the process id.
***************************************/
private Color customizeFont( int pid ) {
Color myColor = Color.BLACK;
switch ( pid ) {
case 1: myColor = LIGHT_GOLD;
break;
case 2: myColor = Color.BLUE;
break;
case 3: myColor = Color.CYAN;
break;
case 4: myColor = CAMO_GREEN;
break;
case 5: myColor = Color.GREEN;
break;
case 6: myColor = Color.MAGENTA;
break;
case 7: myColor = Color.ORANGE;
break;
case 8: myColor = Color.PINK;
break;
case 9: myColor = Color.YELLOW;
break;
default: myColor = Color.BLACK;
break;
}
return myColor;
}
}