Java Code Examples for java.awt.Rectangle.union()

The following are Jave code examples for showing how to use union() of the java.awt.Rectangle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: ToolTipSupport.java   View Source Code Vote up 6 votes
private Rectangle computeMouseMoveIgnoredArea(Rectangle toolTipBounds, Rectangle blockBounds, Rectangle cursorBounds) {
    Rectangle _toolTipBounds = new Rectangle(toolTipBounds);
    extendBounds(_toolTipBounds);
    
    Rectangle area = new Rectangle();
    Rectangle.union(_toolTipBounds, cursorBounds, area);
    if (blockBounds != null) {
        area.x = blockBounds.x;
        area.width = blockBounds.width;
    }
    area.x -= cursorBounds.width;
    area.width += 2 * cursorBounds.width;
    
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "toolTip.bounds={0}, blockBounds={1}, cursorBounds={2}, mouseMoveIgnoredArea={3}", new Object [] { _toolTipBounds, blockBounds, cursorBounds, area });
    }
    
    return area;
}
 
Example 2
Project: ramus   File: ScrollPanePreview.java   View Source Code Vote up 6 votes
private void moveRectangle(int aDeltaX, int aDeltaY) {
    if (theStartRectangle == null)
        return;

    Insets insets = getInsets();
    Rectangle newRect = new Rectangle(theStartRectangle);
    newRect.x += aDeltaX;
    newRect.y += aDeltaY;
    newRect.x = Math.min(Math.max(newRect.x, insets.left), getWidth()
            - insets.right - newRect.width);
    newRect.y = Math.min(Math.max(newRect.y, insets.right), getHeight()
            - insets.bottom - newRect.height);
    Rectangle clip = new Rectangle();
    Rectangle.union(theRectangle, newRect, clip);
    clip.grow(2, 2);
    theRectangle = newRect;
    paintImmediately(clip);
}
 
Example 3
Project: TrabalhoFinalEDA2   File: mxGraphOutline.java   View Source Code Vote up 6 votes
/**
 * 
 */
public void updateFinderBounds(Rectangle bounds, boolean repaint)
{
	if (bounds != null && !bounds.equals(finderBounds))
	{
		Rectangle old = new Rectangle(finderBounds);
		finderBounds = bounds;

		// LATER: Fix repaint region to be smaller
		if (repaint)
		{
			old = old.union(finderBounds);
			old.grow(3, 3);
			repaint(old);
		}
	}
}
 
Example 4
Project: MaxSim   File: LoopClusterWidget.java   View Source Code Vote up 6 votes
public void updateClusterBounds(){      
    Rectangle boundRect=null;
    
    for(NodeWidget nw : this.members){
        if(boundRect==null){
            boundRect = nw.convertLocalToScene(nw.getBounds());  
        } else {
            boundRect = boundRect.union(nw.convertLocalToScene(nw.getBounds()));
        }  
    }
    if(boundRect==null) return;
    for(Widget w : this.getChildren()) {
        if(w instanceof LoopClusterWidget) {            
            LoopClusterWidget lc = (LoopClusterWidget)w;
            lc.updateClusterBounds();
            boundRect = boundRect.union(w.convertLocalToScene(w.getBounds()));
        }
    }
   
    boundRect.grow(INSET, INSET);
    this.setPreferredBounds(boundRect);               
}
 
Example 5
Project: incubator-netbeans   File: HintsUI.java   View Source Code Vote up 5 votes
private Rectangle getScreenBounds() throws HeadlessException {
  Rectangle virtualBounds = new Rectangle();
  GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice[] gs = ge.getScreenDevices();

  if (gs.length == 0 || gs.length == 1) {
      return new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
  }
 
  for (GraphicsDevice gd : gs) {
      virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
  }

  return virtualBounds;
}
 
Example 6
Project: incubator-netbeans   File: BaseCaret.java   View Source Code Vote up 5 votes
private void updateRectangularSelectionPaintRect() {
    // Repaint current rect
    JTextComponent c = component;
    Rectangle repaintRect = rsPaintRect;
    if (rsDotRect == null || rsMarkRect == null) {
        return;
    }
    Rectangle newRect = new Rectangle();
    if (rsDotRect.x < rsMarkRect.x) { // Swap selection to left
        newRect.x = rsDotRect.x; // -1 to make the visual selection non-empty
        newRect.width = rsMarkRect.x - newRect.x;
    } else { // Extend or shrink on right
        newRect.x = rsMarkRect.x;
        newRect.width = rsDotRect.x - newRect.x;
    }
    if (rsDotRect.y < rsMarkRect.y) {
        newRect.y = rsDotRect.y;
        newRect.height = (rsMarkRect.y + rsMarkRect.height) - newRect.y;
    } else {
        newRect.y = rsMarkRect.y;
        newRect.height = (rsDotRect.y + rsDotRect.height) - newRect.y;
    }
    if (newRect.width < 2) {
        newRect.width = 2;
    }
    rsPaintRect = newRect;

    // Repaint merged region with original rect
    if (repaintRect == null) {
        repaintRect = rsPaintRect;
    } else {
        repaintRect = repaintRect.union(rsPaintRect);
    }
    c.repaint(repaintRect);
    
    updateRectangularSelectionPositionBlocks();
}
 
Example 7
Project: incubator-netbeans   File: EditorCaret.java   View Source Code Vote up 5 votes
private void updateRectangularSelectionPaintRect() {
    // Repaint current rect
    JTextComponent c = component;
    Rectangle repaintRect = rsPaintRect;
    if (rsDotRect == null || rsMarkRect == null) {
        return;
    }
    Rectangle newRect = new Rectangle();
    if (rsDotRect.x < rsMarkRect.x) { // Swap selection to left
        newRect.x = rsDotRect.x; // -1 to make the visual selection non-empty
        newRect.width = rsMarkRect.x - newRect.x;
    } else { // Extend or shrink on right
        newRect.x = rsMarkRect.x;
        newRect.width = rsDotRect.x - newRect.x;
    }
    if (rsDotRect.y < rsMarkRect.y) {
        newRect.y = rsDotRect.y;
        newRect.height = (rsMarkRect.y + rsMarkRect.height) - newRect.y;
    } else {
        newRect.y = rsMarkRect.y;
        newRect.height = (rsDotRect.y + rsDotRect.height) - newRect.y;
    }
    if (newRect.width < 2) {
        newRect.width = 2;
    }
    rsPaintRect = newRect;

    // Repaint merged region with original rect
    if (repaintRect == null) {
        repaintRect = rsPaintRect;
    } else {
        repaintRect = repaintRect.union(rsPaintRect);
    }
    c.repaint(repaintRect);
    
    updateRectangularSelectionPositionBlocks();
}
 
Example 8
Project: openjdk-jdk10   File: BasicGraphicsUtils.java   View Source Code Vote up 5 votes
/**
 * Returns the preferred size of the button.
 *
 * @param b an instance of {@code AbstractButton}
 * @param textIconGap a gap between text and icon
 * @return the preferred size of the button
 */
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
Example 9
Project: jdk8u-jdk   File: BasicGraphicsUtils.java   View Source Code Vote up 5 votes
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
Example 10
Project: incubator-netbeans   File: FindSupport.java   View Source Code Vote up 5 votes
private void scrollToCurrent() {
    try {
        Rectangle r1 = currentComp.modelToView(currentStart);
        Rectangle r2 = currentComp.modelToView(currentStart);
        Rectangle r = r1.union(r2);
        currentComp.scrollRectToVisible(r);
    } catch (BadLocationException blex) {
        BugtrackingManager.LOG.log(Level.INFO, blex.getMessage(), blex);
    }
}
 
Example 11
Project: JavaGraph   File: LibrariesTable.java   View Source Code Vote up 5 votes
@Override
public void mouseMoved(MouseEvent e) {
    JTable table = (JTable) e.getSource();
    Point pt = e.getPoint();
    int prev_row = this.row;
    int prev_col = this.col;
    this.row = table.rowAtPoint(pt);
    this.col = table.columnAtPoint(pt);
    if (this.row != prev_row || this.col != prev_col) {
        Rectangle r = table.getCellRect(this.row, this.col, false);
        r = r.union(table.getCellRect(prev_row, prev_col, false));
        table.repaint(r);
    }
}
 
Example 12
Project: JavaGraph   File: ContributorsTable.java   View Source Code Vote up 5 votes
@Override
public void mouseMoved(MouseEvent e) {
    JTable table = (JTable) e.getSource();
    Point pt = e.getPoint();
    int prev_row = this.row;
    int prev_col = this.col;
    this.row = table.rowAtPoint(pt);
    this.col = table.columnAtPoint(pt);
    if (this.row != prev_row || this.col != prev_col) {
        Rectangle r = table.getCellRect(this.row, this.col, false);
        r = r.union(table.getCellRect(prev_row, prev_col, false));
        table.repaint(r);
    }
}
 
Example 13
Project: JavaGraph   File: JGraphUI.java   View Source Code Vote up 5 votes
/** 
 * Updates the bounds of the rubber band,
 * and optionally repaints the dirty area.
 */
private void update(int x, int y, int width, int height) {
    Rectangle dirty = (Rectangle) this.bounds.clone();
    this.bounds.setBounds(x, y, width, height);
    dirty = dirty.union(this.bounds);
    // make sure the dirty area includes the contour of the rubber band
    dirty.x -= 1;
    dirty.y -= 1;
    dirty.height += 2;
    dirty.width += 2;
    this.canvas.repaint(dirty);
}
 
Example 14
Project: OpenJSharp   File: BasicGraphicsUtils.java   View Source Code Vote up 5 votes
public static Dimension getPreferredButtonSize(AbstractButton b, int textIconGap)
{
    if(b.getComponentCount() > 0) {
        return null;
    }

    Icon icon = b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle viewR = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    SwingUtilities.layoutCompoundLabel(
        b, fm, text, icon,
        b.getVerticalAlignment(), b.getHorizontalAlignment(),
        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
        viewR, iconR, textR, (text == null ? 0 : textIconGap)
    );

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;

    return r.getSize();
}
 
Example 15
Project: jdk8u-jdk   File: WindowsTextUI.java   View Source Code Vote up 5 votes
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}
 
Example 16
Project: openjdk-jdk10   File: WindowsTextUI.java   View Source Code Vote up 4 votes
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
@SuppressWarnings("deprecation")
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}
 
Example 17
Project: incubator-netbeans   File: CompletionLayoutPopup.java   View Source Code Vote up 4 votes
public Rectangle unionBounds(Rectangle bounds) {
    return isVisible() ? bounds.union(getPopupBounds()) : bounds;
}
 
Example 18
Project: freecol   File: UnitMoveAnimation.java   View Source Code Vote up 4 votes
/**
 * {@inheritDoc}
 */
@Override
public void executeWithUnitOutForAnimation(JLabel unitLabel) {
    final SwingGUI gui = (SwingGUI)getGUI();
    final float scale = gui.getMapScale();
    final int movementRatio = (int)(Math.pow(2, this.speed + 1) * scale);
    final Rectangle r1 = gui.getTileBounds(this.sourceTile);
    final Rectangle r2 = gui.getTileBounds(this.destinationTile);
    final Rectangle bounds = r1.union(r2);
    final double xratio = ImageLibrary.TILE_SIZE.width
        / (double)ImageLibrary.TILE_SIZE.height;

    // Tile positions should be valid at this point.
    final Point srcP = gui.getTilePosition(this.sourceTile);
    if (srcP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at source tile: " + this.sourceTile);
        return;
    }
    final Point dstP = gui.getTilePosition(this.destinationTile);
    if (dstP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at destination tile: " + this.destinationTile);
        return;
    }
        
    final int labelWidth = unitLabel.getWidth();
    final int labelHeight = unitLabel.getHeight();
    final Point srcPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
        labelHeight, srcP);
    final Point dstPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
        labelHeight, dstP);
    final int stepX = (srcPoint.getX() == dstPoint.getX()) ? 0
        : (srcPoint.getX() > dstPoint.getX()) ? -1 : 1;
    final int stepY = (srcPoint.getY() == dstPoint.getY()) ? 0
        : (srcPoint.getY() > dstPoint.getY()) ? -1 : 1;

    int dropFrames = 0;
    Point point = srcPoint;
    while (!point.equals(dstPoint)) {
        long time = System.currentTimeMillis();
        point.x += stepX * xratio * movementRatio;
        point.y += stepY * movementRatio;
        if ((stepX < 0 && point.x < dstPoint.x)
            || (stepX > 0 && point.x > dstPoint.x)) {
            point.x = dstPoint.x;
        }
        if ((stepY < 0 && point.y < dstPoint.y)
            || (stepY > 0 && point.y > dstPoint.y)) {
            point.y = dstPoint.y;
        }
        if (dropFrames <= 0) {
            unitLabel.setLocation(point);
            gui.paintImmediatelyCanvasIn(bounds);
            int timeTaken = (int)(System.currentTimeMillis()-time);
            final int waitTime = ANIMATION_DELAY - timeTaken;
            if (waitTime > 0) {
                Utils.delay(waitTime, "Animation interrupted.");
                dropFrames = 0;
            } else {
                dropFrames = timeTaken / ANIMATION_DELAY - 1;
            }
        } else {
            dropFrames--;
        }
    }
    gui.refresh();
}
 
Example 19
Project: OpenJSharp   File: WindowsTextUI.java   View Source Code Vote up 4 votes
/**
 * Paints a highlight.
 *
 * @param g the graphics context
 * @param offs0 the starting model offset >= 0
 * @param offs1 the ending model offset >= offs1
 * @param bounds the bounding box for the highlight
 * @param c the editor
 */
public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
    Rectangle alloc = bounds.getBounds();
    try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
            g.setColor(c.getSelectionColor());
        }
        else {
            g.setColor(color);
        }
        boolean firstIsDot = false;
        boolean secondIsDot = false;
        if (c.isEditable()) {
            int dot = c.getCaretPosition();
            firstIsDot = (offs0 == dot);
            secondIsDot = (offs1 == dot);
        }
        if (p0.y == p1.y) {
            // same line, render a rectangle
            Rectangle r = p0.union(p1);
            if (r.width > 0) {
                if (firstIsDot) {
                    r.x++;
                    r.width--;
                }
                else if (secondIsDot) {
                    r.width--;
                }
            }
            g.fillRect(r.x, r.y, r.width, r.height);
        } else {
            // different lines
            int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
            if (firstIsDot && p0ToMarginWidth > 0) {
                p0.x++;
                p0ToMarginWidth--;
            }
            g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
            if ((p0.y + p0.height) != p1.y) {
                g.fillRect(alloc.x, p0.y + p0.height, alloc.width,
                           p1.y - (p0.y + p0.height));
            }
            if (secondIsDot && p1.x > alloc.x) {
                p1.x--;
            }
            g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
    } catch (BadLocationException e) {
        // can't render
    }
}
 
Example 20
Project: FreeCol   File: UnitMoveAnimation.java   View Source Code Vote up 4 votes
/**
 * Do the animation.
 *
 * @return False if there was an error.
 */
public boolean animate() {
    final int movementSpeed
        = getFreeColClient().getAnimationSpeed(unit.getOwner());
    if (movementSpeed <= 0) return true;
    
    final SwingGUI gui = (SwingGUI)getGUI();
    final Point srcP = gui.getTilePosition(sourceTile);
    final Point dstP = gui.getTilePosition(destinationTile);
    if (srcP == null || dstP == null) return false;

    float scale = gui.getMapScale();
    final int movementRatio = (int)(Math.pow(2, movementSpeed + 1) * scale);
    final Rectangle r1 = gui.getTileBounds(sourceTile);
    final Rectangle r2 = gui.getTileBounds(destinationTile);
    final Rectangle bounds = r1.union(r2);

    gui.executeWithUnitOutForAnimation(unit, sourceTile,
        (JLabel unitLabel) -> {
            final int labelWidth = unitLabel.getWidth();
            final int labelHeight = unitLabel.getHeight();
            final Point srcPoint = gui.calculateUnitLabelPositionInTile(labelWidth, labelHeight, srcP);
            final Point dstPoint = gui.calculateUnitLabelPositionInTile(labelWidth, labelHeight, dstP);
            final double xratio = ImageLibrary.TILE_SIZE.width
                / (double)ImageLibrary.TILE_SIZE.height;
            final int stepX = (srcPoint.getX() == dstPoint.getX()) ? 0
                : (srcPoint.getX() > dstPoint.getX()) ? -1 : 1;
            final int stepY = (srcPoint.getY() == dstPoint.getY()) ? 0
                : (srcPoint.getY() > dstPoint.getY()) ? -1 : 1;

            gui.requireFocus(sourceTile);
            // Painting the whole screen once to get rid of
            // disposed dialog-boxes.
            gui.paintImmediatelyCanvasInItsBounds();

            int dropFrames = 0;
            Point point = srcPoint;
            while (!point.equals(dstPoint)) {
                long time = System.currentTimeMillis();

                point.x += stepX * xratio * movementRatio;
                point.y += stepY * movementRatio;
                if ((stepX < 0 && point.x < dstPoint.x)
                    || (stepX > 0 && point.x > dstPoint.x)) {
                    point.x = dstPoint.x;
                }
                if ((stepY < 0 && point.y < dstPoint.y)
                    || (stepY > 0 && point.y > dstPoint.y)) {
                    point.y = dstPoint.y;
                }
                if (dropFrames <= 0) {
                    unitLabel.setLocation(point);
                    gui.paintImmediatelyCanvasIn(bounds);
                        
                    int timeTaken = (int)(System.currentTimeMillis() - time);
                    final int waitTime = ANIMATION_DELAY - timeTaken;
                    if (waitTime > 0) {
                        Utils.delay(waitTime, "Animation interrupted.");
                        dropFrames = 0;
                    } else {
                        dropFrames = timeTaken / ANIMATION_DELAY - 1;
                    }
                } else {
                    dropFrames--;
                }
            }
            gui.refresh();
        });
    return true;
}