Skip to content
Snippets Groups Projects
Commit 2bb916cb authored by Piotr Gawron's avatar Piotr Gawron
Browse files

cleaning imports

parent a81228d9
No related branches found
No related tags found
2 merge requests!630WIP: Resolve "The privileges of a new user are not saved in some cases",!491Resolve "change arrows for Transcription Starting Sites"
Pipeline #7267 passed
Showing
with 248 additions and 258 deletions
package lcsb.mapviewer.converter.graphics;
import java.awt.Graphics2D;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
......@@ -26,90 +25,91 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
*
*/
public class PdfImageGenerator extends AbstractImageGenerator {
/**
* Stream where pdf data will be generated. When request to save pdf appears
* this stream is used to generate file.
*/
private ByteArrayOutputStream inMemoryOutputStream;
/**
* Object representing pdf document.
*/
private Document pdfDocument;
@Override
protected void createImageObject(final double width, final double height) {
try {
inMemoryOutputStream = new ByteArrayOutputStream();
pdfDocument = new Document(new Rectangle((int) width, (int) height));
PdfWriter writer = PdfWriter.getInstance(pdfDocument, inMemoryOutputStream);
pdfDocument.open();
PdfContentByte cb = writer.getDirectContent();
PdfGraphics2D g2d = new PdfGraphics2D(cb, (float) width, (float) height, new PdfFontMapper());
setGraphics(g2d);
} catch (DocumentException e) {
throw new InvalidStateException("Problem with initializing pdf generator", e);
}
}
@Override
public void saveToFileImplementation(final String fileName) throws IOException {
FileOutputStream fos = new FileOutputStream(fileName);
saveToOutputStreamImplementation(fos);
fos.close();
}
/**
* Default constructor. Create an image that is described by params. For more
* information see
* {@link lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params
* params}.
*
* @param params
* parameters used for the image creation.
* @throws DrawingException
* thrown when there was a problem with drawing a map
*/
public PdfImageGenerator(final Params params) throws DrawingException {
super(params);
}
@Override
protected void closeImageObject() {
getGraphics().dispose();
pdfDocument.close();
}
@Override
public void saveToOutputStreamImplementation(OutputStream os) throws IOException {
inMemoryOutputStream.writeTo(os);
}
@Override
public void savePartToFileImplementation(int x, int y, int width, int height, String fileName) throws IOException {
throw new NotImplementedException("Partial save is not implemented in PNG image generator");
}
@Override
public void savePartToOutputStreamImplementation(int x, int y, int width, int height, OutputStream os) throws IOException {
throw new NotImplementedException("Partial save is not implemented in PNG image generator");
}
@Override
public String getFormatName() {
return "PDF";
}
@Override
public MimeType getMimeType() {
return MimeType.PDF;
}
@Override
public String getFileExtension() {
return "pdf";
}
/**
* Stream where pdf data will be generated. When request to save pdf appears
* this stream is used to generate file.
*/
private ByteArrayOutputStream inMemoryOutputStream;
/**
* Object representing pdf document.
*/
private Document pdfDocument;
@Override
protected void createImageObject(final double width, final double height) {
try {
inMemoryOutputStream = new ByteArrayOutputStream();
pdfDocument = new Document(new Rectangle((int) width, (int) height));
PdfWriter writer = PdfWriter.getInstance(pdfDocument, inMemoryOutputStream);
pdfDocument.open();
PdfContentByte cb = writer.getDirectContent();
PdfGraphics2D g2d = new PdfGraphics2D(cb, (float) width, (float) height, new PdfFontMapper());
setGraphics(g2d);
} catch (DocumentException e) {
throw new InvalidStateException("Problem with initializing pdf generator", e);
}
}
@Override
public void saveToFileImplementation(final String fileName) throws IOException {
FileOutputStream fos = new FileOutputStream(fileName);
saveToOutputStreamImplementation(fos);
fos.close();
}
/**
* Default constructor. Create an image that is described by params. For more
* information see
* {@link lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params
* params}.
*
* @param params
* parameters used for the image creation.
* @throws DrawingException
* thrown when there was a problem with drawing a map
*/
public PdfImageGenerator(final Params params) throws DrawingException {
super(params);
}
@Override
protected void closeImageObject() {
getGraphics().dispose();
pdfDocument.close();
}
@Override
public void saveToOutputStreamImplementation(OutputStream os) throws IOException {
inMemoryOutputStream.writeTo(os);
}
@Override
public void savePartToFileImplementation(int x, int y, int width, int height, String fileName) throws IOException {
throw new NotImplementedException("Partial save is not implemented in PNG image generator");
}
@Override
public void savePartToOutputStreamImplementation(int x, int y, int width, int height, OutputStream os)
throws IOException {
throw new NotImplementedException("Partial save is not implemented in PNG image generator");
}
@Override
public String getFormatName() {
return "PDF";
}
@Override
public MimeType getMimeType() {
return MimeType.PDF;
}
@Override
public String getFileExtension() {
return "pdf";
}
}
......@@ -29,161 +29,163 @@ import lcsb.mapviewer.model.map.species.Species;
*/
public class ComplexConverter extends SpeciesConverter<Complex> {
/**
* How big is the triangle trimmed part of the complex.
*/
private static final int TRIMMED_CORNER_SIZE = 5;
/**
* Describes the distance between border of complex and internal border in
* brief view (without children).
*/
private static final double INTERNAL_BORDER_DIST = 5.0;
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(ComplexConverter.class.getName());
/**
* Default constructor.
*
* @param colorExtractor
* Object that helps to convert {@link ColorSchema} values into
* colors when drawing {@link Species}
*/
public ComplexConverter(ColorExtractor colorExtractor) {
super(colorExtractor);
}
@Override
public void draw(final Complex alias, final Graphics2D graphics, final ConverterParams params) {
if (alias.getState().equalsIgnoreCase("complexnoborder")) {
return;
}
int homodir;
if (params.isSbgnFormat()) {
// If the SBGN display mode is set, multimer is shown as two stacked
// glyphs
if (alias.getHomodimer() > 1) {
homodir = 2;
} else {
homodir = 1;
}
} else {
homodir = alias.getHomodimer();
}
alias.setWidth(alias.getWidth() - SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
alias.setHeight(alias.getHeight() - SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
alias.setX(alias.getX() + SpeciesConverter.HOMODIMER_OFFSET * (homodir));
alias.setY(alias.getY() + SpeciesConverter.HOMODIMER_OFFSET * (homodir));
for (int i = 0; i < homodir; i++) {
alias.setX(alias.getX() - SpeciesConverter.HOMODIMER_OFFSET);
alias.setY(alias.getY() - SpeciesConverter.HOMODIMER_OFFSET);
GeneralPath path = getAliasPath(alias);
Color c = graphics.getColor();
Stroke stroke = graphics.getStroke();
graphics.setColor(alias.getColor());
graphics.fill(path);
graphics.setColor(c);
graphics.setStroke(getBorderLine(alias));
graphics.draw(path);
if (alias.getState().equals("brief")) {
alias.increaseBorder(-INTERNAL_BORDER_DIST);
path = getAliasPath(alias);
alias.increaseBorder(INTERNAL_BORDER_DIST);
graphics.setStroke(LineType.DOTTED.getStroke());
graphics.draw(path);
}
if (alias.getActivity() && !params.isSbgnFormat()) {
alias.increaseBorder(INTERNAL_BORDER_DIST);
path = getAliasPath(alias);
alias.increaseBorder(-INTERNAL_BORDER_DIST);
graphics.setStroke(LineType.DOTTED.getStroke());
graphics.draw(path);
}
graphics.setStroke(stroke);
}
alias.setWidth(alias.getWidth() + SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
alias.setHeight(alias.getHeight() + SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
// SBGN view - multimers are displayed with a unit of information containing
// cardinality
if (params.isSbgnFormat()) {
String unitOfInformationText = null;
if (alias.getStatePrefix() != null && alias.getStateLabel() != null) {
unitOfInformationText = alias.getStatePrefix() + ":" + alias.getStateLabel();
}
if (homodir == 2 && (unitOfInformationText == null || !unitOfInformationText.contains("N:"))) {
if (unitOfInformationText != null) {
unitOfInformationText += "; ";
} else {
unitOfInformationText = "";
}
unitOfInformationText += "N:" + alias.getHomodimer();
}
drawUnitOfInformation(unitOfInformationText, alias, graphics);
}
String text = alias.getStructuralState();
drawStructuralState(text, alias, graphics);
drawText(alias, graphics, params);
}
@Override
public void drawText(final Complex complex, final Graphics2D graphics, final ConverterParams params) {
if (complex.getElements().size() > 0) {
if (isTransparent(complex, params)) {
super.drawText(complex, graphics, params);
return;
}
}
String text = getText(complex);
try {
double fontSize = DEFAULT_SPECIES_FONT_SIZE;
if (complex.getFontSize() != null) {
fontSize = complex.getFontSize();
}
int size = (int) FontFinder.findMaxFontSize(params.getScale() * fontSize, Font.SANS_SERIF, graphics, complex.getBorder(), text);
FontFinder.drawText(size, Font.SANS_SERIF, graphics, complex.getBorder(), text);
} catch (RectangleTooSmallException e) {
}
}
/**
* Returns the border of {@link Complex}.
*
* @param complex
* exact object for which we want to get a border
* @return border of the {@link Complex}
*/
private GeneralPath getAliasPath(final Complex complex) {
GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD);
path.moveTo(complex.getX() + TRIMMED_CORNER_SIZE, complex.getY());
path.lineTo(complex.getX() + complex.getWidth() - TRIMMED_CORNER_SIZE, complex.getY());
path.lineTo(complex.getX() + complex.getWidth(), complex.getY() + TRIMMED_CORNER_SIZE);
path.lineTo(complex.getX() + complex.getWidth(), complex.getY() + complex.getHeight() - TRIMMED_CORNER_SIZE);
path.lineTo(complex.getX() + complex.getWidth() - TRIMMED_CORNER_SIZE, complex.getY() + complex.getHeight());
path.lineTo(complex.getX() + TRIMMED_CORNER_SIZE, complex.getY() + complex.getHeight());
path.lineTo(complex.getX(), complex.getY() + complex.getHeight() - TRIMMED_CORNER_SIZE);
path.lineTo(complex.getX(), complex.getY() + TRIMMED_CORNER_SIZE);
path.closePath();
return path;
}
@Override
public PathIterator getBoundPathIterator(final Complex complex) {
return getAliasPath(complex).getPathIterator(new AffineTransform());
}
/**
* How big is the triangle trimmed part of the complex.
*/
private static final int TRIMMED_CORNER_SIZE = 5;
/**
* Describes the distance between border of complex and internal border in brief
* view (without children).
*/
private static final double INTERNAL_BORDER_DIST = 5.0;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(ComplexConverter.class);
/**
* Default constructor.
*
* @param colorExtractor
* Object that helps to convert {@link ColorSchema} values into colors
* when drawing {@link Species}
*/
public ComplexConverter(ColorExtractor colorExtractor) {
super(colorExtractor);
}
@Override
public void draw(final Complex alias, final Graphics2D graphics, final ConverterParams params) {
if (alias.getState().equalsIgnoreCase("complexnoborder")) {
return;
}
int homodir;
if (params.isSbgnFormat()) {
// If the SBGN display mode is set, multimer is shown as two stacked
// glyphs
if (alias.getHomodimer() > 1) {
homodir = 2;
} else {
homodir = 1;
}
} else {
homodir = alias.getHomodimer();
}
alias.setWidth(alias.getWidth() - SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
alias.setHeight(alias.getHeight() - SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
alias.setX(alias.getX() + SpeciesConverter.HOMODIMER_OFFSET * (homodir));
alias.setY(alias.getY() + SpeciesConverter.HOMODIMER_OFFSET * (homodir));
for (int i = 0; i < homodir; i++) {
alias.setX(alias.getX() - SpeciesConverter.HOMODIMER_OFFSET);
alias.setY(alias.getY() - SpeciesConverter.HOMODIMER_OFFSET);
GeneralPath path = getAliasPath(alias);
Color c = graphics.getColor();
Stroke stroke = graphics.getStroke();
graphics.setColor(alias.getColor());
graphics.fill(path);
graphics.setColor(c);
graphics.setStroke(getBorderLine(alias));
graphics.draw(path);
if (alias.getState().equals("brief")) {
alias.increaseBorder(-INTERNAL_BORDER_DIST);
path = getAliasPath(alias);
alias.increaseBorder(INTERNAL_BORDER_DIST);
graphics.setStroke(LineType.DOTTED.getStroke());
graphics.draw(path);
}
if (alias.getActivity() && !params.isSbgnFormat()) {
alias.increaseBorder(INTERNAL_BORDER_DIST);
path = getAliasPath(alias);
alias.increaseBorder(-INTERNAL_BORDER_DIST);
graphics.setStroke(LineType.DOTTED.getStroke());
graphics.draw(path);
}
graphics.setStroke(stroke);
}
alias.setWidth(alias.getWidth() + SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
alias.setHeight(alias.getHeight() + SpeciesConverter.HOMODIMER_OFFSET * (alias.getHomodimer() - 1));
// SBGN view - multimers are displayed with a unit of information containing
// cardinality
if (params.isSbgnFormat()) {
String unitOfInformationText = null;
if (alias.getStatePrefix() != null && alias.getStateLabel() != null) {
unitOfInformationText = alias.getStatePrefix() + ":" + alias.getStateLabel();
}
if (homodir == 2 && (unitOfInformationText == null || !unitOfInformationText.contains("N:"))) {
if (unitOfInformationText != null) {
unitOfInformationText += "; ";
} else {
unitOfInformationText = "";
}
unitOfInformationText += "N:" + alias.getHomodimer();
}
drawUnitOfInformation(unitOfInformationText, alias, graphics);
}
String text = alias.getStructuralState();
drawStructuralState(text, alias, graphics);
drawText(alias, graphics, params);
}
@Override
public void drawText(final Complex complex, final Graphics2D graphics, final ConverterParams params) {
if (complex.getElements().size() > 0) {
if (isTransparent(complex, params)) {
super.drawText(complex, graphics, params);
return;
}
}
String text = getText(complex);
try {
double fontSize = DEFAULT_SPECIES_FONT_SIZE;
if (complex.getFontSize() != null) {
fontSize = complex.getFontSize();
}
int size = (int) FontFinder.findMaxFontSize(params.getScale() * fontSize, Font.SANS_SERIF, graphics,
complex.getBorder(), text);
FontFinder.drawText(size, Font.SANS_SERIF, graphics, complex.getBorder(), text);
} catch (RectangleTooSmallException e) {
}
}
/**
* Returns the border of {@link Complex}.
*
* @param complex
* exact object for which we want to get a border
* @return border of the {@link Complex}
*/
private GeneralPath getAliasPath(final Complex complex) {
GeneralPath path = new GeneralPath(Path2D.WIND_EVEN_ODD);
path.moveTo(complex.getX() + TRIMMED_CORNER_SIZE, complex.getY());
path.lineTo(complex.getX() + complex.getWidth() - TRIMMED_CORNER_SIZE, complex.getY());
path.lineTo(complex.getX() + complex.getWidth(), complex.getY() + TRIMMED_CORNER_SIZE);
path.lineTo(complex.getX() + complex.getWidth(), complex.getY() + complex.getHeight() - TRIMMED_CORNER_SIZE);
path.lineTo(complex.getX() + complex.getWidth() - TRIMMED_CORNER_SIZE, complex.getY() + complex.getHeight());
path.lineTo(complex.getX() + TRIMMED_CORNER_SIZE, complex.getY() + complex.getHeight());
path.lineTo(complex.getX(), complex.getY() + complex.getHeight() - TRIMMED_CORNER_SIZE);
path.lineTo(complex.getX(), complex.getY() + TRIMMED_CORNER_SIZE);
path.closePath();
return path;
}
@Override
public PathIterator getBoundPathIterator(final Complex complex) {
return getAliasPath(complex).getPathIterator(new AffineTransform());
}
}
......@@ -6,7 +6,6 @@ import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.species;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
......@@ -29,8 +27,6 @@ import lcsb.mapviewer.model.map.species.ReceptorProtein;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.TruncatedProtein;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.Residue;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
......
......@@ -6,7 +6,6 @@ import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
......@@ -28,6 +27,7 @@ public class SimpleMoleculeConverter extends SpeciesConverter<SimpleMolecule> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(SimpleMoleculeConverter.class.getName());
/**
......
......@@ -6,7 +6,6 @@ import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
......@@ -30,6 +29,7 @@ public class UnknownConverter extends SpeciesConverter<Unknown> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(UnknownConverter.class.getName());
/**
......
......@@ -2,25 +2,19 @@ package lcsb.mapviewer.converter.graphics.bioEntity.element.species;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import org.apache.log4j.Logger;
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.map.species.Complex;
import lcsb.mapviewer.model.map.species.field.TranscriptionSite;
public class ComplexConverterTest {
Logger logger = Logger.getLogger(ComplexConverterTest.class);
......@@ -83,6 +77,7 @@ public class ComplexConverterTest {
throw e;
}
}
private Complex createComplex() {
Complex protein = new Complex("id");
protein.setName("NAME_OF_THE_ELEMENT");
......
package lcsb.mapviewer.converter.graphics.bioEntity.reaction;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
......@@ -9,7 +8,6 @@ import static org.mockito.Mockito.verify;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment