Skip to content
Snippets Groups Projects
Verified Commit 5b4bca98 authored by tristan.muller's avatar tristan.muller Committed by philippe.verley_ird.fr
Browse files

Add a listener for the min and max slider in the Colorbar preview.

parent b1ebba39
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ import javax.swing.JOptionPane;
import javax.swing.WindowConstants;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
import org.joml.Vector2f;
/**
* Main view of the project.
......@@ -144,10 +145,21 @@ public class MainView extends FrameView {
propertiesView.setParentView(this);
propertiesView.setOnChangePropertyCallback((name) -> {
if (scene != null) {
final float min = scene.getVoxelSpaceComponent().getFile().getMinPropertyValue(name);
final float max = scene.getVoxelSpaceComponent().getFile().getMaxPropertyValue(name);
final Vector2f minAndMax = scene.getVoxelSpaceComponent().getMinAndMaxPropertyValues();
final float min = minAndMax.x;
final float max = minAndMax.y;
final float medium = (max - min) / 2;
viewView.setGradientTexts(Float.toString(min),
viewView.setGradientTexts(Float.toString(min),
Float.toString(medium), Float.toString(max));
}
});
propertiesView.setOnChangeMinAndMaxCallback((name) -> {
if (scene != null) {
final Vector2f minAndMax = scene.getVoxelSpaceComponent().getMinAndMaxPropertyValues();
final float min = minAndMax.x;
final float max = minAndMax.y;
final float medium = (max - min) / 2;
viewView.setGradientTexts(Float.toString(min),
Float.toString(medium), Float.toString(max));
}
});
......
......@@ -58,6 +58,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
import org.joml.Vector2f;
/**
* Properties view of the project.
......@@ -83,6 +84,9 @@ public class PropertiesView extends FrameView {
@GuardedBy("this")
private Consumer<String> onChangePropertyCallback;
@GuardedBy("this")
private Consumer<Vector2f> onChangeMinAndMaxCallback;
private JXPanel minAndMaxPanel;
private JXLabel minAndMaxLabel;
......@@ -127,6 +131,11 @@ public class PropertiesView extends FrameView {
final Consumer<String> onChangePropertyCallback) {
this.onChangePropertyCallback = onChangePropertyCallback;
}
public final synchronized void setOnChangeMinAndMaxCallback(
final Consumer<Vector2f> onChangeMinAndMaxCallback) {
this.onChangeMinAndMaxCallback = onChangeMinAndMaxCallback;
}
public final synchronized void setColorBar(final Color[] colorBar) {
minAndMaxSlider.getModel().getThumbAt(0).setObject(colorBar[0]);
......@@ -272,10 +281,16 @@ public class PropertiesView extends FrameView {
public void thumbMoved(int thumb, float pos) {
if (thumb == minThumb) {
controller.changeMinAndMax(pos, lastMax);
if (onChangeMinAndMaxCallback != null) {
onChangeMinAndMaxCallback.accept(new Vector2f(pos, lastMax));
}
lastMin = pos;
}
if (thumb == maxThumb) {
controller.changeMinAndMax(lastMin, pos);
if (onChangeMinAndMaxCallback != null) {
onChangeMinAndMaxCallback.accept(new Vector2f(lastMin, pos));
}
lastMax = pos;
}
}
......
......@@ -54,13 +54,13 @@ public class ViewView extends FrameView {
private NephosPanel nephosPanel;
private JXPanel gradientPanel;
@GuardedBy("this")
private JXLabel gradientMinLabel;
@GuardedBy("this")
private JXLabel gradientMediumLabel;
@GuardedBy("this")
private JXLabel gradientMaxLabel;
......@@ -114,14 +114,15 @@ public class ViewView extends FrameView {
+ colors[maxID].getGreen() + colors[maxID].getBlue()) / 3f / 255;
gradientMaxLabel.setForeground(maxColor < 0.5f ? Color.WHITE : Color.BLACK);
gradientPanel.setBackgroundPainter(new ImagePainter((BufferedImage) ColorBars.asIcon(colors, gradientPanel.getWidth(),
gradientPanel.setBackgroundPainter(new ImagePainter((BufferedImage)
ColorBars.asIcon(colors, gradientPanel.getWidth(),
gradientPanel.getHeight()).getImage()));
} catch (Exception ex) {
}
}
public final synchronized void setGradientTexts(final String min,
public final synchronized void setGradientTexts(final String min,
final String medium, final String max) {
gradientMinLabel.setText(" " + min);
gradientMediumLabel.setText(medium);
......
......@@ -50,6 +50,7 @@ import java.util.Collection;
import java.util.Collections;
import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;
import org.joml.Vector2f;
/**
* Component used to display a voxel space.
......@@ -394,6 +395,17 @@ public class VoxelSpace extends Component {
setProperty(currentProperty);
}
/**
* Get the min and max values of the current property.
* @return
*/
public final synchronized Vector2f getMinAndMaxPropertyValues() {
final float minValue = file.getMinPropertyValue(currentProperty);
final float maxValue = file.getMaxPropertyValue(currentProperty);
return new Vector2f(minValue + (maxValue - minValue) * colorMin,
minValue + (maxValue - minValue) * colorMax);
}
/**
* Change if the fast drawing mode is enabled or not.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment