fixed LabelVisualizer to work with empty strings and null

parent 06a9e9ed
...@@ -328,9 +328,11 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe ...@@ -328,9 +328,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
if(!label.trim().isEmpty()) {
IndexedLineSet labelLineSet = ttfLineSetFactory.getIndexLineSet(prefix + label); //with the factory: generate a lineset out of the string 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 labelComponent.setGeometry(labelLineSet); // and set this lineset as geometry of the SGC
} }
}
/** /**
* Generates a String from given Data with chosen options. If the data is a Double it is rounded to have the chosen decimals. * Generates a String from given Data with chosen options. If the data is a Double it is rounded to have the chosen decimals.
...@@ -341,7 +343,9 @@ public class LabelVisualizer extends DataVisualizerPlugin implements ActionListe ...@@ -341,7 +343,9 @@ 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 = "";
} else if(data.getClass() == Double.class){
label = n.format(data); //cuts off the Double to have #decimals after comma and makes it a string label = n.format(data); //cuts off the Double to have #decimals after comma and makes it a string
}else{ }else{
label = data.toString(); label = data.toString();
......
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