diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/LightSheetManagerFrame.java b/src/main/java/org/micromanager/lightsheetmanager/gui/LightSheetManagerFrame.java index d001233..c462f0b 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/LightSheetManagerFrame.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/LightSheetManagerFrame.java @@ -34,7 +34,7 @@ public class LightSheetManagerFrame extends JFrame { private TabPanel tabPanel_; - private LightSheetManagerModel model_; + private final LightSheetManagerModel model_; public LightSheetManagerFrame(final LightSheetManagerModel model, final boolean isLoaded) { model_ = Objects.requireNonNull(model); @@ -48,7 +48,7 @@ public LightSheetManagerFrame(final LightSheetManagerModel model, final boolean // create the user interface if (isLoaded) { initDialogs(); - GeometryType geometryType = model_.devices() + final GeometryType geometryType = model_.devices() .getDeviceAdapter().getMicroscopeGeometry(); switch (geometryType) { case DISPIM: diff --git a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java index e82fbc1..4b79511 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java +++ b/src/main/java/org/micromanager/lightsheetmanager/gui/tabs/setup/CameraPanel.java @@ -1,9 +1,12 @@ package org.micromanager.lightsheetmanager.gui.tabs.setup; +import com.google.common.eventbus.Subscribe; +import org.micromanager.events.LiveModeEvent; import org.micromanager.lightsheetmanager.api.data.CameraMode; import org.micromanager.lightsheetmanager.api.data.GeometryType; import org.micromanager.lightsheetmanager.gui.components.Button; import org.micromanager.lightsheetmanager.gui.components.Panel; +import org.micromanager.lightsheetmanager.gui.components.ToggleButton; import org.micromanager.lightsheetmanager.gui.data.Icons; import org.micromanager.lightsheetmanager.model.LightSheetManagerModel; import org.micromanager.lightsheetmanager.model.devices.cameras.CameraBase; @@ -16,13 +19,18 @@ */ public class CameraPanel extends Panel { + private boolean isPreviewPressed = false; + private boolean isLivePressed = false; + private Button btnImagingPath_; private Button btnEpiPath_; private Button btnMultiPath_; - private Button btnInvertedPath_; - private Button btnLiveMode_; + + private ToggleButton btnInvertedPath_; + private ToggleButton btnLiveMode_; private final LightSheetManagerModel model_; + public CameraPanel(final LightSheetManagerModel model) { super("Cameras"); model_ = Objects.requireNonNull(model); @@ -40,14 +48,23 @@ private void createUserInterface() { "[]5[]" ); + // register micro-manager events + model_.studio().events().registerForEvents(this); + Button.setDefaultSize(80, 26); btnImagingPath_ = new Button("Imaging"); btnMultiPath_ = new Button("Multi"); btnEpiPath_ = new Button("Epi"); - btnInvertedPath_ = new Button("Inverted"); - Button.setDefaultSize(165, 26); - btnLiveMode_ = new Button("Live", Icons.CAMERA); + ToggleButton.setDefaultSize(165, 26); + btnInvertedPath_ = new ToggleButton( + "Preview", "Stop Preview", + Icons.CAMERA, Icons.CANCEL + ); + btnLiveMode_ = new ToggleButton( + "Live", "Stop Live", + Icons.CAMERA, Icons.CANCEL + ); switch (geometryType) { case DISPIM: @@ -58,7 +75,7 @@ private void createUserInterface() { add(btnLiveMode_, "span 2"); break; case SCAPE: - btnInvertedPath_.setAbsoluteSize(165, 26); + //btnInvertedPath_.setAbsoluteSize(165, 26); add(btnInvertedPath_, "wrap"); add(btnLiveMode_, ""); break; @@ -94,9 +111,8 @@ private void createEventHandlers() { }); break; case SCAPE: - btnInvertedPath_.setText("Preview"); + //btnInvertedPath_.setText("Preview"); btnInvertedPath_.registerListener(e -> { - // TODO: make this work, needs Device Adapter pull request and name for camera... closeLiveModeWindow(); final CameraBase camera = model_.devices().getDevice("PreviewCamera"); if (camera != null) { @@ -105,9 +121,12 @@ private void createEventHandlers() { camera.setTriggerMode(CameraMode.INTERNAL); } catch (Exception ex) { model_.studio().logs().showError("could not set camera to " + camera.getDeviceName()); + return; // early exit } + isPreviewPressed = true; model_.studio().live().setLiveModeOn(true); } else { + btnInvertedPath_.setState(false); model_.studio().logs().showError( "No device for \"PreviewCamera\" set in the device adapter."); } @@ -123,7 +142,9 @@ private void createEventHandlers() { camera.setTriggerMode(CameraMode.INTERNAL); } catch (Exception ex) { model_.studio().logs().showError("could not set camera to " + camera.getDeviceName()); + return; // early exit } + isLivePressed = true; model_.studio().live().setLiveModeOn(true); } else { model_.studio().logs().showError( @@ -150,4 +171,18 @@ private void closeLiveModeWindow() { } } + @Subscribe + public void liveModeListener(LiveModeEvent event) { + if (!model_.studio().live().isLiveModeOn()) { + if (isPreviewPressed) { + isPreviewPressed = false; + btnInvertedPath_.setState(false); + } + if (isLivePressed) { + isLivePressed = false; + btnLiveMode_.setState(false);; + } + } + } + } diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java b/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java index 38d56ef..5be8c5e 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/devices/cameras/CameraBase.java @@ -87,7 +87,6 @@ public int roiReadoutRowsSplitReadout(Rectangle roi, Rectangle sensor) { @Override public void setTriggerMode(CameraMode cameraMode) { - System.out.println("this!"); mode_ = cameraMode; }