-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineChartController.java
More file actions
executable file
·89 lines (81 loc) · 3.21 KB
/
LineChartController.java
File metadata and controls
executable file
·89 lines (81 loc) · 3.21 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
package View;
import Parsing.ShareData_compare;
import Parsing.SharedData;
import com.jfoenix.controls.JFXButton;
import javafx.embed.swing.SwingFXUtils;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.SnapshotParameters;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.XYChart;
import javafx.scene.image.WritableImage;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.ResourceBundle;
/**
* Created by Ray_Jung on 2017-04-07.
*/
public class LineChartController implements Initializable {
private Stage dialogStage;
@FXML
private JFXButton closeButton;
@FXML
private LineChart lineChart;
private LinkedHashMap<String, Integer> overlapMap1;
private LinkedHashMap<String, Integer> overlapMap2;
@FXML
private void doExit (){
// get a handle to the stage
Stage stage = (Stage) closeButton.getScene().getWindow();
// do what you have to do
stage.close();
}
@FXML
public void saveAsPng() throws IOException {
WritableImage image = lineChart.snapshot(new SnapshotParameters(), null);
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Image");
// Set extension filter
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(
"PNG files (*.png)", "*.png");
fileChooser.getExtensionFilters().add(extFilter);
// Show save file dialog
File file = fileChooser.showSaveDialog(this.dialogStage);
if (file != null) {
// Make sure it has the correct extension
if (!file.getPath().endsWith(".png")) {
file = new File(file.getPath() + ".png");
}
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
overlapMap1= (LinkedHashMap<String, Integer>) SharedData.getInstance().getInfo().get(2);
XYChart.Series<String, Number> set1 = new XYChart.Series<String, Number>();
for (HashMap.Entry<String, Integer> entry : overlapMap1.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
set1.getData().add(new XYChart.Data<String,Number>(key,value));
}
set1.setName("First File");
overlapMap2= (LinkedHashMap<String, Integer>) ShareData_compare.getInstance().getInfo().get(2);
XYChart.Series<String, Number> set2 = new XYChart.Series<String, Number>();
for (HashMap.Entry<String, Integer> entry : overlapMap2.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
set2.getData().add(new XYChart.Data<String,Number>(key,value));
}
set2.setName("Second File");
lineChart.getData().addAll(set1,set2);
}
public void setDialogStage(Stage dialogStage) {
this.dialogStage = dialogStage;
}
}