Skip to content
Snippets Groups Projects
Commit 7ec74eda authored by Piotr Gawron's avatar Piotr Gawron
Browse files

sbml stroke contains code color

parent f204ea4a
No related branches found
No related tags found
1 merge request!706Resolve "Handle coloring of reaction parts"
package lcsb.mapviewer.common.comparator;
import java.util.Comparator;
import lcsb.mapviewer.common.Configuration;
/**
* Comparator used for {@link Float} class.
*
* @author Piotr Gawron
*
*/
public class FloatComparator implements Comparator<Float> {
/**
* Epsilon value used for comparison of doubles.
*/
private double epsilon;
/**
* Default constructor.
*/
public FloatComparator() {
this(Configuration.EPSILON);
}
/**
* Constructor that requires {@link #epsilon} parameter.
*
* @param epsilon
* {@link #epsilon}
*/
public FloatComparator(double epsilon) {
this.epsilon = epsilon;
}
@Override
public int compare(Float arg0, Float arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
if (Math.abs(arg0 - arg1) < epsilon) {
return 0;
} else {
return arg0.compareTo(arg1);
}
}
}
......@@ -294,10 +294,9 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
LocalStyle style = new LocalStyle();
style.setGroup(new RenderGroup());
renderInformation.addLocalStyle(style);
style.getGroup().setStroke(node.getLine().getType().name());
ColorDefinition color = getColorDefinition(node.getLine().getColor());
style.getGroup().setStroke(color.getId());
style.getGroup().setStrokeWidth(node.getLine().getWidth());
style.getGroup().setFill(color.getId());
style.getGroup().setStrokeDashArray(strokeToArray(node.getLine().getType().getStroke()));
return style;
......
......@@ -11,7 +11,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import lcsb.mapviewer.common.XmlParser;
import org.apache.log4j.Logger;
import org.sbml.jsbml.KineticLaw;
import org.sbml.jsbml.ListOf;
......@@ -31,6 +30,7 @@ import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderGroup;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
......@@ -414,8 +414,8 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
public void applyStyleToReaction(Reaction reactionWithLayout, LocalStyle style) {
RenderGroup group = style.getGroup();
if (group.getFill() != null) {
Color color = getColorByColorDefinition(group.getFill());
if (group.isSetStroke()) {
Color color = getColorByColorDefinition(group.getStroke());
for (AbstractNode node : reactionWithLayout.getNodes()) {
node.getLine().setColor(color);
}
......@@ -425,15 +425,10 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
node.getLine().setWidth(group.getStrokeWidth());
}
}
if (group.isSetStroke()) {
try {
LineType type = LineType.valueOf(group.getStroke());
for (AbstractNode node : reactionWithLayout.getNodes()) {
node.getLine().setType(type);
}
} catch (Exception e) {
logger.warn(new ElementUtils().getElementTag(reactionWithLayout) + "Problematic line type: "
+ group.getStroke(), e);
if (group.isSetStrokeDashArray()) {
LineType type = LineType.getTypeByDashArray(group.getStrokeDashArray());
for (AbstractNode node : reactionWithLayout.getNodes()) {
node.getLine().setType(type);
}
}
if (group.isSetEndHead()) {
......
......@@ -2,7 +2,9 @@ package lcsb.mapviewer.model.graphics;
import java.awt.BasicStroke;
import java.awt.Stroke;
import java.util.List;
import lcsb.mapviewer.common.comparator.FloatComparator;
import lcsb.mapviewer.common.geometry.CompositeStroke;
/**
......@@ -21,7 +23,7 @@ public enum LineType {
* Solid bold line.
*/
SOLID_BOLD(3),
/**
* Dash-dot-dot line:
*
......@@ -30,7 +32,7 @@ public enum LineType {
* </pre>
*/
DASH_DOT_DOT(1, new float[] { 11.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f }),
/**
* Dash-dot line:
*
......@@ -132,4 +134,25 @@ public enum LineType {
public Stroke getStroke() {
return stroke;
}
public static LineType getTypeByDashArray(List<Short> strokeDashArray) {
FloatComparator doubleComparator = new FloatComparator();
for (LineType type : LineType.values()) {
if (type.getStroke() instanceof BasicStroke) {
BasicStroke basicStroke = (BasicStroke) type.getStroke();
if (basicStroke.getDashArray() != null && strokeDashArray.size() == basicStroke.getDashArray().length) {
boolean match = true;
for (int i = 0; i < strokeDashArray.size(); i++) {
if (doubleComparator.compare(basicStroke.getDashArray()[i], (float) strokeDashArray.get(i)) != 0) {
match = false;
}
}
if (match) {
return type;
}
}
}
}
return LineType.SOLID;
}
}
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