private void dragFrameFaster(JComponent f, int newX, int newY) { Rectangle previousBounds = new Rectangle(currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height); // move the frame currentBounds.x = newX; currentBounds.y = newY; if (didDrag) { // Only initiate cleanup if we have actually done a drag. emergencyCleanup(f); } else { didDrag = true; // We reset the danger field as until now we haven't actually // moved the internal frame so we don't need to initiate repaint. ((JInternalFrame) f).danger = false; } boolean floaterCollision = isFloaterCollision(previousBounds, currentBounds); // System.out.println(previousBounds); JComponent parent = (JComponent) f.getParent(); Rectangle visBounds = previousBounds.intersection(desktopBounds); // System.out.println(previousBounds); // System.out.println(visBounds); RepaintManager currentManager = RepaintManager.currentManager(f); currentManager.beginPaint(); try { if (!floaterCollision) { currentManager.copyArea( parent, desktopGraphics, visBounds.x, visBounds.y, visBounds.width, visBounds.height, newX - previousBounds.x, newY - previousBounds.y, true); } f.setBounds(currentBounds); if (floaterCollision) { // since we couldn't blit we just redraw as fast as possible // the isDragging mucking is to avoid activating emergency // cleanup ((JInternalFrame) f).isDragging = false; parent.paintImmediately(currentBounds); ((JInternalFrame) f).isDragging = true; } // fake out the repaint manager. We'll take care of everything currentManager.markCompletelyClean(parent); currentManager.markCompletelyClean(f); // compute the minimal newly exposed area // if the rects intersect then we use computeDifference. Otherwise // we'll repaint the entire previous bounds Rectangle[] dirtyRects = null; if (previousBounds.intersects(currentBounds)) { dirtyRects = SwingUtilities.computeDifference(previousBounds, currentBounds); } else { dirtyRects = new Rectangle[1]; dirtyRects[0] = previousBounds; // System.out.println("no intersection"); } ; // Fix the damage for (int i = 0; i < dirtyRects.length; i++) { parent.paintImmediately(dirtyRects[i]); } // new areas of blit were exposed if (!(visBounds.equals(previousBounds))) { dirtyRects = SwingUtilities.computeDifference(previousBounds, desktopBounds); for (int i = 0; i < dirtyRects.length; i++) { dirtyRects[i].x += newX - previousBounds.x; dirtyRects[i].y += newY - previousBounds.y; ((JInternalFrame) f).isDragging = false; parent.paintImmediately(dirtyRects[i]); ((JInternalFrame) f).isDragging = true; // System.out.println(dirtyRects[i]); } } } finally { currentManager.endPaint(); } // update window if it's non-opaque Window topLevel = SwingUtilities.getWindowAncestor(f); Toolkit tk = Toolkit.getDefaultToolkit(); if (!AWTAccessor.getWindowAccessor().isOpaque(topLevel) && (tk instanceof SunToolkit) && ((SunToolkit) tk).needUpdateWindow()) { AWTAccessor.getWindowAccessor().updateWindow(topLevel); } }