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

The following examples show how to use java.awt.Rectangle#setRect() . These examples are extracted from open source projects. 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
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 2
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 3
Source Project: jdk8u60   File: CStrike.java    License: GNU General Public License v2.0 6 votes vote down vote up
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 4
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 5
Source Project: netbeans   File: DialogBoundsPreserver.java    License: Apache License 2.0 6 votes vote down vote up
private Rectangle getDialogBounds() {
    String size = preferences.get(key, DELIMITER);        
    if(size != null) {                                    
        String[] dim = size.split(DELIMITER);             
        if(dim.length != 4 || 
           dim[0].trim().equals("") ||                                      // NOI18N 
           dim[1].trim().equals("") ||                                      // NOI18N
           dim[2].trim().equals("") ||                                      // NOI18N    
           dim[3].trim().equals("") )                                       // NOI18N
        {
            return null;
        }
        Rectangle r = new Rectangle();
        r.setRect(Double.parseDouble(dim[0]), 
                  Double.parseDouble(dim[1]), 
                  Double.parseDouble(dim[2]), 
                  Double.parseDouble(dim[3]));
        return r;
    }
    return null;                
}
 
Example 6
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 7
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 8
@Override
public Shape modelToView(int pos, Shape a, Bias b)
        throws BadLocationException
{
    TextLayout layout = getTextLayout();
    int offs = pos - getStartOffset(); // the start position this view is responsible for
    Rectangle alloc = new Rectangle(toRect(a));
    TextHitInfo hit = ((b == Position.Bias.Forward) ? TextHitInfo.afterOffset(offs) : TextHitInfo.beforeOffset(offs));
    float[] locs = layout.getCaretInfo(hit);

    // hint: nie je lepsie to prepisat na setBounds, ktory berie int ?
    alloc.setRect(alloc.getX() + locs[0], alloc.getY(), 1D,
            alloc.getHeight());

    return alloc;
}
 
Example 9
Source Project: hifive-pitalium   File: ImageUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * if the given rectangle may occur raster error, reshape it
 *
 * @param rectangle Rectangle which will be reshaped
 * @param xLimit limit of x+width of given rectangle
 * @param yLimit limit of y+height of given rectangle
 */
public static void reshapeRect(Rectangle rectangle, int xLimit, int yLimit) {
	double width = rectangle.getWidth(), height = rectangle.getHeight();
	double x = rectangle.getX(), y = rectangle.getY();

	if (x < 0) {
		width += x;
		x = 0;
	}
	if (y < 0) {
		height += y;
		y = 0;
	}

	if (x + width >= xLimit)
		width = xLimit - x;
	if (y + height >= yLimit)
		height = yLimit - y;

	rectangle.setRect(x, y, Math.max(width, 1), Math.max(height, 1));
}
 
Example 10
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 11
Source Project: openjdk-8   File: CStrike.java    License: GNU General Public License v2.0 6 votes vote down vote up
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 12
Source Project: jdk8u_jdk   File: CStrike.java    License: GNU General Public License v2.0 6 votes vote down vote up
void getGlyphImageBounds(int glyphCode, Point2D.Float pt, Rectangle result) {
    Rectangle2D.Float floatRect = new Rectangle2D.Float();

    if (invDevTx != null) {
        invDevTx.transform(pt, pt);
    }

    getGlyphImageBounds(glyphCode, pt.x, pt.y, floatRect);

    if (floatRect.width == 0 && floatRect.height == 0) {
        result.setRect(0, 0, -1, -1);
        return;
    }

    result.setRect(floatRect.x + pt.x, floatRect.y + pt.y, floatRect.width, floatRect.height);
}
 
Example 13
Source Project: TrakEM2   File: Tree.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public Rectangle getBounds(final Rectangle tmp, final Layer layer) {
	synchronized (node_layer_map) {
		final Collection<Node<T>> nodes = node_layer_map.get(layer);
		if (null == nodes) {
			if (null == tmp) return new Rectangle(); // 0 width and 0 height: no data
			tmp.setBounds(0, 0, 0, 0);
			return tmp;
		}
		final Rectangle r = getBounds(nodes);
		if (null == tmp) {
			if (null == r) return new Rectangle();
			return r;
		} else {
			if (null == r) tmp.setRect(0, 0, 0, 0);
			else tmp.setRect(r);
			return tmp;
		}
	}
}
 
Example 14
/**
 * Check cloning of the legendItemShape field.
 */
@Test
public void testCloning_LegendItemShape() throws CloneNotSupportedException {
    Rectangle shape = new Rectangle(-4, -4, 8, 8);
    PiePlot p1 = new PiePlot();
    p1.setLegendItemShape(shape);
    PiePlot p2 = (PiePlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // change the shape and make sure it only affects p1
    shape.setRect(1.0, 2.0, 3.0, 4.0);
    assertFalse(p1.equals(p2));
}
 
Example 15
/**
 * Check cloning of the legendItemShape field.
 */
@Test
public void testCloning_LegendItemShape() throws CloneNotSupportedException {
    Rectangle shape = new Rectangle(-4, -4, 8, 8);
    PiePlot p1 = new PiePlot();
    p1.setLegendItemShape(shape);
    PiePlot p2 = (PiePlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // change the shape and make sure it only affects p1
    shape.setRect(1.0, 2.0, 3.0, 4.0);
    assertFalse(p1.equals(p2));
}
 
Example 16
Source Project: SIMVA-SoS   File: PiePlotTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check cloning of the legendItemShape field.
 */
@Test
public void testCloning_LegendItemShape() throws CloneNotSupportedException {
    Rectangle shape = new Rectangle(-4, -4, 8, 8);
    PiePlot p1 = new PiePlot();
    p1.setLegendItemShape(shape);
    PiePlot p2 = (PiePlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // change the shape and make sure it only affects p1
    shape.setRect(1.0, 2.0, 3.0, 4.0);
    assertFalse(p1.equals(p2));
}
 
Example 17
/**
 * Check cloning of the legendItemShape field.
 */
@Test
public void testCloning_LegendItemShape() throws CloneNotSupportedException {
    Rectangle shape = new Rectangle(-4, -4, 8, 8);
    PiePlot p1 = new PiePlot();
    p1.setLegendItemShape(shape);
    PiePlot p2 = (PiePlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // change the shape and make sure it only affects p1
    shape.setRect(1.0, 2.0, 3.0, 4.0);
    assertFalse(p1.equals(p2));
}
 
Example 18
Source Project: netbeans   File: ViewUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static Rectangle toRect(Rectangle2D r2d) {
    Rectangle r = new Rectangle();
    r.setRect(r2d);
    return r;
}
 
Example 19
Source Project: geowave   File: WarpOpImage.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Warps a rectangle. If ROI is present, the intersection between ROI and tile bounds is
 * calculated; The result ROI will be used for calculations inside the computeRect() method.
 */
@Override
protected void computeRect(
    final PlanarImage[] sources,
    final WritableRaster dest,
    final Rectangle destRect) {
  // Retrieve format tags.
  final RasterFormatTag[] formatTags = getFormatTags();

  final RasterAccessor dst = new RasterAccessor(dest, destRect, formatTags[1], getColorModel());

  RandomIter roiIter = null;

  boolean roiContainsTile = false;
  boolean roiDisjointTile = false;

  // If a ROI is present, then only the part contained inside the current
  // tile bounds is taken.
  if (hasROI) {
    final Rectangle srcRectExpanded = mapDestRect(destRect, 0);
    // The tile dimension is extended for avoiding border errors
    srcRectExpanded.setRect(
        srcRectExpanded.getMinX() - leftPad,
        srcRectExpanded.getMinY() - topPad,
        srcRectExpanded.getWidth() + rightPad + leftPad,
        srcRectExpanded.getHeight() + bottomPad + topPad);

    if (!roiBounds.intersects(srcRectExpanded)) {
      roiDisjointTile = true;
    } else {
      roiContainsTile = roi.contains(srcRectExpanded);
      if (!roiContainsTile) {
        if (!roi.intersects(srcRectExpanded)) {
          roiDisjointTile = true;
        } else {
          final PlanarImage roiIMG = getImage();
          roiIter = RandomIterFactory.create(roiIMG, null, TILE_CACHED, ARRAY_CALC);
        }
      }
    }
  }

  if (!hasROI || !roiDisjointTile) {
    switch (dst.getDataType()) {
      case DataBuffer.TYPE_BYTE:
        computeRectByte(sources[0], dst, roiIter, roiContainsTile);
        break;
      case DataBuffer.TYPE_USHORT:
        computeRectUShort(sources[0], dst, roiIter, roiContainsTile);
        break;
      case DataBuffer.TYPE_SHORT:
        computeRectShort(sources[0], dst, roiIter, roiContainsTile);
        break;
      case DataBuffer.TYPE_INT:
        computeRectInt(sources[0], dst, roiIter, roiContainsTile);
        break;
      case DataBuffer.TYPE_FLOAT:
        computeRectFloat(sources[0], dst, roiIter, roiContainsTile);
        break;
      case DataBuffer.TYPE_DOUBLE:
        computeRectDouble(sources[0], dst, roiIter, roiContainsTile);
        break;
    }
    // After the calculations, the output data are copied into the
    // WritableRaster
    if (dst.isDataCopy()) {
      dst.clampDataArrays();
      dst.copyDataToRaster();
    }
  } else {
    // If the tile is outside the ROI, then the destination Raster is
    // set to backgroundValues
    if (setBackground) {
      ImageUtil.fillBackground(dest, destRect, backgroundValues);
    }
  }
}
 
Example 20
/** Selects the most recent history node, expanding the tree if necessary. */
public void goToEnd() {
  final HistoryNode last;
  try {
    data.acquireWriteLock();
    last = data.getHistory().getLastNode();
  } finally {
    data.releaseWriteLock();
  }
  final TreePath path = new TreePath(last.getPath());
  final TreePath parent = path.getParentPath();
  if (!mouseOverPanel) {
    // make sure we undo our change of the lock property

    gotoNode(last);
    if (lastParent == null) {
      lastParent = tree.getSelectionPath();
    }
    tree.setSelectionPath(path);
    collapseExpanded(path);
    collapseUpFromLastParent(parent);
    final Rectangle rect = tree.getPathBounds(path);
    rect.setRect(0, rect.getY(), rect.getWidth(), rect.getHeight());
    tree.scrollRectToVisible(rect);
  } else {
    if (!mouseWasOverPanel) {
      // save the lock property so that we can undo it

      TreePath root = parent;
      while (root.getPathCount() > 1) {
        root = root.getParentPath();
      }
      final Enumeration<TreePath> expandedDescendants = tree.getExpandedDescendants(root);
      addToStayExpanded(expandedDescendants);
    } else {
      collapseUpFromLastParent(parent);
    }
    tree.expandPath(parent);
  }
  mouseWasOverPanel = mouseOverPanel;
  lastParent = parent;
}