Skip to content
Snippets Groups Projects
Commit 260c91a5 authored by Håvard Daleng's avatar Håvard Daleng
Browse files

Improved error handling so that trying to load a fractal from file with the...

Improved error handling so that trying to load a fractal from file with the same name as a file in target gives proper error message.
parent 3580c7bb
No related branches found
No related tags found
No related merge requests found
Pipeline #288828 passed
......@@ -8,6 +8,8 @@ target/
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea/
.DS_Store
*.iws
*.iml
*.ipr
......
......@@ -304,11 +304,15 @@ public class GuiButtonController {
if (selectedFile != null) {
Path dest = Paths.get(
"src/main/resources/descriptions/saved_descriptions/" + selectedFile.getName());
try {
Files.copy(selectedFile.toPath(), dest);
factory = new ChaosGameDescriptionFactory();
} catch (IOException e) {
PopupManager.displayError("Error", "Could not load the fractal from file.");
if (Files.exists(dest)) {
PopupManager.displayError("Error", "File already exists in the target location.");
} else {
try {
Files.copy(selectedFile.toPath(), dest);
factory = new ChaosGameDescriptionFactory();
} catch (IOException e) {
PopupManager.displayError("Error", "Could not load the fractal from file.");
}
}
}
}
......
......@@ -34,17 +34,17 @@ public class ChaosCanvas {
/**
* The minimum coordinates of the canvas.
*/
private Vector2D minCoords;
private final Vector2D minCoords;
/**
* The maximum coordinates of the canvas.
*/
private Vector2D maxCoords;
private final Vector2D maxCoords;
/**
* Affine transformation for converting coordinates to canvas indices.
*/
private AffineTransform2D transformCoordsToIndices;
private final AffineTransform2D transformCoordsToIndices;
/**
* Parameterized constructor for the class.
......@@ -88,7 +88,6 @@ public class ChaosCanvas {
if (xindex >= 0 && xindex < width && yindex >= 0 && yindex < height) {
canvas[xindex][yindex] = 1;
canvasIntensityArray[xindex][yindex]++;
}
}
......
Affine2D
Heighway-Dragon
-1.0, -1.0
1.5, 1.5
0.5, -0.5, 0.5, 0.5, 0.0, 0.0
-0.5, -0.5, 0.5, -0.5, 1.0, 0.0
Affine2D
Heighway-Dragon
-1, -1 # Lower left
1.5, 1.5 # Upper right
0.5, -0.5, 0.5, 0.5, 0, 0 # 1st transform
-0.5, -0.5, 0.5, -0.5, 1, 0 # 2nd transform
Affine2D
Heighway-Dragon
-1, -1 # Lower left
1.5, 1.5 # Upper right
0.5, -0.5, 0.5, 0.5, 0, 0 # 1st transform
-0.5, -0.5, 0.5, -0.5, 1, 0 # 2nd transform
Affine2D # Type of transform
Testytest
0, 0 # Lower Left
1, 1 # Upper Right
.5, 0, 0, .5, 0, 0 # 1st transform (a00, a01, a10, a11, b0, b1)
.5, 0, 0, .5, .25, .5 # 2nd transform
.5, 0, 0, .5, .5, 0 # 3rd transform
\ No newline at end of file
......@@ -14,8 +14,14 @@ import org.junit.jupiter.api.Test;
*/
public class ChaosGameTest {
/**
* The ChaosGame object for testing.
*/
private ChaosGame game;
/**
* Set up the test environment by defining the fields.
*/
@BeforeEach
void setUp() {
ChaosGameDescriptionFactory factory = new ChaosGameDescriptionFactory();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment