package greenfoot.guifx.classes;

import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import threadchecker.OnThread;
import threadchecker.Tag;

import java.util.List;


| I tried many different variants before using this design: | - If you have each L piece in the diagram as separate items, it is difficult | to get the join to line up | - The same applies if you have the triangle as a separate piece | - If you use Polyline, it's awkward to draw multiple dangling "side-arms" |* as you have to redraw parts of the line. * Hence the finished solution: A Path that does all the inheritance arrows for * a particular class (down to its subclasses) as a single item, using a mixture | of LineTo and MoveTo. | @OnThread(Tag.FXPlatform) public class InheritArrow extends Path{ private final double ARROWHEAD_WIDTH = 10; private final double ARROWHEAD_HEIGHT = 10; public InheritArrow() { getStyleClass().add("inherit-arrow"); }
| Set the locations of the subclass arms (the pieces going from the main vertical | line across to the right to touch the classes). | @param width The width of each subclass arm from the vertical line | @param yPositions The Y positions (relative to the top of this inherit arrow) of | the arms to draw. | public void setArmLocations(double width, List<Double> yPositions) { if (yPositions.isEmpty()) { getElements().clear(); return; } getElements().setAll( new MoveTo(ARROWHEAD_WIDTH / 2.0, ARROWHEAD_HEIGHT), new LineTo(0.0, ARROWHEAD_HEIGHT), new LineTo(ARROWHEAD_WIDTH / 2.0, 0.0), new LineTo(ARROWHEAD_WIDTH, ARROWHEAD_HEIGHT), new LineTo(ARROWHEAD_WIDTH / 2.0, ARROWHEAD_HEIGHT) ); double indent = ARROWHEAD_WIDTH / 2.0; for (Double yPosition : yPositions) { getElements().addAll( new LineTo(indent, yPosition), new LineTo(width, yPosition), new MoveTo(indent, yPosition) ); } } }
top, use, map, class InheritArrow

.   InheritArrow
.   setArmLocations




64 neLoCode + 11 LoComm