Commit 02a7b0f9 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

border and background color are extracted from notes in the same way as other parameters

parent 7bb43312
......@@ -496,16 +496,6 @@ public class LayerXmlParser {
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equalsIgnoreCase("celldesigner:layerNotes")) {
String notes = XmlParser.getNodeValue(node).trim();
Color backgroundColor = extractBackgroundColor(notes);
if (backgroundColor != null) {
result.setBackgroundColor(backgroundColor);
notes = removeBackgroundColor(notes);
}
Color borderColor = extractBorderColor(notes);
if (borderColor != null) {
result.setBorderColor(borderColor);
notes = removeBorderColor(notes);
}
result.setNotes(notes);
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) {
result.setColor(commonParser.getColor(node));
......@@ -545,25 +535,6 @@ public class LayerXmlParser {
return result.toString();
}
Color extractBackgroundColor(String notes) {
return extractColor(notes, "BackgroundColor");
}
Color extractBorderColor(String notes) {
return extractColor(notes, "BorderColor");
}
private Color extractColor(String notes, String string) {
String lines[] = notes.split("[\n\r]+");
for (String line : lines) {
if (line.startsWith(string + "=") || line.startsWith(string + ":")) {
String colorString = line.replace(string + "=", "").replace(string + ":", "");
return new ColorParser().parse(colorString);
}
}
return null;
}
/**
* Transforms LayerText object into CellDesigner xml node.
*
......
package lcsb.mapviewer.converter.model.celldesigner.annotation;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
......@@ -134,6 +135,12 @@ public enum NoteField {
@ImportOnly
TRANSPARENCY_ZOOM_LEVEL_VISIBILITY("SemanticZoomLevelTransparency", Element.class, null),
@ImportOnly
BACKGROUND_COLOR("BackgroundColor", LayerText.class, null),
@ImportOnly
BORDER_COLOR("BorderColor", LayerText.class, null),
/**
* {@link Element#getSemanticZoomLevelVisibility()}.
*/
......
package lcsb.mapviewer.converter.model.celldesigner.annotation;
import java.awt.Color;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.*;
......@@ -14,7 +15,10 @@ import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.comparator.*;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.reaction.Reaction;
......@@ -761,10 +765,13 @@ public class RestAnnotationParser {
for (String string2 : string) {
boolean remove = false;
for (NoteField field : NoteField.values()) {
if (string2.startsWith(field.getCommonName() + ":") && field.getClazz().isAssignableFrom(object.getClass())) {
remove = true;
} else if (string2.startsWith(field.getCommonName() + "=")
&& field.getClazz().isAssignableFrom(object.getClass())) {
remove = true;
}
}
if (remove) {
annotations.append(string2 + "\n");
......@@ -775,7 +782,10 @@ public class RestAnnotationParser {
String ann = annotations.toString();
setZIndex(object, ann);
if (object instanceof LayerText) {
((LayerText) object).setNotes(newNotes.toString().trim());
LayerText layerText = (LayerText) object;
setBackgroundColor(layerText, ann);
setBorderColor(layerText, ann);
layerText.setNotes(newNotes.toString().trim());
}
if (object instanceof BioEntity) {
BioEntity bioEntity = (BioEntity) object;
......@@ -814,6 +824,47 @@ public class RestAnnotationParser {
}
}
private void setBackgroundColor(LayerText layerText, String ann) {
Color color = getColor(ann, NoteField.BACKGROUND_COLOR.getCommonName());
if (color == null) {
return;
}
if (layerText.getBackgroundColor() == null || layerText.getBackgroundColor().equals(Color.LIGHT_GRAY)) {
layerText.setBackgroundColor(color);
} else if (!layerText.getBackgroundColor().equals(color)) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, layerText),
" New background color different than default [" + color + "]["
+ layerText.getBackgroundColor() + "]. Ignoring.");
}
}
private void setBorderColor(LayerText layerText, String ann) {
Color color = getColor(ann, NoteField.BORDER_COLOR.getCommonName());
if (color == null) {
return;
}
if (layerText.getBorderColor() == null || layerText.getBorderColor().equals(Color.LIGHT_GRAY)) {
layerText.setBorderColor(color);
} else if (!layerText.getBorderColor().equals(color)) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, layerText),
" New border color different than default [" + color + "]["
+ layerText.getBorderColor() + "]. Ignoring.");
}
}
Color getColor(String notes, String string) {
String lines[] = notes.split("[\n\r]+");
for (String line : lines) {
if (line.startsWith(string + "=") || line.startsWith(string + ":")) {
String colorString = line.replace(string + "=", "").replace(string + ":", "");
return new ColorParser().parse(colorString);
}
}
return null;
}
/**
* Process RDF description from notes, removes it from the description and adds
* appropriate information to miriam data set.
......
......@@ -279,24 +279,6 @@ public class LayerXmlParserTest extends CellDesignerTestFunctions {
assertNotNull(xml);
}
@Test
public void testExtractBackgroundColor() throws Exception {
Color color = parser.extractBackgroundColor("dcxvxcvxcvx\nBackgroundColor=#ccffcc");
assertNotNull(color);
}
@Test
public void testExtractBackgroundColorWithColon() throws Exception {
Color color = parser.extractBackgroundColor("dcxvxcvxcvx\nBackgroundColor:#ccffcc");
assertNotNull(color);
}
@Test
public void testExtractNonExistingBackgroundColor() throws Exception {
Color color = parser.extractBackgroundColor("dcxvxcvxcvx\nBackgroundCffcc");
assertNull(color);
}
@Test
public void testRemoveBackgroundColor() throws Exception {
String notes = parser.removeBackgroundColor("dcxvxcvxcvx\nBackgroundColor=#ccffcc");
......
......@@ -2,6 +2,7 @@ package lcsb.mapviewer.converter.model.celldesigner.annotation;
import static org.junit.Assert.*;
import java.awt.Color;
import java.util.List;
import java.util.Set;
......@@ -18,6 +19,7 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.*;
......@@ -333,4 +335,27 @@ public class RestAnnotationParserTest extends CellDesignerTestFunctions {
assertFalse(protein.getNotes().contains("Description"));
}
@Test
public void testExtractBackgroundColor() throws Exception {
RestAnnotationParser parser = new RestAnnotationParser();
Color color = parser.getColor("dcxvxcvxcvx\nBackgroundColor=#ccffcc", NoteField.BACKGROUND_COLOR.getCommonName());
assertNotNull(color);
}
@Test
public void testExtractBackgroundColorWithColon() throws Exception {
RestAnnotationParser parser = new RestAnnotationParser();
Color color = parser.getColor("dcxvxcvxcvx\nBackgroundColor:#ccffcc", NoteField.BACKGROUND_COLOR.getCommonName());
assertNotNull(color);
}
@Test
public void testExtractNonExistingBackgroundColor() throws Exception {
RestAnnotationParser parser = new RestAnnotationParser();
Color color = parser.getColor("dcxvxcvxcvx\nBackgroundCffcc", NoteField.BACKGROUND_COLOR.getCommonName());
assertNull(color);
}
}
......@@ -4,6 +4,7 @@ import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.reaction.ReactionNode;
public class LogMarker implements Marker {
......@@ -29,6 +30,15 @@ public class LogMarker implements Marker {
}
}
public LogMarker(ProjectLogEntryType type, LayerText layerText) {
entry = new ProjectLogEntry();
entry.setType(type);
if (layerText != null) {
entry.setObjectIdentifier(layerText.getElementId());
entry.setObjectClass(layerText.getClass().getSimpleName());
}
}
public LogMarker(ProjectLogEntryType type, ReactionNode node) {
entry = new ProjectLogEntry();
entry.setType(type);
......
Supports Markdown
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