fixed LabelVisualizer to work with empty strings and null

parent 06a9e9ed
...@@ -327,9 +327,11 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe ...@@ -327,9 +327,11 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
public Label(Node<?,?,?> node, Object data) { public Label(Node<?,?,?> node, Object data) {
String label = generateDataString(data); String label = generateDataString(data);
labelComponent = new SceneGraphComponent(getNodePrefix() + String.format("%0"+getNumDigits()+"d",node.getIndex())); //name the sgc with its prefix, e.g. V, and format s.t. leading zeros are added labelComponent = new SceneGraphComponent(getNodePrefix() + String.format("%0"+getNumDigits()+"d",node.getIndex())); //name the sgc with its prefix, e.g. V, and format s.t. leading zeros are added
IndexedLineSet labelLineSet = ttfLineSetFactory.getIndexLineSet(prefix + label); //with the factory: generate a lineset out of the string if(!label.trim().isEmpty()) {
labelComponent.setGeometry(labelLineSet); // and set this lineset as geometry of the SGC IndexedLineSet labelLineSet = ttfLineSetFactory.getIndexLineSet(prefix + label); //with the factory: generate a lineset out of the string
labelComponent.setGeometry(labelLineSet); // and set this lineset as geometry of the SGC
}
} }
/** /**
...@@ -341,11 +343,13 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe ...@@ -341,11 +343,13 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe
NumberFormat n = NumberFormat.getInstance(); NumberFormat n = NumberFormat.getInstance();
n.setMaximumFractionDigits(decimals); n.setMaximumFractionDigits(decimals);
String label = new String(); String label = new String();
if(data.getClass() == Double.class){ if(data == null) {
label = n.format(data); //cuts off the Double to have #decimals after comma and makes it a string label = "";
}else{ } else if(data.getClass() == Double.class){
label = data.toString(); label = n.format(data); //cuts off the Double to have #decimals after comma and makes it a string
} }else{
label = data.toString();
}
return label; return label;
} }
......
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