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

drawing of glyphs implemented

parent e4ea5135
......@@ -63,7 +63,7 @@ public class SBGNNucleicAcidFeatureConverter extends SpeciesConverter<Species> {
}
@Override
public void draw(Species species, Graphics2D graphics, ConverterParams params) {
protected void drawImpl(Species species, Graphics2D graphics, ConverterParams params) {
// Unit of information text - multimer cardinality
String unitOfInformationText = null;
if (species.getStatePrefix() != null && species.getStateLabel() != null) {
......
......@@ -42,7 +42,7 @@ public class SimpleMoleculeConverter extends SpeciesConverter<SimpleMolecule> {
}
@Override
public void draw(final SimpleMolecule simpleMolecule, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final SimpleMolecule simpleMolecule, final Graphics2D graphics, final ConverterParams params) {
int homodir;
if (params.isSbgnFormat()) {
// If the SBGN display mode is set, multimer is shown as two stacked
......
......@@ -498,7 +498,7 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
@Override
public void draw(T species, Graphics2D graphics, ConverterParams params,
List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException {
draw(species, graphics, params);
drawImpl(species, graphics, params);
Color oldColor = graphics.getColor();
int count = 0;
......
......@@ -44,7 +44,7 @@ public class UnknownConverter extends SpeciesConverter<Unknown> {
}
@Override
public void draw(Unknown unknown, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(Unknown unknown, final Graphics2D graphics, final ConverterParams params) {
if (unknown.getActivity()) {
int border = ACTIVITY_BORDER_DISTANCE;
unknown.increaseBorder(border);
......
......@@ -35,7 +35,7 @@ import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.type.ReactionRect;
/**
* Thics class allows to draw reaction on the graphics2D.
* This class allows to draw reaction on the graphics2D.
*
* @author Piotr Gawron
*
......@@ -196,7 +196,7 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
}
@Override
public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params) {
protected void drawImpl(final Reaction reaction, final Graphics2D graphics, final ConverterParams params) {
Color color = graphics.getColor();
graphics.setColor(reaction.getReactants().get(0).getLine().getColor());
// first reactants
......@@ -231,19 +231,19 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
}
@Override
public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) {
public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException {
if (visualizedLayoutsColorSchemas.size() == 0) {
draw(reaction, graphics, params);
drawImpl(reaction, graphics, params);
} else if (visualizedLayoutsColorSchemas.size() == 1) {
if (visualizedLayoutsColorSchemas.get(0) == null) {
draw(reaction, graphics, params);
drawImpl(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));
draw(reaction, graphics, params);
drawImpl(reaction, graphics, params);
for (Pair<AbstractNode, PolylineData> pair : oldData) {
pair.getLeft().setLine(pair.getRight());
}
......@@ -256,14 +256,14 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
}
}
if (count == 0) {
draw(reaction, graphics, params);
drawImpl(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);
draw(reaction, graphics, params);
drawImpl(reaction, graphics, params);
for (Pair<AbstractNode, PolylineData> pair : oldData) {
pair.getLeft().setLine(pair.getRight());
}
......
......@@ -7,16 +7,24 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
......@@ -26,8 +34,10 @@ import org.mockito.Mockito;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.geometry.ArrowTransformation;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.layout.GenericColorSchema;
import lcsb.mapviewer.model.map.layout.graphics.Glyph;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.field.BindingRegion;
......@@ -369,6 +379,32 @@ public class SpeciesConverterTest {
}
}
@Test
public void testDrawAliasWithGlyph() throws Exception {
try {
BufferedImage bi = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = Mockito.spy(bi.createGraphics());
ProteinConverter rc = new ProteinConverter(colorExtractor);
GenericProtein alias = createProtein();
Glyph glyph = new Glyph();
UploadedFileEntry file = new UploadedFileEntry();
file.setOriginalFileName("test");
byte[] fileContent = Files.readAllBytes(new File("testFiles/glyph.png").toPath());
file.setFileContent(fileContent);
glyph.setFile(file);
alias.setGlyph(glyph);
rc.draw(alias, graphics, new ConverterParams());
verify(graphics, times(1)).drawImage(any(Image.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(),
anyInt(), anyInt(), nullable(ImageObserver.class));
} catch (Exception e) {
throw e;
}
}
private GenericProtein createProtein() {
GenericProtein protein = new GenericProtein("id");
protein.setName("NAME_OF_THE_ELEMENT");
......
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