Пример #1
0
 public static void convertPointFromScreen(Object display, P3 ptTemp) {
   Point xyTemp = new Point();
   xyTemp.x = (int) ptTemp.x;
   xyTemp.y = (int) ptTemp.y;
   SwingUtilities.convertPointFromScreen(xyTemp, (Component) display);
   ptTemp.set(xyTemp.x, xyTemp.y, Float.NaN);
 }
Пример #2
0
  public void mouseEntered() {
    try {
      loadedMutex.acquire();
      if (rootCrowdLoaded) {
        Point mousePosition = new Point(MouseInfo.getPointerInfo().getLocation());
        SwingUtilities.convertPointFromScreen(mousePosition, this);

        for (int i = 0; i < rootCrowd.getMouseActionList().size(); i++) {
          // if the mouse click is in the hitbox then peform the action
          if (rootCrowd.getMouseActionList().get(i).isActive()
              && rootCrowd
                  .getMouseActionList()
                  .get(i)
                  .isInBounds(mousePosition.x, mousePosition.y)) {
            rootCrowd.getMouseActionList().get(i).mI(mousePosition);
          } else if (rootCrowd.getMouseActionList().get(i).isActive()
              && !rootCrowd
                  .getMouseActionList()
                  .get(i)
                  .isInBounds(mousePosition.x, mousePosition.y)) {
            rootCrowd.getMouseActionList().get(i).mO(mousePosition);
          }
        }
      }
      loadedMutex.release();
    } catch (InterruptedException ie) {
      System.err.println("interrupedMouseEnter");
      Thread.currentThread().interrupt();
    }
  }
 private static void dispatchEvent(JComponent component, MouseEvent event) {
   if (component != null && event != null) {
     Point point = event.getLocationOnScreen();
     SwingUtilities.convertPointFromScreen(point, component);
     component.dispatchEvent(MouseEventAdapter.convert(event, component, point.x, point.y));
   }
 }
Пример #4
0
  public void mouseReleased(MouseEvent e) {

    Point mousePosition = new Point(MouseInfo.getPointerInfo().getLocation());
    SwingUtilities.convertPointFromScreen(mousePosition, this);

    // Mouse 1
    if (e.getButton() == MouseEvent.BUTTON1) {
      L_MOUSE_DOWN = false;
      for (int i = 0; i < rootCrowd.getMouseActionList().size(); i++) {
        // if the mouse click is in the hitbox then peform the action
        if (rootCrowd.getMouseActionList().get(i).isActive()
            && rootCrowd.getMouseActionList().get(i).isInBounds(mousePosition.x, mousePosition.y)) {
          if (rootCrowd.getMouseActionList().get(i).mU(mousePosition, e)) return;
        }
      }
    }
    // Mouse 2, BUTTON2 is middle mouse
    else if (e.getButton() == MouseEvent.BUTTON3) {
      for (int i = 0; i < rootCrowd.getMouseActionList().size(); i++) {
        // if the mouse click is in the hitbox then peform the action
        if (rootCrowd.getMouseActionList().get(i).isActive()
            && rootCrowd.getMouseActionList().get(i).isInBounds(mousePosition.x, mousePosition.y)) {
          if (rootCrowd.getMouseActionList().get(i).rMU(mousePosition, e)) return;
        }
      }
    }
  }
Пример #5
0
  @Override
  public void mouseDragged(MouseEvent arg0) {
    if (dragging) {
      setDragTileLocation(new Point(arg0.getXOnScreen(), arg0.getYOnScreen()));

      // find drop target on world
      Point os = new Point(arg0.getXOnScreen(), arg0.getYOnScreen());
      SwingUtilities.convertPointFromScreen(os, parent.world);

      Component component =
          SwingUtilities.getDeepestComponentAt(parent.world, (int) os.getX(), (int) os.getY());

      if (component instanceof TileView) {
        // available drop target reached
        draggedOverTile = ((TileView) component);

        // change cursor symbol to drop target symbol
        Cursor cursor = DragSource.DefaultCopyDrop;
        draggedTile.setCursor(cursor);
      } else {
        draggedOverTile = null;

        // reset cursor symbol
        draggedTile.setCursor(null);
      }
    }
  }
Пример #6
0
  private void repaintBadge(JComponent field) {
    Point p = field.getLocationOnScreen();
    SwingUtilities.convertPointFromScreen(p, this);

    int x = p.x - warningIcon.getWidth() / 2;
    int y = (int) (p.y + field.getHeight() - warningIcon.getHeight() / 1.5);

    repaint(x, y, warningIcon.getWidth(), warningIcon.getHeight());
  }
 /**
  * Compute the bounds in which the user can move the mouse without the tip window disappearing.
  */
 private void computeTipVisibleBounds() {
   // Compute area that the mouse can move in without hiding the
   // tip window. Note that Java 1.4 can only detect mouse events
   // in Java windows, not globally.
   Rectangle r = tipWindow.getBounds();
   Point p = r.getLocation();
   SwingUtilities.convertPointFromScreen(p, textArea);
   r.setLocation(p);
   tipVisibleBounds.setBounds(r.x, r.y - 15, r.width, r.height + 15 * 2);
 }
Пример #8
0
  public void mouseDragged(MouseEvent e) {
    Component c = e.getComponent();

    Point p = (Point) e.getPoint().clone();
    SwingUtilities.convertPointToScreen(p, c);
    SwingUtilities.convertPointFromScreen(p, glassPane);
    glassPane.setPoint(p);

    glassPane.repaint();
  }
Пример #9
0
  private Point2D convertPoint(double centreX, double centreY, double width, double height) {
    // Step 1: screen coordinates to panel coordinates
    Point p = new Point((int) centreX, (int) centreY);
    SwingUtilities.convertPointFromScreen(p, this);

    // Step 2: we have the middle, we need the top left
    double topLeftX = p.x - (width / 2);
    double topLeftY = p.y - (height / 2);

    return new Point2D.Double(topLeftX, topLeftY);
  }
Пример #10
0
 /**
  * Creates a new JInternalFrame based on the contents of an existing JFrame
  *
  * @param f the JFrame that will be used to create the JInternalFrame
  * @param desktop the JDesktopPane that will receive the JInternalFrame, if null it only retunrs
  *     the internal frame
  * @return a new JInternalFrame
  */
 public JInternalFrame transformToInternalFrame(JFrame f, JDesktopPane desktop) {
   JInternalFrame jif = new JInternalFrame(f.getTitle(), true, true, true, true);
   if (f.getIconImage() != null) jif.setFrameIcon(new ImageIcon(f.getIconImage()));
   if (desktop != null) desktop.add(jif);
   jif.setSize(f.getSize());
   jif.setContentPane(f.getContentPane());
   if (desktop != null) SwingUtilities.convertPointFromScreen(f.getLocation(), desktop);
   jif.setLocation(new Point(0, 0));
   jif.setBounds(f.getBounds());
   f.dispose();
   jif.setVisible(true);
   return (jif);
 }
Пример #11
0
  public static Point convertPoint(
      final Component source, final int x, final int y, final Component destination) {
    Point convertedPoint = new Point(x, y);
    if (source != null && destination != null) {
      convertPointToScreen(convertedPoint, source);
      convertPointFromScreen(convertedPoint, destination);
    } else {
      translateRelatedPoint(convertedPoint, source, 1, true);
      translateRelatedPoint(convertedPoint, destination, -1, true);
    }

    return convertedPoint;
  }
  /**
   * Returns the component in the currently selected path which contains sourcePoint.
   *
   * @param source The component in whose coordinate space sourcePoint is given
   * @param sourcePoint The point which is being tested
   * @return The component in the currently selected path which contains sourcePoint (relative to
   *     the source component's coordinate space. If sourcePoint is not inside a component on the
   *     currently selected path, null is returned.
   */
  public Component componentForPoint(Component source, Point sourcePoint) {
    int screenX, screenY;
    Point p = sourcePoint;
    int i, c, j, d;
    Component mc;
    Rectangle r2;
    int cWidth, cHeight;
    MenuElement menuElement;
    MenuElement subElements[];
    Vector<MenuElement> tmp;
    int selectionSize;

    SwingUtilities.convertPointToScreen(p, source);

    screenX = p.x;
    screenY = p.y;

    tmp = (Vector<MenuElement>) selection.clone();
    selectionSize = tmp.size();
    for (i = selectionSize - 1; i >= 0; i--) {
      menuElement = (MenuElement) tmp.elementAt(i);
      subElements = menuElement.getSubElements();

      for (j = 0, d = subElements.length; j < d; j++) {
        if (subElements[j] == null) continue;
        mc = subElements[j].getComponent();
        if (!mc.isShowing()) continue;
        if (mc instanceof JComponent) {
          cWidth = mc.getWidth();
          cHeight = mc.getHeight();
        } else {
          r2 = mc.getBounds();
          cWidth = r2.width;
          cHeight = r2.height;
        }
        p.x = screenX;
        p.y = screenY;
        SwingUtilities.convertPointFromScreen(p, mc);

        /**
         * Return the deepest component on the selection path in whose bounds the event's point
         * occurs
         */
        if (p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight) {
          return mc;
        }
      }
    }
    return null;
  }
Пример #13
0
  @Override
  public void mouseReleased(MouseEvent e) {
    Component c = e.getComponent();

    Point p = (Point) e.getPoint().clone();
    SwingUtilities.convertPointToScreen(p, c);

    Point eventPoint = (Point) p.clone();
    SwingUtilities.convertPointFromScreen(p, glassPane);

    glassPane.setPoint(p);
    glassPane.setVisible(false);
    glassPane.setImage(null);

    fireGhostDropEvent(new GhostDropEvent(action, eventPoint, this.component, null));
  }
 protected static void processMagnification(IdeFrame frame, double magnification) {
   Point mouse = MouseInfo.getPointerInfo().getLocation();
   SwingUtilities.convertPointFromScreen(mouse, frame.getComponent());
   Component componentAt =
       SwingUtilities.getDeepestComponentAt(frame.getComponent(), mouse.x, mouse.y);
   if (componentAt != null) {
     Editor editor =
         PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(componentAt));
     if (editor != null) {
       double currentSize = editor.getColorsScheme().getEditorFontSize();
       int defaultFontSize =
           EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
       ((EditorEx) editor)
           .setFontSize((int) (Math.max(currentSize + magnification * 3, defaultFontSize)));
     }
   }
 }
  public Point getLocationOn(JComponent c) {
    Point location;
    if (isRealPopup()) {
      location = myPopup.getLocationOnScreen();
      SwingUtilities.convertPointFromScreen(location, c);
    } else {
      if (myCurrentIdeTooltip != null) {
        Point tipPoint = myCurrentIdeTooltip.getPoint();
        Component tipComponent = myCurrentIdeTooltip.getComponent();
        return SwingUtilities.convertPoint(tipComponent, tipPoint, c);
      } else {
        location =
            SwingUtilities.convertPoint(myComponent.getParent(), myComponent.getLocation(), c);
      }
    }

    return location;
  }
Пример #16
0
  @Override
  public void mousePressed(MouseEvent e) {
    Component c = e.getComponent();

    BufferedImage image =
        new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.getGraphics();
    c.paint(g);

    glassPane.setVisible(true);

    Point p = (Point) e.getPoint().clone();
    SwingUtilities.convertPointToScreen(p, c);
    SwingUtilities.convertPointFromScreen(p, glassPane);

    glassPane.setPoint(p);
    glassPane.setImage(image);
    glassPane.repaint();
  }
Пример #17
0
  @Override
  protected void paintComponent(Graphics g) {
    for (JComponent invalid : invalidFields) {
      if (invalid.getParent() instanceof JViewport) {
        JViewport viewport = (JViewport) invalid.getParent();
        // the parent of the viewport is a JScrollPane
        invalid = (JComponent) viewport.getParent();
      }

      Point p = invalid.getLocationOnScreen();
      SwingUtilities.convertPointFromScreen(p, this);

      int x = p.x - warningIcon.getWidth() / 2;
      int y = (int) (p.y + invalid.getHeight() - warningIcon.getHeight() / 1.5);

      if (g.getClipBounds().intersects(x, y, warningIcon.getWidth(), warningIcon.getHeight())) {
        g.drawImage(warningIcon, x, y, null);
      }
    }
  }
 public void setVisible(boolean visible) {
   if (!visible && myView != null) {
     disposeAndUpdate(false);
   } else if (visible && myView == null) {
     Window owner = UIUtil.getWindow(myOwner);
     if (owner != null) {
       if (myHeavyWeight) {
         Window view = pop(owner);
         if (view == null) {
           view = new JWindow(owner);
           setPopupType(view);
         }
         setAlwaysOnTop(view, myAlwaysOnTop);
         setWindowFocusable(view, myWindowFocusable);
         setWindowShadow(view, myWindowShadow);
         myView = view;
       } else if (owner instanceof RootPaneContainer) {
         JLayeredPane parent = ((RootPaneContainer) owner).getLayeredPane();
         if (parent != null) {
           JPanel view = new JPanel(new BorderLayout());
           view.setVisible(false);
           parent.add(view, JLayeredPane.POPUP_LAYER, 0);
           myView = view;
         }
       }
     }
     if (myView != null) {
       myView.add(myContent);
       Component parent = myView instanceof Window ? null : myView.getParent();
       if (parent != null) {
         Point location = myViewBounds.getLocation();
         SwingUtilities.convertPointFromScreen(location, parent);
         myViewBounds.setLocation(location);
       }
       myView.setBackground(UIUtil.getLabelBackground());
       myView.setBounds(myViewBounds);
       myView.setVisible(true);
       myViewBounds = null;
     }
   }
 }
Пример #19
0
  /** @param event */
  private void showTooltipWindow(MouseEvent event) {
    Point p = new Point(event.getPoint());
    SwingUtilities.convertPointToScreen(p, this);
    Point p2 = new Point(p);
    SwingUtilities.convertPointFromScreen(p2, textComponent);

    // annotation for target line
    AnnotateLine al = null;
    if (!elementAnnotations.isEmpty()) {
      al = getAnnotateLine(getLineFromMouseEvent(event));
    }

    /**
     * al.getCommitMessage() != null - since commit messages are initialized separately from the AL
     * constructor
     */
    if (al != null && al.getCommitMessage() != null) {
      TooltipWindow ttw = new TooltipWindow(this, al);
      ttw.show(new Point(p.x - p2.x, p.y));
    }
  }
 private void setBounds(Point location, Dimension size) {
   if (myView != null) {
     if (size == null) {
       size = myView.getSize();
     }
     if (location == null) {
       location = myView.getLocation();
     } else {
       Component parent = myView instanceof Window ? null : myView.getParent();
       if (parent != null) {
         SwingUtilities.convertPointFromScreen(location, parent);
       }
     }
     myView.setBounds(location.x, location.y, size.width, size.height);
     if (myView.isVisible()) {
       myView.invalidate();
       myView.validate();
       myView.repaint();
     }
   }
 }
Пример #21
0
  /**
   * Prepares to move or drop a figure on this board.
   *
   * @param x the x-coordinate of the mouse
   * @param y the y-coordinate of the mouse
   * @param figure the figure which is grabbed
   * @return <code>true</code> if a valid location for <code>figure</code> was found, <code>false
   *     </code> otherwise
   */
  private StationDropOperation prepare(int x, int y, ChessFigure figure) {
    Point location = new Point(x, y);
    SwingUtilities.convertPointFromScreen(location, this);

    int w = getWidth();
    int h = getHeight();

    if (location.x < 0 || location.y < 0 || location.x > w || location.y > h) {
      return null;
    }

    int r = -1;
    int c = 7;

    while (c * w / 8 > location.x) c--;

    while ((7 - r) * h / 8 > location.y) r++;

    final DropInfo drop = new DropInfo();

    figure
        .getFigure()
        .reachable(
            new Board.CellVisitor() {
              public boolean visit(int r, int c, Figure figure) {
                drop.targets[r][c] = true;
                return true;
              }
            });

    drop.figure = figure;

    drop.row = r;
    drop.column = c;

    drop.valid = drop.targets[drop.row][drop.column];

    return drop;
  }
Пример #22
0
  public static void feedMouseEventToPanel(int x, int y) {
    Point p = new Point(x, y);
    SwingUtilities.convertPointFromScreen(p, frame.getContentPane());

    System.out.println("x " + x + " y " + y);
    System.out.println("p.x " + p.x + " p.y " + p.y);

    if ((p.x > 0 && p.x < frame.getWidth()) && (p.y > 0 && p.y < frame.getHeight())) {
      Component comp = SwingUtilities.getDeepestComponentAt(frame.getContentPane(), p.x, p.y);

      System.out.println(comp.toString());

      Toolkit.getDefaultToolkit()
          .getSystemEventQueue()
          .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_PRESSED, 0, 0, p.x, p.y, 1, false));
      Toolkit.getDefaultToolkit()
          .getSystemEventQueue()
          .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_RELEASED, 0, 0, p.x, p.y, 1, false));
      Toolkit.getDefaultToolkit()
          .getSystemEventQueue()
          .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_CLICKED, 0, 0, p.x, p.y, 1, false));
    }
  }
  /**
   * When a MenuElement receives an event from a MouseListener, it should never process the event
   * directly. Instead all MenuElements should call this method with the event.
   *
   * @param event a MouseEvent object
   */
  public void processMouseEvent(MouseEvent event) {
    int screenX, screenY;
    Point p;
    int i, c, j, d;
    Component mc;
    Rectangle r2;
    int cWidth, cHeight;
    MenuElement menuElement;
    MenuElement subElements[];
    MenuElement path[];
    Vector<MenuElement> tmp;
    int selectionSize;
    p = event.getPoint();

    Component source = event.getComponent();

    if ((source != null) && !source.isShowing()) {
      // This can happen if a mouseReleased removes the
      // containing component -- bug 4146684
      return;
    }

    int type = event.getID();
    int modifiers = event.getModifiers();
    // 4188027: drag enter/exit added in JDK 1.1.7A, JDK1.2
    if ((type == MouseEvent.MOUSE_ENTERED || type == MouseEvent.MOUSE_EXITED)
        && ((modifiers
                & (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK))
            != 0)) {
      return;
    }

    if (source != null) {
      SwingUtilities.convertPointToScreen(p, source);
    }

    screenX = p.x;
    screenY = p.y;

    tmp = (Vector<MenuElement>) selection.clone();
    selectionSize = tmp.size();
    boolean success = false;
    for (i = selectionSize - 1; i >= 0 && success == false; i--) {
      menuElement = (MenuElement) tmp.elementAt(i);
      subElements = menuElement.getSubElements();

      path = null;
      for (j = 0, d = subElements.length; j < d && success == false; j++) {
        if (subElements[j] == null) continue;
        mc = subElements[j].getComponent();
        if (!mc.isShowing()) continue;
        if (mc instanceof JComponent) {
          cWidth = mc.getWidth();
          cHeight = mc.getHeight();
        } else {
          r2 = mc.getBounds();
          cWidth = r2.width;
          cHeight = r2.height;
        }
        p.x = screenX;
        p.y = screenY;
        SwingUtilities.convertPointFromScreen(p, mc);

        /**
         * Send the event to visible menu element if menu element currently in the selected path or
         * contains the event location
         */
        if ((p.x >= 0 && p.x < cWidth && p.y >= 0 && p.y < cHeight)) {
          int k;
          if (path == null) {
            path = new MenuElement[i + 2];
            for (k = 0; k <= i; k++) path[k] = (MenuElement) tmp.elementAt(k);
          }
          path[i + 1] = subElements[j];
          MenuElement currentSelection[] = getSelectedPath();

          // Enter/exit detection -- needs tuning...
          if (currentSelection[currentSelection.length - 1] != path[i + 1]
              && (currentSelection.length < 2
                  || currentSelection[currentSelection.length - 2] != path[i + 1])) {
            Component oldMC = currentSelection[currentSelection.length - 1].getComponent();

            MouseEvent exitEvent =
                new MouseEvent(
                    oldMC,
                    MouseEvent.MOUSE_EXITED,
                    event.getWhen(),
                    event.getModifiers(),
                    p.x,
                    p.y,
                    event.getXOnScreen(),
                    event.getYOnScreen(),
                    event.getClickCount(),
                    event.isPopupTrigger(),
                    MouseEvent.NOBUTTON);
            currentSelection[currentSelection.length - 1].processMouseEvent(exitEvent, path, this);

            MouseEvent enterEvent =
                new MouseEvent(
                    mc,
                    MouseEvent.MOUSE_ENTERED,
                    event.getWhen(),
                    event.getModifiers(),
                    p.x,
                    p.y,
                    event.getXOnScreen(),
                    event.getYOnScreen(),
                    event.getClickCount(),
                    event.isPopupTrigger(),
                    MouseEvent.NOBUTTON);
            subElements[j].processMouseEvent(enterEvent, path, this);
          }
          MouseEvent mouseEvent =
              new MouseEvent(
                  mc,
                  event.getID(),
                  event.getWhen(),
                  event.getModifiers(),
                  p.x,
                  p.y,
                  event.getXOnScreen(),
                  event.getYOnScreen(),
                  event.getClickCount(),
                  event.isPopupTrigger(),
                  MouseEvent.NOBUTTON);
          subElements[j].processMouseEvent(mouseEvent, path, this);
          success = true;
          event.consume();
        }
      }
    }
  }
  /**
   * Searches the dock where the dockable will be docked for the current mouse location. A rectangle
   * is painted that shows, where the dockable will be docked. The cursor shows, if we can dock, or
   * if we cannot dock for the current location.
   */
  public void drag(MouseEvent mouseEvent) {

    // Get the component of the mouse event.
    Component mouseComponent = (Component) mouseEvent.getSource();

    // Get the mouse location in screen coordinates.
    computeScreenLocation(mouseEvent);

    // Do we have to move an externalized dockable?
    if (draggedDockable.getState() == DockableState.EXTERNALIZED) {
      // Move the dockable.
      ExternalizedDraggerSupport.moveExternalizedDockable(
          draggedDockable, screenLocation, dockableOffset);
      return;
    }

    // Get the destination dock for this position for the dockable that we are dragging.
    Dock[] destinationDocks =
        dockRetriever.retrieveHighestPriorityDock(screenLocation, draggedDockable);
    if (destinationDocks == null) {
      // We have no destination dock any more. Clean up what was painted before.
      clearPainting();

      // Set the 'cannot dock' cursor.
      cursorManager.setCursor(mouseComponent, retrieveCanNotDockCursor());

      return;
    }
    Dock destinationDock = destinationDocks[0];

    // Do we have a destination dock?
    if (destinationDock != null) {

      // Does the destination dock inherit from java.awt.Component or is it the float dock?
      if (destinationDock instanceof Component) {

        // Get the docking rectangle for the destination dock.
        locationInDestinationDock.setLocation(screenLocation.x, screenLocation.y);
        SwingUtilities.convertPointFromScreen(
            locationInDestinationDock, (Component) destinationDock);
        destinationDock.retrieveDockingRectangle(
            draggedDockable, locationInDestinationDock, dockableOffset, dockableDragRectangle);

        // Paint the new rectangle.
        dockableDragPainter.paintDockableDrag(
            draggedDockable, destinationDock, dockableDragRectangle, locationInDestinationDock);

        // Set the 'can dock' cursor.
        cursorManager.setCursor((Component) destinationDock, retrieveCanDockCursor());

      } else if (destinationDock instanceof FloatDock) {

        // Are we in the special situation that we will move a child dock of the float dock?
        boolean move = false;

        // Get the root dock and the dock under the root.
        Dock rootDock = originDock;
        Dock dockUnderRoot = null;
        while (rootDock.getParentDock() != null) {
          dockUnderRoot = rootDock;
          rootDock = rootDock.getParentDock();
        }

        // Is the root dock the float dock?
        if (rootDock instanceof FloatDock) {
          // Is the dockable already in this dock and are there no others?
          List childrenOfDockable = new ArrayList();
          List childrenOfDock = new ArrayList();
          DockingUtil.retrieveDockables(draggedDockable, childrenOfDockable);
          DockingUtil.retrieveDockables(dockUnderRoot, childrenOfDock);
          if (sameElements(childrenOfDockable, childrenOfDock)) {
            move = true;
          }
        }

        // We cannot paint on the screen, but maybe we can paint in the pane of the origin dock.
        if (originDock instanceof Component) {
          if (move) {
            locationInDestinationDock.setLocation(
                screenLocation.x - dockableOffset.x, screenLocation.y - dockableOffset.y);
            SwingUtilities.convertPointFromScreen(
                locationInDestinationDock, (Component) originDock);
            dockableDragRectangle.setLocation(locationInDestinationDock);
            Window window = SwingUtilities.getWindowAncestor((Component) dockUnderRoot);
            dockableDragRectangle.setSize(window.getSize());
            locationInDestinationDock.setLocation(
                locationInDestinationDock.x + dockableOffset.x,
                locationInDestinationDock.y + dockableOffset.y);
          } else {
            // Get the docking rectangle for the destination float dock.
            destinationDock.retrieveDockingRectangle(
                draggedDockable, screenLocation, dockableOffset, dockableDragRectangle);

            // Convert this rectangle to the origindock.
            locationInDestinationDock.setLocation(dockableDragRectangle.x, dockableDragRectangle.y);
            SwingUtilities.convertPointFromScreen(
                locationInDestinationDock, (Component) originDock);
            dockableDragRectangle.setLocation(locationInDestinationDock);
            locationInDestinationDock.setLocation(
                locationInDestinationDock.x + dockableOffset.x,
                locationInDestinationDock.y + dockableOffset.y);
          }
          // Paint the new rectangle.
          dockableDragPainter.paintDockableDrag(
              draggedDockable, originDock, dockableDragRectangle, locationInDestinationDock);
        } else {
          // We couldn't find a dock where we can paint.
          clearPainting();
        }

        // Set the 'can dock' cursor.
        cursorManager.setCursor(mouseComponent, retrieveCanDockCursor());

      } else {
        // Currentle this should not happen. All docks, except the float dock inherit from
        // java.awt.Component.
        // We have a dock where we cannot paint. Clean up what was painted before.
        clearPainting();

        // Set the 'can dock' cursor.
        cursorManager.setCursor(mouseComponent, retrieveCanDockCursor());
      }

    } else {
      // We have no destination dock any more. Clean up what was paintedbefore.
      clearPainting();

      // Set the 'cannot dock' cursor.
      cursorManager.setCursor(mouseComponent, retrieveCanNotDockCursor());
    }
  }
  /**
   * Resets the cursor. Cleans up what was painted before. Searches a destination dock for the last
   * mouse location and tries to dock the dragged dockable in this dock.
   */
  public void stopDragging(MouseEvent mouseEvent) {

    // Reset the old cursor.
    cursorManager.resetCursor();

    // Clean up what was painted for dragging.
    dockableDragPainter.clear();

    // Get the mouse location in screen coordinates.
    computeScreenLocation(mouseEvent);

    // Do we have to move an externalized dockable?
    if (draggedDockable.getState() == DockableState.EXTERNALIZED) {
      // Move the dockable.
      ExternalizedDraggerSupport.moveExternalizedDockable(
          draggedDockable, screenLocation, dockableOffset);

      // No dragging anymore.
      reset();

      return;
    }

    // Get the destination dock.
    Dock[] destinationDocks =
        dockRetriever.retrieveHighestPriorityDock(screenLocation, draggedDockable);
    if (destinationDocks == null) {
      return;
    }
    Dock destinationDock = destinationDocks[0];

    // Is the destination dock different from the origin?
    if (destinationDock != null) {
      if (!destinationDock.equals(originDock)) {
        // Get the mouse location for the new dock.
        locationInDestinationDock.setLocation(screenLocation.x, screenLocation.y);
        if (destinationDock instanceof Component) {
          SwingUtilities.convertPointFromScreen(
              locationInDestinationDock, (Component) destinationDock);
        }

        // Check if we can move the dock of the dockable in the float dock.
        if (destinationDock instanceof FloatDock) {
          // Get the root dock and the dock under the root.
          Dock rootDock = originDock;
          Dock dockUnderRoot = null;
          while (rootDock.getParentDock() != null) {
            dockUnderRoot = rootDock;
            rootDock = rootDock.getParentDock();
          }

          // Is the root dock the float dock?
          if (rootDock instanceof FloatDock) {
            // Is the dockable already in this dock and are there no others?
            List childrenOfDockable = new ArrayList();
            List childrenOfDock = new ArrayList();
            DockingUtil.retrieveDockables(draggedDockable, childrenOfDockable);
            DockingUtil.retrieveDockables(dockUnderRoot, childrenOfDock);
            if (sameElements(childrenOfDockable, childrenOfDock)) {
              ((FloatDock) rootDock)
                  .moveDock(dockUnderRoot, locationInDestinationDock, dockableOffset);
              return;
            }
          }
        }

        // Get the real dockable in the model with this ID.
        Dockable dockableWrapper = DockingUtil.retrieveDockableOfDockModel(draggedDockable.getID());
        if (dockableWrapper == null) {
          throw new IllegalStateException(
              "The dragged dockable should be docked in the dock model.");
        }

        // Remove the dockable from the old dock, add to the new dock.
        // Use the docking manager for the addition and removal, because the listenenrs have to
        // informed.
        if (!originDock.equals(draggedDockable.getDock())) {
          throw new IllegalStateException("The origin dock is not the parent of the dockable.");
        }
        DockingManager.getDockingExecutor()
            .changeDocking(
                dockableWrapper, destinationDock, locationInDestinationDock, dockableOffset);

        // Clean the dock from which the dockable is removed.
        DockingManager.getDockingExecutor().cleanDock(originDock, false);

      } else {
        // Get the real dockable in the model with this ID.
        Dockable dockableWrapper = DockingUtil.retrieveDockableOfDockModel(draggedDockable.getID());
        if (dockableWrapper == null) {
          throw new IllegalStateException(
              "The dragged dockable should be docked in the dock model.");
        }

        // Move the dockable to a new position in the same dock.
        if (!originDock.equals(draggedDockable.getDock())) {
          throw new IllegalStateException("The origin dock is not the parent of the dockable.");
        }
        DockingManager.getDockingExecutor()
            .changeDocking(dockableWrapper, originDock, locationInDestinationDock, new Point(0, 0));
      }
    }

    // No dragging anymore.
    reset();
  }
  /**
   * Get an instance of a {@link JPopupMenu} for a given {@link VPathwayElement}
   *
   * @param e The {@link VPathwayElement} to create the popup menu for. If e is an instance of
   *     {@link Handle}, the menu is based on the parent element.
   * @return The {@link JPopupMenu} for the given pathway element
   */
  private JPopupMenu getMenuInstance(SwingEngine swingEngine, VPathwayElement e) {
    if (e instanceof Citation) return null;

    JMenu pathLitRef = null;
    if (e instanceof Handle) {
      e = ((Handle) e).getParent();
      pathLitRef = new JMenu("Literature for pathway");
    }

    VPathway vp = e.getDrawing();
    VPathwaySwing component = (VPathwaySwing) vp.getWrapper();
    ViewActions vActions = vp.getViewActions();

    JPopupMenu menu = new JPopupMenu();

    // Don't show delete if the element cannot be deleted
    if (!(e instanceof InfoBox)) {
      menu.add(vActions.delete1);
    }

    JMenu selectMenu = new JMenu("Select");
    selectMenu.add(vActions.selectAll);
    selectMenu.add(vActions.selectDataNodes);
    selectMenu.add(vActions.selectInteractions);
    selectMenu.add(vActions.selectLines);
    selectMenu.add(vActions.selectShapes);
    selectMenu.add(vActions.selectLabels);
    menu.add(selectMenu);
    menu.addSeparator();

    // new feature to copy and paste with the right-click menu
    menu.add(vActions.copy);

    PositionPasteAction a = vActions.positionPaste;
    Point loc = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(loc, component);
    a.setPosition(loc);

    menu.add(a);
    menu.addSeparator();

    // Only show group/ungroup when multiple objects or a group are selected
    if ((e instanceof Group)) {
      GroupStyle s = ((Group) e).getPathwayElement().getGroupStyle();
      if (s == GroupStyle.GROUP) {
        menu.add(vActions.toggleGroup);
      } else {
        menu.add(vActions.toggleComplex);
      }
      menu.addSeparator();
    } else if (vp.getSelectedGraphics().size() > 1) {
      menu.add(vActions.toggleGroup);
      menu.add(vActions.toggleComplex);
    }

    if (e instanceof GeneProduct) {
      menu.add(vActions.addState);
    }
    if (e instanceof State) {
      menu.add(vActions.removeState);
    }

    if ((e instanceof Line)) {
      final Line line = (Line) e;

      menu.add(vActions.addAnchor);

      if (line.getPathwayElement().getConnectorType() == ConnectorType.SEGMENTED) {
        menu.add(vActions.addWaypoint);
        menu.add(vActions.removeWaypoint);
      }

      JMenu typeMenu = new JMenu("Line type");

      ButtonGroup buttons = new ButtonGroup();

      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              line.getPathwayElement()
                  .setConnectorType(ConnectorType.fromName(e.getActionCommand()));
            }
          };
      for (ConnectorType t : ConnectorType.getValues()) {
        JRadioButtonMenuItem mi = new JRadioButtonMenuItem(t.getName());
        mi.setActionCommand(t.getName());
        mi.setSelected(t.equals(line.getPathwayElement().getConnectorType()));
        mi.addActionListener(listener);
        typeMenu.add(mi);
        buttons.add(mi);
      }
      menu.add(typeMenu);
    }

    if ((e instanceof VAnchor)) {
      final VAnchor anchor = ((VAnchor) e);

      JMenu anchorMenu = new JMenu("Anchor type");
      ButtonGroup buttons = new ButtonGroup();

      ActionListener listener =
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              anchor.getMAnchor().setShape(AnchorType.fromName(e.getActionCommand()));
            }
          };

      for (AnchorType at : AnchorType.getValues()) {
        JRadioButtonMenuItem mi = new JRadioButtonMenuItem(at.getName());
        mi.setActionCommand(at.getName());
        mi.setSelected(at.equals(anchor.getMAnchor().getShape()));
        mi.addActionListener(listener);
        anchorMenu.add(mi);
        buttons.add(mi);
      }

      menu.add(anchorMenu);
    }

    JMenu orderMenu = new JMenu("Order");
    orderMenu.add(vActions.orderBringToFront);
    orderMenu.add(vActions.orderSendToBack);
    orderMenu.add(vActions.orderUp);
    orderMenu.add(vActions.orderDown);
    menu.add(orderMenu);

    if (e instanceof Graphics) {
      JMenu litMenu = new JMenu("Literature");
      litMenu.add(new AddLiteratureAction(swingEngine, component, e));
      litMenu.add(new EditLiteratureAction(swingEngine, component, e));
      menu.add(litMenu);

      menu.addSeparator();
      menu.add(new PropertiesAction(swingEngine, component, e));
    }

    if (pathLitRef != null) {
      menu.addSeparator();
      pathLitRef.add(
          new AddLiteratureAction(
              swingEngine, component, swingEngine.getEngine().getActiveVPathway().getMappInfo()));
      pathLitRef.add(
          new EditLiteratureAction(
              swingEngine, component, swingEngine.getEngine().getActiveVPathway().getMappInfo()));
      menu.add(pathLitRef);
    }

    // give plug-ins a chance to add menu items.
    for (PathwayElementMenuHook hook : hooks) {
      hook.pathwayElementMenuHook(e, menu);
    }

    return menu;
  }