From dddc43b92296cffd90f1b064635c766eb6804b44 Mon Sep 17 00:00:00 2001 From: phrack Date: Sat, 5 Mar 2016 18:08:35 -0500 Subject: [PATCH] Fix label management to close #406 --- .../com/shootoff/camera/CameraManager.java | 12 +++++----- .../java/com/shootoff/camera/CameraView.java | 5 ++++ .../shootoff/camera/CamerasSupervisor.java | 6 ++--- .../java/com/shootoff/gui/CanvasManager.java | 10 ++++++++ .../gui/controller/ShootOFFController.java | 2 +- .../plugins/TrainingExerciseBase.java | 23 ++++++++----------- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/shootoff/camera/CameraManager.java b/src/main/java/com/shootoff/camera/CameraManager.java index 0dbf1c20..777c5df6 100644 --- a/src/main/java/com/shootoff/camera/CameraManager.java +++ b/src/main/java/com/shootoff/camera/CameraManager.java @@ -134,25 +134,25 @@ public DeduplicationProcessor getDeduplicationProcessor() { return deduplicationProcessor; } - public CameraManager(Camera webcam, CameraErrorView cameraErrorView, CameraView canvas, Configuration config) { + public CameraManager(Camera webcam, CameraErrorView cameraErrorView, CameraView view, Configuration config) { this.webcam = Optional.of(webcam); this.cameraErrorView = Optional.ofNullable(cameraErrorView); - this.cameraView = canvas; + this.cameraView = view; this.config = config; this.cameraView.setCameraManager(this); initDetector(new Detector()); - this.shotDetectionManager = new ShotDetectionManager(this, config, canvas); + this.shotDetectionManager = new ShotDetectionManager(this, config, view); } - protected CameraManager(CameraView canvas, Configuration config) { + protected CameraManager(CameraView view, Configuration config) { this.webcam = Optional.empty(); this.cameraErrorView = Optional.empty(); - this.cameraView = canvas; + this.cameraView = view; this.config = config; - this.shotDetectionManager = new ShotDetectionManager(this, config, canvas); + this.shotDetectionManager = new ShotDetectionManager(this, config, view); } private void initDetector(Detector detector) { diff --git a/src/main/java/com/shootoff/camera/CameraView.java b/src/main/java/com/shootoff/camera/CameraView.java index d44b0502..3c250c7d 100644 --- a/src/main/java/com/shootoff/camera/CameraView.java +++ b/src/main/java/com/shootoff/camera/CameraView.java @@ -7,10 +7,13 @@ import com.shootoff.gui.Target; import javafx.geometry.Bounds; +import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.paint.Color; public interface CameraView { + public boolean addChild(Node c); + public void addShot(Color color, double x, double y); public Optional addTarget(File targetFile); @@ -23,6 +26,8 @@ public interface CameraView { public void close(); + public boolean removeChild(Node c); + public void removeDiagnosticMessage(Label diagnosticLabel); public void reset(); diff --git a/src/main/java/com/shootoff/camera/CamerasSupervisor.java b/src/main/java/com/shootoff/camera/CamerasSupervisor.java index e6997773..031e07b8 100644 --- a/src/main/java/com/shootoff/camera/CamerasSupervisor.java +++ b/src/main/java/com/shootoff/camera/CamerasSupervisor.java @@ -104,13 +104,13 @@ public CameraManager getCameraManager(final int index) { } public List getCameraViews() { - final List canvasManagers = new ArrayList(); + final List cameraViews = new ArrayList(); for (final CameraManager manager : managers) { - canvasManagers.add(manager.getCameraView()); + cameraViews.add(manager.getCameraView()); } - return canvasManagers; + return cameraViews; } public CameraView getCameraView(final int index) { diff --git a/src/main/java/com/shootoff/gui/CanvasManager.java b/src/main/java/com/shootoff/gui/CanvasManager.java index 99d748fb..1b333e89 100644 --- a/src/main/java/com/shootoff/gui/CanvasManager.java +++ b/src/main/java/com/shootoff/gui/CanvasManager.java @@ -165,6 +165,16 @@ public CameraManager getCameraManager() { return cameraManager; } + @Override + public boolean addChild(Node c) { + return getCanvasGroup().getChildren().add(c); + } + + @Override + public boolean removeChild(Node c) { + return getCanvasGroup().getChildren().remove(c); + } + public Label addDiagnosticMessage(final String message, final long chimeDelay, final Color backgroundColor) { final Label diagnosticLabel = new Label(message); diagnosticLabel.setStyle("-fx-background-color: " + colorToWebCode(backgroundColor)); diff --git a/src/main/java/com/shootoff/gui/controller/ShootOFFController.java b/src/main/java/com/shootoff/gui/controller/ShootOFFController.java index 4d038766..912c73ed 100644 --- a/src/main/java/com/shootoff/gui/controller/ShootOFFController.java +++ b/src/main/java/com/shootoff/gui/controller/ShootOFFController.java @@ -606,9 +606,9 @@ public void registerExercise(TrainingExercise exercise) { } TrainingExercise newExercise = (TrainingExercise) ctor.newInstance(knownTargets); + config.setExercise(newExercise); ((TrainingExerciseBase) newExercise).init(config, camerasSupervisor, this); newExercise.init(); - config.setExercise(newExercise); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/src/main/java/com/shootoff/plugins/TrainingExerciseBase.java b/src/main/java/com/shootoff/plugins/TrainingExerciseBase.java index 1fe02fdc..91a8bf09 100644 --- a/src/main/java/com/shootoff/plugins/TrainingExerciseBase.java +++ b/src/main/java/com/shootoff/plugins/TrainingExerciseBase.java @@ -44,7 +44,6 @@ import com.shootoff.camera.CameraView; import com.shootoff.camera.CamerasSupervisor; import com.shootoff.config.Configuration; -import com.shootoff.gui.CanvasManager; import com.shootoff.gui.DelayedStartListener; import com.shootoff.gui.ParListener; import com.shootoff.gui.ShotEntry; @@ -92,7 +91,7 @@ public class TrainingExerciseBase { private TableView shotTimerTable; private boolean changedRowColor = false; - private final static Map exerciseLabels = new HashMap(); + private final static Map exerciseLabels = new HashMap(); private final static Map> exerciseColumns = new HashMap>(); private final static List