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

The following are Jave code examples for showing how to use setBounds() 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: OpenJSharp   File: SunGraphics2D.java   View Source Code Vote up 7 votes
public Rectangle getClipBounds(Rectangle r) {
    if (clipState != CLIP_DEVICE) {
        if (transformState <= TRANSFORM_INT_TRANSLATE) {
            if (usrClip instanceof Rectangle) {
                r.setBounds((Rectangle) usrClip);
            } else {
                r.setFrame(usrClip.getBounds2D());
            }
            r.translate(-transX, -transY);
        } else {
            r.setFrame(getClip().getBounds2D());
        }
    } else if (r == null) {
        throw new NullPointerException("null rectangle parameter");
    }
    return r;
}
 
Example 2
Project: openjdk-jdk10   File: MetalToolBarUI.java   View Source Code Vote up 6 votes
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    if (!toolBar.isEnabled()) {
        return;
    }
    pressedInBumps = false;
    Rectangle bumpRect = new Rectangle();

    if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
        int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14;
        bumpRect.setBounds(x, 0, 14, toolBar.getSize().height);
    } else {  // vertical
        bumpRect.setBounds(0, 0, toolBar.getSize().width, 14);
    }
    if (bumpRect.contains(e.getPoint())) {
        pressedInBumps = true;
        Point dragOffset = e.getPoint();
        if (!MetalUtils.isLeftToRight(toolBar)) {
            dragOffset.x -= (toolBar.getSize().width
                             - toolBar.getPreferredSize().width);
        }
        setDragOffset(dragOffset);
    }
}
 
Example 3
Project: rapidminer   File: ToolBarUI.java   View Source Code Vote up 6 votes
@Override
public void mousePressed(MouseEvent e) {
	super.mousePressed(e);
	if (!this.toolBar.isEnabled()) {
		return;
	}
	this.pressedToolbarHandler = false;
	Rectangle bumpRect = new Rectangle();

	if (this.toolBar.getOrientation() == SwingConstants.HORIZONTAL) {
		int x = RapidLookTools.isLeftToRight(this.toolBar) ? 0 : this.toolBar.getSize().width - 14;
		bumpRect.setBounds(x, 0, 14, this.toolBar.getSize().height);
	} else { // vertical
		bumpRect.setBounds(0, 0, this.toolBar.getSize().width, 14);
	}
	if (bumpRect.contains(e.getPoint())) {
		this.pressedToolbarHandler = true;
		Point dragOffset = e.getPoint();
		if (!RapidLookTools.isLeftToRight(this.toolBar)) {
			dragOffset.x -= (this.toolBar.getSize().width - this.toolBar.getPreferredSize().width);
		}
		setDragOffset(dragOffset);
	}
}
 
Example 4
Project: VASSAL-src   File: Footprint.java   View Source Code Vote up 6 votes
private Rectangle getBB() {
  final Rectangle bb = piece.boundingBox();
  final Point pos = piece.getPosition();

  bb.x += pos.x;
  bb.y += pos.y;

  final int circleDiameter = 2*circleRadius;
  final Rectangle pr = new Rectangle();

  for (final Point p: pointList) {
    pr.setBounds(
      p.x - circleRadius, p.y - circleRadius, circleDiameter, circleDiameter
    );
    bb.add(pr);
  }

  bb.x -= pos.x;
  bb.y -= pos.y;

  return bb;
}
 
Example 5
Project: VASSAL-src   File: Footprint.java   View Source Code Vote up 6 votes
/**
 * Return the boundingBox including the trail
 */
public Rectangle getMyBoundingBox() {
  if (myBoundingBox == null) {
    final Rectangle bb = piece.boundingBox();
    final Point pos = piece.getPosition();

    bb.x += pos.x;
    bb.y += pos.y;

    final int circleDiameter = 2*circleRadius;
    final Rectangle pr = new Rectangle();

    for (final Point p: pointList) {
      pr.setBounds(
        p.x - circleRadius, p.y - circleRadius, circleDiameter, circleDiameter
      );
      bb.add(pr);
    }

    bb.x -= pos.x;
    bb.y -= pos.y;

    myBoundingBox = bb;
  }
  return myBoundingBox;
}
 
Example 6
Project: WordnetLoom   File: SpanTableUI.java   View Source Code Vote up 6 votes
/**
 * narysowanie komorki
 *
 * @param row - wiersz
 * @param column - kolumna
 * @param g - kontekt graficzny
 * @param area - obszar do narysowania
 */
private void paintCell(int row, int column, Graphics g, Rectangle area) {
    int verticalMargin = table.getRowMargin();
    int horizontalMargin = table.getColumnModel().getColumnMargin();

    Color oldColor = g.getColor();
    g.setColor(table.getGridColor());
    g.drawLine(area.x + area.width - 1, area.y, area.x + area.width - 1, area.y + area.height - 1);
    g.drawLine(area.x, area.y + area.height - 1, area.x + area.width - 1, area.y + area.height - 1);

    g.setColor(oldColor);

    area.setBounds(area.x + horizontalMargin / 2, area.y + verticalMargin
            / 2, area.width - horizontalMargin, area.height
            - verticalMargin);

    TableCellRenderer renderer = table.getCellRenderer(row, column);
    Component component = table.prepareRenderer(renderer, row, column);
    if (component.getParent() == null) {
        rendererPane.add(component);
    }
    rendererPane.paintComponent(g, component, table, area.x, area.y, area.width, area.height, true);
}
 
Example 7
Project: OpenJSharp   File: MetalToolBarUI.java   View Source Code Vote up 6 votes
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    if (!toolBar.isEnabled()) {
        return;
    }
    pressedInBumps = false;
    Rectangle bumpRect = new Rectangle();

    if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
        int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14;
        bumpRect.setBounds(x, 0, 14, toolBar.getSize().height);
    } else {  // vertical
        bumpRect.setBounds(0, 0, toolBar.getSize().width, 14);
    }
    if (bumpRect.contains(e.getPoint())) {
        pressedInBumps = true;
        Point dragOffset = e.getPoint();
        if (!MetalUtils.isLeftToRight(toolBar)) {
            dragOffset.x -= (toolBar.getSize().width
                             - toolBar.getPreferredSize().width);
        }
        setDragOffset(dragOffset);
    }
}
 
Example 8
Project: jdk8u-jdk   File: SunGraphics2D.java   View Source Code Vote up 6 votes
public Rectangle getClipBounds(Rectangle r) {
    if (clipState != CLIP_DEVICE) {
        if (transformState <= TRANSFORM_INT_TRANSLATE) {
            if (usrClip instanceof Rectangle) {
                r.setBounds((Rectangle) usrClip);
            } else {
                r.setFrame(usrClip.getBounds2D());
            }
            r.translate(-transX, -transY);
        } else {
            r.setFrame(getClip().getBounds2D());
        }
    } else if (r == null) {
        throw new NullPointerException("null rectangle parameter");
    }
    return r;
}
 
Example 9
Project: jdk8u-jdk   File: MetalToolBarUI.java   View Source Code Vote up 6 votes
public void mousePressed(MouseEvent e) {
    super.mousePressed(e);
    if (!toolBar.isEnabled()) {
        return;
    }
    pressedInBumps = false;
    Rectangle bumpRect = new Rectangle();

    if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
        int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14;
        bumpRect.setBounds(x, 0, 14, toolBar.getSize().height);
    } else {  // vertical
        bumpRect.setBounds(0, 0, toolBar.getSize().width, 14);
    }
    if (bumpRect.contains(e.getPoint())) {
        pressedInBumps = true;
        Point dragOffset = e.getPoint();
        if (!MetalUtils.isLeftToRight(toolBar)) {
            dragOffset.x -= (toolBar.getSize().width
                             - toolBar.getPreferredSize().width);
        }
        setDragOffset(dragOffset);
    }
}
 
Example 10
Project: openjdk-jdk10   File: SunGraphics2D.java   View Source Code Vote up 6 votes
public Rectangle getClipBounds(Rectangle r) {
    if (clipState != CLIP_DEVICE) {
        if (transformState <= TRANSFORM_INT_TRANSLATE) {
            if (usrClip instanceof Rectangle) {
                r.setBounds((Rectangle) usrClip);
            } else {
                r.setFrame(usrClip.getBounds2D());
            }
            r.translate(-transX, -transY);
        } else {
            r.setFrame(getClip().getBounds2D());
        }
    } else if (r == null) {
        throw new NullPointerException("null rectangle parameter");
    }
    return r;
}
 
Example 11
Project: incubator-netbeans   File: DragManager.java   View Source Code Vote up 5 votes
public void recalculateSize(Point p) {
    if (dragMode != null && !p.equals(gesturePoint)) {
        Rectangle oldtDragRect = new Rectangle();
        oldtDragRect.setBounds(currentDragRect);
        dragMode.recalculateSize(p);
        int x = currentDragRect.x;
        int y = currentDragRect.y;
        int w = currentDragRect.width;
        int h = currentDragRect.height;
        
        if (bounds != null && !bounds.contains(currentDragRect)) {
            if (h  + y > bounds.height + bounds.y) {
                if (y == oldtDragRect.y) {
                    h = (bounds.height + bounds.y) - y;
                } else {
                    y = (bounds.height + bounds.y) - h;
                }
            }
            if (w + x > bounds.width + bounds.x ) {
                if (x == oldtDragRect.x) {
                    w = (bounds.width + bounds.x) - x;
                } else {
                    x = (bounds.width + bounds.x) - w;
                }
            }
            if (x < bounds.x) {
                x = bounds.x;
            }
            if (y < bounds.y) {
                y = bounds.y;
            }                                        
            currentDragRect.setBounds(x,y,w,h);
        }
        if (w <= 3 || h <= 3 && !(dragMode instanceof MoveMode)) {                    
            currentDragRect.setBounds(oldtDragRect);
        } 
    }
    
}
 
Example 12
Project: incubator-netbeans   File: Outline.java   View Source Code Vote up 5 votes
@Override
public Rectangle getNodeDimensions(Object value, int row, int depth, 
    boolean expanded, Rectangle bounds) {
        int wid = Outline.this.getColumnModel().getColumn(0).getPreferredWidth();
        bounds.setBounds (0, row * getRowHeight(), wid, getRowHeight());
        return bounds;
}
 
Example 13
Project: PekaED   File: PK2Map.java   View Source Code Vote up 5 votes
public Rectangle calculateUsedArea(int[] array) {
	Rectangle r = new Rectangle(0, 0, 0, 0);
	
	int x, y;
	int map_left = MAP_WIDTH;
	int map_right = 0;
	int map_upper = MAP_HEIGHT;
	int map_lower = 0;
	
	for (y = 0; y < MAP_HEIGHT; y++) {
		for (x = 0; x < MAP_WIDTH; x++) {
			if (MAP_WIDTH * x + y < array.length) {
				if (array[MAP_WIDTH * x + y] != 255) {
					if (x < map_left)
						map_left = x;
					
					if (y < map_upper)
						map_upper = y;
					
					if (x > map_right)
						map_right = x;
					
					if (y > map_lower)
						map_lower = y;
				}
			}
		}
	}
	
	if (map_right < map_left || map_lower < map_upper) {
		map_left = 0;
		map_upper = 0;
		map_lower = 1;
		map_right = 1;
	}
	
	r.setBounds(map_left, map_upper, map_right, map_lower);
	
	return r;
}
 
Example 14
Project: incubator-netbeans   File: NimbusEditorTabCellRenderer.java   View Source Code Vote up 4 votes
public void getCloseButtonRectangle(JComponent jc,
                                    final Rectangle rect,
                                    Rectangle bounds) {
    rect.setBounds(-20, -20, 0, 0);
}
 
Example 15
Project: incubator-netbeans   File: NimbusEditorTabCellRenderer.java   View Source Code Vote up 4 votes
public void getCloseButtonRectangle(JComponent jc,
                                    final Rectangle rect,
                                    Rectangle bounds) {
    rect.setBounds(-20, -20, 0, 0);
}
 
Example 16
Project: incubator-netbeans   File: TransformableCanvasComponent.java   View Source Code Vote up 4 votes
private void shift(Graphics g, int idx, int idy, int width, int height) {
    Rectangle areaToRepaint = new Rectangle();

    if (idx == 0) {
        // Vertical shift
        if (idy > 0) {
            // --- Shift down --------------------------------------
            g.copyArea(0, 0, width, height - idy, 0, idy);
            areaToRepaint.setBounds(0, 0, width, idy);
        } else {
            // --- Shift up ----------------------------------------
            g.copyArea(0, -idy, width, height + idy, 0, idy);
            areaToRepaint.setBounds(0, height + idy, width, -idy);
        }
    } else if (idy == 0) {
        // Horizontal shift
        if (idx > 0) {
            // --- Shift right -------------------------------------
            g.copyArea(0, 0, width - idx, height, idx, 0);
            areaToRepaint.setBounds(0, 0, idx, height);
        } else {
            // --- Shift left --------------------------------------
            g.copyArea(-idx, 0, width + idx, height, idx, 0);
            areaToRepaint.setBounds(width + idx, 0, -idx, height);
        }
    } else {
        // Diagonal shift
        if (idx > 0) {
            // Shift right
            if (idy > 0) {
                // --- Shift right down ------------------------
                g.copyArea(0, 0, width - idx, height - idy, idx, idy);
                areaToRepaint.setBounds(0, 0, width, idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(0, idy, idx, height - idy);
            } else {
                // --- Shift right up --------------------------
                g.copyArea(0, -idy, width - idx, height + idy, idx, idy);
                areaToRepaint.setBounds(0, height + idy, width, -idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(0, 0, idx, height + idy);
            }
        } else {
            // Shift left
            if (idy > 0) {
                // --- Shift left down -------------------------
                g.copyArea(-idx, 0, width + idx, height - idy, idx, idy);
                areaToRepaint.setBounds(0, 0, width, idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(width + idx, idy, -idx, height - idy);
            } else {
                // --- Shift left up ---------------------------
                g.copyArea(-idx, -idy, width + idx, height + idy, idx, idy);
                areaToRepaint.setBounds(0, height + idy, width, -idy);
                paintContents(g, areaToRepaint);
                areaToRepaint.setBounds(width + idx, 0, -idx, height + idy);
            }
        }
    }

    paintContents(g, areaToRepaint);
}
 
Example 17
Project: OpenJSharp   File: GIFImageWriter.java   View Source Code Vote up 4 votes
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 18
Project: jdk8u-jdk   File: GIFImageWriter.java   View Source Code Vote up 4 votes
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 19
Project: openjdk-jdk10   File: GIFImageWriter.java   View Source Code Vote up 4 votes
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 20
Project: Pixie   File: ObjectBBox.java   View Source Code Vote up 2 votes
/**
 * Changes the size of the box with the specified offsets.
 *
 * @param left - how much should the object be modified on the left side
 * @param top - how much should the object be modified on the top part
 * @param right - how much should the object be modified on the right side
 * @param bottom - how much should the object be modified on the bottom part
 * @param boxPosOrig - the initial position of the selected box in image
 * coordinates
 */
private void changeSize(int left, int top, int right, int bottom, Rectangle bboxOrigPos) {
    bboxOrigPos.setBounds(bboxOrigPos.x + left, bboxOrigPos.y + top, bboxOrigPos.width + right - left, bboxOrigPos.height + bottom - top);
}