下面列出了java.awt.Rectangle#setRect ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
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);
}
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);
}
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);
}
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;
}
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);
}
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);
}
@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;
}
/**
* 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));
}
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);
}
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);
}
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);
}
@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;
}
}
}
/**
* 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));
}
/**
* 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));
}
/**
* 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));
}
/**
* 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));
}
public static Rectangle toRect(Rectangle2D r2d) {
Rectangle r = new Rectangle();
r.setRect(r2d);
return r;
}
/**
* 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);
}
}
}
/** 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;
}