-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToolTipContent.java
80 lines (73 loc) · 2.27 KB
/
ToolTipContent.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
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
/**
* The class constructs the pane of tooltip of the symbols in line chart and area line chart.
*
* @Author: Junxiang Chen
* @RegistrationNumber: 180127586
* @Email: [email protected]
*/
/*
import dependencies
*/
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* ToolTipContent class
*/
class ToolTipContent extends GridPane {
/*
declare member variables
*/
private Label dateValueLabel = new Label();
private Label yValueLabel = new Label();
/**
* the constructor function
*
* @param yText String, the text in the left of value
*/
public ToolTipContent(String yText) {
/*
construct labels
*/
Label date = new Label("DATE:");
Label yLabel = new Label(yText);
/*
set layouts
*/
setConstraints(date, 0, 0);
setConstraints(dateValueLabel, 1, 0);
setConstraints(yLabel, 0, 1);
setConstraints(yValueLabel, 1, 1);
// set style of labels
String labelStyle =
"-fx-font-size: 0.75em;\n" +
"-fx-font-weight: bold;\n" +
"-fx-text-fill: #666666;\n" +
"-fx-padding: 2 5 2 0;";
date.setStyle(labelStyle);
yLabel.setStyle(labelStyle);
// add components to the pane
getChildren().addAll(date, dateValueLabel, yLabel, yValueLabel);
}
/*
define instant methods
*/
/**
* update values of the pane every time the user's mouse hovers a symbol
*
* @param date String, the date
* @param val Number, the relative value with regard to the pane
* @throws ParseException the exception of the error
*/
public void update(String date, Number val) throws ParseException {
DateFormat parseDateFormat = new SimpleDateFormat("MM/dd/yy");
Date dateValue = parseDateFormat.parse(date);
DateFormat toStringDateFormatter = new SimpleDateFormat("E, MMM dd yyyy");
String strDate = toStringDateFormatter.format(dateValue);
dateValueLabel.setText(strDate);
yValueLabel.setText(val.toString());
}
}