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> { ...@@ -72,6 +72,22 @@ public abstract class BioEntityConverter<T extends BioEntity> {
draw(bioEntity, graphics, params, new ArrayList<>()); 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. * This function draw representation of the alias on the graphics object.
* *
...@@ -90,7 +106,7 @@ public abstract class BioEntityConverter<T extends BioEntity> { ...@@ -90,7 +106,7 @@ public abstract class BioEntityConverter<T extends BioEntity> {
* thrown when there is a problem with drawing {@link 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) List<ColorSchema> visualizedOverlaysColorSchemas)
throws DrawingException; throws DrawingException;
......
...@@ -199,4 +199,10 @@ public class BioEntityConverterImpl extends BioEntityConverter<BioEntity> { ...@@ -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; 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.converter.graphics.bioEntity.BioEntityConverter;
import lcsb.mapviewer.model.map.layout.graphics.Glyph;
import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Element;
/** /**
...@@ -14,4 +24,37 @@ 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> { 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 ...@@ -45,7 +45,7 @@ public class BottomSquareCompartmentConverter extends CompartmentConverter<Botto
} }
@Override @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 // keep the old values of colors and line
Color oldColor = graphics.getColor(); Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke(); Stroke oldStroke = graphics.getStroke();
......
...@@ -179,7 +179,7 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen ...@@ -179,7 +179,7 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen
@Override @Override
public void draw(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException { 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(); Color oldColor = graphics.getColor();
int count = 0; int count = 0;
......
...@@ -45,7 +45,7 @@ public class LeftSquareCompartmentConverter extends CompartmentConverter<LeftSqu ...@@ -45,7 +45,7 @@ public class LeftSquareCompartmentConverter extends CompartmentConverter<LeftSqu
} }
@Override @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 // keep the old values of color and line type
Color oldColor = graphics.getColor(); Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke(); Stroke oldStroke = graphics.getStroke();
......
...@@ -48,7 +48,7 @@ public class OvalCompartmentConverter extends CompartmentConverter<OvalCompartme ...@@ -48,7 +48,7 @@ public class OvalCompartmentConverter extends CompartmentConverter<OvalCompartme
} }
@Override @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 // keep the old values of color and line type
Color oldColor = graphics.getColor(); Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke(); Stroke oldStroke = graphics.getStroke();
......
...@@ -36,7 +36,7 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom ...@@ -36,7 +36,7 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom
} }
@Override @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 { throws DrawingException {
// keep the old values of colors and line // keep the old values of colors and line
Color oldColor = graphics.getColor(); Color oldColor = graphics.getColor();
......
...@@ -45,7 +45,7 @@ public class RightSquareCompartmentConverter extends CompartmentConverter<RightS ...@@ -45,7 +45,7 @@ public class RightSquareCompartmentConverter extends CompartmentConverter<RightS
} }
@Override @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 // keep the old values of color and line type
Color oldColor = graphics.getColor(); Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke(); Stroke oldStroke = graphics.getStroke();
......
...@@ -61,7 +61,7 @@ public class SquareCompartmentConverter extends CompartmentConverter<SquareCompa ...@@ -61,7 +61,7 @@ public class SquareCompartmentConverter extends CompartmentConverter<SquareCompa
} }
@Override @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 // keep the old values of color and line type
Color oldColor = graphics.getColor(); Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke(); Stroke oldStroke = graphics.getStroke();
......
...@@ -45,7 +45,7 @@ public class TopSquareCompartmentConverter extends CompartmentConverter<TopSquar ...@@ -45,7 +45,7 @@ public class TopSquareCompartmentConverter extends CompartmentConverter<TopSquar
} }
@Override @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(); Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke(); Stroke oldStroke = graphics.getStroke();
......
...@@ -44,7 +44,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> { ...@@ -44,7 +44,7 @@ public class AntisenseRnaConverter extends SpeciesConverter<AntisenseRna> {
} }
@Override @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); GeneralPath path = getAntisenseRnaPath(antisenseRna);
Color c = graphics.getColor(); Color c = graphics.getColor();
graphics.setColor(antisenseRna.getColor()); graphics.setColor(antisenseRna.getColor());
......
...@@ -57,7 +57,7 @@ public class ComplexConverter extends SpeciesConverter<Complex> { ...@@ -57,7 +57,7 @@ public class ComplexConverter extends SpeciesConverter<Complex> {
} }
@Override @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")) { if (alias.getState().equalsIgnoreCase("complexnoborder")) {
return; return;
} }
......
...@@ -49,7 +49,7 @@ public class DegradedConverter extends SpeciesConverter<Degraded> { ...@@ -49,7 +49,7 @@ public class DegradedConverter extends SpeciesConverter<Degraded> {
} }
@Override @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 diameter = getDiameter(degraded);
double x = getXCoord(degraded, diameter); double x = getXCoord(degraded, diameter);
double y = getYCoord(degraded); double y = getYCoord(degraded);
......
...@@ -67,7 +67,7 @@ public class DrugConverter extends SpeciesConverter<Drug> { ...@@ -67,7 +67,7 @@ public class DrugConverter extends SpeciesConverter<Drug> {
} }
@Override @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); Shape a1 = getDrugShape(drug);
double offset = OFFSET_BETWEEN_BORDERS; double offset = OFFSET_BETWEEN_BORDERS;
Shape a2 = new RoundRectangle2D.Double( Shape a2 = new RoundRectangle2D.Double(
......
...@@ -43,7 +43,7 @@ public class GeneConverter extends SpeciesConverter<Gene> { ...@@ -43,7 +43,7 @@ public class GeneConverter extends SpeciesConverter<Gene> {
} }
@Override @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); Shape shape = getGeneShape(gene);
Color c = graphics.getColor(); Color c = graphics.getColor();
graphics.setColor(gene.getColor()); graphics.setColor(gene.getColor());
......
...@@ -42,7 +42,7 @@ public class IonConverter extends SpeciesConverter<Ion> { ...@@ -42,7 +42,7 @@ public class IonConverter extends SpeciesConverter<Ion> {
} }
@Override @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 diameter = getDiameter(ion);
double x = getXCoord(ion, diameter); double x = getXCoord(ion, diameter);
double y = getYCoord(ion); double y = getYCoord(ion);
......
...@@ -42,7 +42,7 @@ public class PhenotypeConverter extends SpeciesConverter<Phenotype> { ...@@ -42,7 +42,7 @@ public class PhenotypeConverter extends SpeciesConverter<Phenotype> {
} }
@Override @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); GeneralPath path = getPhenotypePath(phenotype);
Color c = graphics.getColor(); Color c = graphics.getColor();
......
...@@ -87,7 +87,7 @@ public class ProteinConverter extends SpeciesConverter<Protein> { ...@@ -87,7 +87,7 @@ public class ProteinConverter extends SpeciesConverter<Protein> {
} }
@Override @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 // Local variable setting the SBGN visualization
boolean sbgnFormat = params.isSbgnFormat(); boolean sbgnFormat = params.isSbgnFormat();
......
...@@ -50,7 +50,7 @@ public class RnaConverter extends SpeciesConverter<Rna> { ...@@ -50,7 +50,7 @@ public class RnaConverter extends SpeciesConverter<Rna> {
} }
@Override @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); GeneralPath path = getRnaPath(rna);
Color c = graphics.getColor(); Color c = graphics.getColor();
graphics.setColor(rna.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