@Override public void update(Observable observable, Object notification) { // System.out.println("Connector received "+notification+" from "+observable); super.update(observable, notification); if (observable instanceof ForegroundStyle) { notifyAttributeChange(Parameters.foreground); } if (notification instanceof ObjectWillMove || notification instanceof ObjectWillResize) { connector.connectorWillBeModified(); // Propagate notification to views setChanged(); notifyObservers(notification); } if (notification instanceof ObjectHasMoved || notification instanceof ObjectHasResized) { connector.connectorHasBeenModified(); // Propagate notification to views setChanged(); notifyObservers(notification); } if (notification instanceof ObjectMove || notification instanceof ObjectResized || notification instanceof ShapeChanged) { // if (observable == startObject || observable == endObject) { // !!! or any of ancestors refreshConnector(); // } } }
@Override public final void setsWith(GraphicalRepresentation<?> gr) { super.setsWith(gr); if (gr instanceof ConnectorGraphicalRepresentation) { for (Parameters p : Parameters.values()) { if (p != Parameters.connector) { _setParameterValueWith(p, gr); } } Connector connectorToCopy = ((ConnectorGraphicalRepresentation<?>) gr).getConnector(); Connector clone = connectorToCopy.clone(); setConnector(clone); } }
@Override public void paint(Graphics g, DrawingController<?> controller) { if (!isRegistered()) { setRegistered(true); } super.paint(g, controller); if (getStartObject() == null || getStartObject().isDeleted()) { logger.warning("Could not paint connector: start object is null or deleted"); return; } if (getEndObject() == null || getEndObject().isDeleted()) { logger.warning("Could not paint connector: end object is null or deleted"); return; } Graphics2D g2 = (Graphics2D) g; graphics.createGraphics(g2, controller); if (FGEConstants.DEBUG) { g2.setColor(Color.PINK); g2.drawRect( 0, 0, getViewWidth(controller.getScale()) - 1, getViewHeight(controller.getScale()) - 1); } if (connector != null) { if (!isValidated()) { logger.warning( "paint connector requested for not validated connector graphical representation: " + this); return; } if (getStartObject() == null || getStartObject().isDeleted() || !getStartObject().isValidated()) { logger.warning( "paint connector requested for invalid start object (either null, deleted or not validated) : " + this + " start=" + getStartObject()); return; } if (getEndObject() == null || getEndObject().isDeleted() || !getEndObject().isValidated()) { logger.warning( "paint connector requested for invalid start object (either null, deleted or not validated) : " + this + " end=" + getEndObject()); return; } connector.paintConnector(graphics); } graphics.releaseGraphics(); }
protected void refreshConnector(boolean forceRefresh) { if (!isConnectorConsistent()) { // Dont' go further for connector that are inconsistent (this may happen // during big model restructurations (for example during a multiple delete) return; } try { if (forceRefresh || connector.needsRefresh()) { connector.refreshConnector(); checkViewBounds(); setChanged(); notifyObservers(new ConnectorModified()); } } catch (Exception e) { logger.warning("Unexpected exception: " + e); e.printStackTrace(); } }
public void setConnector(Connector aConnector) { if (aConnector != null) { aConnector.setGraphicalRepresentation(this); } FGENotification notification = requireChange(Parameters.connector, aConnector); if (notification != null) { this.connector = aConnector; hasChanged(notification); } }
@Override public final void setsWith(GraphicalRepresentation<?> gr, GRParameter... exceptedParameters) { super.setsWith(gr, exceptedParameters); if (gr instanceof ConnectorGraphicalRepresentation) { for (Parameters p : Parameters.values()) { boolean excepted = false; for (GRParameter ep : exceptedParameters) { if (p == ep) { excepted = true; } } if (p != Parameters.connector && !excepted) { _setParameterValueWith(p, gr); } } Connector connectorToCopy = ((ConnectorGraphicalRepresentation<?>) gr).getConnector(); Connector clone = connectorToCopy.clone(); setConnector(clone); } }
/** * Return distance from point to connector representation with a given scale * * @param aPoint expressed in local normalized coordinates system * @param scale * @return */ public double distanceToConnector(FGEPoint aPoint, double scale) { return connector.distanceToConnector(aPoint, scale); }
public void setConnectorType(ConnectorType connectorType) { if (getConnectorType() != connectorType) { setConnector(Connector.makeConnector(connectorType, this)); } }
public ConnectorType getConnectorType() { if (connector != null) { return connector.getConnectorType(); } return null; }