/**
   * Moves the visible location of the frame being dragged to the location specified. The means by
   * which this occurs can vary depending on the dragging algorithm being used. The actual logical
   * location of the frame might not change until <code>endDraggingFrame</code> is called.
   */
  public void dragFrame(JComponent f, int newX, int newY) {

    if (dragMode == OUTLINE_DRAG_MODE) {
      JDesktopPane desktopPane = getDesktopPane(f);
      if (desktopPane != null) {
        Graphics g = JComponent.safelyGetGraphics(desktopPane);

        g.setXORMode(Color.white);
        if (currentLoc != null) {
          g.drawRect(currentLoc.x, currentLoc.y, f.getWidth() - 1, f.getHeight() - 1);
        }
        g.drawRect(newX, newY, f.getWidth() - 1, f.getHeight() - 1);
        /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
         * Swing doesn't expect that its XOR drawRect did
         * not complete, so believes that on re-entering at
         * the next update location, that there is an XOR rect
         * to draw out at "currentLoc". But in fact
         * it's now got a new clean surface without that rect,
         * so drawing it "out" in fact draws it on, leaving garbage.
         * So only update/set currentLoc if the draw completed.
         */
        sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData();

        if (!sData.isSurfaceLost()) {
          currentLoc = new Point(newX, newY);
        }
        g.dispose();
      }
    } else if (dragMode == FASTER_DRAG_MODE) {
      dragFrameFaster(f, newX, newY);
    } else {
      setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
    }
  }
  /**
   * Calls <code>setBoundsForFrame</code> with the new values.
   *
   * @param f the component to be resized
   * @param newX the new x-coordinate
   * @param newY the new y-coordinate
   * @param newWidth the new width
   * @param newHeight the new height
   */
  public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {

    if (dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE) {
      setBoundsForFrame(f, newX, newY, newWidth, newHeight);
    } else {
      JDesktopPane desktopPane = getDesktopPane(f);
      if (desktopPane != null) {
        Graphics g = JComponent.safelyGetGraphics(desktopPane);

        g.setXORMode(Color.white);
        if (currentBounds != null) {
          g.drawRect(
              currentBounds.x, currentBounds.y, currentBounds.width - 1, currentBounds.height - 1);
        }
        g.drawRect(newX, newY, newWidth - 1, newHeight - 1);

        // Work around for 6635462, see comment in dragFrame()
        sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData();
        if (!sData.isSurfaceLost()) {
          currentBounds = new Rectangle(newX, newY, newWidth, newHeight);
        }

        g.setPaintMode();
        g.dispose();
      }
    }
  }
  // implements javax.swing.DesktopManager
  public void beginDraggingFrame(JComponent f) {
    setupDragMode(f);

    if (dragMode == FASTER_DRAG_MODE) {
      Component desktop = f.getParent();
      floatingItems = findFloatingItems(f);
      currentBounds = f.getBounds();
      if (desktop instanceof JComponent) {
        desktopBounds = ((JComponent) desktop).getVisibleRect();
      } else {
        desktopBounds = desktop.getBounds();
        desktopBounds.x = desktopBounds.y = 0;
      }
      desktopGraphics = JComponent.safelyGetGraphics(desktop);
      ((JInternalFrame) f).isDragging = true;
      didDrag = false;
    }
  }