-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuItems.java
108 lines (97 loc) · 2.93 KB
/
MenuItems.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
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
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Node;
import javafx.scene.image.WritableImage;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javax.imageio.ImageIO;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* Created by Mushra on 2017-09-19.
*/
public class MenuItems {
// it would be cool
// if this one could save wherever we saved last
// and suggest that for next time
// both in session and maybe i guess between sessions?
public static void imageSaver(Node save) {
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("pictuer (*.png)", "*.png");
fileChooser.getExtensionFilters().add(extFilter);
Stage stage = new Stage();
File saveLocation;
try {
saveLocation = fileChooser.showSaveDialog(stage);
if (saveLocation != null) {
try {
WritableImage writableImage = new WritableImage(204,94);
save.snapshot(null,writableImage);
RenderedImage renderedImage = SwingFXUtils.fromFXImage(writableImage, null);
// createfile
try {
ImageIO.write(renderedImage, "png", saveLocation);
} catch(Exception e) {
System.out.println("exception in file saving");
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (NullPointerException npe) {
}
}
public static void fileSaver(byte[] saveme) {
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("thing (*.msapint)", "*.msapint");
fileChooser.getExtensionFilters().add(extFilter);
Stage stage = new Stage();
File saveLocation;
try {
saveLocation = fileChooser.showSaveDialog(stage);
if (saveLocation != null) {
try {
// create file
try {
FileOutputStream fos = new FileOutputStream(saveLocation);
fos.write(saveme);
fos.close();
} catch(Exception e) {
System.out.println("exception in file saving");
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (NullPointerException npe) {
}
}
public static byte[] fileLoader() {
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("thing (*.msapint)", "*.msapint");
fileChooser.getExtensionFilters().add(extFilter);
Stage stage = new Stage();
File loadLocation;
try {
loadLocation = fileChooser.showOpenDialog(stage);
if (loadLocation != null) {
try {
try {
byte[] input = new byte[1022];
FileInputStream inStream = new FileInputStream(loadLocation);
inStream.read(input);
inStream.close();
return input;
} catch(Exception e) {
System.out.println("exception in file loading");
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (NullPointerException npe) {
}
return null;
}
}