Commit 4b7bd7d5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch...

Merge branch '1471-arrows-without-a-process-box-have-an-irregular-empty-space-in-their-lines' into 'master'

Resolve "Arrows without a "process" box have an irregular empty space in their lines"

Closes #1471

See merge request !1296
parents 14497a71 3057ed94
Pipeline #40142 passed with stage
in 22 minutes and 3 seconds
......@@ -7,6 +7,8 @@ minerva (16.0.0~alpha.2) stable; urgency=medium
* Small improvement: missing info about species for SBML parsing warning
(#1472)
* Small improvement: glyph quality is improved (#1458)
* Bug fix: arrows without a "process" box had an irregular empty space in
their lines (#1471)
-- Piotr Gawron <piotr.gawron@uni.lu> Fri, 26 Mar 2021 10:00:00 +0200
......
......@@ -121,7 +121,8 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
*/
protected void drawRectangleData(final PolylineData line, Point2D processCoordinates, final ReactionRect insideType,
final Graphics2D graphics) {
Color color = graphics.getColor();
Color oldColor = graphics.getColor();
graphics.setColor(line.getColor());
Point2D startPoint = line.getLines().get((line.getLines().size() - 1) / 2).getP1();
......@@ -176,12 +177,24 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
Point2D centerPoint = new Point2D.Double(pointX, pointY);
if (insideType == null) {
Stroke oldStroke = graphics.getStroke();
Stroke newStroke = line.getType().getStroke();
if (line.getWidth() != 1.0 && newStroke instanceof BasicStroke) {
BasicStroke basicStroke = (BasicStroke) newStroke;
newStroke = new BasicStroke((float) line.getWidth(), basicStroke.getEndCap(), basicStroke.getLineJoin(),
basicStroke.getMiterLimit(), basicStroke.getDashArray(), basicStroke.getDashPhase());
}
graphics.setStroke(newStroke);
Point2D topPoint = new Point2D.Double(pointX + RECT_SIZE / 2, pointY);
topPoint = new PointTransformation().rotatePoint(topPoint, angle, centerPoint);
Point2D bottomPoint = new Point2D.Double(pointX - RECT_SIZE / 2, pointY);
bottomPoint = new PointTransformation().rotatePoint(bottomPoint, angle, centerPoint);
graphics.draw(new Line2D.Double(topPoint, bottomPoint));
graphics.setStroke(oldStroke);
} else {
// find rectangle
......@@ -223,7 +236,7 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
}
}
graphics.setColor(color);
graphics.setColor(oldColor);
}
@Override
......@@ -273,11 +286,13 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
for (AbstractNode node : reaction.getNodes()) {
oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine()));
}
PolylineData oldReactionData = reaction.getLine();
applyColorSchema(reaction, visualizedDataOverlaysColorSchemas.get(0));
drawImpl(reaction, graphics, params);
for (Pair<AbstractNode, PolylineData> pair : oldData) {
pair.getLeft().setLine(pair.getRight());
}
reaction.setLine(oldReactionData);
}
} else {
int count = 0;
......@@ -293,11 +308,13 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
for (AbstractNode node : reaction.getNodes()) {
oldData.add(new Pair<AbstractNode, PolylineData>(node, node.getLine()));
}
PolylineData oldReactionData = reaction.getLine();
applyColorSchema(reaction, DEFAULT_COLOR_SCHEMA);
drawImpl(reaction, graphics, params);
for (Pair<AbstractNode, PolylineData> pair : oldData) {
pair.getLeft().setLine(pair.getRight());
}
reaction.setLine(oldReactionData);
}
}
}
......
......@@ -158,11 +158,11 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
ImageIO.write(bi, "PNG", outputStream);
byte[] output2 = outputStream.toByteArray();
// FileUtils.writeByteArrayToFile(new File("tmp.png"), output1);
// FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2);
// FileUtils.writeByteArrayToFile(new File("tmp.png"), output1);
// FileUtils.writeByteArrayToFile(new File("tmp2.png"), output2);
// Desktop.getDesktop().open(new File("tmp.png"));
// Desktop.getDesktop().open(new File("tmp2.png"));
// Desktop.getDesktop().open(new File("tmp.png"));
// Desktop.getDesktop().open(new File("tmp2.png"));
assertTrue(Arrays.equals(output1, output2));
......@@ -185,6 +185,7 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
result.addProduct(product);
result.addReactant(reactant);
result.setLine(new PolylineData(new Point2D.Double(105, 90), new Point2D.Double(95, 90)));
result.getLine().setWidth(lineWidth);
return result;
}
......@@ -434,6 +435,19 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
Mockito.verify(graphics, times(3)).draw(any(Shape.class));
}
@Test
public void testDrawRectangleDataWithLineDifferentWidth() throws Exception {
Graphics2D graphics = createGraphicsMock();
ReactionConverter rc = new ReactionConverter(colorExtractor);
PolylineData line = new PolylineData(new Point2D.Double(10, 20),
new Point2D.Double(10 + ReactionConverter.RECT_SIZE + 100, 20));
rc.drawRectangleData(line, null, null, graphics);
Mockito.verify(graphics, times(7)).setStroke(any(Stroke.class));
}
@Test
public void testDrawRectangleDataWithOneSidePolyLineAround() throws Exception {
Graphics2D graphics = createGraphicsMock();
......
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