Commit 384243b2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

parsing and processing background color for layer texts

parent 1a7fc855
Pipeline #6563 failed with stage
in 6 minutes and 43 seconds
......@@ -7,7 +7,7 @@ import java.util.Map;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
/**
* Parser clas to extract {@link Color} objects from {@link String}.
* Parser class to extract {@link Color} objects from {@link String}.
*
* @author Piotr Gawron
*
......@@ -74,4 +74,16 @@ public class ColorParser {
result.put("rgb", color.getRGB());
return result;
}
/**
* Transforms {@link Color} into html RGB representation: #RRGGBB
*
* @param color
* @return
*/
public String colorToHtml(Color color) {
return "#" + String.format("%02x", color.getRed()) + String.format("%02x", color.getGreen())
+ String.format("%02x", color.getBlue());
}
}
......@@ -14,55 +14,72 @@ import lcsb.mapviewer.common.exception.InvalidArgumentException;
public class ColorParserTest {
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSetInvalidColor() throws Exception {
try {
ColorParser parser = new ColorParser();
parser.parse("qwe");
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetInvalidColor() throws Exception {
try {
ColorParser parser = new ColorParser();
parser.parse("qwe");
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetInvalidColor2() throws Exception {
try {
ColorParser parser = new ColorParser();
parser.parse("fffffff");
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetInvalidColor2() throws Exception {
try {
ColorParser parser = new ColorParser();
parser.parse("fffffff");
fail("Exception expected");
} catch (InvalidArgumentException e) {
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetColor() throws Exception {
try {
ColorParser parser = new ColorParser();
Color color = parser.parse("#ffffff");
assertEquals(Color.WHITE, color);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetColor() throws Exception {
try {
ColorParser parser = new ColorParser();
Color color = parser.parse("#ffffff");
assertEquals(Color.WHITE, color);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSetColorToHtmlString() throws Exception {
try {
ColorParser parser = new ColorParser();
String colorString = "#ffffff";
Color color = parser.parse(colorString);
assertEquals(colorString, parser.colorToHtml(color));
colorString = "#fc00ff";
color = parser.parse(colorString);
assertEquals(colorString, parser.colorToHtml(color));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
......@@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
......@@ -23,15 +24,15 @@ import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.kinetics.SbmlUnitType;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.AntisenseRna;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.AbstractSiteModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
......@@ -54,9 +55,8 @@ public class ComplexParserTests extends CellDesignerTestFunctions {
@Test
public void testParseFunctions() throws Exception {
Model model;
try {
model = getModelForFile("testFiles/function.xml");
Model model = getModelForFile("testFiles/function.xml");
assertEquals(1, model.getFunctions().size());
......@@ -66,6 +66,24 @@ public class ComplexParserTests extends CellDesignerTestFunctions {
}
}
@Test
public void testParseTextWithBackground() throws Exception {
try {
Model model = getModelForFile("testFiles/layer_text_with_background.xml");
Layer layer = model.getLayers().iterator().next();
LayerText text = layer.getTexts().get(0);
assertFalse(text.getBackgroundColor().equals(Color.LIGHT_GRAY));
assertFalse(text.getNotes().contains("BackgroundColor"));
text = layer.getTexts().get(1);
assertTrue(text.getBackgroundColor().equals(Color.LIGHT_GRAY));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testParseParameters() throws Exception {
try {
......
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" xmlns:celldesigner="http://www.sbml.org/2001/ns/celldesigner" level="2" version="4">
<model metaid="untitled" id="untitled">
<annotation>
<celldesigner:extension>
<celldesigner:modelVersion>4.0</celldesigner:modelVersion>
<celldesigner:modelDisplay sizeX="600" sizeY="400"/>
<celldesigner:listOfCompartmentAliases/>
<celldesigner:listOfComplexSpeciesAliases/>
<celldesigner:listOfSpeciesAliases/>
<celldesigner:listOfGroups/>
<celldesigner:listOfProteins/>
<celldesigner:listOfGenes/>
<celldesigner:listOfRNAs/>
<celldesigner:listOfAntisenseRNAs/>
<celldesigner:listOfLayers>
<celldesigner:layer id="1" name="Layer0001" locked="false" visible="true">
<celldesigner:listOfTexts>
<celldesigner:layerSpeciesAlias x="0.0" y="0.0">
<celldesigner:layerNotes>
dcxvxcvxcvx
BackgroundColor=#ccffcc
</celldesigner:layerNotes>
<celldesigner:bounds x="63.0" y="42.0" w="338.0" h="216.0"/>
<celldesigner:paint color="ff5e4da9"/>
<celldesigner:font size="16"/>
</celldesigner:layerSpeciesAlias>
<celldesigner:layerSpeciesAlias x="0.0" y="0.0">
<celldesigner:layerNotes>
xx
</celldesigner:layerNotes>
<celldesigner:bounds x="445.0" y="53.0" w="104.0" h="63.0"/>
<celldesigner:paint color="ff000000"/>
<celldesigner:font size="11"/>
</celldesigner:layerSpeciesAlias>
<celldesigner:layerSpeciesAlias x="0.0" y="0.0">
<celldesigner:layerNotes>
yy
</celldesigner:layerNotes>
<celldesigner:bounds x="148.0" y="318.0" w="301.0" h="48.0"/>
<celldesigner:paint color="ff000000"/>
<celldesigner:font size="11"/>
</celldesigner:layerSpeciesAlias>
</celldesigner:listOfTexts>
</celldesigner:layer>
</celldesigner:listOfLayers>
<celldesigner:listOfBlockDiagrams/>
</celldesigner:extension>
</annotation>
<listOfUnitDefinitions>
<unitDefinition metaid="substance" id="substance" name="substance">
<listOfUnits>
<unit metaid="CDMT00001" kind="mole"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="volume" id="volume" name="volume">
<listOfUnits>
<unit metaid="CDMT00002" kind="litre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="area" id="area" name="area">
<listOfUnits>
<unit metaid="CDMT00003" kind="metre" exponent="2"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="length" id="length" name="length">
<listOfUnits>
<unit metaid="CDMT00004" kind="metre"/>
</listOfUnits>
</unitDefinition>
<unitDefinition metaid="time" id="time" name="time">
<listOfUnits>
<unit metaid="CDMT00005" kind="second"/>
</listOfUnits>
</unitDefinition>
</listOfUnitDefinitions>
<listOfCompartments>
<compartment metaid="default" id="default" size="1" units="volume"/>
</listOfCompartments>
</model>
</sbml>
......@@ -35,11 +35,6 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom
super(colorExtractor);
}
/**
* Background color of drawn compartments.
*/
private Color backgroundColor = Color.LIGHT_GRAY;
@Override
public void draw(final PathwayCompartment compartment, final Graphics2D graphics, final ConverterParams params)
throws DrawingException {
......@@ -50,16 +45,15 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom
Shape shape = new Rectangle2D.Double(compartment.getX(), compartment.getY(), compartment.getWidth(),
compartment.getHeight());
Color color = compartment.getColor();
Color color = compartment.getFontColor();
Color backgroundColor = compartment.getColor();
// fill the background
boolean fill = !isTransparent(compartment, params);
if (fill) {
graphics.setColor(backgroundColor);
} else {
Color bgAlphaColor = new Color(0, 0, 0, getAlphaLevel());
graphics.setColor(bgAlphaColor);
if (!fill) {
backgroundColor = new Color(0, 0, 0, getAlphaLevel());
}
graphics.setColor(backgroundColor);
graphics.fill(shape);
// draw the border
......
......@@ -152,7 +152,7 @@ public class CreateHierarchyCommand extends ModelCommand {
alias.setY(rect.getY());
alias.setWidth(rect.getWidth());
alias.setHeight(rect.getHeight());
alias.setColor(rect.getColor());
alias.setFontColor(rect.getColor());
alias.setNamePoint(new Point2D.Double(rect.getX() + DEFAULT_TITLE_X_COORD_IN_ARTIFITIAL_COMPARTMENT,
rect.getY() + DEFAULT_TITLE_Y_COORD_IN_ARTIFITIAL_COMPARTMENT));
......@@ -164,7 +164,8 @@ public class CreateHierarchyCommand extends ModelCommand {
alias.setY(text.getY());
alias.setWidth(text.getWidth());
alias.setHeight(text.getHeight());
alias.setColor(text.getColor());
alias.setFontColor(text.getColor());
alias.setColor(text.getBackgroundColor());
alias.setName(text.getNotes().trim());
alias.setNamePoint(new Point2D.Double(text.getX() + DEFAULT_TITLE_X_COORD_IN_ARTIFITIAL_COMPARTMENT,
text.getY() + DEFAULT_TITLE_Y_COORD_IN_ARTIFITIAL_COMPARTMENT));
......
package lcsb.mapviewer.model.map.compartment;
import java.awt.Color;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
......@@ -15,46 +17,47 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
@DiscriminatorValue("Pathway Compartment")
public class PathwayCompartment extends Compartment {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Empty constructor required by hibernate.
*/
PathwayCompartment() {
super();
}
/**
* Default constructor.
*
* @param elementId
* identifier of the compartment
*/
public PathwayCompartment(String elementId) {
super();
setElementId(elementId);
}
/**
* Constructor that intialize object with the data given in the parameter.
*
* @param original
* data for initialization
*/
public PathwayCompartment(PathwayCompartment original) {
super(original);
}
@Override
public PathwayCompartment copy() {
if (this.getClass() == PathwayCompartment.class) {
return new PathwayCompartment(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Empty constructor required by hibernate.
*/
PathwayCompartment() {
super();
}
/**
* Default constructor.
*
* @param elementId
* identifier of the compartment
*/
public PathwayCompartment(String elementId) {
super();
setElementId(elementId);
setColor(Color.LIGHT_GRAY);
}
/**
* Constructor that initialize object with the data given in the parameter.
*
* @param original
* data for initialization
*/
public PathwayCompartment(PathwayCompartment original) {
super(original);
}
@Override
public PathwayCompartment copy() {
if (this.getClass() == PathwayCompartment.class) {
return new PathwayCompartment(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
}
......@@ -24,314 +24,332 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
@Entity
public class LayerText implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default font size of the text.
*/
private static final double DEFAULT_LAYER_FONT_SIZE = 11.0;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(LayerText.class);
/**
* Unique database identifier.
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idDb", unique = true, nullable = false)
private int id;
/**
* Text color.
*/
private Color color = Color.BLACK;
/**
* X coordinate of text start point.
*/
private Double x = 0.0;
/**
* Y coordinate of text start point.
*/
private Double y = 0.0;
/**
* Width of the rectangle where text is drawn.
*/
private Double width = 0.0;
/**
* Height of the rectangle where text is drawn.
*/
private Double height = 0.0;
/**
* Text.
*/
private String notes;
/**
* Font size.
*/
private Double fontSize = DEFAULT_LAYER_FONT_SIZE;
/**
* Default constructor.
*/
public LayerText() {
}
/**
* Default constructor.
*
* @param bound
* bounds in which text is placed
* @param text
* {@link #notes text}
*/
public LayerText(Rectangle2D bound, String text) {
setX(bound.getX());
setY(bound.getY());
setWidth(bound.getWidth());
setHeight(bound.getHeight());
setNotes(text);
}
/**
* Constructor that copies data from the parameter.
*
* @param layerText
* from this paramter line data will be copied
*/
public LayerText(LayerText layerText) {
color = layerText.getColor();
x = layerText.getX();
y = layerText.getY();
width = layerText.getWidth();
height = layerText.getHeight();
notes = layerText.getNotes();
fontSize = layerText.getFontSize();
}
/**
* Set x from string containing double value.
*
* @param param
* x of the line in text format
*/
public void setX(String param) {
try {
x = Double.parseDouble(param);
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid x value: " + param, e);
}
}
/**
* Set y from string containing double value.
*
* @param param
* y of the line in text format
*/
public void setY(String param) {
try {
y = Double.parseDouble(param);
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid y value: " + param, e);
}
}
/**
* Set width from string containing double value.
*
* @param param
* width of the line in text format
*/
public void setWidth(String param) {
try {
width = Double.parseDouble(param);
} catch (NumberFormatException e) {