Commit 2ece8676 authored by Stephane Dallongeville's avatar Stephane Dallongeville
Browse files

Added support for text /object descriptor (as 'name' or 'color')

parent 3a40a81b
package plugins.stef.roi.bloc.property;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -15,7 +16,7 @@ import icy.util.StringUtil;
import plugins.adufour.blocks.tools.roi.ROIBlock;
import plugins.adufour.blocks.util.VarList;
import plugins.adufour.vars.gui.model.ValueSelectionModel;
import plugins.adufour.vars.lang.VarDouble;
import plugins.adufour.vars.lang.VarMutable;
import plugins.adufour.vars.lang.VarROIArray;
import plugins.adufour.vars.lang.VarSequence;
import plugins.adufour.vars.lang.VarString;
......@@ -34,7 +35,7 @@ public class GetROIDescriptorValue extends Plugin implements ROIBlock, PluginLib
final protected VarROIArray rois = new VarROIArray("ROI", null);
final protected VarSequence sequence = new VarSequence("Sequence", null);
final protected VarString descriptors = new VarString("Value of", "");
final protected VarDouble value = new VarDouble("Value", 0d);
final protected VarMutable value = new VarMutable("Value", Double.class);
@Override
public void run()
......@@ -47,8 +48,6 @@ public class GetROIDescriptorValue extends Plugin implements ROIBlock, PluginLib
if (roiDescriptor == null)
throw new VarException(descriptors, "Cannot found '" + descriptorId + "' ROI descriptor !");
value.setValue(null);
for (ROI roi : rois.getValue())
{
if (roi != null)
......@@ -58,12 +57,44 @@ public class GetROIDescriptorValue extends Plugin implements ROIBlock, PluginLib
final Object res = roiDescriptor.compute(roi, seq);
if (res instanceof Number)
{
value.setType(Double.class);
value.setValue(Double.valueOf(((Number) res).doubleValue()));
}
else if (res instanceof Color)
{
final Color color = (Color) res;
String resString = StringUtil.toHexaString(color.getAlpha(), 2)
+ StringUtil.toHexaString(color.getRed(), 2)
+ StringUtil.toHexaString(color.getGreen(), 2)
+ StringUtil.toHexaString(color.getBlue(), 2);
// set color value in form of String
value.setType(String.class);
value.setValue(resString.toUpperCase());
}
else if (res instanceof String)
{
value.setType(String.class);
value.setValue(res);
}
else if (res != null)
{
value.setType(String.class);
value.setValue(res.toString());
}
else
{
value.setType(String.class);
value.setValue("");
}
}
catch (Exception e)
{
IcyExceptionHandler.showErrorMessage(e, false, true);
value.setValue(Double.valueOf(Double.NaN));
value.setType(String.class);
value.setValue("");
}
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment