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 9a6e85e6ec4dc2e086e3f672619f5c62289017d6..973cf072fcee5ea00a6a15e5267feda4227b4fb5 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 @@ -43,7 +43,7 @@ public abstract class ElementConverter<T extends Element> extends BioEntityConve * @throws DrawingException * thrown when there is a problem with drawing */ - private void drawGlyph(T bioEntity, Graphics2D graphics) throws DrawingException { + protected void drawGlyph(T bioEntity, Graphics2D graphics) throws DrawingException { try { Image img = ImageIO.read(new ByteArrayInputStream(bioEntity.getGlyph().getFile().getFileContent())); graphics.drawImage(img, 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 2c9b32cc9002685b3ead55f5a0c90aa2bdc26d9f..4d630b573c10d5fe6f77e19a9066e87a3a0f041e 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,14 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen @Override public void draw(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException { - drawImpl(alias, graphics, params); + logger.debug("Draw: "+alias.getElementId()); + if (alias.getGlyph() != null) { + logger.debug("as glyph"); + drawGlyph(alias, graphics); + } else { + logger.debug("without glyph"); + 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/species/SpeciesConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java index 2aca0689bd3218657dd18a39a0442a7fa7a15124..da4c75cc04293f630c24dfdaa2758501ce4b47fa 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 @@ -496,9 +496,16 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert } @Override - public void draw(T species, Graphics2D graphics, ConverterParams params, + public final void draw(T species, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException { - drawImpl(species, graphics, params); + logger.debug("Draw: "+species.getElementId()); + if (species.getGlyph() != null) { + logger.debug("as glyph"); + drawGlyph(species, graphics); + } else { + logger.debug("without glyph"); + drawImpl(species, graphics, params); + } Color oldColor = graphics.getColor(); int count = 0; diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java index 68060ae78364070ca6f49d320a3be1e10cb31bc1..4cd4aa512cd6c80c8946fe51d53632d959d63d73 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImplTest.java @@ -1,13 +1,23 @@ package lcsb.mapviewer.converter.graphics.bioEntity; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +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.GeneralPath; 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 javax.imageio.ImageIO; import org.junit.After; import org.junit.AfterClass; @@ -17,7 +27,10 @@ import org.mockito.Mockito; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.converter.graphics.GraphicsTestFunctions; +import lcsb.mapviewer.model.cache.UploadedFileEntry; import lcsb.mapviewer.model.graphics.PolylineData; +import lcsb.mapviewer.model.map.layout.graphics.Glyph; import lcsb.mapviewer.model.map.modifier.Catalysis; import lcsb.mapviewer.model.map.reaction.Modifier; import lcsb.mapviewer.model.map.reaction.Product; @@ -25,74 +38,103 @@ import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.GenericProtein; -public class BioEntityConverterImplTest { +public class BioEntityConverterImplTest extends GraphicsTestFunctions{ + + ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN, Color.BLUE); + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testDrawReactionWithSemanticZoomingAndReactantOff() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + Reaction reaction = createReaction(1.0); + reaction.getReactants().get(0).getElement().setVisibilityLevel("11"); + + BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor); + rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10)); + + verify(graphics, times(0)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } - ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN, Color.BLUE); + @Test + public void testDrawReactionWithSemanticZoomingAndProductOff() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); - @AfterClass - public static void tearDownAfterClass() throws Exception { - } + Reaction reaction = createReaction(1.0); + reaction.getProducts().get(0).getElement().setVisibilityLevel("11"); - @Before - public void setUp() throws Exception { - } + BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor); + rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10)); - @After - public void tearDown() throws Exception { - } + verify(graphics, times(0)).draw(any(GeneralPath.class)); - @Test - public void testDrawReactionWithSemanticZoomingAndReactantOff() throws Exception { - try { - Graphics2D graphics = Mockito.mock(Graphics2D.class); - Reaction reaction = createReaction(1.0); - reaction.getReactants().get(0).getElement().setVisibilityLevel("11"); + } catch (Exception e) { + throw e; + } + } - BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor); - rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10)); + @Test + public void testDrawAliasWithGlyph() throws Exception { + try { + BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = Mockito.spy(bi.createGraphics()); - verify(graphics, times(0)).draw(any(GeneralPath.class)); + GenericProtein alias = createProtein(); + Glyph glyph = new Glyph(); + UploadedFileEntry file = new UploadedFileEntry(); + file.setOriginalFileName("test"); + byte[] fileContent = Files.readAllBytes(new File("testFiles/glyph.png").toPath()); - } catch (Exception e) { - throw e; - } - } + file.setFileContent(fileContent); + glyph.setFile(file); + alias.setGlyph(glyph); + BioEntityConverterImpl converter = new BioEntityConverterImpl(alias, false, colorExtractor); + converter.draw(alias, graphics, new ConverterParams()); - @Test - public void testDrawReactionWithSemanticZoomingAndProductOff() throws Exception { - try { - Graphics2D graphics = Mockito.mock(Graphics2D.class); - Reaction reaction = createReaction(1.0); - reaction.getProducts().get(0).getElement().setVisibilityLevel("11"); - BioEntityConverterImpl rc = new BioEntityConverterImpl(reaction, false, colorExtractor); - rc.draw(reaction, graphics, new ConverterParams().nested(true).level(10)); + verify(graphics, times(1)).drawImage(any(Image.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), + anyInt(), anyInt(), nullable(ImageObserver.class)); - verify(graphics, times(0)).draw(any(GeneralPath.class)); - } catch (Exception e) { - throw e; - } - } + } catch (Exception e) { + throw e; + } + } - private Reaction createReaction(double lineWidth) { - Reaction result = new Reaction(); + private Reaction createReaction(double lineWidth) { + Reaction result = new Reaction(); - Modifier modifier = new Catalysis(new GenericProtein("s1")); - modifier.setLine(new PolylineData(new Point2D.Double(100, 20), new Point2D.Double(100, 80))); - modifier.getLine().setWidth(lineWidth); + Modifier modifier = new Catalysis(new GenericProtein("s1")); + modifier.setLine(new PolylineData(new Point2D.Double(100, 20), new Point2D.Double(100, 80))); + modifier.getLine().setWidth(lineWidth); - Reactant reactant = new Reactant(new GenericProtein("s2")); - reactant.setLine(new PolylineData(new Point2D.Double(90, 90), new Point2D.Double(10, 90))); - reactant.getLine().setWidth(lineWidth); - Product product = new Product(new GenericProtein("s3")); - product.setLine(new PolylineData(new Point2D.Double(200, 90), new Point2D.Double(110, 90))); - product.getLine().setWidth(lineWidth); - result.addModifier(modifier); - result.addProduct(product); - result.addReactant(reactant); - return result; - } + Reactant reactant = new Reactant(new GenericProtein("s2")); + reactant.setLine(new PolylineData(new Point2D.Double(90, 90), new Point2D.Double(10, 90))); + reactant.getLine().setWidth(lineWidth); + Product product = new Product(new GenericProtein("s3")); + product.setLine(new PolylineData(new Point2D.Double(200, 90), new Point2D.Double(110, 90))); + product.getLine().setWidth(lineWidth); + result.addModifier(modifier); + result.addProduct(product); + result.addReactant(reactant); + return result; + } } 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 50fabb870e6ef87e738182be7461de64b522c630..12c1aa6efc6bedd84841e429ee12ab9e778bdf86 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 @@ -33,6 +33,7 @@ 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.geometry.ArrowTransformation; import lcsb.mapviewer.model.cache.UploadedFileEntry; import lcsb.mapviewer.model.map.layout.ColorSchema; @@ -49,7 +50,7 @@ import lcsb.mapviewer.model.map.species.field.RegulatoryRegion; import lcsb.mapviewer.model.map.species.field.Residue; import lcsb.mapviewer.model.map.species.field.TranscriptionSite; -public class SpeciesConverterTest { +public class SpeciesConverterTest extends GraphicsTestFunctions{ Logger logger = Logger.getLogger(SpeciesConverterTest.class); ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN, Color.BLUE); @@ -405,15 +406,4 @@ public class SpeciesConverterTest { } } - private GenericProtein createProtein() { - GenericProtein protein = new GenericProtein("id"); - protein.setName("NAME_OF_THE_ELEMENT"); - protein.setX(10); - protein.setY(20); - protein.setWidth(100); - protein.setHeight(80); - protein.setColor(Color.WHITE); - - return protein; - } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Glyph.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Glyph.java index cbf530889c24072202a84138410ded5ff3347631..d23576df24d89847075622045b5e14230b82f523 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Glyph.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/Glyph.java @@ -73,7 +73,7 @@ public class Glyph implements Serializable { */ public Glyph(Glyph original) { // we should reference to the same file - setFile(file); + setFile(original.getFile()); } public UploadedFileEntry getFile() { diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java index 6a4db28730f75eb3fa3408122efdff84d30e8be9..1d3ac88910a57f968efda182a040bf44ba50fab3 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java @@ -302,7 +302,9 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { this.formula = original.getFormula(); setVisibilityLevel(original.getVisibilityLevel()); setTransparencyLevel(original.getTransparencyLevel()); - setGlyph(new Glyph(original.getGlyph())); + if (original.getGlyph() != null) { + setGlyph(new Glyph(original.getGlyph())); + } } /** diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/ElementTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/ElementTest.java index 29c629c7a02c31aae51970e0b4dc9b1060ef1634..0806862ac6938468d5f054aa8e4b4e8ca4245fdb 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/ElementTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/ElementTest.java @@ -130,6 +130,18 @@ public class ElementTest extends ModelTestFunctions { } } + @Test + public void testCopyWithoutGlyph() { + try { + GenericProtein protein = new GenericProtein(); + Element copy = new GenericProtein(protein); + assertNull(copy.getGlyph()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + @Test public void testIncreaseBorder() { try {