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

The following examples show how to use java.awt.Rectangle#setBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AreaList.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Returns the bounds of this object as it shows in the given layer. */
@Override
public Rectangle getBounds(final Rectangle r, final Layer layer) {
	if (null == layer) return super.getBounds(r, null);
	final Area area = (Area)ht_areas.get(layer.getId());
	if (null == area) {
		if (null == r) return new Rectangle();
		r.x = 0;
		r.y = 0;
		r.width = 0;
		r.height = 0;
		return r;
	}
	final Rectangle b = area.createTransformedArea(this.at).getBounds();
	if (null == r) return b;
	r.setBounds(b.x, b.y, b.width, b.height);
	return r;
}
 
Example 2
Source File: SunGraphics2D.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: MetalToolBarUI.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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 4
Source File: BlockCaret.java    From basicv2 with The Unlicense 6 votes vote down vote up
public void paint(Graphics g) {
	if (isVisible()) {
		try {
			JTextComponent component = getComponent();
			Rectangle r = component.getUI().modelToView(component, getDot());
			Color c = g.getColor();
			g.setColor(component.getBackground());
			g.setXORMode(component.getCaretColor());
			r.setBounds(r.x, r.y, g.getFontMetrics().charWidth('w'), g.getFontMetrics().getHeight());
			g.fillRect(r.x, r.y, r.width, r.height);
			g.setPaintMode();
			g.setColor(c);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
	}
}
 
Example 5
Source File: SunGraphics2D.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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 6
Source File: JDomUtility.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
public static Rectangle getRectangle(org.jdom.Element e, String id, Rectangle defaultValue) {
  if (id != null) {
    e = getChildWithId(e, RECTANGLE, id);
  } else if (e != null && !e.getName().equals(RECTANGLE)) {
    e = e.getChild(RECTANGLE);
  }
  if (e == null) {
    return defaultValue;
  }
  Rectangle r = (defaultValue == null ? new Rectangle() : new Rectangle(defaultValue));
  r.setBounds(
      getIntAttr(e, LEFT, r.x),
      getIntAttr(e, TOP, r.y),
      getIntAttr(e, WIDTH, r.width),
      getIntAttr(e, HEIGHT, r.height));
  return r;
}
 
Example 7
Source File: LegendGraphicTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that cloning works.
 */
public void testCloning() {
    Rectangle r = new Rectangle(1, 2, 3, 4);
    LegendGraphic g1 = new LegendGraphic(r, Color.black);
    LegendGraphic g2 = null;
    try {
        g2 = (LegendGraphic) g1.clone();
    }
    catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(g1 != g2);
    assertTrue(g1.getClass() == g2.getClass());
    assertTrue(g1.equals(g2));

    // check independence
    r.setBounds(4, 3, 2, 1);
    assertFalse(g1.equals(g2));
}
 
Example 8
Source File: GuiGraphicBuffer.java    From tn5250j with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fills the passed Rectangle with the starting row and column and width and
 * height of the selected area.
 *
 * 1 BASED so column 1 row one is returned 1,1
 *
 * If there is no area bounded then the full screen area is returned.
 *
 * @param bounds
 */
public void getBoundingArea(Rectangle bounds) {

	// check to see if there is an area selected. If not then return all
	//    screen area.
	if (!gui.rubberband.isAreaSelected()) {

		bounds.setBounds(1, 1, screen.getColumns(), screen.getRows());
	} else {
		// lets get the bounding area using a rectangle that we have already
		// allocated
		gui.rubberband.getBoundingArea(workR);

		// get starting row and column
		int sPos = getRowColFromPoint(workR.x, workR.y);
		// get the width and height
		int ePos = getRowColFromPoint(workR.width, workR.height);

		int row = screen.getRow(sPos) + 1;
		int col = screen.getCol(sPos) + 1;

		bounds.setBounds(row, col, screen.getCol(ePos) + 1, screen.getRow(ePos) + 1);
	}
}
 
Example 9
Source File: MetalToolBarUI.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
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
Source File: XYAreaRenderer2Test.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    XYAreaRenderer2 r1 = new XYAreaRenderer2();
    Rectangle rect = new Rectangle(1, 2, 3, 4);
    r1.setLegendArea(rect);
    XYAreaRenderer2 r2 = (XYAreaRenderer2) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    // check independence
    rect.setBounds(99, 99, 99, 99);
    assertFalse(r1.equals(r2));
}
 
Example 11
Source File: ImagePair.java    From hifive-pitalium with Apache License 2.0 5 votes vote down vote up
/**
 * Expand the splitRectangle, if it borders on subRectangle, as much as border removed
 *
 * @param subRectangle Rectangle for checking expansion
 * @param splitRectangle Rectangle which is expanded
 * @param sub_margin how much border removed
 */
private void expand(Rectangle subRectangle, Rectangle splitRectangle, int sub_margin) {
	int subX = (int) subRectangle.getX(), subY = (int) subRectangle.getY();
	int subWidth = (int) subRectangle.getWidth(), subHeight = (int) subRectangle.getHeight();
	int splitX = (int) splitRectangle.getX(), splitY = (int) splitRectangle.getY();
	int splitWidth = (int) splitRectangle.getWidth(), splitHeight = (int) splitRectangle.getHeight();

	// Left-directional expansion
	if (splitX <= subX) {
		splitX = subX - sub_margin;
		splitWidth = splitWidth + sub_margin;
	}

	// Top-directional expansion
	if (splitY <= subY) {
		splitY = subY - sub_margin;
		splitHeight = splitHeight + sub_margin;
	}

	// Right-directional expansion
	if (splitX + splitWidth >= subX + subWidth) {
		splitWidth = subX + subWidth + sub_margin - splitX;
	}

	// Down-directional expansion
	if (splitY + splitHeight >= subY + subHeight) {
		splitHeight = subY + subHeight + sub_margin - splitY;
	}

	splitRectangle.setBounds(splitX, splitY, splitWidth, splitHeight);
}
 
Example 12
Source File: ActiveMediaPlayer.java    From jclic with GNU General Public License v2.0 5 votes vote down vote up
public void checkVisualComponentBounds(ActiveBox bxi) {
  if (visualComponent == null)
    return;

  Rectangle enclosingRect = new Rectangle();
  if (!mc.free)
    enclosingRect.setBounds(bxi.getBounds());
  else
    enclosingRect.setBounds(ps.getComponent().getBounds());

  Point offset = new Point();
  Dimension dim = new Dimension(visualComponent.getPreferredSize());
  if (mc.absLocation != null) {
    offset.setLocation(mc.absLocation);
    if (offset.x + dim.width > enclosingRect.width)
      offset.x = enclosingRect.width - dim.width;
    if (offset.y + dim.height > enclosingRect.height)
      offset.y = enclosingRect.height - dim.height;
  }
  if (mc.stretch) {
    int extraW = enclosingRect.width - offset.x - dim.width;
    if (extraW < 0) {
      dim.width = enclosingRect.width - offset.x;
      extraW = 0;
    }
    int extraH = enclosingRect.height - offset.y - dim.height;
    if (extraH < 0) {
      dim.height = enclosingRect.height - offset.y;
      extraH = 0;
    }
    if (mc.absLocation == null) {
      offset.x += extraW / 2;
      offset.y += extraH / 2;
    }
  }
  Rectangle vRect = new Rectangle(enclosingRect.x + offset.x, enclosingRect.y + offset.y, dim.width, dim.height);
  visualComponent.setSize(dim);
  visualComponent.setLocation(vRect.getLocation());
  visualComponent.setBounds(vRect);
}
 
Example 13
Source File: GIFImageWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 14
Source File: GIFImageWriter.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 15
Source File: GIFImageWriter.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * 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 16
Source File: GIFImageWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 17
Source File: GIFImageWriter.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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
Source File: TransformableCanvasComponent.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
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 19
Source File: TransformableCanvasComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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 20
Source File: GIFImageWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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!");
    }
}