-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
55 lines (44 loc) · 1.7 KB
/
Copy pathMain.java
File metadata and controls
55 lines (44 loc) · 1.7 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
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.AccessDeniedException;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class Main {
public static int addPadding(int input) {
return (int) (input * 1.2);
}
public static void main(String[] args) {
String filename = "data.csv";
boolean useLogScale = false;
try {
ChartData chartData = CsvReader.readDataFromCSV(filename);
ChartDrawer.draw(chartData, useLogScale);
} catch (FileNotFoundException e) {
System.out.println("File does not exist");
System.exit(1);
} catch (AccessDeniedException e) {
System.out.println("Failed to read file: incorrect permission");
System.exit(1);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("Chart Viewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon icon = new ImageIcon("output.png");
int imageWidth = icon.getIconWidth();
int imageHeight = icon.getIconHeight();
JLabel label = new JLabel(icon);
label.setHorizontalAlignment(JLabel.CENTER);
frame.getContentPane().add(new JScrollPane(label), BorderLayout.CENTER);
frame.setSize(addPadding(imageWidth), addPadding(imageHeight));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
}