Commit a6493bf3 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

border color is used when drawing species

parent fa31a7e3
......@@ -41,12 +41,12 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> {
@Override
protected void drawImpl(final AntisenseRna antisenseRna, final Graphics2D graphics, final ConverterParams params) {
Color oldColor = graphics.getColor();
GeneralPath path = getAntisenseRnaPath(antisenseRna);
Color c = graphics.getColor();
graphics.setColor(antisenseRna.getFillColor());
graphics.fill(path);
graphics.setColor(c);
Stroke stroke = graphics.getStroke();
graphics.setColor(antisenseRna.getBorderColor());
graphics.setStroke(getBorderLine(antisenseRna));
graphics.draw(path);
graphics.setStroke(stroke);
......@@ -56,6 +56,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> {
}
drawText(antisenseRna, graphics, params);
graphics.setColor(oldColor);
}
/**
......
......@@ -56,6 +56,7 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
if (complex.getState().equalsIgnoreCase("complexnoborder")) {
return;
}
Color oldColor = graphics.getColor();
int homodir;
if (params.isSbgnFormat()) {
......@@ -81,11 +82,10 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
GeneralPath path = getAliasPath(complex);
Color c = graphics.getColor();
Stroke stroke = graphics.getStroke();
graphics.setColor(complex.getFillColor());
graphics.fill(path);
graphics.setColor(c);
graphics.setColor(complex.getBorderColor());
graphics.setStroke(getBorderLine(complex));
graphics.draw(path);
......@@ -131,6 +131,7 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
drawStructuralState(complex.getStructuralState(), graphics);
drawText(complex, graphics, params);
graphics.setColor(oldColor);
}
@Override
......@@ -142,8 +143,10 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
return;
}
}
Color oldColor = graphics.getColor();
String text = getText(complex);
try {
graphics.setColor(complex.getFontColor());
double fontSize = DEFAULT_SPECIES_FONT_SIZE;
if (complex.getFontSize() != null) {
fontSize = complex.getFontSize();
......@@ -152,6 +155,8 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
complex.getBorder(), text);
FontFinder.drawText(size, Font.SANS_SERIF, graphics, complex.getBorder(), text);
} catch (RectangleTooSmallException e) {
} finally {
graphics.setColor(oldColor);
}
}
......
......@@ -64,15 +64,16 @@ public class DegradedConverter extends SpeciesConverter<Degraded> {
path.closePath();
a1.exclusiveOr(new Area(path));
Color c = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(degraded.getFillColor());
graphics.fill(a1);
graphics.setColor(c);
graphics.setColor(degraded.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(degraded));
graphics.draw(a1);
graphics.setStroke(stroke);
drawText(degraded, graphics, params);
graphics.setColor(oldColor);
}
/**
......
......@@ -70,16 +70,17 @@ public class DrugConverter extends SpeciesConverter<Drug> {
drug.getX() + offset, drug.getY() + offset, drug.getWidth() - 2 * offset, drug.getHeight() - 2 * offset,
RECTANGLE_CORNER_ARC_SIZE,
RECTANGLE_CORNER_ARC_SIZE);
Color c = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(drug.getFillColor());
graphics.fill(a1);
graphics.setColor(c);
graphics.setColor(drug.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(drug));
graphics.draw(a1);
graphics.draw(a2);
graphics.setStroke(stroke);
drawText(drug, graphics, params);
graphics.setColor(oldColor);
}
/**
......
......@@ -45,7 +45,7 @@ public class GeneConverter extends SpeciesConverter<Gene> {
Color c = graphics.getColor();
graphics.setColor(gene.getFillColor());
graphics.fill(shape);
graphics.setColor(c);
graphics.setColor(gene.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(gene));
graphics.draw(shape);
......@@ -56,6 +56,7 @@ public class GeneConverter extends SpeciesConverter<Gene> {
}
drawText(gene, graphics, params);
graphics.setColor(c);
}
/**
......
......@@ -45,15 +45,16 @@ public class IonConverter extends SpeciesConverter<Ion> {
double x = getXCoord(ion, diameter);
double y = getYCoord(ion);
Shape shape = new Ellipse2D.Double(x, y, diameter, diameter);
Color c = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(ion.getFillColor());
graphics.fill(shape);
graphics.setColor(c);
graphics.setColor(ion.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(ion));
graphics.draw(shape);
graphics.setStroke(stroke);
drawText(ion, graphics, params);
graphics.setColor(oldColor);
}
/**
......
......@@ -41,15 +41,16 @@ public class PhenotypeConverter extends SpeciesConverter<Phenotype> {
protected void drawImpl(Phenotype phenotype, final Graphics2D graphics, final ConverterParams params) {
GeneralPath path = getPhenotypePath(phenotype);
Color c = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(phenotype.getFillColor());
graphics.fill(path);
graphics.setColor(c);
graphics.setColor(phenotype.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(phenotype));
graphics.draw(path);
graphics.setStroke(stroke);
drawText(phenotype, graphics, params);
graphics.setColor(oldColor);
}
/**
......
......@@ -148,14 +148,15 @@ public class ProteinConverter extends SpeciesConverter<Protein> {
logger.warn(eu.getElementTag(protein) + "Unknown shape for protein");
shape = getDefaultAliasShape(protein);
}
Color c = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(protein.getFillColor());
graphics.fill(shape);
graphics.setColor(c);
graphics.setColor(protein.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(protein));
graphics.draw(shape);
graphics.setStroke(stroke);
graphics.setColor(oldColor);
// SBGN display mode - units of information and state variables are
// printed on the top element only
......
......@@ -48,14 +48,15 @@ public class RnaConverter extends SpeciesConverter<Rna> {
@Override
protected void drawImpl(final Rna rna, final Graphics2D graphics, final ConverterParams params) {
GeneralPath path = getRnaPath(rna);
Color c = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(rna.getFillColor());
graphics.fill(path);
graphics.setColor(c);
graphics.setColor(rna.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(rna));
graphics.draw(path);
graphics.setStroke(stroke);
graphics.setColor(oldColor);
for (ModificationResidue mr : rna.getRegions()) {
drawModification(mr, graphics, false);
......
......@@ -72,14 +72,15 @@ public class SimpleMoleculeConverter extends SpeciesConverter<SimpleMolecule> {
simpleMolecule.setY(simpleMolecule.getY() - SpeciesConverter.HOMODIMER_OFFSET);
Shape shape = new Ellipse2D.Double(simpleMolecule.getX(), simpleMolecule.getY(), simpleMolecule.getWidth(),
simpleMolecule.getHeight());
Color c = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(simpleMolecule.getFillColor());
graphics.fill(shape);
graphics.setColor(c);
graphics.setColor(simpleMolecule.getBorderColor());
Stroke stroke = graphics.getStroke();
graphics.setStroke(getBorderLine(simpleMolecule));
graphics.draw(shape);
graphics.setStroke(stroke);
graphics.setColor(oldColor);
// SBGN view - multimers are displayed with a unit of information
// containing cardinality
......
......@@ -6,7 +6,8 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ ComplexConverterTest.class,
SpeciesConverterTest.class })
SpeciesConverterTest.class,
SpeciesGenericConverterTests.class })
public class AllSpeciesConverterTests {
}
......@@ -3,7 +3,8 @@ package lcsb.mapviewer.converter.graphics.bioEntity.element.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.awt.*;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import org.apache.logging.log4j.LogManager;
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atLeastOnce;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.GraphicsTestFunctions;
import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverter;
import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverterImpl;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.*;
@RunWith(Parameterized.class)
public class SpeciesGenericConverterTests extends GraphicsTestFunctions {
Logger logger = LogManager.getLogger();
ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN, Color.BLUE);
private Element species;
public SpeciesGenericConverterTests(Species species) {
this.species = species;
}
@Parameters(name = "{index} : {0}")
public static Collection<Object[]> data() throws IOException {
Collection<Object[]> data = new ArrayList<Object[]>();
data.add(new Object[] { assignData(new AntisenseRna("id")) });
data.add(new Object[] { assignData(new Complex("id")) });
data.add(new Object[] { assignData(new Degraded("id")) });
data.add(new Object[] { assignData(new Drug("id")) });
data.add(new Object[] { assignData(new Gene("id")) });
data.add(new Object[] { assignData(new Ion("id")) });
data.add(new Object[] { assignData(new Phenotype("id")) });
data.add(new Object[] { assignData(new GenericProtein("id")) });
data.add(new Object[] { assignData(new IonChannelProtein("id")) });
data.add(new Object[] { assignData(new ReceptorProtein("id")) });
data.add(new Object[] { assignData(new TruncatedProtein("id")) });
data.add(new Object[] { assignData(new Rna("id")) });
data.add(new Object[] { assignData(new SimpleMolecule("id")) });
return data;
}
private static Element assignData(Element element) {
element.setX(10);
element.setY(10);
element.setWidth(100);
element.setHeight(200);
element.setFillColor(Color.BLUE);
element.setBorderColor(Color.YELLOW);
element.setFontColor(Color.GREEN);
element.setName("xyz");
element.setTransparencyLevel("100");
return element;
}
@Test
public void testDrawAndColorUsage() throws Exception {
BioEntityConverter<BioEntity> converter = new BioEntityConverterImpl(species, colorExtractor);
int size = 600;
Model model = new ModelFullIndexed(null);
BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = Mockito.spy(bi.createGraphics());
model.addElement(species);
graphics.setColor(Color.PINK);
converter.draw(species, graphics, new ConverterParams().nested(true));
assertEquals("Color was changed by the converter", Color.PINK, graphics.getColor());
ArgumentCaptor<Color> argument = ArgumentCaptor.forClass(Color.class);
Mockito.verify(graphics, atLeastOnce()).setColor(argument.capture());
List<Color> values = removeAlpha(argument.getAllValues());
assertTrue("Fill colour wasn't used", values.contains(Color.BLUE));
assertTrue("Border colour wasn't used", values.contains(Color.YELLOW));
assertTrue("Font colour wasn't used", values.contains(Color.GREEN));
}
}
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