Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Info Tool Bar and Location Card #167

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update source info toolbar and location card sliders when source changes
trautmane committed Oct 25, 2023
commit bb1f4e25a3da96861dbb009e118ca69b498b502c
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ public class DimensionCoordinateComponents {
public static final String DEFAULT_VALUE_FORMAT = "%1.0f";

private final int dimension;
private final double minPosition;
private final double maxPosition;
private double minPosition;
private double maxPosition;
private final JLabel valueLabel;
private final JTextField valueTextField;
private final JSlider valueSlider;
@@ -60,8 +60,6 @@ public DimensionCoordinateComponents(final String name,

this.dimension = dimension;
this.dimensionValueChangeListener = null;
this.minPosition = minPosition;
this.maxPosition = maxPosition;
this.valueFormat = valueFormat;
this.position = 0.0;

@@ -77,13 +75,8 @@ public DimensionCoordinateComponents(final String name,
this.valueSlider = new JSlider();
this.valueSlider.setMajorTickSpacing(25);
this.valueSlider.setPaintTicks(true);

final Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
labelTable.put(0, new JLabel(formatSliderValue(minPosition)));
labelTable.put(100, new JLabel(formatSliderValue(maxPosition)));
this.valueSlider.setLabelTable(labelTable);

this.valueSlider.setPaintLabels(true);
this.setMinAndMaxPosition(minPosition, maxPosition);

this.sliderChangeListener = e -> {
setPosition(getSliderPosition());
@@ -122,6 +115,16 @@ public JSlider getValueSlider() {
return valueSlider;
}

public void setMinAndMaxPosition(final double minPosition,
final double maxPosition) {
this.minPosition = minPosition;
this.maxPosition = maxPosition;
final Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
labelTable.put(0, new JLabel(formatSliderValue(minPosition)));
labelTable.put(100, new JLabel(formatSliderValue(maxPosition)));
this.valueSlider.setLabelTable(labelTable);
}

public void setNextDimensionComponents(final DimensionCoordinateComponents nextDimensionComponents) {
this.nextDimensionComponents = nextDimensionComponents;
}
7 changes: 7 additions & 0 deletions src/main/java/bdv/viewer/location/LocationPanel.java
Original file line number Diff line number Diff line change
@@ -78,6 +78,13 @@ public void setDimensionValueChangeListener(final ChangeListener changeListener)
}
}

public void setSourceInterval(final Interval sourceInterval) {
for (int dimension = 0; dimension < sourceInterval.numDimensions(); dimension++) {
this.dimensionComponentsList.get(dimension).setMinAndMaxPosition(sourceInterval.min(dimension),
sourceInterval.max(dimension));
}
}

public void requestFocusOnFirstComponent() {
if (! dimensionComponentsList.isEmpty()) {
this.dimensionComponentsList.get(0).getValueTextField().requestFocus();
Original file line number Diff line number Diff line change
@@ -41,18 +41,23 @@
import bdv.ui.appearance.Appearance;
import bdv.ui.appearance.AppearanceManager;
import bdv.ui.splitpanel.SplitPanel;
import bdv.viewer.Source;
import bdv.viewer.SourceAndConverter;
import bdv.viewer.ViewerFrame;
import bdv.viewer.ViewerPanel;
import bdv.viewer.ViewerStateChange;
import bdv.viewer.ViewerStateChangeListener;
import bdv.viewer.overlay.SourceInfoOverlayRenderer;
import net.imglib2.Interval;
import net.imglib2.RealPoint;
import net.imglib2.util.Intervals;

/**
* Helper class to set up the highly-coupled SourceInfoToolBar and LocationPanel UI components.
*
* @author Eric Trautman
*/
public class SourceInfoToolbarAndLocationCardManager {
public class SourceInfoToolbarAndLocationCardManager implements ViewerStateChangeListener {
private final AppearanceManager appearanceManager;
private final ViewerPanel viewer;
private final SourceInfoToolBar sourceInfoToolBar;
@@ -70,8 +75,7 @@ public SourceInfoToolbarAndLocationCardManager(final AppearanceManager appearanc
updateListeners.add(() -> sourceInfoToolBar.setVisible(showSourceInfoToolBar()));

// create card locationPanel and connect it to sourceInfoToolBar
final Interval interval = viewer.state().getCurrentSource().getSpimSource().getSource(0, 0);
this.locationPanel = new LocationPanel(interval);
this.locationPanel = new LocationPanel(getCurrentSourceInterval());
locationPanel.setDimensionValueChangeListener(e -> {
final DimensionCoordinateComponents coordinateComponents = (DimensionCoordinateComponents) e.getSource();
viewer.centerViewAt(coordinateComponents.getPosition(),
@@ -82,6 +86,10 @@ public SourceInfoToolbarAndLocationCardManager(final AppearanceManager appearanc
sourceInfoToolBar.revalidate();
});

// register for (source) state change updates
viewer.state().changeListeners().add(this);

// register for mouse events
addViewerMouseListeners();

// populate everything with starting location info
@@ -114,6 +122,39 @@ public void addLocationCardToSplitPanel(final SplitPanel splitPanel,
});
}

@Override
public void viewerStateChanged(final ViewerStateChange change) {
switch (change) {
case CURRENT_SOURCE_CHANGED:
case GROUP_NAME_CHANGED:
case CURRENT_GROUP_CHANGED:
case CURRENT_TIMEPOINT_CHANGED:
case NUM_TIMEPOINTS_CHANGED:
updateSourceInfo();
locationPanel.setSourceInterval(getCurrentSourceInterval());
break;
case VIEWER_TRANSFORM_CHANGED:
updateCenterPosition();
updateMousePosition();
}
}

private Interval getCurrentSourceInterval() {
Interval interval = null;
final SourceAndConverter<?> currentSource = viewer.state().getCurrentSource();
if (currentSource != null) {
final Source<?> spimSource = currentSource.getSpimSource();
if (spimSource != null) {
final int timePoint = viewer.state().getCurrentTimepoint();
interval = spimSource.getSource(timePoint, 0);
}
}
if (interval == null) {
interval = Intervals.createMinMax(0, 0, 0, 0, 0, 0);
}
return interval;
}

private boolean showSourceInfoToolBar() {
return appearanceManager.appearance().showSourceInfoToolBar();
}
37 changes: 21 additions & 16 deletions src/test/java/bdv/viewer/location/GridViewerTest.java
Original file line number Diff line number Diff line change
@@ -58,12 +58,17 @@ public static void main(String[] args)
final ProgressWriterConsole progressWriter = new ProgressWriterConsole();
final ViewerOptions viewerOptions = ViewerOptions.options();

final RealARGBColorConverter<IntType> converter = RealARGBColorConverter.create(new IntType(), 0, 127);
final ConverterSetup converterSetup = new RealARGBColorConverterSetup(0, converter);
converterSetups.add(converterSetup);
for (int i = 0; i < 3; i++) {
final RealARGBColorConverter<IntType> converter = RealARGBColorConverter.create(new IntType(), 0, 127);
final ConverterSetup converterSetup = new RealARGBColorConverterSetup(i, converter);
converterSetups.add(converterSetup);

final SourceAndConverter<IntType> soc = new SourceAndConverter<>(GRID_SOURCE, converter);
sources.add(soc);
final String suffix = String.valueOf((char)('A' + i));
final int size = 100 * (i + 1);
final RealRandomAccessibleSource<IntType> source = buildGridSource("Grid " + suffix, size);
final SourceAndConverter<IntType> soc = new SourceAndConverter<>(source, converter);
sources.add(soc);
}

BigDataViewer.open(converterSetups,
sources,
@@ -94,15 +99,15 @@ public static void main(String[] args)
},
IntType::new);

public static final RealRandomAccessibleSource<IntType> GRID_SOURCE =
new RealRandomAccessibleSource<IntType>(GRID, new IntType(), "Grid" ) {
private final int s = 100;
private final Interval interval = Intervals.createMinMax(-s, -s, -s, s, s, s);
@Override
public Interval getInterval(final int t,
final int level) {
return interval;
}
};

public static RealRandomAccessibleSource<IntType> buildGridSource(final String name,
final int size) {
return new RealRandomAccessibleSource<IntType>(GRID, new IntType(), name) {
private final Interval interval = Intervals.createMinMax(-size, -size, -size, size, size, size);
@Override
public Interval getInterval(final int t,
final int level) {
return interval;
}
};
}
}