Skip to content

Commit

Permalink
Fix label management to close #406
Browse files Browse the repository at this point in the history
  • Loading branch information
phrack committed Mar 5, 2016
1 parent cb3ef44 commit dddc43b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/shootoff/camera/CameraManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/shootoff/camera/CameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Target> addTarget(File targetFile);
Expand All @@ -23,6 +26,8 @@ public interface CameraView {

public void close();

public boolean removeChild(Node c);

public void removeDiagnosticMessage(Label diagnosticLabel);

public void reset();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/shootoff/camera/CamerasSupervisor.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public CameraManager getCameraManager(final int index) {
}

public List<CameraView> getCameraViews() {
final List<CameraView> canvasManagers = new ArrayList<CameraView>();
final List<CameraView> cameraViews = new ArrayList<CameraView>();

for (final CameraManager manager : managers) {
canvasManagers.add(manager.getCameraView());
cameraViews.add(manager.getCameraView());
}

return canvasManagers;
return cameraViews;
}

public CameraView getCameraView(final int index) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/shootoff/gui/CanvasManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/com/shootoff/plugins/TrainingExerciseBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,7 +91,7 @@ public class TrainingExerciseBase {
private TableView<ShotEntry> shotTimerTable;
private boolean changedRowColor = false;

private final static Map<CanvasManager, Label> exerciseLabels = new HashMap<CanvasManager, Label>();
private final static Map<CameraView, Label> exerciseLabels = new HashMap<CameraView, Label>();
private final static Map<String, TableColumn<ShotEntry, String>> exerciseColumns = new HashMap<String, TableColumn<ShotEntry, String>>();
private final static List<Button> exerciseButtons = new ArrayList<Button>();

Expand All @@ -119,12 +118,10 @@ public void init(final Configuration config, final CamerasSupervisor camerasSupe
this.shotTimerTable = shotEntryTable;

for (final CameraView cv : camerasSupervisor.getCameraViews()) {
final CanvasManager cm = (CanvasManager) cv;

final Label exerciseLabel = new Label();
exerciseLabel.setTextFill(Color.WHITE);
cm.getCanvasGroup().getChildren().add(exerciseLabel);
exerciseLabels.put(cm, exerciseLabel);
cv.addChild(exerciseLabel);
exerciseLabels.put(cv, exerciseLabel);
}
}

Expand Down Expand Up @@ -271,8 +268,9 @@ public void showTextOnFeed(String message) {
}

Platform.runLater(() -> {
for (Label exerciseLabel : exerciseLabels.values())
for (Label exerciseLabel : exerciseLabels.values()) {
exerciseLabel.setText(message);
}
});
}

Expand Down Expand Up @@ -383,7 +381,7 @@ private static void playSound(AudioInputStream audioInputStream, Optional<LineLi
final DataLine.Info info = new DataLine.Info(Clip.class, format);

Clip clip = null;

try {
clip = (Clip) AudioSystem.getLine(info);
clip.open(audioInputStream);
Expand Down Expand Up @@ -454,16 +452,17 @@ public void destroy() {
}

if (shotTimerTable != null) {
for (final TableColumn<ShotEntry, String> column : exerciseColumns.values()) {
for (TableColumn<ShotEntry, String> column : exerciseColumns.values()) {
shotTimerTable.getColumns().remove(column);
}
}

for (final CameraView cv : camerasSupervisor.getCameraViews()) {
final CanvasManager cm = (CanvasManager) cv;
cm.getCanvasGroup().getChildren().remove(exerciseLabels.get(cm));
cv.removeChild(exerciseLabels.get(cv));
}

exerciseLabels.clear();

final Iterator<Button> itExerciseButtons = exerciseButtons.iterator();

while (itExerciseButtons.hasNext()) {
Expand All @@ -472,8 +471,6 @@ public void destroy() {
itExerciseButtons.remove();
}

exerciseLabels.clear();

pauseShotDetection(false);
}

Expand Down

0 comments on commit dddc43b

Please sign in to comment.