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

drawing of compartments uses border color, fill color, font color when necessary

parent 1ac37e09
......@@ -9,7 +9,7 @@ package lcsb.mapviewer.converter.graphics;
public class ConverterParams {
/**
* At which level the object is visualized. It helps to deterimine font size.
* At which level the object is visualized. It helps to determine font size.
* However it's possible that this value is not required.
*/
private int level = 0;
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.Shape;
import java.awt.geom.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.model.map.compartment.BottomSquareCompartment;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.species.Species;
......@@ -40,55 +37,19 @@ public class BottomSquareCompartmentConverter extends CompartmentConverter<Botto
}
@Override
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();
protected Shape getOuterShape(BottomSquareCompartment compartment) {
return new Line2D.Double(0, compartment.getY(), compartment.getWidth(), compartment.getY());
}
// create shape of the compartment
Shape s1 = new Line2D.Double(0, compartment.getY(), compartment.getWidth(), compartment.getY());
Shape s3 = new Line2D.Double(0, compartment.getY() + compartment.getThickness(), compartment.getWidth(),
@Override
protected Shape getInnerShape(BottomSquareCompartment compartment) {
return new Line2D.Double(0, compartment.getY() + compartment.getThickness(), compartment.getWidth(),
compartment.getY() + compartment.getThickness());
Area a1 = new Area(
new Rectangle2D.Double(0.0, compartment.getY(), compartment.getWidth(), compartment.getHeight()));
Color c1 = compartment.getFillColor();
Color c2 = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), HIGH_ALPHA_LEVEL);
if (c1.equals(Color.WHITE)) {
c1 = Color.BLACK;
}
// fill the background
boolean fill = !isTransparent(compartment, params);
if (fill) {
graphics.setColor(c1);
} else {
Color bgAlphaColor = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), getAlphaLevel());
graphics.setColor(bgAlphaColor);
}
graphics.fill(s1);
// create borders
graphics.setColor(c1);
graphics.setStroke(LineType.SOLID_BOLD.getStroke());
graphics.draw(s1);
graphics.setStroke(LineType.SOLID.getStroke());
graphics.draw(s3);
graphics.setColor(c2);
if (fill) {
graphics.fill(a1);
}
// restore color and line type
graphics.setColor(oldColor);
graphics.setStroke(oldStroke);
}
// draw description
if (fill) {
Point2D tmpPoint = compartment.getNamePoint();
compartment.setNamePoint(compartment.getCenter());
drawText(compartment, graphics, params);
compartment.setNamePoint(tmpPoint);
}
@Override
protected Shape getBorderShape(BottomSquareCompartment compartment) {
return new Area(new Rectangle2D.Double(0.0, compartment.getY(), compartment.getWidth(), compartment.getHeight()));
}
}
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.geom.*;
import java.util.List;
import org.apache.logging.log4j.LogManager;
......@@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
......@@ -16,6 +17,7 @@ import lcsb.mapviewer.converter.graphics.bioEntity.element.ElementConverter;
import lcsb.mapviewer.converter.graphics.geometry.FontFinder;
import lcsb.mapviewer.converter.graphics.geometry.RectangleTooSmallException;
import lcsb.mapviewer.converter.graphics.placefinder.PlaceFinder;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -58,7 +60,7 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen
*/
private LineTransformation lineTransformation = new LineTransformation();
/**
* Class used for finding place to draw desciption of the compartment.
* Class used for finding place to draw description of the compartment.
*/
private PlaceFinder placeFinder;
......@@ -114,6 +116,68 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen
this.lineTransformation = lineTransformation;
}
@Override
protected void drawImpl(T compartment, Graphics2D graphics, ConverterParams params) throws DrawingException {
// keep the old values of color and line type
Color oldColor = graphics.getColor();
Stroke oldStroke = graphics.getStroke();
Shape s1 = getOuterShape(compartment);
Shape s3 = getInnerShape(compartment);
Shape a1 = getBorderShape(compartment);
Color borderColor = compartment.getBorderColor();
Color fillColor = compartment.getFillColor();
// fill the background
boolean fill = !isTransparent(compartment, params);
if (fill) {
graphics.setColor(fillColor);
} else {
Color bgAlphaColor = new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), getAlphaLevel());
graphics.setColor(bgAlphaColor);
}
graphics.fill(s1);
// create borders
graphics.setColor(borderColor);
graphics.setStroke(LineType.SOLID_BOLD.getStroke());
graphics.draw(s1);
graphics.setStroke(LineType.SOLID.getStroke());
graphics.draw(s3);
fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), HIGH_ALPHA_LEVEL);
graphics.setColor(fillColor);
graphics.fill(a1);
// restore color and line type
graphics.setColor(oldColor);
graphics.setStroke(oldStroke);
// draw description
if (fill) {
Point2D tmpPoint = compartment.getNamePoint();
compartment.setNamePoint(compartment.getCenter());
drawText(compartment, graphics, params);
compartment.setNamePoint(tmpPoint);
}
}
protected Shape getOuterShape(T compartment) {
throw new NotImplementedException();
}
protected Shape getInnerShape(T compartment) {
throw new NotImplementedException();
}
protected Shape getBorderShape(T compartment) {
Area result = new Area(getOuterShape(compartment));
result.subtract(new Area(getInnerShape(compartment)));
return result;
}
@Override
public void draw(T alias, Graphics2D graphics, ConverterParams params,
List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException {
......@@ -172,13 +236,17 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen
fontSize = compartment.getFontSize() * params.getScale();
}
String fontName = Font.SANS_SERIF;
Color tmpColor = graphics.getColor();
try {
graphics.setColor(compartment.getFontColor());
fontSize = FontFinder.findMaxFontSize((int) Math.round(fontSize), fontName, graphics, border,
compartment.getName());
FontFinder.drawText((int) fontSize, fontName, graphics, border, compartment.getName(), textCentered);
} catch (RectangleTooSmallException e) {
// if it's too small then don't draw
return;
} finally {
graphics.setColor(tmpColor);
}
}
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.Shape;
import java.awt.geom.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.model.map.compartment.LeftSquareCompartment;
import lcsb.mapviewer.model.map.layout.ColorSchema;
......@@ -40,56 +37,20 @@ public class LeftSquareCompartmentConverter extends CompartmentConverter<LeftSqu
}
@Override
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();
protected Shape getOuterShape(LeftSquareCompartment compartment) {
return new Line2D.Double(compartment.getWidth(), compartment.getHeight(), compartment.getWidth(), 0);
}
// create shape of the compartment
Shape s1 = new Line2D.Double(compartment.getWidth(), compartment.getHeight(), compartment.getWidth(), 0);
Shape s3 = new Line2D.Double(
@Override
protected Shape getInnerShape(LeftSquareCompartment compartment) {
return new Line2D.Double(
compartment.getWidth() - compartment.getThickness(), 0, compartment.getWidth() - compartment.getThickness(),
compartment.getHeight());
Area a1 = new Area(new Rectangle2D.Double(0.0, 0.0, compartment.getWidth(), compartment.getHeight()));
Color c1 = compartment.getFillColor();
Color c2 = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), HIGH_ALPHA_LEVEL);
if (c1.equals(Color.WHITE)) {
c1 = Color.BLACK;
}
// fill the background
boolean fill = !isTransparent(compartment, params);
if (fill) {
graphics.setColor(c1);
} else {
Color bgAlphaColor = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), getAlphaLevel());
graphics.setColor(bgAlphaColor);
}
graphics.fill(s1);
// create borders
graphics.setColor(c1);
graphics.setStroke(LineType.SOLID_BOLD.getStroke());
graphics.draw(s1);
graphics.setStroke(LineType.SOLID.getStroke());
graphics.draw(s3);
graphics.setColor(c2);
if (fill) {
graphics.fill(a1);
}
// restore color and line type
graphics.setColor(oldColor);
graphics.setStroke(oldStroke);
}
// draw description
if (fill) {
Point2D tmpPoint = compartment.getNamePoint();
compartment.setNamePoint(compartment.getCenter());
drawText(compartment, graphics, params);
compartment.setNamePoint(tmpPoint);
}
@Override
protected Shape getBorderShape(LeftSquareCompartment compartment) {
return new Area(new Rectangle2D.Double(0.0, 0.0, compartment.getWidth(), compartment.getHeight()));
}
}
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.geom.*;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.OvalCompartment;
import lcsb.mapviewer.model.map.layout.ColorSchema;
......@@ -44,61 +41,15 @@ public class OvalCompartmentConverter extends CompartmentConverter<OvalCompartme
}
@Override
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();
protected Shape getOuterShape(OvalCompartment compartment) {
return getShape(compartment);
}
// create shape of the compartment
Shape s1 = getShape(compartment);
@Override
protected Shape getInnerShape(OvalCompartment compartment) {
compartment.increaseBorder(-compartment.getThickness());
Shape s3 = getShape(compartment);
Shape result = getShape(compartment);
compartment.increaseBorder(compartment.getThickness());
Color c1 = compartment.getFillColor();
Color c2 = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), HIGH_ALPHA_LEVEL);
if (c1.equals(Color.WHITE)) {
c1 = Color.BLACK;
}
Area a1 = new Area(s1);
a1.subtract(new Area(s3));
// fill the background
boolean fill = !isTransparent(compartment, params);
if (fill) {
graphics.setColor(c1);
} else {
Color bgAlphaColor = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), getAlphaLevel());
graphics.setColor(bgAlphaColor);
}
graphics.fill(s1);
// create borders
graphics.setColor(c1);
graphics.setStroke(LineType.SOLID_BOLD.getStroke());
graphics.draw(s1);
graphics.setStroke(LineType.SOLID.getStroke());
graphics.draw(s3);
graphics.setColor(c2);
graphics.fill(a1);
// restore color and line type
graphics.setColor(oldColor);
graphics.setStroke(oldStroke);
// draw description
if (fill) {
Point2D tmpPoint = compartment.getNamePoint();
compartment.setNamePoint(compartment.getCenter());
drawText(compartment, graphics, params);
compartment.setNamePoint(tmpPoint);
} else {
if (!compartment.containsIdenticalSpecies()) {
drawText(compartment, graphics, params);
}
}
return result;
}
}
......@@ -42,7 +42,7 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom
Shape shape = new Rectangle2D.Double(compartment.getX(), compartment.getY(), compartment.getWidth(),
compartment.getHeight());
Color color = compartment.getFontColor();
Color borderColor = compartment.getBorderColor();
Color backgroundColor = compartment.getFillColor();
// fill the background
......@@ -55,7 +55,7 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom
graphics.fill(shape);
// draw the border
graphics.setColor(color);
graphics.setColor(borderColor);
graphics.setStroke(LineType.SOLID_BOLD.getStroke());
graphics.draw(shape);
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.Shape;
import java.awt.geom.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.model.map.compartment.RightSquareCompartment;
import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.species.Species;
......@@ -40,62 +37,19 @@ public class RightSquareCompartmentConverter extends CompartmentConverter<RightS
}
@Override
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();
protected Shape getOuterShape(RightSquareCompartment compartment) {
return new Line2D.Double(compartment.getX(), compartment.getHeight(), compartment.getX(), 0);
}
// create shape of the compartment
Shape s1 = new Line2D.Double(compartment.getX(), compartment.getHeight(), compartment.getX(), 0);
Shape s3 = new Line2D.Double(compartment.getX() + compartment.getThickness(), compartment.getHeight(),
@Override
protected Shape getInnerShape(RightSquareCompartment compartment) {
return new Line2D.Double(compartment.getX() + compartment.getThickness(), compartment.getHeight(),
compartment.getX(), 0);
Area a1 = new Area(
new Rectangle2D.Double(compartment.getX(), 0.0, compartment.getWidth(), compartment.getHeight()));
Color c1 = compartment.getFillColor();
Color c2 = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), HIGH_ALPHA_LEVEL);
if (c1.equals(Color.WHITE)) {
c1 = Color.BLACK;
}
// fill the background
boolean fill = !isTransparent(compartment, params);
if (fill) {
graphics.setColor(c1);
} else {
Color bgAlphaColor = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), getAlphaLevel());
graphics.setColor(bgAlphaColor);
}
graphics.fill(s1);
// create borders
graphics.setColor(c1);
graphics.setStroke(LineType.SOLID_BOLD.getStroke());
graphics.draw(s1);
graphics.setStroke(LineType.SOLID.getStroke());
graphics.draw(s3);
graphics.setColor(c2);
if (fill) {
graphics.fill(a1);
}
// restore color and line type
graphics.setColor(oldColor);
graphics.setStroke(oldStroke);
// three lines below are only temporary fix...
double x = compartment.getNamePoint().getX() - compartment.getX();
double y = compartment.getNamePoint().getY();
compartment.getNamePoint().setLocation(x, y);
}
// draw description
if (fill) {
Point2D tmpPoint = compartment.getNamePoint();
compartment.setNamePoint(compartment.getCenter());
drawText(compartment, graphics, params);
compartment.setNamePoint(tmpPoint);
}
x += compartment.getX();
compartment.getNamePoint().setLocation(x, y);
@Override
protected Shape getBorderShape(RightSquareCompartment compartment) {
return new Area(
new Rectangle2D.Double(compartment.getX(), 0.0, compartment.getWidth(), compartment.getHeight()));
}
}
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.geom.*;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.model.graphics.LineType;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.SquareCompartment;
import lcsb.mapviewer.model.map.layout.ColorSchema;
......@@ -58,56 +56,15 @@ public class SquareCompartmentConverter extends CompartmentConverter<SquareCompa
}
@Override
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();
protected Shape getOuterShape(SquareCompartment compartment) {
return getShape(compartment);
}
// create shape of the compartment
Shape s1 = getShape(compartment);
@Override
protected Shape getInnerShape(SquareCompartment compartment) {
compartment.increaseBorder(-compartment.getThickness());
Shape s3 = getShape(compartment);
Shape result = getShape(compartment);
compartment.increaseBorder(compartment.getThickness());
Color c1 = compartment.getFillColor();