From 0230122311629a1dc5b13fc030659ae270ffb023 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 16 Jun 2017 15:14:12 +0200 Subject: [PATCH] drawing of reactions for semantic zooming --- .../annotation/RestAnnotationParserTest.java | 12 + .../model/sbgnml/SbgnmlXmlExporter.java | 2 +- .../model/sbgnml/SbgnmlXmlParser.java | 2 +- .../graphics/AbstractImageGenerator.java | 23 +- .../converter/graphics/ConverterParams.java | 35 +- .../BioEntityConverter.java} | 40 +- .../BioEntityConverterImpl.java} | 71 +-- .../bioEntity/element/ElementConverter.java | 17 + .../BottomSquareCompartmentConverter.java | 4 +- .../compartment/CompartmentConverter.java | 8 +- .../LeftSquareCompartmentConverter.java | 4 +- .../compartment/OvalCompartmentConverter.java | 4 +- .../PathwayCompartmentConverter.java | 4 +- .../RightSquareCompartmentConverter.java | 4 +- .../SquareCompartmentConverter.java | 4 +- .../TopSquareCompartmentConverter.java | 4 +- .../element}/compartment/package-info.java | 2 +- .../species/AntisenseRnaConverter.java | 4 +- .../element}/species/ComplexConverter.java | 4 +- .../element}/species/DegradedConverter.java | 4 +- .../element}/species/DrugConverter.java | 4 +- .../element}/species/GeneConverter.java | 4 +- .../element}/species/IonConverter.java | 4 +- .../element}/species/PhenotypeConverter.java | 4 +- .../element}/species/ProteinConverter.java | 4 +- .../element}/species/RnaConverter.java | 4 +- .../SBGNNucleicAcidFeatureConverter.java | 4 +- .../species/SimpleMoleculeConverter.java | 4 +- .../element}/species/SpeciesConverter.java | 8 +- .../element}/species/UnknownConverter.java | 4 +- .../element}/species/package-info.java | 2 +- .../reaction/ReactionConverter.java | 125 +++++- .../reaction/package-info.java | 2 +- .../converter/graphics/AllGraphicsTests.java | 4 +- .../converter/graphics/ConverterTest.java | 9 +- .../graphics/NormalImageGeneratorTest.java | 2 +- .../species/AllSpeciesConverterTests.java | 2 +- .../species/SpeciesConverterTest.java | 17 +- .../reaction/AllReactionTests.java | 2 +- .../reaction/ReactionConverterTest.java | 407 ++++++++++++++++++ .../reaction/ReactionConverterTest.java | 196 --------- .../mapviewer/model/map/AnnotatedObject.java | 8 +- .../model/map/reaction/Reaction.java | 15 + .../mapviewer/model/map/species/Element.java | 14 + 44 files changed, 745 insertions(+), 356 deletions(-) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ElementConverter.java => bioEntity/BioEntityConverter.java} (50%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ElementConverterImpl.java => bioEntity/BioEntityConverterImpl.java} (62%) create mode 100644 converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/ElementConverter.java rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/BottomSquareCompartmentConverter.java (90%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/CompartmentConverter.java (92%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/LeftSquareCompartmentConverter.java (90%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/OvalCompartmentConverter.java (90%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/PathwayCompartmentConverter.java (89%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/RightSquareCompartmentConverter.java (91%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/SquareCompartmentConverter.java (91%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/TopSquareCompartmentConverter.java (90%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/compartment/package-info.java (59%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/AntisenseRnaConverter.java (93%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/ComplexConverter.java (94%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/DegradedConverter.java (92%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/DrugConverter.java (92%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/GeneConverter.java (93%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/IonConverter.java (92%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/PhenotypeConverter.java (91%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/ProteinConverter.java (96%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/RnaConverter.java (94%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/SBGNNucleicAcidFeatureConverter.java (93%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/SimpleMoleculeConverter.java (93%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/SpeciesConverter.java (95%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/UnknownConverter.java (91%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/package-info.java (65%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity}/reaction/ReactionConverter.java (74%) rename converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/{ => bioEntity}/reaction/package-info.java (70%) rename converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/AllSpeciesConverterTests.java (73%) rename converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/{ => bioEntity/element}/species/SpeciesConverterTest.java (87%) rename converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/{ => bioEntity}/reaction/AllReactionTests.java (74%) create mode 100644 converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java delete mode 100644 converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverterTest.java diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java index ff04e70426..f8ab6d2d44 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java @@ -417,6 +417,18 @@ public class RestAnnotationParserTest extends CellDesignerTestFunctions { // TODO Auto-generated method stub return null; } + + @Override + public void setSemanticZoomLevelVisibility(String zoomLevelVisibility) { + // TODO Auto-generated method stub + + } + + @Override + public String getSemanticZoomLevelVisibility() { + // TODO Auto-generated method stub + return null; + } }); fail("Exception expected"); } catch (NotImplementedException e) { diff --git a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java index c408b252ec..c6d7b70674 100644 --- a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java +++ b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlExporter.java @@ -27,7 +27,7 @@ import org.sbgn.bindings.Sbgn; import lcsb.mapviewer.common.comparator.DoubleComparator; import lcsb.mapviewer.common.exception.InvalidArgumentException; -import lcsb.mapviewer.converter.graphics.reaction.ReactionConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter; import lcsb.mapviewer.model.graphics.ArrowType; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.model.Model; diff --git a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java index f808c488be..b66908389d 100644 --- a/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java +++ b/converter-SBGNML/src/main/java/lcsb/mapviewer/converter/model/sbgnml/SbgnmlXmlParser.java @@ -28,7 +28,7 @@ import lcsb.mapviewer.common.comparator.DoubleComparator; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.converter.ConverterParams; import lcsb.mapviewer.converter.InvalidInputDataExecption; -import lcsb.mapviewer.converter.graphics.species.SpeciesConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.SpeciesConverter; import lcsb.mapviewer.converter.model.celldesigner.types.ModifierType; import lcsb.mapviewer.converter.model.celldesigner.types.ModifierTypeUtils; import lcsb.mapviewer.converter.model.sbgnml.structures.Process; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java index c07d1422e6..e452e977f3 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/AbstractImageGenerator.java @@ -16,8 +16,9 @@ import org.apache.log4j.Logger; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.common.MimeType; +import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverterImpl; +import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter; import lcsb.mapviewer.converter.graphics.layer.LayerConverter; -import lcsb.mapviewer.converter.graphics.reaction.ReactionConverter; import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.PathwayCompartment; import lcsb.mapviewer.model.map.layout.ColorSchema; @@ -172,11 +173,11 @@ public abstract class AbstractImageGenerator { * Should the visualization include hierarchical view or not. */ private boolean nested = false; - + /** * Should sbgn standard be used. */ - private boolean sbgn = false; + private boolean sbgn = false; /** * List of objects containging information about layouts visualized in the @@ -561,7 +562,8 @@ public abstract class AbstractImageGenerator { } /** - * @param sbgn the sbgn to set + * @param sbgn + * the sbgn to set * @see #sbgn * @return object with all parameters */ @@ -738,7 +740,7 @@ public abstract class AbstractImageGenerator { } // get a converter for this compartment - ElementConverterImpl converter = new ElementConverterImpl(compartment, colorExtractor); + BioEntityConverterImpl converter = new BioEntityConverterImpl(compartment, colorExtractor); ConverterParams compartmentParams = new ConverterParams().textCentered(fill).level(level); if (nested) { @@ -749,7 +751,7 @@ public abstract class AbstractImageGenerator { // standard compartment (not the pathway) if (nested || !(compartment instanceof PathwayCompartment)) { try { - converter.drawElement(compartment, graphics, compartmentParams, visibleLayouts); + converter.draw(compartment, graphics, compartmentParams, visibleLayouts); } catch (Exception e) { throw new DrawingException(eu.getElementTag(compartment) + "Problem with drawing element.", e); } @@ -825,14 +827,13 @@ public abstract class AbstractImageGenerator { } // at the beginning try to find an appropriate converter - ElementConverterImpl converter = new ElementConverterImpl(species, sbgnFormat, colorExtractor); + BioEntityConverterImpl converter = new BioEntityConverterImpl(species, sbgnFormat, colorExtractor); double customScale = 1; if (rescale) { customScale = scale; } try { - converter - .drawElement(species, graphics, new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat), visibleLayouts); + converter.draw(species, graphics, new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat), visibleLayouts); } catch (Exception e) { throw new DrawingException(eu.getElementTag(species) + "Problem with drawing element.", e); } @@ -866,8 +867,8 @@ public abstract class AbstractImageGenerator { if (!cross(reaction.getLines())) { return; } - ReactionConverter converter = new ReactionConverter(colorExtractor); - converter.drawReaction(reaction, graphics, sbgnFormat, visibleLayouts); + BioEntityConverterImpl converter = new BioEntityConverterImpl(reaction, sbgnFormat, colorExtractor); + converter.draw(reaction, graphics, new ConverterParams().sbgnFormat(sbgnFormat), visibleLayouts); } /** diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java index c7499064c6..59577a9350 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ConverterParams.java @@ -11,28 +11,33 @@ public class ConverterParams { * Should the object be filled with the solid color. In other words it tells * us if the object is not transparent. */ - private boolean fill = false; + private boolean fill = false; /** * At which level the object is visualized. It helps to deterimine font size. * However it's possible that this value is not required. */ - private int level = 0; + private int level = 0; /** * What is the scale. It allows to adjust font size to be readable. */ - private double scale = 1; + private double scale = 1; /** * Should the text describing element be centered or not. */ - private boolean textCentered = false; + private boolean textCentered = false; /** * Should the map be displayed in SBGN format. */ - private boolean sbgnFormat = false; + private boolean sbgnFormat = false; + + /** + * Is the semantic zooming filtered. + */ + private boolean semanticZoomingOn = false; /** * @param fill @@ -56,6 +61,17 @@ public class ConverterParams { return this; } + /** + * @param semanticZoomingOn + * the semanticZoomingOn to set + * @return object with all parameters + * @see #semanticZoomingOn + */ + public ConverterParams semanticZoomingOn(final boolean semanticZoomingOn) { + this.semanticZoomingOn = semanticZoomingOn; + return this; + } + /** * @param textCentered * the textCentered to set @@ -129,6 +145,14 @@ public class ConverterParams { return sbgnFormat; } + /** + * @return the semanticZoomingOn + * @see #semanticZoomingOn + */ + public boolean isSemanticZoomingOn() { + return semanticZoomingOn; + } + @Override public String toString() { String result = "[" + this.getClass().getSimpleName() + "] " + // @@ -136,6 +160,7 @@ public class ConverterParams { "level:" + level + "," + // "scale:" + scale + "," + // "textCentered:" + textCentered + "," + // + "semanticZoomingOn:" + semanticZoomingOn + "," + // "sbgnFormat:" + sbgnFormat; return result; } diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ElementConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java similarity index 50% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ElementConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java index d1992b796c..1d08111d03 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ElementConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverter.java @@ -1,23 +1,26 @@ -package lcsb.mapviewer.converter.graphics; +package lcsb.mapviewer.converter.graphics.bioEntity; import java.awt.Graphics2D; import java.util.List; +import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.converter.graphics.DrawingException; +import lcsb.mapviewer.model.map.AnnotatedObject; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.species.Element; /** * This interface defines what operations should be possible to convert - * {@link Element} into a graphics on Graphics2D object. + * {@link AnnotatedObject} into a graphics on Graphics2D object. * * @author Piotr Gawron * * @param <T> * class of alias to convert */ -public interface ElementConverter<T extends Element> { +public interface BioEntityConverter<T extends AnnotatedObject> { /** - * Alpha value (0..255) used for visualizing layout data that are normally + * Alpha value (0..255) used for visualizing overlay data that are normally * visualized in javascript. */ int LAYOUT_ALPHA = 200; @@ -25,49 +28,50 @@ public interface ElementConverter<T extends Element> { /** * This function draw representation of the alias on the graphics object. * - * @param alias - * alias that should be drawn + * @param bioEntity + * {@link AnnotatedObject} that should be drawn * @param graphics - * where we want to draw alias + * where we want to draw bioEntity * @param params * visuzalization params (like, should the object be filled with * solid color, etc.), for more information see * {@link ConverterParams} * */ - void drawElement(T alias, Graphics2D graphics, ConverterParams params); + void draw(T bioEntity, Graphics2D graphics, ConverterParams params); /** * This function draw representation of the alias on the graphics object. * - * @param alias - * alias that should be drawn + * @param bioEntity + * {@link AnnotatedObject} that should be drawn * @param graphics - * where we want to draw alias + * where we want to draw bioEntity * @param params * visuzalization params (like, should the object be filled with * solid color, etc.), for more information see * {@link ConverterParams} - * @param visualizedLayoutsColorSchemas + * @param visualizedOverlaysColorSchemas * list of {@link ColorSchema} that were used for visualizing this - * alias in different layouts that should be overlayed on the alias + * bioentity in different data overlays that should be overlayed on + * the alias * */ - void drawElement(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas); + void draw(T bioEntity, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedOverlaysColorSchemas); /** * This function will find proper font size to display text within it. Then it * will print this text. * - * @param alias - * alias with description to be drawn + * @param bioEntity + * bioEntity with description to be drawn * @param graphics * where the description should be drawn * @param params * parameters of visualization (centering, scale) * @throws DrawingException - * thrown when there is a problem with drawing alias + * thrown when there is a problem with drawing bioEntity */ - void drawText(T alias, Graphics2D graphics, ConverterParams params) throws DrawingException; + void drawText(T bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException; } diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ElementConverterImpl.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImpl.java similarity index 62% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ElementConverterImpl.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImpl.java index e96615f6ef..621c537345 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/ElementConverterImpl.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/BioEntityConverterImpl.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics; +package lcsb.mapviewer.converter.graphics.bioEntity; import java.awt.Graphics2D; import java.util.List; @@ -8,25 +8,29 @@ import org.apache.log4j.Logger; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; -import lcsb.mapviewer.converter.graphics.compartment.BottomSquareCompartmentConverter; -import lcsb.mapviewer.converter.graphics.compartment.LeftSquareCompartmentConverter; -import lcsb.mapviewer.converter.graphics.compartment.OvalCompartmentConverter; -import lcsb.mapviewer.converter.graphics.compartment.PathwayCompartmentConverter; -import lcsb.mapviewer.converter.graphics.compartment.RightSquareCompartmentConverter; -import lcsb.mapviewer.converter.graphics.compartment.SquareCompartmentConverter; -import lcsb.mapviewer.converter.graphics.compartment.TopSquareCompartmentConverter; -import lcsb.mapviewer.converter.graphics.species.AntisenseRnaConverter; -import lcsb.mapviewer.converter.graphics.species.ComplexConverter; -import lcsb.mapviewer.converter.graphics.species.DegradedConverter; -import lcsb.mapviewer.converter.graphics.species.DrugConverter; -import lcsb.mapviewer.converter.graphics.species.GeneConverter; -import lcsb.mapviewer.converter.graphics.species.IonConverter; -import lcsb.mapviewer.converter.graphics.species.PhenotypeConverter; -import lcsb.mapviewer.converter.graphics.species.ProteinConverter; -import lcsb.mapviewer.converter.graphics.species.RnaConverter; -import lcsb.mapviewer.converter.graphics.species.SBGNNucleicAcidFeatureConverter; -import lcsb.mapviewer.converter.graphics.species.SimpleMoleculeConverter; -import lcsb.mapviewer.converter.graphics.species.UnknownConverter; +import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.converter.graphics.DrawingException; +import lcsb.mapviewer.converter.graphics.bioEntity.element.compartment.BottomSquareCompartmentConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.compartment.LeftSquareCompartmentConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.compartment.OvalCompartmentConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.compartment.PathwayCompartmentConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.compartment.RightSquareCompartmentConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.compartment.SquareCompartmentConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.compartment.TopSquareCompartmentConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.AntisenseRnaConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.ComplexConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.DegradedConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.DrugConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.GeneConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.IonConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.PhenotypeConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.ProteinConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.RnaConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.SBGNNucleicAcidFeatureConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.SimpleMoleculeConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.UnknownConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter; +import lcsb.mapviewer.model.map.AnnotatedObject; import lcsb.mapviewer.model.map.compartment.BottomSquareCompartment; import lcsb.mapviewer.model.map.compartment.LeftSquareCompartment; import lcsb.mapviewer.model.map.compartment.OvalCompartment; @@ -35,6 +39,7 @@ import lcsb.mapviewer.model.map.compartment.RightSquareCompartment; import lcsb.mapviewer.model.map.compartment.SquareCompartment; import lcsb.mapviewer.model.map.compartment.TopSquareCompartment; import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.AntisenseRna; import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Degraded; @@ -59,13 +64,13 @@ import lcsb.mapviewer.modelutils.map.ElementUtils; * @author Piotr Gawron * */ -public class ElementConverterImpl implements ElementConverter<Element> { +public class BioEntityConverterImpl implements BioEntityConverter<AnnotatedObject> { /** * Default class logger. */ @SuppressWarnings("unused") - private static Logger logger = Logger.getLogger(ElementConverterImpl.class.getName()); + private static Logger logger = Logger.getLogger(BioEntityConverterImpl.class.getName()); /** * Returns a converter for given element. If converter doesn't exist then @@ -77,7 +82,7 @@ public class ElementConverterImpl implements ElementConverter<Element> { * object that helps to convert overlay values into colors * @return converter that can be applied for the given element */ - private ElementConverter<? extends Element> getConverterForElement(Element element, ColorExtractor colorExtractor) { + private BioEntityConverter<? extends AnnotatedObject> getConverterForElement(AnnotatedObject element, ColorExtractor colorExtractor) { if (element == null) { throw new InvalidArgumentException("element cannot be null"); } @@ -123,6 +128,8 @@ public class ElementConverterImpl implements ElementConverter<Element> { return new LeftSquareCompartmentConverter(colorExtractor); } else if (element instanceof RightSquareCompartment) { return new RightSquareCompartmentConverter(colorExtractor); + } else if (element instanceof Reaction) { + return new ReactionConverter(colorExtractor); } else { throw new NotImplementedException(new ElementUtils().getElementTag(element) + "Unknown element class"); } @@ -132,7 +139,7 @@ public class ElementConverterImpl implements ElementConverter<Element> { * Converter used for conversion of the {@link Element} given in constructor. */ @SuppressWarnings("rawtypes") - private ElementConverter elementConverter = null; + private BioEntityConverter elementConverter = null; /** * Support constructor. Used in case of SBGN format display @@ -144,7 +151,7 @@ public class ElementConverterImpl implements ElementConverter<Element> { * @param sbgnFormat * boolean value indicating if SBGN display format should be used */ - public ElementConverterImpl(final Element element, final boolean sbgnFormat, ColorExtractor colorExtractor) { + public BioEntityConverterImpl(final AnnotatedObject element, final boolean sbgnFormat, ColorExtractor colorExtractor) { // If element is a nucleic acid feature to be displayed in SBGN if (sbgnFormat && (element instanceof AntisenseRna || element instanceof Rna || element instanceof Gene)) { @@ -156,7 +163,7 @@ public class ElementConverterImpl implements ElementConverter<Element> { // if we don't know which converter to use then throw an exception if (elementConverter == null) { - throw new InvalidArgumentException("Unknown converter for class: " + element.getClass() + ". Element id: " + element.getElementId()); + throw new InvalidArgumentException(new ElementUtils().getElementTag(element) + "Unknown converter for class: " + element.getClass()); } } @@ -168,25 +175,25 @@ public class ElementConverterImpl implements ElementConverter<Element> { * @param element * {@link Element} for which this converter will be used */ - public ElementConverterImpl(final Element element, ColorExtractor colorExtractor) { + public BioEntityConverterImpl(final Element element, ColorExtractor colorExtractor) { this(element, false, colorExtractor); } @SuppressWarnings("unchecked") @Override - public void drawElement(final Element element, final Graphics2D graphics, final ConverterParams params) { - elementConverter.drawElement(element, graphics, params); + public void draw(final AnnotatedObject element, final Graphics2D graphics, final ConverterParams params) { + elementConverter.draw(element, graphics, params); } @SuppressWarnings("unchecked") @Override - public void drawText(final Element element, final Graphics2D graphics, final ConverterParams params) throws DrawingException { + public void drawText(final AnnotatedObject element, final Graphics2D graphics, final ConverterParams params) throws DrawingException { elementConverter.drawText(element, graphics, params); } @SuppressWarnings("unchecked") @Override - public void drawElement(Element element, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { - elementConverter.drawElement(element, graphics, params, visualizedLayoutsColorSchemas); + public void draw(AnnotatedObject element, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { + elementConverter.draw(element, graphics, params, visualizedLayoutsColorSchemas); } } 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 new file mode 100644 index 0000000000..de6dae1ae8 --- /dev/null +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/ElementConverter.java @@ -0,0 +1,17 @@ +package lcsb.mapviewer.converter.graphics.bioEntity.element; + +import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverter; +import lcsb.mapviewer.model.map.species.Element; + +/** + * This interface defines what operations should be possible to convert + * {@link Element} into a graphics on Graphics2D object. + * + * @author Piotr Gawron + * + * @param <T> + * class of alias to convert + */ +public interface ElementConverter<T extends Element> extends BioEntityConverter<T> { + +} diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/BottomSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/BottomSquareCompartmentConverter.java similarity index 90% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/BottomSquareCompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/BottomSquareCompartmentConverter.java index 07087ec3cd..c13cdbdaf2 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/BottomSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/BottomSquareCompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Graphics2D; @@ -44,7 +44,7 @@ public class BottomSquareCompartmentConverter extends CompartmentConverter<Botto } @Override - public void drawElement(final BottomSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final BottomSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { // 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/compartment/CompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/CompartmentConverter.java similarity index 92% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/CompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/CompartmentConverter.java index ce31fb93bb..93dd6f583e 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/CompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/CompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Font; @@ -14,7 +14,7 @@ import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.geometry.EllipseTransformation; import lcsb.mapviewer.common.geometry.LineTransformation; import lcsb.mapviewer.converter.graphics.ConverterParams; -import lcsb.mapviewer.converter.graphics.ElementConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.ElementConverter; import lcsb.mapviewer.converter.graphics.geometry.FontFinder; import lcsb.mapviewer.converter.graphics.geometry.RectangleTooSmallException; import lcsb.mapviewer.converter.graphics.placefinder.PlaceFinder; @@ -175,8 +175,8 @@ public abstract class CompartmentConverter<T extends Compartment> implements Ele } @Override - public void drawElement(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { - drawElement(alias, graphics, params); + public void draw(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { + draw(alias, graphics, params); Color oldColor = graphics.getColor(); int count = 0; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/LeftSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/LeftSquareCompartmentConverter.java similarity index 90% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/LeftSquareCompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/LeftSquareCompartmentConverter.java index a3cac76c0b..513684d8ad 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/LeftSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/LeftSquareCompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Graphics2D; @@ -44,7 +44,7 @@ public class LeftSquareCompartmentConverter extends CompartmentConverter<LeftSqu } @Override - public void drawElement(final LeftSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final LeftSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { // 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/compartment/OvalCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/OvalCompartmentConverter.java similarity index 90% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/OvalCompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/OvalCompartmentConverter.java index 3c385168fb..611eb3dead 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/OvalCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/OvalCompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Graphics2D; @@ -47,7 +47,7 @@ public class OvalCompartmentConverter extends CompartmentConverter<OvalCompartme } @Override - public void drawElement(final OvalCompartment alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final OvalCompartment alias, final Graphics2D graphics, final ConverterParams params) { // 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/compartment/PathwayCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/PathwayCompartmentConverter.java similarity index 89% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/PathwayCompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/PathwayCompartmentConverter.java index a3d6fd00ff..6d691cfab2 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/PathwayCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/PathwayCompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Graphics2D; @@ -40,7 +40,7 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom private Color backgroundColor = Color.LIGHT_GRAY; @Override - public void drawElement(final PathwayCompartment alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final PathwayCompartment alias, final Graphics2D graphics, final ConverterParams params) { // 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/compartment/RightSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/RightSquareCompartmentConverter.java similarity index 91% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/RightSquareCompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/RightSquareCompartmentConverter.java index 72099129b6..c1dbe6fa02 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/RightSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/RightSquareCompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Graphics2D; @@ -44,7 +44,7 @@ public class RightSquareCompartmentConverter extends CompartmentConverter<RightS } @Override - public void drawElement(final RightSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final RightSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { // 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/compartment/SquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/SquareCompartmentConverter.java similarity index 91% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/SquareCompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/SquareCompartmentConverter.java index e67b330c23..169950485e 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/SquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/SquareCompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Graphics2D; @@ -59,7 +59,7 @@ public class SquareCompartmentConverter extends CompartmentConverter<SquareCompa } @Override - public void drawElement(final SquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final SquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { // 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/compartment/TopSquareCompartmentConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/TopSquareCompartmentConverter.java similarity index 90% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/TopSquareCompartmentConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/TopSquareCompartmentConverter.java index b074e084f5..bdc72589df 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/TopSquareCompartmentConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/TopSquareCompartmentConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; import java.awt.Color; import java.awt.Graphics2D; @@ -44,7 +44,7 @@ public class TopSquareCompartmentConverter extends CompartmentConverter<TopSquar } @Override - public void drawElement(final TopSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final TopSquareCompartment alias, final Graphics2D graphics, final ConverterParams params) { Color oldColor = graphics.getColor(); Stroke oldStroke = graphics.getStroke(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/package-info.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/package-info.java similarity index 59% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/package-info.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/package-info.java index 238015b528..992fd5cbdd 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/compartment/package-info.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/compartment/package-info.java @@ -2,4 +2,4 @@ * Provides classes that draws different implemention of * {@link Compartment} on the {@link Graphics2D}. */ -package lcsb.mapviewer.converter.graphics.compartment; +package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/AntisenseRnaConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java similarity index 93% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/AntisenseRnaConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java index acc16bc98c..84d00dc02a 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/AntisenseRnaConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AntisenseRnaConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Font; @@ -50,7 +50,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> { @Override - public void drawElement(final AntisenseRna alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final AntisenseRna alias, final Graphics2D graphics, final ConverterParams params) { GeneralPath path = getAntisenseRnaPath(alias); Color c = graphics.getColor(); graphics.setColor(alias.getColor()); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/ComplexConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ComplexConverter.java similarity index 94% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/ComplexConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ComplexConverter.java index 6a59e89cc6..345fb93944 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/ComplexConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ComplexConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Font; @@ -58,7 +58,7 @@ public class ComplexConverter extends SpeciesConverter<Complex> { @Override - public void drawElement(final Complex alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(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/species/DegradedConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DegradedConverter.java similarity index 92% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/DegradedConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DegradedConverter.java index de6bcebb35..42152ef9f1 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/DegradedConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DegradedConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Graphics2D; @@ -50,7 +50,7 @@ public class DegradedConverter extends SpeciesConverter<Degraded> { } @Override - public void drawElement(final Degraded alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final Degraded alias, final Graphics2D graphics, final ConverterParams params) { double diameter = getDiameter(alias); double x = getXCoord(alias, diameter); double y = getYCoord(alias); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/DrugConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DrugConverter.java similarity index 92% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/DrugConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DrugConverter.java index f55cf04258..4c412634f4 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/DrugConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/DrugConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Graphics2D; @@ -68,7 +68,7 @@ public class DrugConverter extends SpeciesConverter<Drug> { } @Override - public void drawElement(Drug alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(Drug alias, final Graphics2D graphics, final ConverterParams params) { Shape a1 = getDrugShape(alias); double offset = OFFSET_BETWEEN_BORDERS; Shape a2 = new RoundRectangle2D.Double( diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/GeneConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/GeneConverter.java similarity index 93% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/GeneConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/GeneConverter.java index f5493ee149..514475cf86 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/GeneConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/GeneConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Font; @@ -48,7 +48,7 @@ public class GeneConverter extends SpeciesConverter<Gene> { } @Override - public void drawElement(final Gene alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final Gene alias, final Graphics2D graphics, final ConverterParams params) { Shape shape = getGeneShape(alias); Color c = graphics.getColor(); graphics.setColor(alias.getColor()); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/IonConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/IonConverter.java similarity index 92% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/IonConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/IonConverter.java index fe8699ac72..733f3b7ddb 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/IonConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/IonConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Graphics2D; @@ -45,7 +45,7 @@ public class IonConverter extends SpeciesConverter<Ion> { } @Override - public void drawElement(Ion alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(Ion alias, final Graphics2D graphics, final ConverterParams params) { double diameter = getDiameter(alias); double x = getXCoord(alias, diameter); double y = getYCoord(alias); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/PhenotypeConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/PhenotypeConverter.java similarity index 91% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/PhenotypeConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/PhenotypeConverter.java index 4ca043e210..0a6a2a059b 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/PhenotypeConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/PhenotypeConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Graphics2D; @@ -44,7 +44,7 @@ public class PhenotypeConverter extends SpeciesConverter<Phenotype> { } @Override - public void drawElement(Phenotype alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(Phenotype alias, final Graphics2D graphics, final ConverterParams params) { GeneralPath path = getPhenotypePath(alias); Color c = graphics.getColor(); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/ProteinConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ProteinConverter.java similarity index 96% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/ProteinConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ProteinConverter.java index b3af8c09cb..0e794ffa6e 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/ProteinConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/ProteinConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Font; @@ -89,7 +89,7 @@ public class ProteinConverter extends SpeciesConverter<Protein> { } @Override - public void drawElement(final Protein alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final Protein alias, 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/species/RnaConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/RnaConverter.java similarity index 94% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/RnaConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/RnaConverter.java index 6b13ac398f..277a8afc65 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/RnaConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/RnaConverter.java @@ -5,7 +5,7 @@ * Object that helps to convert {@link ColorSchema} values into * colors when drawing {@link Species} */ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Font; @@ -55,7 +55,7 @@ public class RnaConverter extends SpeciesConverter<Rna> { } @Override - public void drawElement(final Rna alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final Rna alias, final Graphics2D graphics, final ConverterParams params) { GeneralPath path = getRnaPath(alias); Color c = graphics.getColor(); graphics.setColor(alias.getColor()); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SBGNNucleicAcidFeatureConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SBGNNucleicAcidFeatureConverter.java similarity index 93% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SBGNNucleicAcidFeatureConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SBGNNucleicAcidFeatureConverter.java index 8dc25a7ffd..5412c1b961 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SBGNNucleicAcidFeatureConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SBGNNucleicAcidFeatureConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Graphics2D; @@ -64,7 +64,7 @@ public class SBGNNucleicAcidFeatureConverter extends SpeciesConverter<Species> { } @Override - public void drawElement(Species alias, Graphics2D graphics, ConverterParams params) { + public void draw(Species alias, Graphics2D graphics, ConverterParams params) { // Unit of information text - multimer cardinality String unitOfInformationText = null; if (alias.getStatePrefix() != null && alias.getStateLabel() != null) { diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SimpleMoleculeConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SimpleMoleculeConverter.java similarity index 93% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SimpleMoleculeConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SimpleMoleculeConverter.java index ca287bfc97..8abca141bd 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SimpleMoleculeConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SimpleMoleculeConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Graphics2D; @@ -42,7 +42,7 @@ public class SimpleMoleculeConverter extends SpeciesConverter<SimpleMolecule> { } @Override - public void drawElement(final SimpleMolecule alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(final SimpleMolecule alias, 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/species/SpeciesConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java similarity index 95% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SpeciesConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java index cf3ca8313c..1f861eaef4 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/SpeciesConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Font; @@ -21,7 +21,7 @@ import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.geometry.EllipseTransformation; import lcsb.mapviewer.common.geometry.LineTransformation; import lcsb.mapviewer.converter.graphics.ConverterParams; -import lcsb.mapviewer.converter.graphics.ElementConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.ElementConverter; import lcsb.mapviewer.model.graphics.LineType; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.species.Complex; @@ -576,8 +576,8 @@ public abstract class SpeciesConverter<T extends Species> implements ElementConv } @Override - public void drawElement(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { - drawElement(alias, graphics, params); + public void draw(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { + draw(alias, graphics, params); Color oldColor = graphics.getColor(); int count = 0; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/UnknownConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/UnknownConverter.java similarity index 91% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/UnknownConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/UnknownConverter.java index 4d2045ebf9..e304953c08 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/UnknownConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/UnknownConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import java.awt.Color; import java.awt.Graphics2D; @@ -45,7 +45,7 @@ public class UnknownConverter extends SpeciesConverter<Unknown> { } @Override - public void drawElement(Unknown alias, final Graphics2D graphics, final ConverterParams params) { + public void draw(Unknown alias, final Graphics2D graphics, final ConverterParams params) { if (alias.getActivity()) { int border = ACTIVITY_BORDER_DISTANCE; alias.increaseBorder(border); diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/package-info.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/package-info.java similarity index 65% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/package-info.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/package-info.java index 19c8857d76..2fb83e5d85 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/species/package-info.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/package-info.java @@ -3,5 +3,5 @@ * {@link lcsb.mapviewer.db.model.map.species.Species Species} on the Graphics2D * object. */ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverter.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java similarity index 74% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverter.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java index 2697266eb8..0060e3a9b3 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverter.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverter.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.reaction; +package lcsb.mapviewer.converter.graphics.bioEntity.reaction; import java.awt.Color; import java.awt.Font; @@ -15,12 +15,19 @@ import org.apache.log4j.Logger; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.common.exception.InvalidArgumentException; +import lcsb.mapviewer.common.exception.InvalidStateException; import lcsb.mapviewer.common.geometry.LineTransformation; import lcsb.mapviewer.common.geometry.PointTransformation; +import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.converter.graphics.DrawingException; +import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverter; import lcsb.mapviewer.converter.graphics.geometry.ArrowTransformation; import lcsb.mapviewer.model.graphics.ArrowType; import lcsb.mapviewer.model.graphics.ArrowTypeData; import lcsb.mapviewer.model.graphics.PolylineData; +import lcsb.mapviewer.model.map.AnnotatedObject; +import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.layout.GenericColorSchema; import lcsb.mapviewer.model.map.reaction.AbstractNode; @@ -29,7 +36,11 @@ import lcsb.mapviewer.model.map.reaction.NodeOperator; import lcsb.mapviewer.model.map.reaction.Product; import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.model.map.reaction.ReactionNode; import lcsb.mapviewer.model.map.reaction.type.ReactionRect; +import lcsb.mapviewer.model.map.species.Complex; +import lcsb.mapviewer.model.map.species.Element; +import lcsb.mapviewer.model.map.species.Species; /** * Thics class allows to draw reaction on the graphics2D. @@ -37,7 +48,7 @@ import lcsb.mapviewer.model.map.reaction.type.ReactionRect; * @author Piotr Gawron * */ -public class ReactionConverter { +public class ReactionConverter implements BioEntityConverter<Reaction> { /** * When drawing operator this value defines radius of the joining operator @@ -184,35 +195,34 @@ public class ReactionConverter { } } - /** - * Draw reaction on the graphics2D. - * - * @param reaction - * object to be drawn - * @param graphics - * where we want to draw the object - * @param sbgnFormat - * true if reaction is to be drawn in SBGN format - */ - public void drawReaction(final Reaction reaction, final Graphics2D graphics, boolean sbgnFormat) { + @Override + public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params) { Color color = graphics.getColor(); graphics.setColor(reaction.getReactants().get(0).getLine().getColor()); // first reactants for (Reactant reactant : reaction.getReactants()) { - drawReactant(graphics, reactant); + if (isVisible(reactant, params)) { + drawReactant(graphics, reactant); + } } // now products for (Product product : reaction.getProducts()) { - drawProduct(graphics, product); + if (isVisible(product, params)) { + drawProduct(graphics, product); + } } // draw modifiers for (Modifier modifier : reaction.getModifiers()) { - drawModifier(graphics, modifier); + if (isVisible(modifier, params)) { + drawModifier(graphics, modifier); + } } // and operators for (NodeOperator operator : reaction.getOperators()) { - drawOperator(graphics, operator, sbgnFormat); + if (isVisible(operator, params)) { + drawOperator(graphics, operator, params.isSbgnFormat()); + } } // in the end we draw rectangle in the middle @@ -220,6 +230,71 @@ public class ReactionConverter { graphics.setColor(color); } + private boolean isVisible(AbstractNode node, ConverterParams params) { + if (node instanceof NodeOperator) { + return isVisible((NodeOperator) node, params); + } else if (node instanceof ReactionNode) { + return isVisible(((ReactionNode) node).getElement(), params); + } else { + throw new InvalidArgumentException("Unknown class type: " + node.getClass()); + } + } + + private boolean isVisible(NodeOperator operator, ConverterParams params) { + boolean result = false; + if (operator.isModifierOperator() || operator.isReactantOperator()) { + for (AbstractNode input : operator.getInputs()) { + result |= isVisible(input, params); + } + } else if (operator.isProductOperator()) { + for (AbstractNode output : operator.getOutputs()) { + result |= isVisible(output, params); + } + } else { + throw new InvalidStateException("Unknown class state: " + operator); + } + return result; + } + + private boolean isVisible(AnnotatedObject bioEntity, ConverterParams params) { + if (params.isSemanticZoomingOn()) { + boolean result = matchLevel(params.getLevel(), bioEntity.getSemanticZoomLevelVisibility()); + if (bioEntity instanceof Element) { + Compartment compartment = ((Element) bioEntity).getCompartment(); + if (compartment != null) { + result &= isVisible(compartment, params); + } + if (bioEntity instanceof Species) { + Complex complex = ((Species) bioEntity).getComplex(); + if (complex != null) { + result &= isVisible(complex, params); + } + } + } + return result; + } + return true; + } + + private boolean matchLevel(int level, String semanticZoomLevelVisibility) { + if (semanticZoomLevelVisibility == null || semanticZoomLevelVisibility.isEmpty()) { + return true; + } + if (semanticZoomLevelVisibility.contains("{")) { + String strLevels = semanticZoomLevelVisibility.replace("{", "").replace("}", ""); + String[] ranges = strLevels.split(","); + for (String string : ranges) { + if (Integer.valueOf(string).equals(level)) { + return true; + } + } + } + if (Integer.valueOf(semanticZoomLevelVisibility) <= level) { + return true; + } + return false; + } + /** * Draw reaction on the graphics2D. * @@ -233,19 +308,19 @@ public class ReactionConverter { * list of {@link ColorSchema} that were used for visualizing this * alias in different layouts that should be overlayed on the alias */ - public void drawReaction(final Reaction reaction, final Graphics2D graphics, boolean sbgnFormat, List<ColorSchema> visualizedLayoutsColorSchemas) { + public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) { if (visualizedLayoutsColorSchemas.size() == 0) { - drawReaction(reaction, graphics, sbgnFormat); + draw(reaction, graphics, params); } else if (visualizedLayoutsColorSchemas.size() == 1) { if (visualizedLayoutsColorSchemas.get(0) == null) { - drawReaction(reaction, graphics, sbgnFormat); + draw(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)); - drawReaction(reaction, graphics, sbgnFormat); + draw(reaction, graphics, params); for (Pair<AbstractNode, PolylineData> pair : oldData) { pair.getLeft().setLine(pair.getRight()); } @@ -258,14 +333,14 @@ public class ReactionConverter { } } if (count == 0) { - drawReaction(reaction, graphics, sbgnFormat); + draw(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); - drawReaction(reaction, graphics, sbgnFormat); + draw(reaction, graphics, params); for (Pair<AbstractNode, PolylineData> pair : oldData) { pair.getLeft().setLine(pair.getRight()); } @@ -448,4 +523,8 @@ public class ReactionConverter { this.pointTransformation = pointTransformation; } + @Override + public void drawText(Reaction bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException { + } + } \ No newline at end of file diff --git a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/package-info.java b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/package-info.java similarity index 70% rename from converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/package-info.java rename to converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/package-info.java index b03d32c941..d3b737737c 100644 --- a/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/reaction/package-info.java +++ b/converter-graphics/src/main/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/package-info.java @@ -3,5 +3,5 @@ * {@link lcsb.mapviewer.db.model.map.reaction.Reaction reactions} on the * {@link java.awt.Graphics2D Graphics2D} object. */ -package lcsb.mapviewer.converter.graphics.reaction; +package lcsb.mapviewer.converter.graphics.bioEntity.reaction; diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java index 940247e162..9407853563 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/AllGraphicsTests.java @@ -1,9 +1,9 @@ package lcsb.mapviewer.converter.graphics; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.AllSpeciesConverterTests; +import lcsb.mapviewer.converter.graphics.bioEntity.reaction.AllReactionTests; import lcsb.mapviewer.converter.graphics.geometry.AllGeometryTests; import lcsb.mapviewer.converter.graphics.placefinder.AllPlaceFinderTest; -import lcsb.mapviewer.converter.graphics.reaction.AllReactionTests; -import lcsb.mapviewer.converter.graphics.species.AllSpeciesConverterTests; import org.junit.runner.RunWith; import org.junit.runners.Suite; diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/ConverterTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/ConverterTest.java index 66e7eaa7ed..59f4964c75 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/ConverterTest.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/ConverterTest.java @@ -7,6 +7,7 @@ import org.junit.Before; import org.junit.Test; import lcsb.mapviewer.commands.ColorExtractor; +import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverterImpl; import lcsb.mapviewer.model.map.compartment.BottomSquareCompartment; import lcsb.mapviewer.model.map.compartment.LeftSquareCompartment; import lcsb.mapviewer.model.map.compartment.RightSquareCompartment; @@ -26,10 +27,10 @@ public class ConverterTest { public void test() { try { ColorExtractor colorExtractor = new ColorExtractor(Color.BLUE, Color.RED); - new ElementConverterImpl(new BottomSquareCompartment("id1"), colorExtractor); - new ElementConverterImpl(new TopSquareCompartment("id2"), colorExtractor); - new ElementConverterImpl(new LeftSquareCompartment("id3"), colorExtractor); - new ElementConverterImpl(new RightSquareCompartment("id4"), colorExtractor); + new BioEntityConverterImpl(new BottomSquareCompartment("id1"), colorExtractor); + new BioEntityConverterImpl(new TopSquareCompartment("id2"), colorExtractor); + new BioEntityConverterImpl(new LeftSquareCompartment("id3"), colorExtractor); + new BioEntityConverterImpl(new RightSquareCompartment("id4"), colorExtractor); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/NormalImageGeneratorTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/NormalImageGeneratorTest.java index 36d384f007..36d84707d1 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/NormalImageGeneratorTest.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/NormalImageGeneratorTest.java @@ -15,7 +15,7 @@ import org.junit.Test; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.commands.CreateHierarchyCommand; import lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params; -import lcsb.mapviewer.converter.graphics.species.ComplexConverter; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.ComplexConverter; import lcsb.mapviewer.model.graphics.PolylineData; import lcsb.mapviewer.model.map.layout.graphics.Layer; import lcsb.mapviewer.model.map.layout.graphics.LayerText; diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/species/AllSpeciesConverterTests.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AllSpeciesConverterTests.java similarity index 73% rename from converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/species/AllSpeciesConverterTests.java rename to converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AllSpeciesConverterTests.java index f964383c73..69e9b97b05 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/species/AllSpeciesConverterTests.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/AllSpeciesConverterTests.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import org.junit.runner.RunWith; import org.junit.runners.Suite; diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/species/SpeciesConverterTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverterTest.java similarity index 87% rename from converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/species/SpeciesConverterTest.java rename to converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverterTest.java index bc8c2b2eaf..1bdacdc9d7 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/species/SpeciesConverterTest.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/element/species/SpeciesConverterTest.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.species; +package lcsb.mapviewer.converter.graphics.bioEntity.element.species; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -15,6 +15,7 @@ import org.junit.Test; import lcsb.mapviewer.commands.ColorExtractor; import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.converter.graphics.bioEntity.element.species.ProteinConverter; import lcsb.mapviewer.model.map.layout.ColorSchema; import lcsb.mapviewer.model.map.layout.GenericColorSchema; import lcsb.mapviewer.model.map.species.GenericProtein; @@ -65,7 +66,7 @@ public class SpeciesConverterTest { ProteinConverter rc = new ProteinConverter(colorExtractor); GenericProtein alias = createAlias(); - rc.drawElement(alias, graphics, new ConverterParams()); + rc.draw(alias, graphics, new ConverterParams()); int val = bi.getRGB((int) alias.getCenterX(), (int) alias.getCenterY()); @@ -79,7 +80,7 @@ public class SpeciesConverterTest { List<ColorSchema> schemas = new ArrayList<>(); schemas.add(schema); - rc.drawElement(alias2, graphics, new ConverterParams(), schemas); + rc.draw(alias2, graphics, new ConverterParams(), schemas); int val2 = bi.getRGB((int) alias.getCenterX(), (int) alias.getCenterY()); @@ -98,7 +99,7 @@ public class SpeciesConverterTest { ProteinConverter rc = new ProteinConverter(colorExtractor); GenericProtein alias = createAlias(); - rc.drawElement(alias, graphics, new ConverterParams()); + rc.draw(alias, graphics, new ConverterParams()); int val = bi.getRGB((int) alias.getCenterX(), (int) alias.getCenterY()); @@ -112,14 +113,14 @@ public class SpeciesConverterTest { List<ColorSchema> schemas = new ArrayList<>(); schemas.add(schema); - rc.drawElement(alias2, graphics, new ConverterParams(), schemas); + rc.draw(alias2, graphics, new ConverterParams(), schemas); int val2 = bi.getRGB((int) alias.getCenterX(), (int) alias.getCenterY()); bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); graphics = bi.createGraphics(); - rc.drawElement(alias2, graphics, new ConverterParams(), new ArrayList<>()); + rc.draw(alias2, graphics, new ConverterParams(), new ArrayList<>()); int val3 = bi.getRGB((int) alias.getCenterX(), (int) alias.getCenterY()); @@ -139,7 +140,7 @@ public class SpeciesConverterTest { ProteinConverter rc = new ProteinConverter(colorExtractor); GenericProtein alias = createAlias(); - rc.drawElement(alias, graphics, new ConverterParams()); + rc.draw(alias, graphics, new ConverterParams()); int val = bi.getRGB((int) alias.getCenterX(), (int) alias.getCenterY()); @@ -157,7 +158,7 @@ public class SpeciesConverterTest { schema.setColor(Color.BLUE); schemas.add(schema); - rc.drawElement(alias2, graphics, new ConverterParams(), schemas); + rc.draw(alias2, graphics, new ConverterParams(), schemas); int val2 = bi.getRGB((int) (alias.getX() + alias.getWidth() / 4), (int) alias.getCenterY()); int val3 = bi.getRGB((int) (alias.getCenterX()), (int) alias.getCenterY()); diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/reaction/AllReactionTests.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/AllReactionTests.java similarity index 74% rename from converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/reaction/AllReactionTests.java rename to converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/AllReactionTests.java index 532c850e89..eb1ffeb4e9 100644 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/reaction/AllReactionTests.java +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/AllReactionTests.java @@ -1,4 +1,4 @@ -package lcsb.mapviewer.converter.graphics.reaction; +package lcsb.mapviewer.converter.graphics.bioEntity.reaction; import org.junit.runner.RunWith; import org.junit.runners.Suite; diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java new file mode 100644 index 0000000000..6d2fe4eb5e --- /dev/null +++ b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/bioEntity/reaction/ReactionConverterTest.java @@ -0,0 +1,407 @@ +package lcsb.mapviewer.converter.graphics.bioEntity.reaction; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.awt.Color; +import java.awt.Desktop; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.geom.GeneralPath; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.imageio.ImageIO; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import lcsb.mapviewer.commands.ColorExtractor; +import lcsb.mapviewer.converter.graphics.ConverterParams; +import lcsb.mapviewer.model.graphics.PolylineData; +import lcsb.mapviewer.model.map.layout.ColorSchema; +import lcsb.mapviewer.model.map.layout.GenericColorSchema; +import lcsb.mapviewer.model.map.modifier.Catalysis; +import lcsb.mapviewer.model.map.reaction.AndOperator; +import lcsb.mapviewer.model.map.reaction.Modifier; +import lcsb.mapviewer.model.map.reaction.OrOperator; +import lcsb.mapviewer.model.map.reaction.Product; +import lcsb.mapviewer.model.map.reaction.Reactant; +import lcsb.mapviewer.model.map.reaction.Reaction; +import lcsb.mapviewer.model.map.reaction.SplitOperator; +import lcsb.mapviewer.model.map.species.GenericProtein; + +public class ReactionConverterTest { + + ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testDrawReactionWithLayouts() throws Exception { + try { + BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = bi.createGraphics(); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createReaction(5.0); + rc.draw(reaction, graphics, new ConverterParams().sbgnFormat(false)); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageIO.write(bi, "PNG", outputStream); + byte[] output1 = outputStream.toByteArray(); + + Reaction reaction2 = createReaction(1.0); + + bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + graphics = bi.createGraphics(); + + ColorSchema schema = new GenericColorSchema(); + schema.setColor(Color.BLACK); + schema.setLineWidth(5.0); + List<ColorSchema> schemas = new ArrayList<>(); + schemas.add(schema); + + rc.draw(reaction2, graphics, new ConverterParams().sbgnFormat(false), schemas); + + outputStream = new ByteArrayOutputStream(); + ImageIO.write(bi, "PNG", outputStream); + byte[] output2 = outputStream.toByteArray(); + + // FileUtils.writeByteArrayToFile(new File("tmp.png"), output1); + // FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2); + // + // Desktop.getDesktop().open(new File("tmp.png")); + // Desktop.getDesktop().open(new File("tmp2.png")); + + assertTrue(Arrays.equals(output1, output2)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawAfterDrawingReactionWithLayouts() throws Exception { + try { + BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = bi.createGraphics(); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createReaction(1.0); + rc.draw(reaction, graphics, new ConverterParams().sbgnFormat(false)); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageIO.write(bi, "PNG", outputStream); + byte[] output1 = outputStream.toByteArray(); + + Reaction reaction2 = createReaction(1.0); + + bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + graphics = bi.createGraphics(); + + ColorSchema schema = new GenericColorSchema(); + schema.setColor(Color.BLACK); + schema.setLineWidth(5.0); + List<ColorSchema> schemas = new ArrayList<>(); + schemas.add(schema); + + rc.draw(reaction2, graphics, new ConverterParams().sbgnFormat(false), schemas); + bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + graphics = bi.createGraphics(); + rc.draw(reaction2, graphics, new ConverterParams().sbgnFormat(false), new ArrayList<>()); + + outputStream = new ByteArrayOutputStream(); + ImageIO.write(bi, "PNG", outputStream); + byte[] output2 = outputStream.toByteArray(); + + // FileUtils.writeByteArrayToFile(new File("tmp.png"), output1); + // FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2); + // + // Desktop.getDesktop().open(new File("tmp.png")); + // Desktop.getDesktop().open(new File("tmp2.png")); + + assertTrue(Arrays.equals(output1, output2)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawReactionWithFewLayouts() throws Exception { + try { + BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = bi.createGraphics(); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createReaction(3.0); + rc.draw(reaction, graphics, new ConverterParams().sbgnFormat(false)); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ImageIO.write(bi, "PNG", outputStream); + byte[] output1 = outputStream.toByteArray(); + + Reaction reaction2 = createReaction(1.0); + + bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); + graphics = bi.createGraphics(); + + ColorSchema schema = new GenericColorSchema(); + schema.setColor(Color.BLACK); + schema.setLineWidth(5.0); + List<ColorSchema> schemas = new ArrayList<>(); + schemas.add(schema); + schemas.add(schema); + + rc.draw(reaction2, graphics, new ConverterParams().sbgnFormat(false), schemas); + + outputStream = new ByteArrayOutputStream(); + ImageIO.write(bi, "PNG", outputStream); + byte[] output2 = outputStream.toByteArray(); + + // FileUtils.writeByteArrayToFile(new File("tmp.png"), output1); + // FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2); + // + // Desktop.getDesktop().open(new File("tmp.png")); + // Desktop.getDesktop().open(new File("tmp2.png")); + + assertTrue(Arrays.equals(output1, output2)); + + } catch (Exception e) { + throw e; + } + } + + 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); + + 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; + } + + private Reaction createComplexReaction(double lineWidth) { + Reaction result = new Reaction(); + + Modifier modifier1 = new Catalysis(new GenericProtein("s1-1")); + modifier1.setLine(new PolylineData(new Point2D.Double(80, 20), new Point2D.Double(100, 40))); + modifier1.getLine().setWidth(lineWidth); + + Modifier modifier2 = new Catalysis(new GenericProtein("s1-2")); + modifier2.setLine(new PolylineData(new Point2D.Double(120, 20), new Point2D.Double(100, 40))); + modifier2.getLine().setWidth(lineWidth); + + AndOperator modifierOperator = new AndOperator(); + modifierOperator.addInput(modifier1); + modifierOperator.addInput(modifier2); + modifierOperator.setLine(new PolylineData(new Point2D.Double(100, 40), new Point2D.Double(100, 80))); + + Reactant reactant1 = new Reactant(new GenericProtein("s2-1")); + reactant1.setLine(new PolylineData(new Point2D.Double(60, 90), new Point2D.Double(10, 70))); + reactant1.getLine().setWidth(lineWidth); + Reactant reactant2 = new Reactant(new GenericProtein("s2-1")); + reactant2.setLine(new PolylineData(new Point2D.Double(60, 90), new Point2D.Double(10, 110))); + reactant2.getLine().setWidth(lineWidth); + OrOperator reactantOperator = new OrOperator(); + reactantOperator.addInput(reactant1); + reactantOperator.addInput(reactant2); + reactantOperator.setLine(new PolylineData(new Point2D.Double(60, 90), new Point2D.Double(90, 90))); + + Product product1 = new Product(new GenericProtein("s3-1")); + product1.setLine(new PolylineData(new Point2D.Double(200, 70), new Point2D.Double(130, 90))); + product1.getLine().setWidth(lineWidth); + Product product2 = new Product(new GenericProtein("s3-2")); + product2.setLine(new PolylineData(new Point2D.Double(200, 110), new Point2D.Double(130, 90))); + product2.getLine().setWidth(lineWidth); + SplitOperator productOperator = new SplitOperator(); + productOperator.addOutput(product1); + productOperator.addOutput(product2); + productOperator.setLine(new PolylineData(new Point2D.Double(130, 90), new Point2D.Double(110, 90))); + + result.addModifier(modifier1); + result.addModifier(modifier2); + result.addNode(modifierOperator); + result.addProduct(product1); + result.addProduct(product2); + result.addNode(productOperator); + result.addReactant(reactant1); + result.addReactant(reactant2); + result.addNode(reactantOperator); + return result; + } + + @Test + public void testDrawReactionWithSemanticZooming() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createReaction(1.0); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(4)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawReactionWithSemanticZoomingAndModifierOff() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createReaction(1.0); + reaction.getModifiers().get(0).getElement().setSemanticZoomLevelVisibility("11"); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(3)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawReactionWithSemanticZoomingAndReactantOff() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createReaction(1.0); + reaction.getReactants().get(0).getElement().setSemanticZoomLevelVisibility("11"); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(3)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawReactionWithSemanticZoomingAndProductOff() throws Exception { + try { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createReaction(1.0); + reaction.getProducts().get(0).getElement().setSemanticZoomLevelVisibility("11"); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(3)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawComplexReactionWithSemanticZoomingAndModiferOff() throws Exception { + try { + Graphics2D graphics = createGraphicsMock(); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createComplexReaction(1.0); + reaction.getModifiers().get(0).getElement().setSemanticZoomLevelVisibility("11"); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(12)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawComplexReactionWithSemanticZoomingAndAllModifersOff() throws Exception { + try { + Graphics2D graphics = createGraphicsMock(); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createComplexReaction(1.0); + reaction.getModifiers().get(0).getElement().setSemanticZoomLevelVisibility("11"); + reaction.getModifiers().get(1).getElement().setSemanticZoomLevelVisibility("11"); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(9)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + private Graphics2D createGraphicsMock() { + Graphics2D graphics = Mockito.mock(Graphics2D.class); + FontMetrics fontMetrics = Mockito.mock(FontMetrics.class); + when(fontMetrics.getStringBounds(any(), any())).thenReturn(new Rectangle2D.Double()); + when(graphics.getFontMetrics()).thenReturn(fontMetrics); + return graphics; + } + + @Test + public void testDrawComplexReactionWithSemanticZoomingAndReactantOff() throws Exception { + try { + Graphics2D graphics = createGraphicsMock(); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createComplexReaction(1.0); + reaction.getReactants().get(0).getElement().setSemanticZoomLevelVisibility("11"); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(12)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + + @Test + public void testDrawComplexReactionWithSemanticZoomingAndProductOff() throws Exception { + try { + Graphics2D graphics = createGraphicsMock(); + ReactionConverter rc = new ReactionConverter(colorExtractor); + + Reaction reaction = createComplexReaction(1.0); + reaction.getProducts().get(0).getElement().setSemanticZoomLevelVisibility("11"); + rc.draw(reaction, graphics, new ConverterParams().semanticZoomingOn(true).level(10)); + + verify(graphics, times(12)).draw(any(GeneralPath.class)); + + } catch (Exception e) { + throw e; + } + } + +} diff --git a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverterTest.java b/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverterTest.java deleted file mode 100644 index fa4a9c6b2b..0000000000 --- a/converter-graphics/src/test/java/lcsb/mapviewer/converter/graphics/reaction/ReactionConverterTest.java +++ /dev/null @@ -1,196 +0,0 @@ -package lcsb.mapviewer.converter.graphics.reaction; - -import static org.junit.Assert.assertTrue; - -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.geom.Point2D; -import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.imageio.ImageIO; - -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import lcsb.mapviewer.commands.ColorExtractor; -import lcsb.mapviewer.model.graphics.PolylineData; -import lcsb.mapviewer.model.map.layout.ColorSchema; -import lcsb.mapviewer.model.map.layout.GenericColorSchema; -import lcsb.mapviewer.model.map.modifier.Catalysis; -import lcsb.mapviewer.model.map.reaction.Modifier; -import lcsb.mapviewer.model.map.reaction.Product; -import lcsb.mapviewer.model.map.reaction.Reactant; -import lcsb.mapviewer.model.map.reaction.Reaction; - -public class ReactionConverterTest { - - ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testDrawReactionWithLayouts() throws Exception { - try { - BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); - Graphics2D graphics = bi.createGraphics(); - ReactionConverter rc = new ReactionConverter(colorExtractor); - - Reaction reaction = createReaction(5.0); - rc.drawReaction(reaction, graphics, false); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ImageIO.write(bi, "PNG", outputStream); - byte[] output1 = outputStream.toByteArray(); - - Reaction reaction2 = createReaction(1.0); - - bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); - graphics = bi.createGraphics(); - - ColorSchema schema = new GenericColorSchema(); - schema.setColor(Color.BLACK); - schema.setLineWidth(5.0); - List<ColorSchema> schemas = new ArrayList<>(); - schemas.add(schema); - - rc.drawReaction(reaction2, graphics, false, schemas); - - outputStream = new ByteArrayOutputStream(); - ImageIO.write(bi, "PNG", outputStream); - byte[] output2 = outputStream.toByteArray(); - - // FileUtils.writeByteArrayToFile(new File("tmp.png"), output1); - // FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2); - // - // Desktop.getDesktop().open(new File("tmp.png")); - // Desktop.getDesktop().open(new File("tmp2.png")); - - assertTrue(Arrays.equals(output1, output2)); - - } catch (Exception e) { - throw e; - } - } - - @Test - public void testDrawAfterDrawingReactionWithLayouts() throws Exception { - try { - BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); - Graphics2D graphics = bi.createGraphics(); - ReactionConverter rc = new ReactionConverter(colorExtractor); - - Reaction reaction = createReaction(1.0); - rc.drawReaction(reaction, graphics, false); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ImageIO.write(bi, "PNG", outputStream); - byte[] output1 = outputStream.toByteArray(); - - Reaction reaction2 = createReaction(1.0); - - bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); - graphics = bi.createGraphics(); - - ColorSchema schema = new GenericColorSchema(); - schema.setColor(Color.BLACK); - schema.setLineWidth(5.0); - List<ColorSchema> schemas = new ArrayList<>(); - schemas.add(schema); - - rc.drawReaction(reaction2, graphics, false, schemas); - bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); - graphics = bi.createGraphics(); - rc.drawReaction(reaction2, graphics, false, new ArrayList<>()); - - outputStream = new ByteArrayOutputStream(); - ImageIO.write(bi, "PNG", outputStream); - byte[] output2 = outputStream.toByteArray(); - - // FileUtils.writeByteArrayToFile(new File("tmp.png"), output1); - // FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2); - // - // Desktop.getDesktop().open(new File("tmp.png")); - // Desktop.getDesktop().open(new File("tmp2.png")); - - assertTrue(Arrays.equals(output1, output2)); - - } catch (Exception e) { - throw e; - } - } - - @Test - public void testDrawReactionWithFewLayouts() throws Exception { - try { - BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); - Graphics2D graphics = bi.createGraphics(); - ReactionConverter rc = new ReactionConverter(colorExtractor); - - Reaction reaction = createReaction(3.0); - rc.drawReaction(reaction, graphics, false); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ImageIO.write(bi, "PNG", outputStream); - byte[] output1 = outputStream.toByteArray(); - - Reaction reaction2 = createReaction(1.0); - - bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); - graphics = bi.createGraphics(); - - ColorSchema schema = new GenericColorSchema(); - schema.setColor(Color.BLACK); - schema.setLineWidth(5.0); - List<ColorSchema> schemas = new ArrayList<>(); - schemas.add(schema); - schemas.add(schema); - - rc.drawReaction(reaction2, graphics, false, schemas); - - outputStream = new ByteArrayOutputStream(); - ImageIO.write(bi, "PNG", outputStream); - byte[] output2 = outputStream.toByteArray(); - - // FileUtils.writeByteArrayToFile(new File("tmp.png"), output1); - // FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2); - // - // Desktop.getDesktop().open(new File("tmp.png")); - // Desktop.getDesktop().open(new File("tmp2.png")); - - assertTrue(Arrays.equals(output1, output2)); - - } catch (Exception e) { - throw e; - } - } - - private Reaction createReaction(double lineWidth) { - Reaction result = new Reaction(); - Modifier modifier = new Catalysis(); - modifier.setLine(new PolylineData(new Point2D.Double(10, 20), new Point2D.Double(10, 100))); - modifier.getLine().setWidth(lineWidth); - - Reactant reactant = new Reactant(); - reactant.setLine(new PolylineData(new Point2D.Double(100, 20), new Point2D.Double(100, 100))); - reactant.getLine().setWidth(lineWidth); - Product product = new Product(); - product.setLine(new PolylineData(new Point2D.Double(150, 20), new Point2D.Double(150, 100))); - product.getLine().setWidth(lineWidth); - result.addModifier(modifier); - result.addProduct(product); - result.addReactant(reactant); - return result; - } - -} diff --git a/model/src/main/java/lcsb/mapviewer/model/map/AnnotatedObject.java b/model/src/main/java/lcsb/mapviewer/model/map/AnnotatedObject.java index e13e3aa864..cca3829b52 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/AnnotatedObject.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/AnnotatedObject.java @@ -126,13 +126,15 @@ public interface AnnotatedObject extends Serializable { void setName(String name); int getId(); - /** * Return human readable {@link String} representing class. * * @return human readable {@link String} representing class */ - public abstract String getStringType(); - + String getStringType(); + + void setSemanticZoomLevelVisibility(String zoomLevelVisibility); + + String getSemanticZoomLevelVisibility(); } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java b/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java index 90c1e5cdc6..79059ab4cb 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/reaction/Reaction.java @@ -180,6 +180,11 @@ public class Reaction implements AnnotatedObject { */ private String geneProteinReaction = null; + /** + * Zoom level visibility for semantic zooming. + */ + private String zoomLevelVisibility; + /** * Lists of all synonyms used for describing this element. */ @@ -867,4 +872,14 @@ public class Reaction implements AnnotatedObject { this.synonyms.add(synonym); } + @Override + public String getSemanticZoomLevelVisibility() { + return zoomLevelVisibility; + } + + @Override + public void setSemanticZoomLevelVisibility(String zoomLevelVisibility) { + this.zoomLevelVisibility = zoomLevelVisibility; + } + } 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 e624b92ffb..80530dda25 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 @@ -214,6 +214,11 @@ public abstract class Element implements AnnotatedObject, Serializable { */ private String fullName; + /** + * Zoom level visibility for semantic zooming. + */ + private String zoomLevelVisibility; + /** * Abbreviation associated with the element. */ @@ -1086,4 +1091,13 @@ public abstract class Element implements AnnotatedObject, Serializable { dataMining.setElement(this); } + @Override + public void setSemanticZoomLevelVisibility(String zoomLevelVisibility) { + this.zoomLevelVisibility = zoomLevelVisibility; + } + + public String getSemanticZoomLevelVisibility(){ + return this.zoomLevelVisibility; + } + } \ No newline at end of file -- GitLab