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

javadocs

parent 668e2a0e
...@@ -69,6 +69,10 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService { ...@@ -69,6 +69,10 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
* Url that list of all child nodes for chembl ontology term. * Url that list of all child nodes for chembl ontology term.
*/ */
private static final String PARENT_CHILD_API_URL = "https://www.ebi.ac.uk/chembl/api/data/molecule_form/"; private static final String PARENT_CHILD_API_URL = "https://www.ebi.ac.uk/chembl/api/data/molecule_form/";
/**
* Suffix that should be added to {@link #PARENT_CHILD_API_URL}.
*/
private static final String PARENT_CHILD_API_URL_SUFFIX = ".xml"; private static final String PARENT_CHILD_API_URL_SUFFIX = ".xml";
/** /**
......
...@@ -4,6 +4,12 @@ import java.awt.Color; ...@@ -4,6 +4,12 @@ import java.awt.Color;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
/**
* Parser clas to extract {@link Color} objects from {@link String}.
*
* @author Piotr Gawron
*
*/
public class ColorParser { public class ColorParser {
/** /**
...@@ -31,6 +37,13 @@ public class ColorParser { ...@@ -31,6 +37,13 @@ public class ColorParser {
*/ */
private static final int COLOR_SUBSTRING_START_BLUE = 5; private static final int COLOR_SUBSTRING_START_BLUE = 5;
/**
* Extracts {@link Color} from input {@link String}.
*
* @param string
* text to process
* @return {@link Color} obtained from input text
*/
public Color parse(String string) { public Color parse(String string) {
if (string.charAt(0) != '#') { if (string.charAt(0) != '#') {
string = "#" + string; string = "#" + string;
......
...@@ -27,6 +27,7 @@ import lcsb.mapviewer.model.map.reaction.Reaction; ...@@ -27,6 +27,7 @@ import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Complex; import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/** /**
* This class is responsible for creation of the image from the model. It's an * This class is responsible for creation of the image from the model. It's an
...@@ -94,8 +95,16 @@ public abstract class AbstractImageGenerator { ...@@ -94,8 +95,16 @@ public abstract class AbstractImageGenerator {
*/ */
private Rectangle2D.Double border = null; private Rectangle2D.Double border = null;
/**
* Object that helps to convert {@link ColorSchema} values into colors.
*/
private ColorExtractor colorExtractor = null; private ColorExtractor colorExtractor = null;
/**
* Util class for simple operations on {@link Element elements}.
*/
private ElementUtils eu = new ElementUtils();
/** /**
* This class contains a list of params that are used for drawing. * This class contains a list of params that are used for drawing.
* *
...@@ -173,8 +182,14 @@ public abstract class AbstractImageGenerator { ...@@ -173,8 +182,14 @@ public abstract class AbstractImageGenerator {
*/ */
private List<Map<Object, ColorSchema>> visibleLayouts = new ArrayList<>(); private List<Map<Object, ColorSchema>> visibleLayouts = new ArrayList<>();
/**
* Color that should be used for drawing overlays with minimum value.
*/
private Color minColor = null; private Color minColor = null;
/**
* Color that should be used for drawing overlays with maximum value.
*/
private Color maxColor = null; private Color maxColor = null;
/** /**
...@@ -488,19 +503,45 @@ public abstract class AbstractImageGenerator { ...@@ -488,19 +503,45 @@ public abstract class AbstractImageGenerator {
return result; return result;
} }
/**
* Returns {@link Color} that should be used for drawing overlays with
* maximum value.
*
* @return {@link Color} that should be used for drawing overlays with
* maximum value
*/
public Color getMaxColor() { public Color getMaxColor() {
return maxColor; return maxColor;
} }
/**
* Returns {@link Color} that should be used for drawing overlays with
* minimum value.
*
* @return {@link Color} that should be used for drawing overlays with
* minimum value
*/
public Color getMinColor() { public Color getMinColor() {
return minColor; return minColor;
} }
/**
* @param minColor
* minColor to set
* @return object with all parameters
* @see #minColor
*/
public Params minColor(Color minColor) { public Params minColor(Color minColor) {
this.minColor = minColor; this.minColor = minColor;
return this; return this;
} }
/**
* @param maxColor
* maxColor to set
* @return object with all parameters
* @see #maxColor
*/
public Params maxColor(Color maxColor) { public Params maxColor(Color maxColor) {
this.maxColor = maxColor; this.maxColor = maxColor;
return this; return this;
...@@ -584,17 +625,18 @@ public abstract class AbstractImageGenerator { ...@@ -584,17 +625,18 @@ public abstract class AbstractImageGenerator {
// Get the SBGN display format option from the model // Get the SBGN display format option from the model
this.sbgnFormat = params.getModel().isSbgnFormat(); this.sbgnFormat = params.getModel().isSbgnFormat();
// Correct order of displaying is: aliases, reactions, compartments, layers. // Correct order of displaying is: elements, reactions, compartments,
// layers.
// In this way we can display all reactions and overlay them by compartments // In this way we can display all reactions and overlay them by compartments
// or layers if they should be solid and hide complexity behind it // or layers if they should be solid and hide complexity behind it
// draw all aliases // draw all elements
for (Element alias : params.getModel().getSortedSpeciesList()) { for (Element element : params.getModel().getSortedSpeciesList()) {
// draw only aliases that don't have parents (aren't included in any // draw only elements that don't have parents (aren't included in any
// compartment/complexes) // compartment/complexes)
if (alias instanceof Species) { if (element instanceof Species) {
if (((Species) alias).getComplex() == null) { if (((Species) element).getComplex() == null) {
drawAlias((Species) alias, params.getVisibleLayoutsForElement(alias)); drawSpecies((Species) element, params.getVisibleLayoutsForElement(element));
} }
} }
} }
...@@ -603,11 +645,11 @@ public abstract class AbstractImageGenerator { ...@@ -603,11 +645,11 @@ public abstract class AbstractImageGenerator {
drawReaction(reaction, params.getVisibleLayoutsForElement(reaction)); drawReaction(reaction, params.getVisibleLayoutsForElement(reaction));
} }
// draw all compartments // draw all compartments
for (Compartment ca : params.getModel().getSortedCompartments()) { for (Compartment compartment : params.getModel().getSortedCompartments()) {
// draw only aliases that don't have parents (aren't included in any // draw only compartment that don't have parents (aren't included in any
// compartment/complexes) // compartment/complexes)
if (ca.getCompartment() == null) { if (compartment.getCompartment() == null) {
drawCompartmentAlias(ca, params.isNested(), params.getVisibleLayoutsForElement(ca), params); drawCompartment(compartment, params.isNested(), params.getVisibleLayoutsForElement(compartment), params);
} }
} }
...@@ -638,25 +680,26 @@ public abstract class AbstractImageGenerator { ...@@ -638,25 +680,26 @@ public abstract class AbstractImageGenerator {
} }
/** /**
* This method draw a compartment alias on a graphics. * This method draw a {@link Compartment} on a graphics.
* *
* @param compAlias * @param compartment
* object that we want to draw * object that we want to draw
* @param nested * @param nested
* are the compartments drawn in hierarchical view * are the compartments drawn in hierarchical view
* @param visibleLayouts * @param visibleLayouts
* list of {@link ColorSchema} used for coloring alias in layouts * list of {@link ColorSchema} used for coloring element in layouts
* @param params * @param params
* list of all params to create apropriate image * list of all params to create apropriate image
* @throws DrawingException * @throws DrawingException
* thrown when there was a problem with drawing compartment alias * thrown when there was a problem with drawing {@link Compartment}
*/ */
protected void drawCompartmentAlias(final Compartment compAlias, final boolean nested, List<ColorSchema> visibleLayouts, Params params) protected void drawCompartment(final Compartment compartment, final boolean nested, List<ColorSchema> visibleLayouts, Params params)
throws DrawingException { throws DrawingException {
// If 'compAlias' has not the big enough visibility level then should not be // If 'compartment' has not the big enough visibility level then should not
// be
// visible. // visible.
if (compAlias.getVisibilityLevel() > level) { if (compartment.getVisibilityLevel() > level) {
return; return;
} }
...@@ -667,25 +710,25 @@ public abstract class AbstractImageGenerator { ...@@ -667,25 +710,25 @@ public abstract class AbstractImageGenerator {
*/ */
boolean fill = true; boolean fill = true;
if (compAlias.getTransparencyLevel() <= level) { if (compartment.getTransparencyLevel() <= level) {
fill = false; fill = false;
} }
// get a converter for this compartment // get a converter for this compartment
AliasConverter converter = new AliasConverter(compAlias, colorExtractor); ElementConverterImpl converter = new ElementConverterImpl(compartment, colorExtractor);
ConverterParams compartmentParams = new ConverterParams().textCentered(fill).level(level); ConverterParams compartmentParams = new ConverterParams().textCentered(fill).level(level);
if (nested) { if (nested) {
compartmentParams.fill(fill).scale(Math.max(scale, 1)); compartmentParams.fill(fill).scale(Math.max(scale, 1));
} }
// we draw compartment alias only when we have hierarchical view or it's // we draw compartment only when we have hierarchical view or it's
// standard compartment (not the artifital pathway) // standard compartment (not the pathway)
if (nested || !(compAlias instanceof PathwayCompartment)) { if (nested || !(compartment instanceof PathwayCompartment)) {
try { try {
converter.drawAlias(compAlias, graphics, compartmentParams, visibleLayouts); converter.drawElement(compartment, graphics, compartmentParams, visibleLayouts);
} catch (Exception e) { } catch (Exception e) {
throw new DrawingException("Problem with drawing alias \"" + compAlias.getElementId() + "\" (name: \"" + compAlias.getName() + "\").", e); throw new DrawingException(eu.getElementTag(compartment) + "Problem with drawing element.", e);
} }
} }
...@@ -695,48 +738,48 @@ public abstract class AbstractImageGenerator { ...@@ -695,48 +738,48 @@ public abstract class AbstractImageGenerator {
if (fill) { if (fill) {
return; return;
} }
List<Element> result = new ArrayList<Element>(); List<Element> result = new ArrayList<>();
result.addAll(compAlias.getElements()); result.addAll(compartment.getElements());
Collections.sort(result, Element.SIZE_COMPARATOR); Collections.sort(result, Element.SIZE_COMPARATOR);
// draw all children of this compartment // draw all children of this compartment
for (Element alias : result) { for (Element element : result) {
// if a child is a standard alias // if a child is a standard species
if (alias instanceof Species) { if (element instanceof Species) {
drawAlias((Species) alias, params.getVisibleLayoutsForElement(alias)); drawSpecies((Species) element, params.getVisibleLayoutsForElement(element));
} else if (alias instanceof Compartment) { } else if (element instanceof Compartment) {
drawCompartmentAlias((Compartment) alias, nested, params.getVisibleLayoutsForElement(alias), params); drawCompartment((Compartment) element, nested, params.getVisibleLayoutsForElement(element), params);
} else { } else {
// if a child is not a compartment or an alias then we have a // if a child is not a compartment or a species then we have a
// problem // problem
throw new DrawingException("Unknown AliasType: " + alias.getClass().getName()); throw new DrawingException(eu.getElementTag(compartment) + "Unknown Element type");
} }
} }
if (!compAlias.containsIdenticalSpecies()) { if (!compartment.containsIdenticalSpecies()) {
if (!(compAlias instanceof PathwayCompartment)) { if (!(compartment instanceof PathwayCompartment)) {
converter.drawText(compAlias, graphics, compartmentParams); converter.drawText(compartment, graphics, compartmentParams);
} }
} }
} }
/** /**
* This method draw a species alias on a graphics. * This method draw a {@link Species} on a graphics.
* *
* @param alias * @param species
* object to be drawn * object to be drawn
* @param visibleLayouts * @param visibleLayouts
* list of {@link ColorSchema} used for coloring alias in layouts * list of {@link ColorSchema} used for coloring species in layouts
* @throws DrawingException * @throws DrawingException
* thrown when there was a problem with drawing an alias * thrown when there was a problem with drawing a {@link Species}
*/ */
protected void drawAlias(final Species alias, List<ColorSchema> visibleLayouts) throws DrawingException { protected void drawSpecies(final Species species, List<ColorSchema> visibleLayouts) throws DrawingException {
// The displaying of alias is indicated by values of VisibilityLevel. If // The displaying of species is indicated by values of VisibilityLevel. If
// VisibilityLevel is big enough, then it is // VisibilityLevel is big enough, then it is
// displayed. // displayed.
if (alias.getVisibilityLevel() > level) { if (species.getVisibilityLevel() > level) {
return; return;
} }
...@@ -745,42 +788,43 @@ public abstract class AbstractImageGenerator { ...@@ -745,42 +788,43 @@ public abstract class AbstractImageGenerator {
* most bottom Complexes. * most bottom Complexes.
*/ */
if (!cross(alias.getBorder())) { if (!cross(species.getBorder())) {
return; return;
} }
boolean rescale = false; boolean rescale = false;
if (alias instanceof Complex) { if (species instanceof Complex) {
if (((Complex) alias).getElements().size() == 0) { if (((Complex) species).getElements().size() == 0) {
rescale = true; rescale = true;
} else if (((Complex) alias).getElements().get(0).getVisibilityLevel() > level) { } else if (((Complex) species).getElements().get(0).getVisibilityLevel() > level) {
rescale = true; rescale = true;
} }
} }
// at the beginning try to find an appropriate converter // at the beginning try to find an appropriate converter
AliasConverter converter = new AliasConverter(alias, sbgnFormat, colorExtractor); ElementConverterImpl converter = new ElementConverterImpl(species, sbgnFormat, colorExtractor);
double customScale = 1; double customScale = 1;
if (rescale) { if (rescale) {
customScale = scale; customScale = scale;
} }
try { try {
converter.drawAlias(alias, graphics, new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat), visibleLayouts); converter
.drawElement(species, graphics, new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat), visibleLayouts);
} catch (Exception e) { } catch (Exception e) {
throw new DrawingException("Problem with drawing alias \"" + alias.getElementId() + "\".", e); throw new DrawingException(eu.getElementTag(species) + "Problem with drawing element.", e);
} }
// if the alias is a complex alias then we may want to draw children // if the species is a complex then we may want to draw children
// objects // objects
if (alias instanceof Complex) { if (species instanceof Complex) {
Complex complex = (Complex) alias; Complex complex = (Complex) species;
// before drawing children check if the view is not set to brief // before drawing children check if the view is not set to brief
// mode // mode
if (!complex.getState().equalsIgnoreCase("brief")) { if (!complex.getState().equalsIgnoreCase("brief")) {
// depending on current zoom level, children are drawn or not // depending on current zoom level, children are drawn or not
if (complex.getTransparencyLevel() <= level) { if (complex.getTransparencyLevel() <= level) {
for (Species a : complex.getElements()) { for (Species a : complex.getElements()) {
drawAlias(a, visibleLayouts); drawSpecies(a, visibleLayouts);
} }
} }
} }
......
...@@ -15,7 +15,7 @@ import lcsb.mapviewer.model.map.species.Element; ...@@ -15,7 +15,7 @@ import lcsb.mapviewer.model.map.species.Element;
* @param <T> * @param <T>
* class of alias to convert * class of alias to convert
*/ */
public interface IAliasConverter<T extends Element> { public interface ElementConverter<T extends Element> {
/** /**
* Alpha value (0..255) used for visualizing layout data that are normally * Alpha value (0..255) used for visualizing layout data that are normally
* visualized in javascript. * visualized in javascript.
...@@ -35,7 +35,7 @@ public interface IAliasConverter<T extends Element> { ...@@ -35,7 +35,7 @@ public interface IAliasConverter<T extends Element> {
* {@link ConverterParams} * {@link ConverterParams}
* *
*/ */
void drawAlias(T alias, Graphics2D graphics, ConverterParams params); void drawElement(T alias, Graphics2D graphics, ConverterParams params);
/** /**
* This function draw representation of the alias on the graphics object. * This function draw representation of the alias on the graphics object.
...@@ -53,7 +53,7 @@ public interface IAliasConverter<T extends Element> { ...@@ -53,7 +53,7 @@ public interface IAliasConverter<T extends Element> {
* alias in different layouts that should be overlayed on the alias * alias in different layouts that should be overlayed on the alias
* *
*/ */
void drawAlias(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas); void drawElement(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas);
/** /**
* This function will find proper font size to display text within it. Then it * This function will find proper font size to display text within it. Then it
......
...@@ -53,136 +53,140 @@ import lcsb.mapviewer.model.map.species.Unknown; ...@@ -53,136 +53,140 @@ import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.modelutils.map.ElementUtils; import lcsb.mapviewer.modelutils.map.ElementUtils;
/** /**
* This class is designed to convert any type of alias into a graphic glyph that * This class is designed to convert any type of {@link Element} into a graphic
* will be visualized on the graphgics2d object. It contains static instances of * glyph that will be visualized on the {@link Graphics2D} object.
* converter for every type and use one that is needed for currently processed
* alias.
* *
* @author Piotr Gawron * @author Piotr Gawron
* *
*/ */
public class AliasConverter implements IAliasConverter<Element> { public class ElementConverterImpl implements ElementConverter<Element> {
/** /**
* Default class logger. * Default class logger.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(AliasConverter.class.getName()); private static Logger logger = Logger.getLogger(ElementConverterImpl.class.getName());
/** /**
* Returns a converter for given alias. If converter doesn't exist then null * Returns a converter for given element. If converter doesn't exist then
* is returned. * exception is thrown.<