Skip to content

Commit

Permalink
add xyz grid settings to PluginSettings object
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon committed Sep 4, 2024
1 parent f981a23 commit 6b9e286
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ public class XYZGridFrame extends JFrame {
private Button btnComputeGrid_;
private Button btnRunOverviewAcq_;

private JLabel lblXStart_;
private JLabel lblYStart_;
private JLabel lblZStart_;

private JLabel lblXStop_;
private JLabel lblYStop_;
private JLabel lblZStop_;

private JLabel lblXDelta_;
private JLabel lblYDelta_;
private JLabel lblZDelta_;

private JLabel lblXCount_;
private JLabel lblYCount_;
private JLabel lblZCount_;

private CheckBox cbxUseX_;
private CheckBox cbxUseY_;
private CheckBox cbxUseZ_;
Expand Down Expand Up @@ -50,6 +66,7 @@ public XYZGridFrame(final LightSheetManager model) {
WindowPositioning.setUpBoundsMemory(this, this.getClass(), this.getClass().getSimpleName());
createUserInterface();
createEventHandlers();
loadFromSettings();
}

private void createUserInterface() {
Expand Down Expand Up @@ -90,67 +107,67 @@ private void createUserInterface() {
final Panel pnlButtons = new Panel();

// X
final JLabel lblXStart = new JLabel("X start [µm]:");
final JLabel lblXStop = new JLabel("X stop [µm]:");
final JLabel lblXDelta = new JLabel("X delta [µm]:");
final JLabel lblXCount = new JLabel("Slice count:");
lblXStart_ = new JLabel("X start [µm]:");
lblXStop_ = new JLabel("X stop [µm]:");
lblXDelta_ = new JLabel("X delta [µm]:");
lblXCount_ = new JLabel("Slice count:");

spnXStart_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);
spnXStop_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);
spnXDelta_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);

// Y
final JLabel lblYStart = new JLabel("Y start [µm]:");
final JLabel lblYStop = new JLabel("Y stop [µm]:");
final JLabel lblYDelta = new JLabel("Y delta [µm]:");
final JLabel lblYCount = new JLabel("Y count:");
lblYStart_ = new JLabel("Y start [µm]:");
lblYStop_ = new JLabel("Y stop [µm]:");
lblYDelta_ = new JLabel("Y delta [µm]:");
lblYCount_ = new JLabel("Y count:");

spnYStart_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);
spnYStop_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);
spnYDelta_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);

// Z
final JLabel lblZStart = new JLabel("Z start [µm]:");
final JLabel lblZStop = new JLabel("Z stop [µm]:");
final JLabel lblZDelta = new JLabel("Z delta [µm]:");
final JLabel lblZCount = new JLabel("Z count:");
lblZStart_ = new JLabel("Z start [µm]:");
lblZStop_ = new JLabel("Z stop [µm]:");
lblZDelta_ = new JLabel("Z delta [µm]:");
lblZCount_ = new JLabel("Z count:");

spnZStart_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);
spnZStop_ = Spinner.createDoubleSpinner(0.0, -Double.MAX_VALUE, Double.MAX_VALUE, 100.0);
spnZDelta_ = Spinner.createDoubleSpinner(0.0,-Double.MAX_VALUE, Double.MAX_VALUE, 100.0);

final Panel pnlSettings = new Panel("Grid Settings");
final JLabel lblOverlap = new JLabel("Overlap (Y and Z) [%]");
final JLabel lblOverlap = new JLabel("Overlap (Y and Z) [%]:");
Spinner.setDefaultSize(4);
spnOverlapYZ_ = Spinner.createIntegerSpinner(10, 0, 100, 1);
cbxClearPositions_ = new CheckBox("Clear position list if YZ unused", false);


pnlX.add(lblXStart, "");
pnlX.add(lblXStart_, "");
pnlX.add(spnXStart_, "wrap");
pnlX.add(lblXStop, "");
pnlX.add(lblXStop_, "");
pnlX.add(spnXStop_, "wrap");
pnlX.add(lblXDelta, "");
pnlX.add(lblXDelta_, "");
pnlX.add(spnXDelta_, "wrap");
pnlX.add(lblXCount, "");
pnlX.add(lblXCount_, "");
pnlX.add(lblXCountValue_, "");

pnlY.add(lblYStart, "");
pnlY.add(lblYStart_, "");
pnlY.add(spnYStart_, "wrap");
pnlY.add(lblYStop, "");
pnlY.add(lblYStop_, "");
pnlY.add(spnYStop_, "wrap");
pnlY.add(lblYDelta, "");
pnlY.add(lblYDelta_, "");
pnlY.add(spnYDelta_, "wrap");
pnlY.add(lblYCount, "");
pnlY.add(lblYCount_, "");
pnlY.add(lblYCountValue_, "");

pnlZ.add(lblZStart, "");
pnlZ.add(lblZStart_, "");
pnlZ.add(spnZStart_, "wrap");
pnlZ.add(lblZStop, "");
pnlZ.add(lblZStop_, "");
pnlZ.add(spnZStop_, "wrap");
pnlZ.add(lblZDelta, "");
pnlZ.add(lblZDelta_, "");
pnlZ.add(spnZDelta_, "wrap");
pnlZ.add(lblZCount, "");
pnlZ.add(lblZCount_, "");
pnlZ.add(lblZCountValue_, "");

pnlSettings.add(lblOverlap, "split 2");
Expand All @@ -172,50 +189,127 @@ private void createUserInterface() {
}

private void createEventHandlers() {
final XYZGrid xyzGrid = model_.getXYZGrid();
final XYZGrid grid = model_.pluginSettings().xyzGrid();

// Check Boxes
cbxUseX_.registerListener(e ->
xyzGrid.setUseX(cbxUseX_.isSelected()));
cbxUseY_.registerListener(e ->
xyzGrid.setUseY(cbxUseY_.isSelected()));
cbxUseZ_.registerListener(e ->
xyzGrid.setUseZ(cbxUseZ_.isSelected()));
cbxUseX_.registerListener(e -> {
final boolean selected = cbxUseX_.isSelected();
grid.setUseX(selected);
setEnabledX(selected);
});

cbxUseY_.registerListener(e -> {
final boolean selected = cbxUseY_.isSelected();
grid.setUseY(selected);
setEnabledY(selected);
});

cbxUseZ_.registerListener(e -> {
final boolean selected = cbxUseZ_.isSelected();
grid.setUseZ(selected);
setEnabledZ(selected);
});

cbxClearPositions_.registerListener(e ->
grid.setClearYZ(cbxClearPositions_.isSelected()));

// Spinners X
spnXStart_.registerListener(e ->
xyzGrid.setStartX(spnXStart_.getDouble()));
grid.setStartX(spnXStart_.getDouble()));
spnXStop_.registerListener(e ->
xyzGrid.setStopX(spnXStop_.getDouble()));
grid.setStopX(spnXStop_.getDouble()));
spnXDelta_.registerListener(e ->
xyzGrid.setDeltaX(spnXDelta_.getDouble()));
grid.setDeltaX(spnXDelta_.getDouble()));

// Spinners Y
spnYStart_.registerListener(e ->
xyzGrid.setStartY(spnYStart_.getDouble()));
grid.setStartY(spnYStart_.getDouble()));
spnYStop_.registerListener(e ->
xyzGrid.setStopY(spnYStop_.getDouble()));
grid.setStopY(spnYStop_.getDouble()));
spnYDelta_.registerListener(e ->
xyzGrid.setDeltaY(spnYDelta_.getDouble()));
grid.setDeltaY(spnYDelta_.getDouble()));

// Spinners Z
spnZStart_.registerListener(e ->
xyzGrid.setStartZ(spnZStart_.getDouble()));
grid.setStartZ(spnZStart_.getDouble()));
spnZStop_.registerListener(e ->
xyzGrid.setStopZ(spnZStop_.getDouble()));
grid.setStopZ(spnZStop_.getDouble()));
spnZDelta_.registerListener(e ->
xyzGrid.setDeltaZ(spnZDelta_.getDouble()));
grid.setDeltaZ(spnZDelta_.getDouble()));

// Overlap
spnOverlapYZ_.registerListener(e ->
xyzGrid.setOverlapYZ(spnOverlapYZ_.getInt()));
grid.setOverlapYZ(spnOverlapYZ_.getInt()));

// Buttons
btnComputeGrid_.registerListener(e ->
xyzGrid.computeGrid());
btnComputeGrid_.registerListener(e -> {
grid.computeGrid(model_);
loadFromSettings();
});
btnEditPositionList_.registerListener(e ->
model_.studio().app().showPositionList());
btnRunOverviewAcq_.registerListener(e ->
model_.studio().logs().showError("Not implemented yet!"));
model_.studio().logs().showError("Not implemented yet!")); // TODO: !!!
}

private void loadFromSettings() {
final XYZGrid grid = model_.pluginSettings().xyzGrid();

cbxUseX_.setSelected(grid.getUseX());
cbxUseY_.setSelected(grid.getUseY());
cbxUseZ_.setSelected(grid.getUseZ());
cbxClearPositions_.setSelected(grid.getClearYZ());

spnXStart_.setValue(grid.getStartX());
spnYStart_.setValue(grid.getStartY());
spnZStart_.setValue(grid.getStartZ());

spnXStop_.setValue(grid.getStopX());
spnYStop_.setValue(grid.getStopY());
spnZStop_.setValue(grid.getStopZ());

spnXDelta_.setValue(grid.getDeltaX());
spnYDelta_.setValue(grid.getDeltaY());
spnZDelta_.setValue(grid.getDeltaZ());

spnOverlapYZ_.setValue(grid.getOverlapYZ());

// enable/disable based on loaded settings
setEnabledX(grid.getUseX());
setEnabledY(grid.getUseY());
setEnabledZ(grid.getUseZ());
}

private void setEnabledX(final boolean state) {
lblXStart_.setEnabled(state);
lblXStop_.setEnabled(state);
lblXDelta_.setEnabled(state);
spnXStart_.setEnabled(state);
spnXStop_.setEnabled(state);
spnXDelta_.setEnabled(state);
lblXCount_.setEnabled(state);
lblXCountValue_.setEnabled(state);
}

private void setEnabledY(final boolean state) {
lblYStart_.setEnabled(state);
lblYStop_.setEnabled(state);
lblYDelta_.setEnabled(state);
spnYStart_.setEnabled(state);
spnYStop_.setEnabled(state);
spnYDelta_.setEnabled(state);
lblYCount_.setEnabled(state);
lblYCountValue_.setEnabled(state);
}

private void setEnabledZ(final boolean state) {
lblZStart_.setEnabled(state);
lblZStop_.setEnabled(state);
lblZDelta_.setEnabled(state);
spnZStart_.setEnabled(state);
spnZStop_.setEnabled(state);
spnZDelta_.setEnabled(state);
lblZCount_.setEnabled(state);
lblZCountValue_.setEnabled(state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public class PluginSettings {

private boolean isPollingPositions_ = true;

private XYZGrid xyzGrid_ = new XYZGrid();

public XYZGrid xyzGrid() {
return xyzGrid_;
}

public void setPollingPositions(final boolean state) {
isPollingPositions_ = state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public class UserSettings {
private final String userName_;
private final MutablePropertyMapView settings_;

private static final String SETTINGS_PLUGIN = "LSM_PLUGIN_SETTINGS";

// This is the prefix String for saving the current acquisition settings
// based on the microscope geometry type, "LSM_ACQ_SETTINGS_SCAPE" for example.
// Note: GeometryType will be converted to uppercase: "LSM_ACQ_SETTINGS_DISPIM".
private static final String SETTINGS_KEY = "LSM_PLUGIN_SETTINGS";
private static final String SETTINGS_PREFIX_KEY = "LSM_ACQ_SETTINGS_";
private static final String SETTINGS_PREFIX = "LSM_ACQ_SETTINGS_";
private static final String SETTINGS_NOT_FOUND = "Settings Not Found";

// Note: increase this value based on the amount of nested json in the settings
Expand Down Expand Up @@ -75,7 +76,7 @@ public void load() {
final GeometryType geometryType = model_.devices()
.getDeviceAdapter().getMicroscopeGeometry();

final String key = SETTINGS_PREFIX_KEY + geometryType.toString().toUpperCase();
final String key = SETTINGS_PREFIX + geometryType.toString().toUpperCase();
final String json = settings_.getString(key, SETTINGS_NOT_FOUND);

// use default settings if settings data not found in profile
Expand All @@ -97,12 +98,12 @@ public void load() {
}

// load plugin settings or default plugin settings
final String jsonStr = settings_.getString(SETTINGS_KEY, SETTINGS_NOT_FOUND);
final String jsonStr = settings_.getString(SETTINGS_PLUGIN, SETTINGS_NOT_FOUND);
if (jsonStr.equals(SETTINGS_NOT_FOUND)) {
model_.studio().logs().logDebugMessage("settings not found, using default plugin settings.");
} else {
model_.pluginSettings(PluginSettings.fromJson(jsonStr));
model_.studio().logs().logDebugMessage("loaded PluginSettings from " + SETTINGS_KEY + ": "
model_.studio().logs().logDebugMessage("loaded PluginSettings from " + SETTINGS_PLUGIN + ": "
+ model_.pluginSettings().toPrettyJson());
}
}
Expand All @@ -117,7 +118,7 @@ public void save() {
// settings key based on geometry type
final GeometryType geometryType = model_.devices()
.getDeviceAdapter().getMicroscopeGeometry();
final String key = SETTINGS_PREFIX_KEY +
final String key = SETTINGS_PREFIX +
geometryType.toString().toUpperCase();

// save acquisition settings
Expand All @@ -126,8 +127,8 @@ public void save() {
+ model_.acquisitions().settings().toPrettyJson());

// save plugin settings
settings_.putString(SETTINGS_KEY, model_.pluginSettings().toJson());
model_.studio().logs().logDebugMessage("saved PluginSettings to " + SETTINGS_KEY + ": "
settings_.putString(SETTINGS_PLUGIN, model_.pluginSettings().toJson());
model_.studio().logs().logDebugMessage("saved PluginSettings to " + SETTINGS_PLUGIN + ": "
+ model_.pluginSettings().toPrettyJson());
}

Expand Down
Loading

0 comments on commit 6b9e286

Please sign in to comment.