Skip to content

Commit

Permalink
prmr#416 rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Farihatanjin committed Mar 6, 2021
1 parent 7a97476 commit 619eaff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/ca/mcgill/cs/jetuml/viewers/nodes/ActorNodeViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,22 @@ public final class ActorNodeViewer extends AbstractNodeViewer
public Rectangle getBounds(Node pNode)
{
Dimension nameBounds = NAME_VIEWER.getDimension(((ActorNode)pNode).getName());
return new Rectangle(pNode.position().getX(), pNode.position().getY(),
Math.max(WIDTH, nameBounds.width()), HEIGHT + nameBounds.height());
return new Rectangle(
pNode.position().getX() + Math.min(0, (WIDTH - nameBounds.width()) / 2),
pNode.position().getY(),
Math.max(WIDTH, nameBounds.width()),
HEIGHT + nameBounds.height()
);
}

@Override
public void draw(Node pNode, GraphicsContext pGraphics)
{
Rectangle bounds = getBounds(pNode);
Dimension nameBox = NAME_VIEWER.getDimension(((ActorNode)pNode).getName());
Rectangle namebox = new Rectangle(bounds.getX() + (int)((bounds.getWidth() - nameBox.width()) / 2.0),
bounds.getY() + HEIGHT, nameBox.width(), nameBox.height());
NAME_VIEWER.draw(((ActorNode)pNode).getName(), pGraphics, namebox);
Dimension nameBounds = NAME_VIEWER.getDimension(((ActorNode)pNode).getName());
Rectangle nameBox = new Rectangle(pNode.position().getX() + (WIDTH - nameBounds.width()) / 2,
bounds.getY() + HEIGHT, nameBounds.width(), nameBounds.height());
NAME_VIEWER.draw(((ActorNode)pNode).getName(), pGraphics, nameBox);
ToolGraphics.strokeSharpPath(pGraphics, createStickManPath(pNode), LineStyle.SOLID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ca.mcgill.cs.jetuml.JavaFXLoader;
import ca.mcgill.cs.jetuml.diagram.nodes.ActorNode;
import ca.mcgill.cs.jetuml.geom.Point;
import ca.mcgill.cs.jetuml.testutils.GeometryUtils;

public class TestActorNodeViewer
{
Expand Down Expand Up @@ -69,7 +70,7 @@ public void testGetBounds_ShortName()
public void testGetBounds_LongName()
{
aNode.setName("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
assertEquals(new Point(0,0), aViewer.getBounds(aNode).getOrigin());
assertEquals(new Point(GeometryUtils.osDependent(-153,-166,-166),0), aViewer.getBounds(aNode).getOrigin());
assertTrue(aViewer.getBounds(aNode).getWidth() > 48);
assertTrue(aViewer.getBounds(aNode).getHeight() > 64);
}
Expand Down

0 comments on commit 619eaff

Please sign in to comment.