/**
  * This method checks to determine whether the specified port is allowed to have incoming flows
  * attached to it.
  *
  * @param portView
  * @return true if flows can end at this port, false otherwise.
  */
 private boolean acceptsIncomingFlows(PortView portView) {
   CellView parentView = portView.getParentView();
   YAWLPort yawlPort = (YAWLPort) portView.getCell();
   YAWLCell vertex = (YAWLCell) parentView.getCell();
   return yawlPort.acceptsIncomingFlows()
       && vertex.acceptsIncomingFlows()
       && getNet().acceptsIncomingFlows(vertex);
 }
 /**
  * This method checks to determine whether the specified port can have outgoing flows drawn from
  * it.
  *
  * @param portView
  * @return true if flows can start from this port, false otherwise.
  */
 private boolean generatesOutgoingFlows(PortView portView) {
   CellView parentView = portView.getParentView();
   YAWLPort yawlPort = (YAWLPort) portView.getCell();
   YAWLCell vertex = (YAWLCell) parentView.getCell();
   return yawlPort.generatesOutgoingFlows()
       && vertex.generatesOutgoingFlows()
       && getNet().generatesOutgoingFlows(vertex);
 }
 /**
  * If there are valid source and target ports specified as a result of a flow relation being
  * drawn, this method will draw a flow connecting these two ports, resulting in a flow relation
  * between the parent elements of the ports. If the flow would be invalid, the flow being drawn
  * will be ignored.
  */
 public void connectElementsOrIgnoreFlow() {
   if (targetPort != null
       && sourcePort != null
       && connectionAllowable(sourcePort, targetPort)
       && acceptsIncomingFlows(targetPort)) {
     getNet().connect((YAWLPort) sourcePort.getCell(), (YAWLPort) targetPort.getCell());
   }
   Rectangle2D clip = getOverlay().getFlowClip();
   getOverlay().clear(); // remove potential flow
   sourcePort = targetPort = null;
   setStartPoint(null);
   setCurrentPoint(null);
   setCursorFromPalette();
   repaintClip(clip);
 }
  /**
   * Defaults to typical marquee behaviour unless a flow relation is being drawn. In that case, each
   * drag event will redraw a line from the mouse cursor to the source port. If there is a valid
   * incoming port under the mouse, this will also be highlighted to identify that a valid flow may
   * be drawn upon a mouse release event.
   */
  public void mouseDragged(MouseEvent event) {
    if (paletteBar.getState() == Palette.SelectionState.MARQUEE) {
      super.mouseDragged(event);
      return;
    }

    if (state == State.DRAWING_FLOW_RELATION) {
      if (sourcePort != null) {
        setCurrentPoint(getNet().snap(event.getPoint()));
        paintPotentialFlow();
        PortView portUnderMouse = getPortViewAt(event.getPoint());
        if (portUnderMouse != null
            && portUnderMouse != sourcePort
            && connectionAllowable(sourcePort, portUnderMouse)
            && acceptsIncomingFlows(portUnderMouse)) {
          if (portUnderMouse != targetPort) {
            targetPort = portUnderMouse;
            getOverlay().setTarget(net.toScreen(targetPort.getBounds()));
          }
        }
        if (portUnderMouse == null) {
          targetPort = null;
          getOverlay().setTarget(null);
        }
      }
      event.consume();
    }
  }
  /**
   * A convenience method to determine whether the current point is above a valid outgoing port of a
   * YAWL Vertex.
   *
   * @param point the current point
   * @return true if above a valid outgoing port, false otherwise.
   */
  private boolean isPointOverOutgoingPort(Point point) {
    PortView portUnderMouse = getPortViewAt(point);
    if (portUnderMouse == null) {
      return false;
    }

    // Selected flows attached to a port take precedence. We consider the mouse
    // to be over the flow, not the port.

    for (Object flowAsObject : ((YAWLPort) portUnderMouse.getCell()).getEdges()) {
      YAWLFlowRelation flow = (YAWLFlowRelation) flowAsObject;
      for (Object selectedCell : getNet().getSelectionCells()) {
        if (flow == selectedCell) {
          return false;
        }
      }
    }

    return generatesOutgoingFlows(portUnderMouse);
  }
 protected void paintPort(PortView port, boolean show) {
   if (port != null) {
     Rectangle2D portBounds = net.toScreen(port.getBounds());
     getOverlay().setMouseOverPort(show ? portBounds : null);
     getOverlay().setScale(getNet().getScale());
     net.repaint(
         (int) portBounds.getX() - 1,
         (int) portBounds.getY() - 1,
         (int) portBounds.getWidth() + 2,
         (int) portBounds.getHeight() + 2);
   }
 }
 private Point2D portToScreenLocation(PortView port) {
   return new Point2D.Double(
       getNet().toScreen(port.getLocation()).getX(), getNet().toScreen(port.getLocation()).getY());
 }
 /**
  * Returns whether the net considers the connection of the two ports specified to be valid or not.
  *
  * @param source
  * @param target
  * @return true if a connection between the ports is valid, false otherwise.
  */
 private boolean connectionAllowable(PortView source, PortView target) {
   return getNet().connectionAllowable((Port) source.getCell(), (Port) target.getCell());
 }