diff --git a/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/Action.java b/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/Action.java index ac26740d4..74d6c52e7 100644 --- a/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/Action.java +++ b/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/Action.java @@ -19,6 +19,7 @@ package uk.ac.ox.poseidon.agents.behaviours; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import lombok.Data; import sim.engine.SimState; import sim.engine.Steppable; @@ -37,6 +38,7 @@ public abstract class Action implements Steppable { private final Duration duration; private final Vessel vessel; + @SuppressFBWarnings("EI_EXPOSE_REP2") public Action( final LocalDateTime start, final Duration duration, diff --git a/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/destination/ChooseRandomDestinationBehaviour.java b/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/destination/ChooseRandomDestinationBehaviour.java index c659e4dd5..f2103df3f 100644 --- a/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/destination/ChooseRandomDestinationBehaviour.java +++ b/agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/destination/ChooseRandomDestinationBehaviour.java @@ -19,6 +19,7 @@ package uk.ac.ox.poseidon.agents.behaviours.destination; +import com.google.common.collect.ImmutableList; import ec.util.MersenneTwisterFast; import sim.util.Int2D; import uk.ac.ox.poseidon.agents.behaviours.travel.TravelBehaviour; @@ -30,7 +31,7 @@ public class ChooseRandomDestinationBehaviour extends DestinationBehaviour { - private final List possibleDestinations; + private final ImmutableList possibleDestinations; private final MersenneTwisterFast rng; public ChooseRandomDestinationBehaviour( @@ -39,7 +40,7 @@ public ChooseRandomDestinationBehaviour( final MersenneTwisterFast rng ) { super(travelBehaviour); - this.possibleDestinations = possibleDestinations; + this.possibleDestinations = ImmutableList.copyOf(possibleDestinations); this.rng = rng; } diff --git a/agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/Vessel.java b/agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/Vessel.java index b00e26d59..e01c154a3 100644 --- a/agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/Vessel.java +++ b/agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/Vessel.java @@ -19,6 +19,7 @@ package uk.ac.ox.poseidon.agents.vessels; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -40,9 +41,10 @@ public class Vessel implements Oriented2D { private double cruisingSpeed; private double heading; + @SuppressFBWarnings("EI_EXPOSE_REP2") public Vessel( final String id, - @NonNull final Port homePort, + final Port homePort, final double cruisingSpeed, final VesselField vesselField ) { diff --git a/biology/src/main/java/uk/ac/ox/poseidon/biology/biomass/BiomassDiffuser.java b/biology/src/main/java/uk/ac/ox/poseidon/biology/biomass/BiomassDiffuser.java index b3ee1c66d..d2ff441fa 100644 --- a/biology/src/main/java/uk/ac/ox/poseidon/biology/biomass/BiomassDiffuser.java +++ b/biology/src/main/java/uk/ac/ox/poseidon/biology/biomass/BiomassDiffuser.java @@ -20,6 +20,7 @@ package uk.ac.ox.poseidon.biology.biomass; import ec.util.MersenneTwisterFast; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import sim.engine.SimState; import sim.engine.Steppable; import sim.util.Double2D; @@ -49,6 +50,7 @@ public class BiomassDiffuser implements Steppable { private final Map> habitableNeighbours; + @SuppressFBWarnings("EI_EXPOSE_REP2") public BiomassDiffuser( final BiomassGrid biomassGrid, final CarryingCapacityGrid carryingCapacityGrid, diff --git a/core/src/main/java/uk/ac/ox/poseidon/core/PathFactory.java b/core/src/main/java/uk/ac/ox/poseidon/core/PathFactory.java index e307e2b62..1427b4747 100644 --- a/core/src/main/java/uk/ac/ox/poseidon/core/PathFactory.java +++ b/core/src/main/java/uk/ac/ox/poseidon/core/PathFactory.java @@ -19,6 +19,7 @@ package uk.ac.ox.poseidon.core; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Streams; import lombok.*; @@ -27,6 +28,9 @@ import java.util.List; import java.util.Optional; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.ImmutableList.toImmutableList; + @Getter @Setter @NoArgsConstructor @@ -34,7 +38,26 @@ public class PathFactory extends GlobalScopeFactory { private Factory parent; - @NonNull private List pathElements; + @NonNull private ImmutableList pathElements; + + public static PathFactory from( + final String path + ) { + return from(null, Path.of(path)); + } + + public static PathFactory from( + final Path path + ) { + return from(null, path); + } + + public static PathFactory from( + final PathFactory parent, + final String path + ) { + return from(parent, Path.of(path)); + } public static PathFactory from( final PathFactory parent, @@ -48,13 +71,17 @@ public static PathFactory from( Streams.stream(path) ) .map(Path::toString) - .toList() + .collect(toImmutableList()) ); } @Override protected Path newInstance(final Simulation simulation) { - final Path path = Paths.get(pathElements.getFirst(), pathElements.removeFirst()); + checkState(!pathElements.isEmpty()); + final Path path = Path.of( + pathElements.getFirst(), + pathElements.subList(1, pathElements.size()).toArray(String[]::new) + ); return parent == null ? path : parent.get(null).resolve(path); } } diff --git a/core/src/main/java/uk/ac/ox/poseidon/core/Simulation.java b/core/src/main/java/uk/ac/ox/poseidon/core/Simulation.java index 7e2f2e845..a1129878b 100644 --- a/core/src/main/java/uk/ac/ox/poseidon/core/Simulation.java +++ b/core/src/main/java/uk/ac/ox/poseidon/core/Simulation.java @@ -22,6 +22,7 @@ */ package uk.ac.ox.poseidon.core; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import lombok.Getter; import sim.engine.SimState; import uk.ac.ox.poseidon.core.schedule.TemporalSchedule; @@ -64,6 +65,7 @@ public Simulation( ); } + @SuppressFBWarnings("EI_EXPOSE_REP2") public Simulation( final long seed, final TemporalSchedule schedule, diff --git a/core/src/test/java/uk/ac/ox/poseidon/core/PathFactoryTest.java b/core/src/test/java/uk/ac/ox/poseidon/core/PathFactoryTest.java new file mode 100644 index 000000000..e8c960678 --- /dev/null +++ b/core/src/test/java/uk/ac/ox/poseidon/core/PathFactoryTest.java @@ -0,0 +1,58 @@ +/* + * POSEIDON: an agent-based model of fisheries + * Copyright (c) 2024 CoHESyS Lab cohesys.lab@gmail.com + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package uk.ac.ox.poseidon.core; + +import com.google.common.collect.ImmutableList; +import org.junit.jupiter.api.Test; + +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.*; + +class PathFactoryTest { + + private static final String FOLDERS = "/a/b/c/"; + private static final String FILENAME = "file.txt"; + + @Test + void newInstanceSimpleFile() { + final PathFactory pathFactory = PathFactory.from(FILENAME); + assertNull(pathFactory.getParent()); + assertEquals(ImmutableList.of(FILENAME), pathFactory.getPathElements()); + assertEquals(Path.of(FILENAME), pathFactory.newInstance(null)); + } + + @Test + void newInstanceFileInFolder() { + final PathFactory pathFactory = PathFactory.from(FOLDERS + FILENAME); + assertNull(pathFactory.getParent()); + assertEquals(ImmutableList.of("/", "a", "b", "c", FILENAME), pathFactory.getPathElements()); + assertEquals(Path.of(FOLDERS + FILENAME), pathFactory.newInstance(null)); + } + + @Test + void newInstanceWithParent() { + final PathFactory pathFactory = PathFactory.from(PathFactory.from(FOLDERS), FILENAME); + assertEquals(Path.of(FOLDERS), pathFactory.getParent().get(null)); + assertEquals(ImmutableList.of(FILENAME), pathFactory.getPathElements()); + assertEquals(Path.of(FOLDERS + FILENAME), pathFactory.newInstance(null)); + } + +} diff --git a/examples/src/test/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMapTest.java b/examples/src/test/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMapTest.java index 3b4d91b37..78f48bff3 100644 --- a/examples/src/test/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMapTest.java +++ b/examples/src/test/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMapTest.java @@ -29,20 +29,20 @@ class PaletteColorMapTest { - private final double max = 5; - private final double min = -max; - private final PaletteColorMap colorMap = new PaletteColorMap(OLERON, min, max); + private static final double MAX = 5; + private static final double MIN = -MAX; + private final PaletteColorMap colorMap = new PaletteColorMap(OLERON, MIN, MAX); @Test void getColor() { final Color[] palette = colorMap.getColors(); Map.of( - min - 1, 0, - min, 0, + MIN - 1, 0, + MIN, 0, -1E-10, 127, 0.0, 128, - max, palette.length - 1, - max + 1, palette.length - 1 + MAX, palette.length - 1, + MAX + 1, palette.length - 1 ).forEach((value, index) -> { final Color expected = palette[index]; final Color actual = colorMap.getColor(value); diff --git a/geography/src/main/java/uk/ac/ox/poseidon/geography/bathymetry/BathymetricGrid.java b/geography/src/main/java/uk/ac/ox/poseidon/geography/bathymetry/BathymetricGrid.java index fbafdcfe4..f61ace94b 100644 --- a/geography/src/main/java/uk/ac/ox/poseidon/geography/bathymetry/BathymetricGrid.java +++ b/geography/src/main/java/uk/ac/ox/poseidon/geography/bathymetry/BathymetricGrid.java @@ -25,14 +25,24 @@ import java.util.List; +import static com.google.common.collect.ImmutableList.toImmutableList; + public interface BathymetricGrid extends NumberGrid { default List getWaterCells() { - return getGridExtent().getAllCells().stream().filter(this::isWater).toList(); + return getGridExtent() + .getAllCells() + .stream() + .filter(this::isWater) + .collect(toImmutableList()); } default List getLandCells() { - return getGridExtent().getAllCells().stream().filter(this::isLand).toList(); + return getGridExtent() + .getAllCells() + .stream() + .filter(this::isLand) + .collect(toImmutableList()); } default List getAllCells() { diff --git a/geography/src/main/java/uk/ac/ox/poseidon/geography/paths/CachingPathFinder.java b/geography/src/main/java/uk/ac/ox/poseidon/geography/paths/CachingPathFinder.java index f5abedfe3..9698a54dd 100644 --- a/geography/src/main/java/uk/ac/ox/poseidon/geography/paths/CachingPathFinder.java +++ b/geography/src/main/java/uk/ac/ox/poseidon/geography/paths/CachingPathFinder.java @@ -20,6 +20,7 @@ package uk.ac.ox.poseidon.geography.paths; import com.google.common.collect.ImmutableList; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Optional; @@ -27,6 +28,7 @@ public class CachingPathFinder

implements PathFinder

{ private final PathFinder

pathFinder; private final PathCache

cache; + @SuppressFBWarnings("EI_EXPOSE_REP2") public CachingPathFinder( final PathFinder

pathFinder, final PathCache

cache diff --git a/gui/out/production/resources/images/port.svg b/gui/out/production/resources/images/port.svg new file mode 100644 index 000000000..c84d7410f --- /dev/null +++ b/gui/out/production/resources/images/port.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + diff --git a/gui/out/production/resources/palettes/imola.txt b/gui/out/production/resources/palettes/imola.txt new file mode 100644 index 000000000..9cdf70fb9 --- /dev/null +++ b/gui/out/production/resources/palettes/imola.txt @@ -0,0 +1,256 @@ +0.101441 0.200110 0.700194 +0.103275 0.203014 0.698806 +0.104955 0.205896 0.697423 +0.106727 0.208726 0.696046 +0.108299 0.211567 0.694659 +0.109977 0.214366 0.693287 +0.111521 0.217161 0.691913 +0.113070 0.219940 0.690533 +0.114496 0.222699 0.689172 +0.116032 0.225438 0.687800 +0.117443 0.228185 0.686435 +0.118906 0.230894 0.685075 +0.120279 0.233585 0.683714 +0.121658 0.236312 0.682359 +0.123038 0.238984 0.681006 +0.124419 0.241675 0.679659 +0.125813 0.244322 0.678320 +0.127111 0.246997 0.676983 +0.128474 0.249641 0.675640 +0.129827 0.252304 0.674306 +0.131137 0.254955 0.672979 +0.132446 0.257568 0.671645 +0.133757 0.260201 0.670328 +0.135070 0.262823 0.669002 +0.136327 0.265434 0.667684 +0.137679 0.268035 0.666360 +0.138935 0.270668 0.665046 +0.140231 0.273263 0.663742 +0.141543 0.275872 0.662432 +0.142820 0.278454 0.661119 +0.144107 0.281028 0.659816 +0.145415 0.283628 0.658510 +0.146648 0.286201 0.657214 +0.147947 0.288802 0.655913 +0.149229 0.291388 0.654606 +0.150503 0.293949 0.653308 +0.151764 0.296539 0.652018 +0.153035 0.299117 0.650721 +0.154318 0.301673 0.649430 +0.155613 0.304252 0.648128 +0.156880 0.306831 0.646841 +0.158164 0.309412 0.645542 +0.159416 0.311952 0.644249 +0.160695 0.314529 0.642960 +0.162002 0.317106 0.641664 +0.163274 0.319678 0.640376 +0.164543 0.322244 0.639079 +0.165794 0.324799 0.637784 +0.167115 0.327367 0.636491 +0.168375 0.329947 0.635186 +0.169688 0.332517 0.633890 +0.170957 0.335083 0.632583 +0.172248 0.337633 0.631277 +0.173551 0.340199 0.629962 +0.174877 0.342765 0.628648 +0.176151 0.345314 0.627322 +0.177520 0.347876 0.625992 +0.178838 0.350435 0.624657 +0.180160 0.352981 0.623315 +0.181504 0.355536 0.621949 +0.182872 0.358073 0.620594 +0.184263 0.360596 0.619216 +0.185685 0.363136 0.617815 +0.187076 0.365668 0.616413 +0.188513 0.368188 0.614982 +0.189944 0.370692 0.613540 +0.191409 0.373200 0.612083 +0.192907 0.375695 0.610606 +0.194447 0.378180 0.609108 +0.195967 0.380661 0.607582 +0.197527 0.383122 0.606021 +0.199102 0.385560 0.604456 +0.200717 0.388001 0.602850 +0.202374 0.390426 0.601219 +0.204080 0.392837 0.599568 +0.205772 0.395241 0.597878 +0.207501 0.397623 0.596167 +0.209253 0.399988 0.594425 +0.211048 0.402341 0.592662 +0.212851 0.404685 0.590855 +0.214697 0.407021 0.589024 +0.216590 0.409339 0.587173 +0.218472 0.411640 0.585301 +0.220405 0.413936 0.583386 +0.222326 0.416219 0.581455 +0.224273 0.418485 0.579507 +0.226292 0.420749 0.577521 +0.228298 0.423003 0.575529 +0.230292 0.425262 0.573509 +0.232354 0.427507 0.571468 +0.234418 0.429738 0.569412 +0.236494 0.431981 0.567351 +0.238559 0.434195 0.565258 +0.240659 0.436433 0.563176 +0.242782 0.438655 0.561063 +0.244908 0.440883 0.558948 +0.247068 0.443126 0.556836 +0.249228 0.445357 0.554707 +0.251414 0.447595 0.552578 +0.253591 0.449854 0.550447 +0.255782 0.452118 0.548322 +0.257992 0.454385 0.546194 +0.260238 0.456657 0.544064 +0.262487 0.458956 0.541944 +0.264746 0.461264 0.539834 +0.267031 0.463588 0.537747 +0.269365 0.465931 0.535653 +0.271670 0.468302 0.533584 +0.274045 0.470701 0.531541 +0.276437 0.473109 0.529517 +0.278846 0.475569 0.527507 +0.281273 0.478037 0.525529 +0.283755 0.480545 0.523580 +0.286254 0.483087 0.521652 +0.288817 0.485665 0.519766 +0.291406 0.488292 0.517923 +0.294012 0.490955 0.516096 +0.296691 0.493641 0.514334 +0.299399 0.496376 0.512590 +0.302129 0.499165 0.510895 +0.304936 0.502001 0.509249 +0.307762 0.504874 0.507643 +0.310668 0.507797 0.506069 +0.313590 0.510755 0.504562 +0.316562 0.513775 0.503071 +0.319579 0.516828 0.501649 +0.322646 0.519921 0.500247 +0.325731 0.523075 0.498902 +0.328896 0.526263 0.497597 +0.332081 0.529491 0.496307 +0.335316 0.532757 0.495080 +0.338565 0.536058 0.493873 +0.341872 0.539398 0.492693 +0.345206 0.542783 0.491567 +0.348575 0.546195 0.490446 +0.351966 0.549630 0.489345 +0.355415 0.553094 0.488287 +0.358852 0.556596 0.487239 +0.362345 0.560123 0.486202 +0.365854 0.563673 0.485185 +0.369381 0.567240 0.484185 +0.372929 0.570823 0.483199 +0.376515 0.574431 0.482229 +0.380098 0.578061 0.481253 +0.383710 0.581709 0.480296 +0.387326 0.585380 0.479342 +0.390980 0.589046 0.478387 +0.394629 0.592751 0.477439 +0.398306 0.596451 0.476496 +0.401978 0.600169 0.475558 +0.405692 0.603906 0.474615 +0.409398 0.607651 0.473662 +0.413126 0.611403 0.472723 +0.416860 0.615163 0.471790 +0.420597 0.618953 0.470843 +0.424359 0.622735 0.469902 +0.428133 0.626534 0.468954 +0.431922 0.630349 0.467997 +0.435709 0.634172 0.467055 +0.439505 0.637999 0.466094 +0.443323 0.641840 0.465140 +0.447143 0.645690 0.464197 +0.450983 0.649560 0.463220 +0.454835 0.653426 0.462265 +0.458687 0.657318 0.461305 +0.462548 0.661207 0.460331 +0.466433 0.665110 0.459373 +0.470328 0.669029 0.458397 +0.474226 0.672957 0.457422 +0.478136 0.676893 0.456446 +0.482064 0.680831 0.455471 +0.485991 0.684792 0.454495 +0.489937 0.688766 0.453502 +0.493897 0.692746 0.452527 +0.497874 0.696730 0.451532 +0.501847 0.700731 0.450538 +0.505825 0.704741 0.449545 +0.509834 0.708768 0.448549 +0.513854 0.712792 0.447538 +0.517878 0.716845 0.446543 +0.521903 0.720893 0.445532 +0.525961 0.724966 0.444538 +0.530021 0.729039 0.443523 +0.534088 0.733130 0.442513 +0.538185 0.737229 0.441493 +0.542279 0.741336 0.440469 +0.546397 0.745461 0.439450 +0.550519 0.749592 0.438427 +0.554662 0.753743 0.437409 +0.558814 0.757902 0.436376 +0.563001 0.762067 0.435350 +0.567196 0.766250 0.434306 +0.571406 0.770443 0.433272 +0.575652 0.774644 0.432249 +0.579917 0.778862 0.431207 +0.584205 0.783089 0.430163 +0.588525 0.787331 0.429123 +0.592898 0.791580 0.428085 +0.597297 0.795841 0.427048 +0.601739 0.800118 0.425999 +0.606235 0.804401 0.424971 +0.610797 0.808695 0.423927 +0.615410 0.812993 0.422894 +0.620108 0.817305 0.421867 +0.624872 0.821627 0.420848 +0.629725 0.825948 0.419844 +0.634681 0.830279 0.418834 +0.639735 0.834610 0.417842 +0.644895 0.838937 0.416866 +0.650187 0.843264 0.415892 +0.655603 0.847585 0.414941 +0.661151 0.851901 0.414009 +0.666842 0.856200 0.413104 +0.672692 0.860483 0.412213 +0.678680 0.864742 0.411341 +0.684831 0.868982 0.410515 +0.691137 0.873182 0.409702 +0.697607 0.877350 0.408922 +0.704236 0.881483 0.408178 +0.711022 0.885567 0.407469 +0.717955 0.889601 0.406798 +0.725038 0.893583 0.406169 +0.732260 0.897513 0.405572 +0.739616 0.901376 0.405005 +0.747090 0.905184 0.404485 +0.754686 0.908919 0.404012 +0.762378 0.912595 0.403574 +0.770173 0.916201 0.403168 +0.778055 0.919746 0.402796 +0.786012 0.923226 0.402459 +0.794034 0.926637 0.402157 +0.802106 0.929992 0.401890 +0.810230 0.933282 0.401656 +0.818395 0.936527 0.401452 +0.826599 0.939711 0.401272 +0.834823 0.942847 0.401115 +0.843067 0.945933 0.400978 +0.851325 0.948981 0.400859 +0.859601 0.951989 0.400755 +0.867883 0.954967 0.400665 +0.876163 0.957911 0.400588 +0.884451 0.960825 0.400522 +0.892736 0.963712 0.400466 +0.901018 0.966580 0.400418 +0.909297 0.969428 0.400377 +0.917577 0.972263 0.400342 +0.925845 0.975074 0.400311 +0.934106 0.977879 0.400283 +0.942371 0.980672 0.400258 +0.950623 0.983452 0.400235 +0.958870 0.986227 0.400212 +0.967110 0.988992 0.400190 +0.975342 0.991749 0.400168 +0.983572 0.994500 0.400145 +0.991797 0.997245 0.400120 +1.000000 0.999989 0.400094 diff --git a/gui/out/production/resources/palettes/oleron.txt b/gui/out/production/resources/palettes/oleron.txt new file mode 100644 index 000000000..d64954312 --- /dev/null +++ b/gui/out/production/resources/palettes/oleron.txt @@ -0,0 +1,256 @@ +0.101051 0.150029 0.350268 +0.107211 0.155787 0.356085 +0.113288 0.161590 0.361920 +0.119268 0.167394 0.367765 +0.125252 0.173224 0.373649 +0.131224 0.179109 0.379544 +0.137168 0.185025 0.385457 +0.143104 0.190934 0.391412 +0.149035 0.196917 0.397368 +0.154983 0.202879 0.403363 +0.160954 0.208894 0.409372 +0.166940 0.214922 0.415405 +0.172908 0.221015 0.421458 +0.178936 0.227090 0.427556 +0.184980 0.233182 0.433649 +0.191019 0.239337 0.439789 +0.197125 0.245483 0.445936 +0.203225 0.251694 0.452129 +0.209359 0.257880 0.458321 +0.215526 0.264132 0.464556 +0.221710 0.270392 0.470798 +0.227941 0.276664 0.477065 +0.234173 0.282966 0.483354 +0.240419 0.289287 0.489668 +0.246722 0.295618 0.496005 +0.253046 0.301978 0.502370 +0.259395 0.308379 0.508757 +0.265751 0.314779 0.515151 +0.272115 0.321218 0.521572 +0.278547 0.327665 0.528019 +0.284964 0.334149 0.534485 +0.291439 0.340636 0.540969 +0.297900 0.347155 0.547475 +0.304404 0.353672 0.554003 +0.310938 0.360224 0.560549 +0.317471 0.366805 0.567119 +0.324030 0.373391 0.573700 +0.330615 0.380003 0.580307 +0.337229 0.386625 0.586927 +0.343842 0.393278 0.593573 +0.350503 0.399944 0.600234 +0.357169 0.406637 0.606920 +0.363837 0.413344 0.613610 +0.370538 0.420064 0.620339 +0.377270 0.426807 0.627069 +0.384009 0.433558 0.633829 +0.390772 0.440340 0.640598 +0.397548 0.447135 0.647388 +0.404341 0.453950 0.654195 +0.411161 0.460775 0.661019 +0.417992 0.467630 0.667869 +0.424850 0.474498 0.674725 +0.431726 0.481373 0.681598 +0.438599 0.488279 0.688501 +0.445502 0.495192 0.695411 +0.452438 0.502125 0.702337 +0.459371 0.509076 0.709288 +0.466322 0.516030 0.716250 +0.473287 0.523024 0.723220 +0.480286 0.530020 0.730221 +0.487295 0.537040 0.737228 +0.494317 0.544063 0.744254 +0.501356 0.551111 0.751301 +0.508414 0.558166 0.758354 +0.515471 0.565243 0.765425 +0.522562 0.572346 0.772503 +0.529669 0.579457 0.779599 +0.536791 0.586575 0.786710 +0.543917 0.593716 0.793824 +0.551067 0.600867 0.800939 +0.558223 0.608041 0.808062 +0.565400 0.615214 0.815181 +0.572603 0.622409 0.822297 +0.579808 0.629615 0.829395 +0.587015 0.636838 0.836468 +0.594243 0.644054 0.843507 +0.601473 0.651290 0.850506 +0.608719 0.658519 0.857445 +0.615947 0.665751 0.864315 +0.623183 0.672978 0.871085 +0.630403 0.680180 0.877748 +0.637601 0.687375 0.884278 +0.644770 0.694530 0.890649 +0.651914 0.701653 0.896848 +0.658997 0.708735 0.902842 +0.666031 0.715748 0.908610 +0.672996 0.722680 0.914138 +0.679866 0.729543 0.919396 +0.686656 0.736302 0.924380 +0.693340 0.742971 0.929074 +0.699907 0.749512 0.933470 +0.706366 0.755950 0.937574 +0.712688 0.762259 0.941373 +0.718898 0.768446 0.944891 +0.724986 0.774514 0.948123 +0.730942 0.780465 0.951099 +0.736792 0.786306 0.953828 +0.742535 0.792032 0.956334 +0.748176 0.797664 0.958640 +0.753726 0.803211 0.960767 +0.759197 0.808685 0.962737 +0.764606 0.814084 0.964572 +0.769952 0.819431 0.966298 +0.775252 0.824734 0.967932 +0.780515 0.830002 0.969481 +0.785750 0.835235 0.970971 +0.790956 0.840451 0.972415 +0.796148 0.845644 0.973813 +0.801330 0.850830 0.975183 +0.806509 0.856015 0.976533 +0.811679 0.861191 0.977867 +0.816850 0.866371 0.979190 +0.822025 0.871554 0.980503 +0.827199 0.876733 0.981812 +0.832379 0.881927 0.983114 +0.837567 0.887121 0.984419 +0.842756 0.892326 0.985718 +0.847948 0.897534 0.987020 +0.853150 0.902750 0.988314 +0.858355 0.907974 0.989617 +0.863572 0.913201 0.990914 +0.868787 0.918435 0.992213 +0.873999 0.923682 0.993511 +0.879219 0.928927 0.994803 +0.884444 0.934184 0.996097 +0.889665 0.939450 0.997391 +0.894892 0.944721 0.998686 +0.900113 0.949993 0.999975 +0.100240 0.299006 0.000155 +0.112059 0.301986 0.000226 +0.123174 0.304970 0.000257 +0.133900 0.307897 0.000247 +0.144183 0.310824 0.000204 +0.154116 0.313690 0.000161 +0.163828 0.316526 0.000125 +0.173231 0.319321 0.000097 +0.182452 0.322081 0.000077 +0.191517 0.324797 0.000069 +0.200403 0.327489 0.000075 +0.209187 0.330157 0.000098 +0.217842 0.332794 0.000144 +0.226396 0.335398 0.000219 +0.234859 0.337967 0.000330 +0.243210 0.340551 0.000490 +0.251560 0.343129 0.000711 +0.259831 0.345692 0.001011 +0.268057 0.348297 0.001410 +0.276308 0.350930 0.001933 +0.284508 0.353583 0.002608 +0.292741 0.356317 0.003469 +0.300991 0.359099 0.004557 +0.309305 0.361990 0.005916 +0.317630 0.364963 0.007597 +0.326018 0.368063 0.009658 +0.334508 0.371283 0.012367 +0.343052 0.374663 0.015348 +0.351666 0.378181 0.018930 +0.360377 0.381864 0.023166 +0.369187 0.385710 0.028136 +0.378064 0.389735 0.033895 +0.387015 0.393928 0.040800 +0.396050 0.398292 0.047888 +0.405124 0.402804 0.055327 +0.414248 0.407471 0.063020 +0.423394 0.412283 0.070789 +0.432574 0.417212 0.078726 +0.441738 0.422234 0.086949 +0.450884 0.427379 0.095228 +0.460001 0.432585 0.103618 +0.469095 0.437854 0.112113 +0.478121 0.443165 0.120649 +0.487104 0.448515 0.129315 +0.496012 0.453885 0.138052 +0.504872 0.459278 0.146755 +0.513661 0.464677 0.155552 +0.522375 0.470077 0.164360 +0.531040 0.475480 0.173148 +0.539637 0.480870 0.181959 +0.548199 0.486280 0.190798 +0.556703 0.491704 0.199617 +0.565164 0.497122 0.208471 +0.573613 0.502563 0.217312 +0.582031 0.508043 0.226158 +0.590441 0.513543 0.234999 +0.598853 0.519090 0.243806 +0.607272 0.524679 0.252670 +0.615690 0.530332 0.261518 +0.624143 0.536045 0.270391 +0.632612 0.541829 0.279258 +0.641111 0.547695 0.288120 +0.649657 0.553632 0.297027 +0.658233 0.559662 0.305938 +0.666846 0.565761 0.314833 +0.675508 0.571955 0.323770 +0.684205 0.578221 0.332732 +0.692958 0.584577 0.341682 +0.701731 0.591002 0.350664 +0.710557 0.597505 0.359644 +0.719414 0.604078 0.368655 +0.728299 0.610707 0.377669 +0.737219 0.617396 0.386700 +0.746161 0.624147 0.395771 +0.755130 0.630945 0.404836 +0.764105 0.637785 0.413942 +0.773094 0.644669 0.423061 +0.782091 0.651605 0.432233 +0.791075 0.658568 0.441410 +0.800051 0.665577 0.450634 +0.808995 0.672625 0.459894 +0.817893 0.679697 0.469215 +0.826745 0.686819 0.478566 +0.835514 0.693969 0.487989 +0.844186 0.701164 0.497461 +0.852739 0.708393 0.506988 +0.861136 0.715654 0.516582 +0.869359 0.722932 0.526244 +0.877367 0.730249 0.535948 +0.885134 0.737573 0.545718 +0.892625 0.744911 0.555514 +0.899805 0.752247 0.565352 +0.906647 0.759568 0.575215 +0.913125 0.766871 0.585083 +0.919214 0.774134 0.594931 +0.924907 0.781355 0.604762 +0.930195 0.788513 0.614543 +0.935066 0.795601 0.624286 +0.939537 0.802617 0.633958 +0.943612 0.809557 0.643549 +0.947313 0.816413 0.653068 +0.950661 0.823182 0.662520 +0.953686 0.829879 0.671879 +0.956415 0.836497 0.681164 +0.958882 0.843049 0.690387 +0.961118 0.849544 0.699548 +0.963155 0.855984 0.708665 +0.965019 0.862387 0.717732 +0.966746 0.868754 0.726764 +0.968355 0.875091 0.735776 +0.969864 0.881418 0.744780 +0.971299 0.887731 0.753777 +0.972677 0.894046 0.762774 +0.974000 0.900360 0.771786 +0.975289 0.906683 0.780806 +0.976553 0.913014 0.789846 +0.977795 0.919355 0.798909 +0.979018 0.925717 0.807992 +0.980230 0.932088 0.817101 +0.981427 0.938483 0.826236 +0.982613 0.944895 0.835399 +0.983785 0.951319 0.844588 +0.984948 0.957763 0.853798 +0.986093 0.964218 0.863044 +0.987224 0.970694 0.872308 +0.988330 0.977184 0.881595 +0.989424 0.983687 0.890903 +0.990487 0.990203 0.900235 diff --git a/gui/out/production/resources/palettes/turku.txt b/gui/out/production/resources/palettes/turku.txt new file mode 100644 index 000000000..cf2beb200 --- /dev/null +++ b/gui/out/production/resources/palettes/turku.txt @@ -0,0 +1,256 @@ +0.000063 0.000005 0.000036 +0.007290 0.007204 0.006548 +0.014710 0.014597 0.013245 +0.021935 0.021794 0.019755 +0.029159 0.028991 0.026252 +0.036570 0.036375 0.032748 +0.043586 0.043359 0.039417 +0.050168 0.049959 0.045556 +0.056203 0.055961 0.051274 +0.061712 0.061463 0.056643 +0.066992 0.066746 0.061506 +0.071921 0.071694 0.066226 +0.076552 0.076296 0.070642 +0.081056 0.080777 0.074828 +0.085276 0.085021 0.078791 +0.089398 0.089110 0.082660 +0.093274 0.092973 0.086288 +0.097120 0.096859 0.089825 +0.101038 0.100786 0.093141 +0.104942 0.104672 0.096482 +0.108926 0.108623 0.099864 +0.112921 0.112617 0.103237 +0.116855 0.116562 0.106586 +0.120820 0.120496 0.109910 +0.124835 0.124484 0.113213 +0.128844 0.128498 0.116492 +0.132892 0.132513 0.119746 +0.136918 0.136502 0.122995 +0.140991 0.140564 0.126296 +0.145046 0.144601 0.129527 +0.149082 0.148613 0.132748 +0.153138 0.152668 0.135908 +0.157222 0.156756 0.139098 +0.161345 0.160812 0.142280 +0.165385 0.164875 0.145443 +0.169533 0.168986 0.148500 +0.173607 0.173041 0.151594 +0.177744 0.177142 0.154657 +0.181809 0.181208 0.157690 +0.185960 0.185342 0.160696 +0.190051 0.189414 0.163707 +0.194194 0.193519 0.166642 +0.198278 0.197608 0.169573 +0.202395 0.201692 0.172431 +0.206547 0.205817 0.175300 +0.210638 0.209903 0.178153 +0.214745 0.214009 0.180907 +0.218872 0.218103 0.183680 +0.222990 0.222187 0.186423 +0.227091 0.226298 0.189124 +0.231200 0.230358 0.191783 +0.235309 0.234470 0.194450 +0.239393 0.238528 0.197043 +0.243470 0.242609 0.199581 +0.247581 0.246687 0.202127 +0.251671 0.250761 0.204658 +0.255736 0.254845 0.207134 +0.259822 0.258900 0.209562 +0.263900 0.262954 0.211994 +0.267938 0.266992 0.214362 +0.271997 0.271056 0.216724 +0.276087 0.275096 0.219036 +0.280118 0.279144 0.221330 +0.284164 0.283175 0.223587 +0.288207 0.287188 0.225833 +0.292251 0.291232 0.228039 +0.296286 0.295240 0.230190 +0.300312 0.299273 0.232366 +0.304341 0.303270 0.234504 +0.308370 0.307283 0.236608 +0.312378 0.311297 0.238663 +0.316418 0.315302 0.240716 +0.320441 0.319304 0.242756 +0.324438 0.323304 0.244764 +0.328462 0.327290 0.246769 +0.332488 0.331280 0.248761 +0.336486 0.335297 0.250701 +0.340511 0.339286 0.252648 +0.344521 0.343272 0.254580 +0.348549 0.347265 0.256467 +0.352572 0.351248 0.258360 +0.356605 0.355248 0.260248 +0.360620 0.359220 0.262115 +0.364666 0.363212 0.263983 +0.368721 0.367205 0.265824 +0.372762 0.371195 0.267635 +0.376835 0.375195 0.269496 +0.380907 0.379198 0.271303 +0.384975 0.383208 0.273127 +0.389080 0.387201 0.274933 +0.393179 0.391225 0.276752 +0.397300 0.395235 0.278557 +0.401442 0.399243 0.280346 +0.405602 0.403280 0.282175 +0.409774 0.407305 0.283967 +0.413963 0.411339 0.285769 +0.418173 0.415382 0.287587 +0.422409 0.419437 0.289423 +0.426680 0.423481 0.291250 +0.430975 0.427557 0.293070 +0.435297 0.431630 0.294913 +0.439639 0.435704 0.296782 +0.444025 0.439786 0.298639 +0.448436 0.443882 0.300514 +0.452890 0.447974 0.302404 +0.457371 0.452098 0.304323 +0.461904 0.456207 0.306269 +0.466474 0.460328 0.308200 +0.471093 0.464479 0.310185 +0.475755 0.468613 0.312149 +0.480458 0.472760 0.314179 +0.485214 0.476920 0.316230 +0.490030 0.481079 0.318289 +0.494902 0.485249 0.320397 +0.499813 0.489423 0.322518 +0.504804 0.493606 0.324659 +0.509839 0.497800 0.326847 +0.514941 0.501978 0.329089 +0.520096 0.506153 0.331326 +0.525329 0.510340 0.333638 +0.530619 0.514527 0.335961 +0.535971 0.518703 0.338327 +0.541388 0.522867 0.340746 +0.546882 0.527027 0.343200 +0.552434 0.531166 0.345677 +0.558042 0.535291 0.348217 +0.563732 0.539401 0.350797 +0.569463 0.543493 0.353400 +0.575270 0.547552 0.356064 +0.581129 0.551588 0.358745 +0.587044 0.555576 0.361493 +0.593020 0.559543 0.364264 +0.599036 0.563464 0.367083 +0.605096 0.567331 0.369934 +0.611203 0.571142 0.372824 +0.617339 0.574902 0.375753 +0.623515 0.578604 0.378712 +0.629702 0.582236 0.381703 +0.635919 0.585808 0.384716 +0.642146 0.589285 0.387761 +0.648375 0.592706 0.390839 +0.654606 0.596023 0.393922 +0.660832 0.599263 0.397028 +0.667046 0.602403 0.400161 +0.673242 0.605450 0.403304 +0.679400 0.608411 0.406452 +0.685537 0.611258 0.409610 +0.691626 0.613996 0.412779 +0.697668 0.616646 0.415935 +0.703665 0.619184 0.419105 +0.709603 0.621600 0.422261 +0.715479 0.623928 0.425434 +0.721279 0.626132 0.428588 +0.727018 0.628240 0.431748 +0.732685 0.630234 0.434886 +0.738264 0.632122 0.438021 +0.743772 0.633913 0.441135 +0.749190 0.635592 0.444261 +0.754538 0.637182 0.447354 +0.759785 0.638671 0.450458 +0.764961 0.640074 0.453543 +0.770042 0.641377 0.456625 +0.775042 0.642610 0.459703 +0.779960 0.643752 0.462766 +0.784800 0.644824 0.465838 +0.789553 0.645828 0.468920 +0.794231 0.646771 0.471996 +0.798829 0.647646 0.475078 +0.803353 0.648471 0.478158 +0.807810 0.649254 0.481257 +0.812197 0.649987 0.484375 +0.816524 0.650686 0.487527 +0.820782 0.651357 0.490694 +0.824986 0.652004 0.493880 +0.829142 0.652627 0.497108 +0.833237 0.653245 0.500370 +0.837292 0.653864 0.503681 +0.841297 0.654478 0.507039 +0.845261 0.655103 0.510449 +0.849192 0.655752 0.513925 +0.853082 0.656418 0.517457 +0.856942 0.657111 0.521050 +0.860774 0.657841 0.524721 +0.864578 0.658606 0.528473 +0.868361 0.659428 0.532304 +0.872114 0.660303 0.536217 +0.875845 0.661242 0.540221 +0.879553 0.662254 0.544323 +0.883246 0.663333 0.548526 +0.886919 0.664485 0.552814 +0.890568 0.665734 0.557222 +0.894201 0.667068 0.561722 +0.897809 0.668505 0.566329 +0.901394 0.670040 0.571039 +0.904958 0.671670 0.575872 +0.908492 0.673419 0.580791 +0.911997 0.675275 0.585829 +0.915467 0.677253 0.590958 +0.918906 0.679333 0.596195 +0.922312 0.681539 0.601525 +0.925669 0.683866 0.606956 +0.928977 0.686316 0.612460 +0.932238 0.688886 0.618058 +0.935448 0.691564 0.623735 +0.938597 0.694360 0.629468 +0.941681 0.697278 0.635273 +0.944702 0.700307 0.641130 +0.947647 0.703444 0.647044 +0.950518 0.706687 0.652983 +0.953313 0.710026 0.658964 +0.956025 0.713462 0.664967 +0.958650 0.716995 0.670991 +0.961187 0.720602 0.677020 +0.963634 0.724299 0.683043 +0.965991 0.728067 0.689068 +0.968259 0.731909 0.695067 +0.970426 0.735806 0.701054 +0.972506 0.739776 0.707015 +0.974483 0.743783 0.712936 +0.976371 0.747846 0.718828 +0.978164 0.751946 0.724680 +0.979870 0.756084 0.730482 +0.981480 0.760255 0.736231 +0.983000 0.764455 0.741938 +0.984437 0.768675 0.747593 +0.985784 0.772921 0.753181 +0.987052 0.777189 0.758725 +0.988234 0.781462 0.764206 +0.989346 0.785749 0.769631 +0.990378 0.790041 0.775001 +0.991341 0.794346 0.780317 +0.992236 0.798651 0.785580 +0.993066 0.802958 0.790784 +0.993829 0.807273 0.795937 +0.994533 0.811585 0.801043 +0.995180 0.815897 0.806101 +0.995775 0.820203 0.811110 +0.996319 0.824512 0.816079 +0.996814 0.828824 0.821000 +0.997265 0.833124 0.825884 +0.997672 0.837430 0.830736 +0.998039 0.841727 0.835548 +0.998368 0.846020 0.840333 +0.998661 0.850316 0.845083 +0.998919 0.854608 0.849810 +0.999146 0.858895 0.854509 +0.999342 0.863188 0.859187 +0.999510 0.867470 0.863851 +0.999652 0.871758 0.868494 +0.999769 0.876039 0.873116 +0.999864 0.880320 0.877730 +0.999937 0.884606 0.882330 +0.999989 0.888890 0.886927 +1.000000 0.893169 0.891512 +1.000000 0.897457 0.896094 +1.000000 0.901739 0.900670 diff --git a/gui/src/main/java/uk/ac/ox/poseidon/gui/ScenarioWithUI.java b/gui/src/main/java/uk/ac/ox/poseidon/gui/ScenarioWithUI.java index f29ab8e94..c6262ffa2 100644 --- a/gui/src/main/java/uk/ac/ox/poseidon/gui/ScenarioWithUI.java +++ b/gui/src/main/java/uk/ac/ox/poseidon/gui/ScenarioWithUI.java @@ -32,6 +32,6 @@ public class ScenarioWithUI { private final List> displays; public Controller createController() { - return new SimulationWithUI(scenario, displays).createController(); + return new SimulationWithUI(scenario::newSimulation, displays).createController(); } } diff --git a/gui/src/main/java/uk/ac/ox/poseidon/gui/SimulationWithUI.java b/gui/src/main/java/uk/ac/ox/poseidon/gui/SimulationWithUI.java index b8ad866e8..93f6fe3b7 100644 --- a/gui/src/main/java/uk/ac/ox/poseidon/gui/SimulationWithUI.java +++ b/gui/src/main/java/uk/ac/ox/poseidon/gui/SimulationWithUI.java @@ -20,24 +20,32 @@ package uk.ac.ox.poseidon.gui; import com.formdev.flatlaf.FlatLightLaf; +import com.google.common.collect.ImmutableList; import sim.display.Controller; import sim.display.GUIState; import uk.ac.ox.poseidon.core.Scenario; import uk.ac.ox.poseidon.core.Simulation; import java.util.List; +import java.util.function.Supplier; public class SimulationWithUI extends GUIState { - private final List> displayWrappers; - private final Scenario scenario; + private final ImmutableList> displayWrappers; + private final Supplier simulationSupplier; public SimulationWithUI( - final Scenario scenario, + final Supplier simulationSupplier, final List> displayWrappers ) { - super(scenario.newSimulation()); - this.scenario = scenario; + this(simulationSupplier, ImmutableList.copyOf(displayWrappers)); + } + public SimulationWithUI( + final Supplier simulationSupplier, + final ImmutableList> displayWrappers + ) { + super(simulationSupplier.get()); + this.simulationSupplier = simulationSupplier; this.displayWrappers = displayWrappers; FlatLightLaf.setup(); } @@ -48,7 +56,7 @@ public static String getName() { @Override public void start() { - final Simulation simulation = scenario.newSimulation(); + final Simulation simulation = simulationSupplier.get(); super.state = simulation; super.start(); displayWrappers.forEach(displayWrapper -> displayWrapper.setupPortrayals(simulation)); diff --git a/gui/src/main/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMap.java b/gui/src/main/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMap.java index a4d819fba..809e0807b 100644 --- a/gui/src/main/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMap.java +++ b/gui/src/main/java/uk/ac/ox/poseidon/gui/palettes/PaletteColorMap.java @@ -44,7 +44,7 @@ public PaletteColorMap( checkNotNull(colors); checkArgument(colors.length > 1); checkArgument(minimum < maximum); - this.colors = colors; + this.colors = colors.clone(); this.minimum = minimum; this.maximum = maximum; } diff --git a/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/PortGridPortrayalFactory.java b/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/PortGridPortrayalFactory.java index 95486724a..e0b7586f4 100644 --- a/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/PortGridPortrayalFactory.java +++ b/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/PortGridPortrayalFactory.java @@ -42,7 +42,7 @@ protected SparseGridPortrayal2D newInstance(final Simulation simulation) { final SparseGridPortrayal2D sparseGridPortrayal2D = new SparseGridPortrayal2D(); sparseGridPortrayal2D.setField(portGrid.get(simulation).getField()); sparseGridPortrayal2D.setPortrayalForAll( - new SvgPortrayal(getClass().getResourceAsStream("/images/port.svg")) + SvgPortrayal.from(getClass().getResourceAsStream("/images/port.svg")) ); return sparseGridPortrayal2D; } diff --git a/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgPortrayal.java b/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgPortrayal.java index 7b7b47581..34a71142e 100644 --- a/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgPortrayal.java +++ b/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgPortrayal.java @@ -19,18 +19,20 @@ package uk.ac.ox.poseidon.gui.portrayals; +import lombok.RequiredArgsConstructor; import sim.portrayal.DrawInfo2D; import sim.portrayal.simple.RectanglePortrayal2D; import java.awt.*; import java.io.InputStream; +@RequiredArgsConstructor public class SvgPortrayal extends RectanglePortrayal2D { private final SvgRenderer renderer; - public SvgPortrayal(final InputStream svgInputStream) { - this.renderer = new SvgRenderer(svgInputStream); + public static SvgPortrayal from(final InputStream svgInputStream) { + return new SvgPortrayal(SvgRenderer.from(svgInputStream)); } @Override diff --git a/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgRenderer.java b/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgRenderer.java index 06ab7f11a..d0ab3dc83 100644 --- a/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgRenderer.java +++ b/gui/src/main/java/uk/ac/ox/poseidon/gui/portrayals/SvgRenderer.java @@ -19,6 +19,7 @@ package uk.ac.ox.poseidon.gui.portrayals; +import lombok.RequiredArgsConstructor; import org.apache.batik.anim.dom.SAXSVGDocumentFactory; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; @@ -31,15 +32,16 @@ import java.io.IOException; import java.io.InputStream; +@RequiredArgsConstructor public class SvgRenderer { private final SVGDocument svgDocument; - public SvgRenderer(final InputStream svgInputStream) { + public static SvgRenderer from(final InputStream svgInputStream) { final String parser = XMLResourceDescriptor.getXMLParserClassName(); final SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser); try { - svgDocument = factory.createSVGDocument(null, svgInputStream); + return new SvgRenderer(factory.createSVGDocument(null, svgInputStream)); } catch (final IOException e) { throw new RuntimeException(e); }