Skip to content

Commit 6e2ec9a

Browse files
authored
FileNotFound Exception handling
1 parent fd6ef02 commit 6e2ec9a

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src_java/com/grimpirate/JavaScript.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.grimpirate;
22

33
import java.awt.Dimension;
4-
import java.io.FileNotFoundException;
5-
import java.io.IOException;
64
import java.time.LocalDateTime;
75
import java.time.format.DateTimeFormatter;
86
import java.util.Arrays;
@@ -16,8 +14,8 @@
1614
public class JavaScript
1715
{
1816
private CoordinateText[] texts;
19-
20-
public JavaScript(String js, String version, Dimension dimension) throws FileNotFoundException, IOException
17+
18+
public JavaScript(String js, String version, Dimension dimension)
2119
{
2220
Context context = Context.enter();
2321
Scriptable scope = new ImporterTopLevel(context);
@@ -30,11 +28,17 @@ public JavaScript(String js, String version, Dimension dimension) throws FileNot
3028
ScriptableObject.putConstProperty(host, "os_arch", Context.javaToJS(System.getProperty("os.name") + " " + System.getProperty("os.arch"), scope));
3129
ScriptableObject.putConstProperty(host, "time", Context.javaToJS(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), scope));
3230
ScriptableObject.putConstProperty(scope, "SVGWall", Context.javaToJS(host, scope));
33-
CoordinateText[] texts = Arrays.stream(((NativeArray) context.evaluateReader(scope, new java.io.FileReader(js), "<cmd>", 1, null)).toArray()).toArray(CoordinateText[]::new);
34-
Context.exit();
35-
this.texts = texts;
31+
try
32+
{
33+
texts = Arrays.stream(((NativeArray) context.evaluateReader(scope, new java.io.FileReader(js), "<cmd>", 1, null)).toArray()).toArray(CoordinateText[]::new);
34+
}
35+
catch (Exception e)
36+
{
37+
Context.exit();
38+
texts = new CoordinateText[] {};
39+
}
3640
}
37-
41+
3842
public CoordinateText[] getText()
3943
{
4044
return texts;

src_java/com/grimpirate/Painter.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,26 @@ public class Painter
2222

2323
public Painter(String svg, Dimension dimension, CoordinateText[] texts)
2424
{
25-
boolean rainbow = false;
25+
this.image = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_ARGB);
26+
2627
try
2728
{
2829
this.image = new BufferedImageTranscoder(svg, (float)dimension.getWidth(), (float)dimension.getHeight()).getBufferedImage();
30+
g2d = image.createGraphics();
31+
g2d.setColor(Color.BLACK);
32+
g2d.drawRect(0, 0, dimension.width, dimension.height);
2933
}
3034
catch (TranscoderException e)
3135
{
32-
this.image = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_ARGB);
33-
rainbow = true;
36+
g2d = image.createGraphics();
37+
drawRainbow();
3438
}
3539

36-
g2d = image.createGraphics();
37-
g2d.setColor(Color.BLACK);
38-
g2d.drawRect(0, 0, dimension.width, dimension.height);
39-
g2d.setColor(COLOR);
40-
g2d.setFont(FONT);
4140
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
4241
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
42+
g2d.setColor(COLOR);
43+
g2d.setFont(FONT);
4344

44-
if(rainbow)
45-
drawRainbow();
46-
4745
drawOverlay(texts);
4846
}
4947

0 commit comments

Comments
 (0)