Skip to content
Snippets Groups Projects
Commit f890f4d0 authored by Daniel Schramm's avatar Daniel Schramm
Browse files

Recompute weighted distance immediately on any checkbox/slider action

parent 608c6fbd
No related branches found
No related tags found
No related merge requests found
......@@ -91,7 +91,7 @@ public class DistanceAction extends ControlPanelAction {
this.hausdorffDistance = null; // recompute only priorities
calculateHausdorffDistance();
break;
case DistancePanel.ACTION_COMMAND_WEIGHTED_DIST_RECOMPUTE:
case DistancePanel.ACTION_COMMAND_DISTANCE_RECOMPUTE:
this.visitor = null; // recompute
calculateHausdorffDistance();
break;
......
......@@ -6,15 +6,12 @@ import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.FeaturePointType;
import cz.fidentis.analyst.scene.DrawableFeaturePoints;
import cz.fidentis.analyst.symmetry.SymmetryPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
......@@ -43,7 +40,7 @@ public class DistancePanel extends ControlPanel {
public static final String ACTION_COMMAND_WEIGHTED_DISTANCE = "switch weighted distance on/off";
public static final String ACTION_COMMAND_FEATURE_POINT_HIGHLIGHT = "highlight feature point with color";
public static final String ACTION_COMMAND_FEATURE_POINT_RESIZE = "set size of feature point";
public static final String ACTION_COMMAND_WEIGHTED_DIST_RECOMPUTE = "recompute weighted distance";
public static final String ACTION_COMMAND_DISTANCE_RECOMPUTE = "recompute the Hausdorff distance";
/*
* Configuration of panel-specific GUI elements
......@@ -82,7 +79,7 @@ public class DistancePanel extends ControlPanel {
builder.addGap();
builder.addLine();
final JCheckBox weightedDistChBx = builder.addCheckBoxOptionLine(
builder.addCheckBoxOptionLine(
null,
"Weighted Hausdorff distance",
false,
......@@ -92,28 +89,22 @@ public class DistancePanel extends ControlPanel {
final JPanel featurePointsPanel = new JPanel();
final ControlPanelBuilder fpBuilder = new ControlPanelBuilder(featurePointsPanel);
final List<JCheckBox> fpCheckBoxes = new ArrayList<>(featurePoints.size());
final List<JTextField> fpSliderInputs = new ArrayList<>(featurePoints.size());
featurePointStats = new HashMap<>(featurePoints.size());
for (int i = 0; i < featurePoints.size(); i++) {
final FeaturePoint featurePoint = featurePoints.get(i);
final JCheckBox checkBox = fpBuilder.addCheckBox(
false,
createListener(action, ACTION_COMMAND_FEATURE_POINT_HIGHLIGHT, i)
createListener(action, ACTION_COMMAND_DISTANCE_RECOMPUTE)
);
checkBox.setText(featurePoint.getFeaturePointType().getName());
fpCheckBoxes.add(checkBox);
checkBox.addActionListener(createListener(action, ACTION_COMMAND_FEATURE_POINT_HIGHLIGHT, i));
final JTextField sliderInput = fpBuilder.addSliderOptionLine(
null,
null,
100,
createListener(action, ACTION_COMMAND_FEATURE_POINT_RESIZE, i)
);
final JTextField sliderInput = fpBuilder.addSliderOptionLine(null, null, 100, null);
sliderInput.setText(ControlPanelBuilder.doubleToStringLocale(DrawableFeaturePoints.DEFAULT_SIZE));
sliderInput.postActionEvent();
fpSliderInputs.add(sliderInput);
sliderInput.postActionEvent(); // Set correct position of slider
sliderInput.addActionListener(createListener(action, ACTION_COMMAND_DISTANCE_RECOMPUTE));
sliderInput.addActionListener(createListener(action, ACTION_COMMAND_FEATURE_POINT_RESIZE, i));
fpBuilder.addGap();
featurePointStats.put(featurePoint.getFeaturePointType(), fpBuilder.addLabelLine(null));
......@@ -125,37 +116,6 @@ public class DistancePanel extends ControlPanel {
.setBorder(BorderFactory.createTitledBorder("Feature points"));
builder.addLine();
final JButton recomputeButton = builder.addButton(
"Recompute",
createListener(action, ACTION_COMMAND_WEIGHTED_DIST_RECOMPUTE)
);
recomputeButton.setEnabled(false);
recomputeButton.addActionListener((ActionEvent ae) ->
recomputeButton.setEnabled(false)
);
weightedDistChBx.addActionListener((ActionEvent ae) -> {
if (!weightedDistChBx.isSelected()) {
recomputeButton.setEnabled(false);
}
});
for (final JCheckBox checkBox: fpCheckBoxes) {
checkBox.addActionListener((ActionEvent ae) -> {
if (weightedDistChBx.isSelected()) {
recomputeButton.setEnabled(true);
}
});
}
for (int i = 0; i < fpSliderInputs.size(); i++) {
final JTextField sliderInput = fpSliderInputs.get(i);
final JCheckBox sliderCheckBox = fpCheckBoxes.get(i);
sliderInput.addActionListener((ActionEvent ae) -> {
if (weightedDistChBx.isSelected() && sliderCheckBox.isSelected()) {
recomputeButton.setEnabled(true);
}
});
}
builder.addLine();
builder.addCaptionLine("Visualization options:");
builder.addLine();
builder.addCheckBoxOptionLine(
......
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