-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHistory.java
55 lines (48 loc) · 1.23 KB
/
History.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
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
/**
* Shows the history of the current running session.
*
* @version 0.8
*/
public class History extends JPanel {
private JTextArea area;
private JScrollPane scroller;
private int nlines;
History() {
super(new GridBagLayout());
area = new JTextArea();
area.setFont(new Font("Sans", Font.PLAIN, 14));
area.setEditable(false);
scroller = new JScrollPane(area);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
add(scroller, new GBC(0,0).weight(1,1).fill(GBC.BOTH));
resetHistory();
}
/** Prints the column headers */
private void showHeaders() {
updateHistory("Distance\tTime\tSpeed\tIncline\tCalories");
nlines = 0;
}
/**
* Adds to the remembered history data.
*
* @param line the data to add
*/
public void updateHistory(String line) {
area.append("\n" + line);
if (++nlines == 15) {
showHeaders();
}
area.setCaretPosition(area.getDocument().getLength());
}
/**
* Resets the remembered history data.
*/
public void resetHistory() {
area.setText("User History for Current Session\n");
showHeaders();
}
}