diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java index a8b145747ac0df7284850bf1f1d19e0bf001dc80..0dd861759ebbcbea498fbb73f27a239f150dc443 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java @@ -72,6 +72,22 @@ public abstract class BioEntityConverter<T extends BioEntity> { draw(bioEntity, graphics, params, new ArrayList<>()); } + /** + * This function draw {@link BioEntity} on the {@link Graphics2D} object. + * + * @param bioEntity + * {@link BioEntity} that should be drawn + * @param graphics + * where we want to draw bioEntity + * @param params + * visualization params (like, should the object be filled with solid + * color, etc.), for more information see {@link ConverterParams} + * @throws DrawingException + * thrown when there is a problem with drawing {@link BioEntity} + * + */ + protected abstract void drawImpl(T bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException; + /** * This function draw representation of the alias on the graphics object. * @@ -90,7 +106,7 @@ public abstract class BioEntityConverter<T extends BioEntity> { * thrown when there is a problem with drawing {@link BioEntity} * */ - public abstract void draw(T bioEntity, Graphics2D graphics, ConverterParams params, + protected abstract void draw(T bioEntity, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedOverlaysColorSchemas) throws DrawingException; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImpl.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImpl.java index f4e895661fc3764c7c552dd8ead11b4f0f35b402..2153b4333e32168ce51092239f70c94b04ef2a14 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImpl.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImpl.java @@ -199,4 +199,10 @@ public class BioEntityConverterImpl extends BioEntityConverter<BioEntity> { } } + @SuppressWarnings("unchecked") + @Override + protected void drawImpl(BioEntity bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException { + elementConverter.draw(bioEntity, graphics, params); + } + } diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/ElementConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/ElementConverter.java index 3f108b2a44be7c966ab56962e5be117d25049e45..9a6e85e6ec4dc2e086e3f672619f5c62289017d6 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/ElementConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/ElementConverter.java @@ -1,6 +1,16 @@ package lcsb.mapviewer.converter.graphics.bioEntity.element; +import java.awt.Graphics2D; +import java.awt.Image; +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.converter.graphics.DrawingException; import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverter; +import lcsb.mapviewer.model.map.layout.graphics.Glyph; import lcsb.mapviewer.model.map.species.Element; /** @@ -14,4 +24,37 @@ import lcsb.mapviewer.model.map.species.Element; */ public abstract class ElementConverter<T extends Element> extends BioEntityConverter<T> { + @Override + public final void draw(T bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException { + if (bioEntity.getGlyph() != null) { + drawGlyph(bioEntity, graphics); + } else { + super.draw(bioEntity, graphics, params); + } + } + + /** + * Draws a {@link Glyph} for given bioEntity. + * + * @param bioEntity + * element that should be visualized as a {@link Glyph} + * @param graphics + * {@link Graphics2D} where we are drawing + * @throws DrawingException + * thrown when there is a problem with drawing + */ + private void drawGlyph(T bioEntity, Graphics2D graphics) throws DrawingException { + try { + Image img = ImageIO.read(new ByteArrayInputStream(bioEntity.getGlyph().getFile().getFileContent())); + graphics.drawImage(img, + bioEntity.getX().intValue(), bioEntity.getY().intValue(), + (int) (bioEntity.getX() + bioEntity.getWidth()), (int) (bioEntity.getY() + bioEntity.getHeight()), + 0, 0, img.getWidth(null), img.getHeight(null), + null); + } catch (IOException e) { + throw new DrawingException( + "Problem with processing glyph file: " + bioEntity.getGlyph().getFile().getOriginalFileName(), e); + } + } + } diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/BottomSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/BottomSquareCompartmentConverter.java index 06b04ff84b2f6ea3c51119fdec84b8ba16681965..49fda869361dfbd4e28bddee5e012d4030e7e992 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/BottomSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/BottomSquareCompartmentConverter.java @@ -45,7 +45,7 @@ public class BottomSquareCompartmentConverter extends CompartmentConverter<Botto } @Override - public void draw(final BottomSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { + protected void drawImpl(final BottomSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { // keep the old values of colors and line Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/CompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/CompartmentConverter.java index 9c6769776f5d52b9075eed3e27aed8fc118b7cc8..2c9b32cc9002685b3ead55f5a0c90aa2bdc26d9f 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/CompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/CompartmentConverter.java @@ -179,7 +179,7 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen @Override public void draw(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException { - draw(alias, graphics, params); + drawImpl(alias, graphics, params); Color oldColor = graphics.getColor(); int count = 0; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/LeftSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/LeftSquareCompartmentConverter.java index fa24065489db34bf30435c41a29d6211c356cf60..860079d2f74b2d7fbfd0a70834194181f469f8ca 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/LeftSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/LeftSquareCompartmentConverter.java @@ -45,7 +45,7 @@ public class LeftSquareCompartmentConverter extends CompartmentConverter<LeftSqu } @Override - public void draw(final LeftSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { + protected void drawImpl(final LeftSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { // keep the old values of color and line type Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/OvalCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/OvalCompartmentConverter.java index 07addb7e2a37f86c74902ae87fc744bdd9179f97..d52073e682881cea7b6abbae43935ee00e3afb8c 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/OvalCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/OvalCompartmentConverter.java @@ -48,7 +48,7 @@ public class OvalCompartmentConverter extends CompartmentConverter<OvalCompartme } @Override - public void draw(final OvalCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { + protected void drawImpl(final OvalCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { // keep the old values of color and line type Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/PathwayCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/PathwayCompartmentConverter.java index 8da05b92fa64ac1fc318a5c1a91fcf8ac5d34cda..87bcb8fb020b110d439e748454b136d7358b63b6 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/PathwayCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/PathwayCompartmentConverter.java @@ -36,7 +36,7 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom } @Override - public void draw(final PathwayCompartment compartment, final Graphics2D graphics, final ConverterParams params) + protected void drawImpl(final PathwayCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { // keep the old values of colors and line Color oldColor = graphics.getColor(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/RightSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/RightSquareCompartmentConverter.java index 4431113ae6628a1bd5b8854ad6ab206f7ce89f1a..d9116520e2d3cecc6271a0ecb1b9d8e14946aecc 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/RightSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/RightSquareCompartmentConverter.java @@ -45,7 +45,7 @@ public class RightSquareCompartmentConverter extends CompartmentConverter<RightS } @Override - public void draw(final RightSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { + protected void drawImpl(final RightSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { // keep the old values of color and line type Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/SquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/SquareCompartmentConverter.java index a524860740d51594dc4747eb38baca0670d35b06..ab6de2d9a5504f9010c1de06e78d475f4f0d4f4f 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/SquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/SquareCompartmentConverter.java @@ -61,7 +61,7 @@ public class SquareCompartmentConverter extends CompartmentConverter<SquareCompa } @Override - public void draw(final SquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { + protected void drawImpl(final SquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { // keep the old values of color and line type Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/TopSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/TopSquareCompartmentConverter.java index c30a6ae45e326246542ded0b5a3680ef01e25076..a1a53b8b3be44b2ad42e32ddbe0ba5268d3673d3 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/TopSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/TopSquareCompartmentConverter.java @@ -45,7 +45,7 @@ public class TopSquareCompartmentConverter extends CompartmentConverter<TopSquar } @Override - public void draw(final TopSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { + protected void drawImpl(final TopSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException { Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java index 136e148f57d3389cf509eaa179a851f0c694a219..3b4b395ac87b1abaffa2069131616149e4f4c3a6 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java @@ -44,7 +44,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> { } @Override - public void draw(final AntisenseRna antisenseRna, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final AntisenseRna antisenseRna, final Graphics2D graphics, final ConverterParams params) { GeneralPath path = getAntisenseRnaPath(antisenseRna); Color c = graphics.getColor(); graphics.setColor(antisenseRna.getColor()); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ComplexConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ComplexConverter.java index bf7e9ff809a48c077225e540cc456967f7188888..f8651b9659f5932f2ed442ca56d4c15e4555b771 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ComplexConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ComplexConverter.java @@ -57,7 +57,7 @@ public class ComplexConverter extends SpeciesConverter<Complex> { } @Override - public void draw(final Complex alias, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final Complex alias, final Graphics2D graphics, final ConverterParams params) { if (alias.getState().equalsIgnoreCase("complexnoborder")) { return; } diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DegradedConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DegradedConverter.java index e51b68f673a024cbc99b54c845ddfe615c4f2d5f..6e9372c56b9fbbe902bf21658c1c8eb6af2b7436 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DegradedConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DegradedConverter.java @@ -49,7 +49,7 @@ public class DegradedConverter extends SpeciesConverter<Degraded> { } @Override - public void draw(final Degraded degraded, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final Degraded degraded, final Graphics2D graphics, final ConverterParams params) { double diameter = getDiameter(degraded); double x = getXCoord(degraded, diameter); double y = getYCoord(degraded); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DrugConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DrugConverter.java index e21d696918e9ba811ed39984f6a715db05c27605..f917d41fcefc584a52b0777c7d1a51abfb8c9d8d 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DrugConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DrugConverter.java @@ -67,7 +67,7 @@ public class DrugConverter extends SpeciesConverter<Drug> { } @Override - public void draw(Drug drug, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(Drug drug, final Graphics2D graphics, final ConverterParams params) { Shape a1 = getDrugShape(drug); double offset = OFFSET_BETWEEN_BORDERS; Shape a2 = new RoundRectangle2D.Double( diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/GeneConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/GeneConverter.java index 2877c47e251f6c0072e261749c6352846053c23e..5f3e6682417ba3c38bfe601b46958cde744c054b 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/GeneConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/GeneConverter.java @@ -43,7 +43,7 @@ public class GeneConverter extends SpeciesConverter<Gene> { } @Override - public void draw(final Gene gene, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final Gene gene, final Graphics2D graphics, final ConverterParams params) { Shape shape = getGeneShape(gene); Color c = graphics.getColor(); graphics.setColor(gene.getColor()); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/IonConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/IonConverter.java index d4ff6fccbae66537cf1610423b7fd827624ad325..0b938b0996af830f811059429017c45041e3492b 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/IonConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/IonConverter.java @@ -42,7 +42,7 @@ public class IonConverter extends SpeciesConverter<Ion> { } @Override - public void draw(Ion ion, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(Ion ion, final Graphics2D graphics, final ConverterParams params) { double diameter = getDiameter(ion); double x = getXCoord(ion, diameter); double y = getYCoord(ion); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/PhenotypeConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/PhenotypeConverter.java index 5d73019e9a7222f39d8a9a72de859ac5c65d9aef..7cd37307323963793183f61023e3466523de5727 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/PhenotypeConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/PhenotypeConverter.java @@ -42,7 +42,7 @@ public class PhenotypeConverter extends SpeciesConverter<Phenotype> { } @Override - public void draw(Phenotype phenotype, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(Phenotype phenotype, final Graphics2D graphics, final ConverterParams params) { GeneralPath path = getPhenotypePath(phenotype); Color c = graphics.getColor(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ProteinConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ProteinConverter.java index 4649301841932a723db74b1e18dc7d7aa3fa692d..26148f80091ba04c270ca15d925433749ddb76c3 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ProteinConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ProteinConverter.java @@ -87,7 +87,7 @@ public class ProteinConverter extends SpeciesConverter<Protein> { } @Override - public void draw(final Protein protein, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final Protein protein, final Graphics2D graphics, final ConverterParams params) { // Local variable setting the SBGN visualization boolean sbgnFormat = params.isSbgnFormat(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/RnaConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/RnaConverter.java index c66fada0f4568f32e76f2634a9a3c49c9973b01d..c36bf559ea53d37821fc7e5443b129288da01f50 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/RnaConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/RnaConverter.java @@ -50,7 +50,7 @@ public class RnaConverter extends SpeciesConverter<Rna> { } @Override - public void draw(final Rna rna, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final Rna rna, final Graphics2D graphics, final ConverterParams params) { GeneralPath path = getRnaPath(rna); Color c = graphics.getColor(); graphics.setColor(rna.getColor()); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SBGNNucleicAcidFeatureConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SBGNNucleicAcidFeatureConverter.java index 4c7ead26d0252f9cdf1ba15f791a9ae9b6af86ef..c62e51d3afae344158c36ac961049b2cbed40f40 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SBGNNucleicAcidFeatureConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SBGNNucleicAcidFeatureConverter.java @@ -63,7 +63,7 @@ public class SBGNNucleicAcidFeatureConverter extends SpeciesConverter<Species> { } @Override - public void draw(Species species, Graphics2D graphics, ConverterParams params) { + protected void drawImpl(Species species, Graphics2D graphics, ConverterParams params) { // Unit of information text - multimer cardinality String unitOfInformationText = null; if (species.getStatePrefix() != null && species.getStateLabel() != null) { diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SimpleMoleculeConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SimpleMoleculeConverter.java index ef50bcde90f1830b18c40e53e2a890cbf040fdd7..9fb6eab78dd74d9caaa59463f0b8ae18b1bd3bbe 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SimpleMoleculeConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SimpleMoleculeConverter.java @@ -42,7 +42,7 @@ public class SimpleMoleculeConverter extends SpeciesConverter<SimpleMolecule> { } @Override - public void draw(final SimpleMolecule simpleMolecule, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final SimpleMolecule simpleMolecule, final Graphics2D graphics, final ConverterParams params) { int homodir; if (params.isSbgnFormat()) { // If the SBGN display mode is set, multimer is shown as two stacked diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java index 980ac89b8315020b225cf2080019aa219c482a3b..2aca0689bd3218657dd18a39a0442a7fa7a15124 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java @@ -498,7 +498,7 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert @Override public void draw(T species, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException { - draw(species, graphics, params); + drawImpl(species, graphics, params); Color oldColor = graphics.getColor(); int count = 0; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/UnknownConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/UnknownConverter.java index 1135513a8c3ac2648376801ff49ff75dc0cf163d..14e17a446350b08b5d75dfebff9d265ffa909e91 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/UnknownConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/UnknownConverter.java @@ -44,7 +44,7 @@ public class UnknownConverter extends SpeciesConverter<Unknown> { } @Override - public void draw(Unknown unknown, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(Unknown unknown, final Graphics2D graphics, final ConverterParams params) { if (unknown.getActivity()) { int border = ACTIVITY_BORDER_DISTANCE; unknown.increaseBorder(border); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java index 72540779895b8b695b7872408c3bd0f19601db2c..910e87eb8e91cd4581c712dfa26fbc5c477a14f7 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java @@ -35,7 +35,7 @@ import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.type.ReactionRect; /** - * Thics class allows to draw reaction on the graphics2D. + * This class allows to draw reaction on the graphics2D. * * @author Piotr Gawron * @@ -196,7 +196,7 @@ public class ReactionConverter extends BioEntityConverter<Reaction> { } @Override - public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params) { + protected void drawImpl(final Reaction reaction, final Graphics2D graphics, final ConverterParams params) { Color color = graphics.getColor(); graphics.setColor(reaction.getReactants().get(0).getLine().getColor()); // first reactants @@ -231,19 +231,19 @@ public class ReactionConverter extends BioEntityConverter<Reaction> { } @Override - public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { + public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException { if (visualizedLayoutsColorSchemas.size() == 0) { - draw(reaction, graphics, params); + drawImpl(reaction, graphics, params); } else if (visualizedLayoutsColorSchemas.size() == 1) { if (visualizedLayoutsColorSchemas.get(0) == null) { - draw(reaction, graphics, params); + drawImpl(reaction, graphics, params); } else { List<Pair<AbstractNode, PolylineData>> oldData = new ArrayList<>(); for (AbstractNode node : reaction.getNodes()) { oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine())); } applyColorSchema(reaction, visualizedLayoutsColorSchemas.get(0)); - draw(reaction, graphics, params); + drawImpl(reaction, graphics, params); for (Pair<AbstractNode, PolylineData> pair : oldData) { pair.getLeft().setLine(pair.getRight()); } @@ -256,14 +256,14 @@ public class ReactionConverter extends BioEntityConverter<Reaction> { } } if (count == 0) { - draw(reaction, graphics, params); + drawImpl(reaction, graphics, params); } else { List<Pair<AbstractNode, PolylineData>> oldData = new ArrayList<>(); for (AbstractNode node : reaction.getNodes()) { oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine())); } applyColorSchema(reaction, DEFAULT_COLOR_SCHEMA); - draw(reaction, graphics, params); + drawImpl(reaction, graphics, params); for (Pair<AbstractNode, PolylineData> pair : oldData) { pair.getLeft().setLine(pair.getRight()); } diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverterTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverterTest.java index d44d12eefa6f4a8162467e4debc206eb89ff566c..50fabb870e6ef87e738182be7461de64b522c630 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverterTest.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverterTest.java @@ -7,16 +7,24 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.nullable; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.awt.Color; +import java.awt.Desktop; import java.awt.Graphics2D; +import java.awt.Image; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; +import java.io.File; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +import javax.imageio.ImageIO; + import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; @@ -26,8 +34,10 @@ import org.mockito.Mockito; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.converter.graphics.ConverterParams; import lcsb.mapviewer.converter.graphics.geometry.ArrowTransformation; +import lcsb.mapviewer.model.cache.UploadedFileEntry; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.layout.GenericColorSchema; +import lcsb.mapviewer.model.map.layout.graphics.Glyph; import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.Protein; import lcsb.mapviewer.model.map.species.field.BindingRegion; @@ -369,6 +379,32 @@ public class SpeciesConverterTest { } } + @Test + public void testDrawAliasWithGlyph() throws Exception { + try { + BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = Mockito.spy(bi.createGraphics()); + ProteinConverter rc = new ProteinConverter(colorExtractor); + + GenericProtein alias = createProtein(); + Glyph glyph = new Glyph(); + UploadedFileEntry file = new UploadedFileEntry(); + file.setOriginalFileName("test"); + byte[] fileContent = Files.readAllBytes(new File("testFiles/glyph.png").toPath()); + + file.setFileContent(fileContent); + glyph.setFile(file); + alias.setGlyph(glyph); + rc.draw(alias, graphics, new ConverterParams()); + + verify(graphics, times(1)).drawImage(any(Image.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), + anyInt(), anyInt(), nullable(ImageObserver.class)); + + } catch (Exception e) { + throw e; + } + } + private GenericProtein createProtein() { GenericProtein protein = new GenericProtein("id"); protein.setName("NAME_OF_THE_ELEMENT"); diff --git a/converter-graphics/testFiles/glyph.png b/converter-graphics/testFiles/glyph.png new file mode 100644 index 0000000000000000000000000000000000000000..a29b0dfdd7bb45af5ef280121fe0115694eb384e Binary files /dev/null and b/converter-graphics/testFiles/glyph.png differ