Commit 21b28450 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

drawing of glyphs implemented

parent e4ea5135
......@@ -72,6 +72,22 @@ public abstract class BioEntityConverter<T extends BioEntity> {
draw(bioEntity, graphics, params, new ArrayList<>());
}
/**
* This function draw {@link BioEntity} on the {@link Graphics2D} object.
*
* @param bioEntity
* {@link BioEntity} that should be drawn
* @param graphics
* where we want to draw bioEntity
* @param params
* visualization params (like, should the object be filled with solid
* color, etc.), for more information see {@link ConverterParams}
* @throws DrawingException
* thrown when there is a problem with drawing {@link BioEntity}
*
*/
protected abstract void drawImpl(T bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException;
/**
* This function draw representation of the alias on the graphics object.
*
......@@ -90,7 +106,7 @@ public abstract class BioEntityConverter<T extends BioEntity> {
* thrown when there is a problem with drawing {@link BioEntity}
*
*/
public abstract void draw(T bioEntity, Graphics2D graphics, ConverterParams params,
protected abstract void draw(T bioEntity, Graphics2D graphics, ConverterParams params,
List<ColorSchema> visualizedOverlaysColorSchemas)
throws DrawingException;
......
......@@ -199,4 +199,10 @@ public class BioEntityConverterImpl extends BioEntityConverter<BioEntity> {
}
}
@SuppressWarnings("unchecked")
@Override
protected void drawImpl(BioEntity bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException {
elementConverter.draw(bioEntity, graphics, params);
}
}
package lcsb.mapviewer.converter.graphics.bioEntity.element;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.converter.graphics.bioEntity.BioEntityConverter;
import lcsb.mapviewer.model.map.layout.graphics.Glyph;
import lcsb.mapviewer.model.map.species.Element;
/**
......@@ -14,4 +24,37 @@ import lcsb.mapviewer.model.map.species.Element;
*/
public abstract class ElementConverter<T extends Element> extends BioEntityConverter<T> {
@Override
public final void draw(T bioEntity, Graphics2D graphics, ConverterParams params) throws DrawingException {
if (bioEntity.getGlyph() != null) {
drawGlyph(bioEntity, graphics);
} else {
super.draw(bioEntity, graphics, params);
}
}
/**
* Draws a {@link Glyph} for given bioEntity.
*
* @param bioEntity
* element that should be visualized as a {@link Glyph}
* @param graphics
* {@link Graphics2D} where we are drawing
* @throws DrawingException
* thrown when there is a problem with drawing
*/
private void drawGlyph(T bioEntity, Graphics2D graphics) throws DrawingException {
try {
Image img = ImageIO.read(new ByteArrayInputStream(bioEntity.getGlyph().getFile().getFileContent()));
graphics.drawImage(img,
bioEntity.getX().intValue(), bioEntity.getY().intValue(),
(int) (bioEntity.getX() + bioEntity.getWidth()), (int) (bioEntity.getY() + bioEntity.getHeight()),
0, 0, img.getWidth(null), img.getHeight(null),
null);
} catch (IOException e) {
throw new DrawingException(
"Problem with processing glyph file: " + bioEntity.getGlyph().getFile().getOriginalFileName(), e);
}
}
}
......@@ -45,7 +45,7 @@ public class BottomSquareCompartmentConverter extends CompartmentConverter<Botto
}
@Override
public void draw(final BottomSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
protected void drawImpl(final BottomSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
// keep the old values of colors and line
Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke();
......
......@@ -179,7 +179,7 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen
@Override
public void draw(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException {
draw(alias, graphics, params);
drawImpl(alias, graphics, params);
Color oldColor = graphics.getColor();
int count = 0;
......
......@@ -45,7 +45,7 @@ public class LeftSquareCompartmentConverter extends CompartmentConverter<LeftSqu
}
@Override
public void draw(final LeftSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
protected void drawImpl(final LeftSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
// keep the old values of color and line type
Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke();
......
......@@ -48,7 +48,7 @@ public class OvalCompartmentConverter extends CompartmentConverter<OvalCompartme
}
@Override
public void draw(final OvalCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
protected void drawImpl(final OvalCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
// keep the old values of color and line type
Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke();
......
......@@ -36,7 +36,7 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom
}
@Override
public void draw(final PathwayCompartment compartment, final Graphics2D graphics, final ConverterParams params)
protected void drawImpl(final PathwayCompartment compartment, final Graphics2D graphics, final ConverterParams params)
throws DrawingException {
// keep the old values of colors and line
Color oldColor = graphics.getColor();
......
......@@ -45,7 +45,7 @@ public class RightSquareCompartmentConverter extends CompartmentConverter<RightS
}
@Override
public void draw(final RightSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
protected void drawImpl(final RightSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
// keep the old values of color and line type
Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke();
......
......@@ -61,7 +61,7 @@ public class SquareCompartmentConverter extends CompartmentConverter<SquareCompa
}
@Override
public void draw(final SquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
protected void drawImpl(final SquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
// keep the old values of color and line type
Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke();
......
......@@ -45,7 +45,7 @@ public class TopSquareCompartmentConverter extends CompartmentConverter<TopSquar
}
@Override
public void draw(final TopSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
protected void drawImpl(final TopSquareCompartment compartment, final Graphics2D graphics, final ConverterParams params) throws DrawingException {
Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke();
......
......@@ -44,7 +44,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> {
}
@Override
public void draw(final AntisenseRna antisenseRna, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final AntisenseRna antisenseRna, final Graphics2D graphics, final ConverterParams params) {
GeneralPath path = getAntisenseRnaPath(antisenseRna);
Color c = graphics.getColor();
graphics.setColor(antisenseRna.getColor());
......
......@@ -57,7 +57,7 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
}
@Override
public void draw(final Complex alias, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final Complex alias, final Graphics2D graphics, final ConverterParams params) {
if (alias.getState().equalsIgnoreCase("complexnoborder")) {
return;
}
......
......@@ -49,7 +49,7 @@ public class DegradedConverter extends SpeciesConverter<Degraded> {
}
@Override
public void draw(final Degraded degraded, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final Degraded degraded, final Graphics2D graphics, final ConverterParams params) {
double diameter = getDiameter(degraded);
double x = getXCoord(degraded, diameter);
double y = getYCoord(degraded);
......
......@@ -67,7 +67,7 @@ public class DrugConverter extends SpeciesConverter<Drug> {
}
@Override
public void draw(Drug drug, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(Drug drug, final Graphics2D graphics, final ConverterParams params) {
Shape a1 = getDrugShape(drug);
double offset = OFFSET_BETWEEN_BORDERS;
Shape a2 = new RoundRectangle2D.Double(
......
......@@ -43,7 +43,7 @@ public class GeneConverter extends SpeciesConverter<Gene> {
}
@Override
public void draw(final Gene gene, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final Gene gene, final Graphics2D graphics, final ConverterParams params) {
Shape shape = getGeneShape(gene);
Color c = graphics.getColor();
graphics.setColor(gene.getColor());
......
......@@ -42,7 +42,7 @@ public class IonConverter extends SpeciesConverter<Ion> {
}
@Override
public void draw(Ion ion, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(Ion ion, final Graphics2D graphics, final ConverterParams params) {
double diameter = getDiameter(ion);
double x = getXCoord(ion, diameter);
double y = getYCoord(ion);
......
......@@ -42,7 +42,7 @@ public class PhenotypeConverter extends SpeciesConverter<Phenotype> {
}
@Override
public void draw(Phenotype phenotype, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(Phenotype phenotype, final Graphics2D graphics, final ConverterParams params) {
GeneralPath path = getPhenotypePath(phenotype);
Color c = graphics.getColor();
......
......@@ -87,7 +87,7 @@ public class ProteinConverter extends SpeciesConverter<Protein> {
}
@Override
public void draw(final Protein protein, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final Protein protein, final Graphics2D graphics, final ConverterParams params) {
// Local variable setting the SBGN visualization
boolean sbgnFormat = params.isSbgnFormat();
......
......@@ -50,7 +50,7 @@ public class RnaConverter extends SpeciesConverter<Rna> {
}
@Override
public void draw(final Rna rna, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final Rna rna, final Graphics2D graphics, final ConverterParams params) {
GeneralPath path = getRnaPath(rna);
Color c = graphics.getColor();
graphics.setColor(rna.getColor());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment