@Override public void setSecond(Double second) { Point2D oldPosition = super.copy(); Point2D newPosition = super.copy(); newPosition.setSecond(second); onChange(oldPosition, newPosition); }
@Override public void setFirst(Double first) { Point2D oldPosition = super.copy(); Point2D newPosition = super.copy(); newPosition.setFirst(first); onChange(oldPosition, newPosition); }
@Nonnull private Point2D onChange(@Nonnull Point2D oldPosition, @Nonnull Point2D newPosition) { if (positionListenerEntries != null) { for (PositionListenerEntry positionListenerEntry : positionListenerEntries) { if (!positionListenerEntry.listener.beforeChangePosition( oldPosition.copy(), newPosition)) { return this; } } } super.setFirst(newPosition.getFirst()); super.setSecond(newPosition.getSecond()); if (positionListenerEntries != null) { for (PositionListenerEntry positionListenerEntry : positionListenerEntries) { positionListenerEntry.listener.afterChangePosition( oldPosition.copy(), newPosition.copy()); } } return this; }
public void setPosition(Point2D position) { Point2D oldPosition = this.position.copy(); Point2D newPosition = position.copy(); if (positionListenerEntries != null) { for (PositionListenerEntry positionListenerEntry : positionListenerEntries) { if (!positionListenerEntry.listener.beforeChangePosition(oldPosition.copy(), newPosition)) { return; } } } this.position = this.new ListeningPoint2D(newPosition); if (positionListenerEntries != null) { for (PositionListenerEntry positionListenerEntry : positionListenerEntries) { positionListenerEntry.listener.afterChangePosition(oldPosition.copy(), newPosition.copy()); } } }