+ private static class RouteTerminalPositionImpl implements RouteTerminalPosition {
+
+ private IDiagram diagram;
+ private DataElementMap dataElementMap;
+ private Resource element;
+ private AffineTransform elementTransform;
+ private TerminalLayout terminalLayout;
+ private Terminal elementTerminal;
+
+ private transient AffineTransform lastTerminalTr;
+ private transient AffineTransform transform;
+
+ public RouteTerminalPositionImpl(IDiagram diagram, DataElementMap dem, Resource element, AffineTransform elementTransform, TerminalLayout terminalLayout, Terminal terminal) {
+ this.diagram = diagram;
+ this.dataElementMap = dem;
+ this.element = element;
+ this.elementTransform = elementTransform;
+ this.terminalLayout = terminalLayout;
+ this.elementTerminal = terminal;
+ }
+
+ @Override
+ public AffineTransform getTransform() {
+ IElement actualElement = dataElementMap.getElement(diagram, element);
+ AffineTransform terminalTr = actualElement != null ? terminalLayout.getTerminalPosition(actualElement, elementTerminal) : null;
+ if (terminalTr == null)
+ return elementTransform;
+
+ // Return cached transform if terminal transform has not changed.
+ AffineTransform result = this.transform;
+ AffineTransform lastTerminalTr = this.lastTerminalTr;
+ if (lastTerminalTr != null) {
+ if (terminalTr.equals(lastTerminalTr))
+ return result;
+ lastTerminalTr.setTransform(terminalTr);
+ } else {
+ lastTerminalTr = this.lastTerminalTr = new AffineTransform(terminalTr);
+ result = this.transform = new AffineTransform();
+ }
+
+ result.setTransform(elementTransform);
+ result.concatenate(terminalTr);
+ return result;
+ }
+
+ }