merged WorldExporterFactory into PerViewerFacadeInjector

master
Stefan Dollase 2017-02-24 20:25:51 +01:00
parent 92be05527c
commit 8b22871654
4 changed files with 41 additions and 43 deletions

View File

@ -20,6 +20,7 @@ import amidst.gui.main.viewer.Drawer;
import amidst.gui.main.viewer.FragmentGraphToScreenTranslator;
import amidst.gui.main.viewer.Graphics2DAccelerationCounter;
import amidst.gui.main.viewer.Movement;
import amidst.gui.main.viewer.ProgressMessageHolder;
import amidst.gui.main.viewer.Viewer;
import amidst.gui.main.viewer.ViewerFacade;
import amidst.gui.main.viewer.ViewerMouseListener;
@ -39,7 +40,8 @@ import amidst.gui.main.viewer.widget.Widget;
import amidst.gui.main.viewer.widget.Widget.CornerAnchorPoint;
import amidst.gui.main.viewer.widget.WidgetManager;
import amidst.mojangapi.world.World;
import amidst.mojangapi.world.export.WorldExporterFactory;
import amidst.mojangapi.world.export.WorldExporter;
import amidst.mojangapi.world.export.WorldExporterConfiguration;
import amidst.threading.WorkerExecutor;
@NotThreadSafe
@ -72,6 +74,8 @@ public class PerViewerFacadeInjector {
// @formatter:on
}
private final WorkerExecutor workerExecutor;
private final World world;
private final Graphics2DAccelerationCounter accelerationCounter;
private final Movement movement;
private final WorldIconSelection worldIconSelection;
@ -80,7 +84,7 @@ public class PerViewerFacadeInjector {
private final FragmentGraphToScreenTranslator translator;
private final FragmentQueueProcessor fragmentQueueProcessor;
private final LayerReloader layerReloader;
private final WorldExporterFactory worldExporterFactory;
private final ProgressMessageHolder progressMessageHolder;
private final List<Widget> widgets;
private final Drawer drawer;
private final WidgetManager widgetManager;
@ -98,6 +102,8 @@ public class PerViewerFacadeInjector {
BiomeSelection biomeSelection,
World world,
Actions actions) {
this.workerExecutor = workerExecutor;
this.world = world;
this.accelerationCounter = new Graphics2DAccelerationCounter();
this.movement = new Movement(settings.smoothScrolling);
this.worldIconSelection = new WorldIconSelection();
@ -107,7 +113,7 @@ public class PerViewerFacadeInjector {
this.translator = new FragmentGraphToScreenTranslator(graph, zoom);
this.fragmentQueueProcessor = fragmentManager.createQueueProcessor(layerManager, settings.dimension);
this.layerReloader = layerManager.createLayerReloader(world);
this.worldExporterFactory = new WorldExporterFactory(workerExecutor, world);
this.progressMessageHolder = new ProgressMessageHolder();
this.widgets = createWidgets(
world,
graph,
@ -119,7 +125,7 @@ public class PerViewerFacadeInjector {
fragmentManager,
accelerationCounter,
settings,
worldExporterFactory::getProgressMessage);
progressMessageHolder::getProgressMessage);
this.drawer = new Drawer(
graph,
translator,
@ -142,12 +148,17 @@ public class PerViewerFacadeInjector {
worldIconSelection,
layerManager,
workerExecutor,
worldExporterFactory,
this::createWorldExporter,
this::onRepainterTick,
this::onFragmentLoaderTick,
this::onPlayerFinishedLoading);
}
@CalledOnlyBy(AmidstThread.EDT)
public WorldExporter createWorldExporter(WorldExporterConfiguration configuration) {
return new WorldExporter(workerExecutor, world, configuration, progressMessageHolder::setProgressMessage);
}
@CalledOnlyBy(AmidstThread.REPAINTER)
private void onRepainterTick() {
viewer.repaintComponent();

View File

@ -0,0 +1,21 @@
package amidst.gui.main.viewer;
import amidst.documentation.AmidstThread;
import amidst.documentation.CalledByAny;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
@NotThreadSafe
public class ProgressMessageHolder {
private volatile String progressMessage;
@CalledByAny
public void setProgressMessage(String progressMessage) {
this.progressMessage = progressMessage;
}
@CalledOnlyBy(AmidstThread.EDT)
public String getProgressMessage() {
return progressMessage;
}
}

View File

@ -5,6 +5,7 @@ import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.List;
import amidst.dependency.injection.Factory1;
import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
@ -16,8 +17,8 @@ import amidst.mojangapi.world.World;
import amidst.mojangapi.world.WorldSeed;
import amidst.mojangapi.world.WorldType;
import amidst.mojangapi.world.coordinates.CoordinatesInWorld;
import amidst.mojangapi.world.export.WorldExporter;
import amidst.mojangapi.world.export.WorldExporterConfiguration;
import amidst.mojangapi.world.export.WorldExporterFactory;
import amidst.mojangapi.world.icon.WorldIcon;
import amidst.mojangapi.world.player.MovablePlayerList;
import amidst.threading.WorkerExecutor;
@ -38,7 +39,7 @@ public class ViewerFacade {
private final WorldIconSelection worldIconSelection;
private final LayerManager layerManager;
private final WorkerExecutor workerExecutor;
private final WorldExporterFactory worldExporterFactory;
private final Factory1<WorldExporterConfiguration, WorldExporter> worldExporterFactory;
private final Runnable onRepainterTick;
private final Runnable onFragmentLoaderTick;
private final Runnable onPlayerFinishedLoading;
@ -54,7 +55,7 @@ public class ViewerFacade {
WorldIconSelection worldIconSelection,
LayerManager layerManager,
WorkerExecutor workerExecutor,
WorldExporterFactory worldExporterFactory,
Factory1<WorldExporterConfiguration, WorldExporter> worldExporterFactory,
Runnable onRepainterTick,
Runnable onFragmentLoaderTick,
Runnable onPlayerFinishedLoading) {

View File

@ -1,35 +0,0 @@
package amidst.mojangapi.world.export;
import amidst.documentation.AmidstThread;
import amidst.documentation.CalledByAny;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
import amidst.mojangapi.world.World;
import amidst.threading.WorkerExecutor;
@NotThreadSafe
public class WorldExporterFactory {
private final WorkerExecutor workerExecutor;
private final World world;
private volatile String progressMessage;
public WorldExporterFactory(WorkerExecutor workerExecutor, World world) {
this.workerExecutor = workerExecutor;
this.world = world;
}
public WorldExporter create(WorldExporterConfiguration configuration) {
return new WorldExporter(workerExecutor, world, configuration, this::setProgressMessage);
}
@CalledByAny
private void setProgressMessage(String progressMessage) {
this.progressMessage = progressMessage;
}
@CalledOnlyBy(AmidstThread.EDT)
public String getProgressMessage() {
return progressMessage;
}
}