下面列出了java.awt.Rectangle#grow ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void process (SIGraph sig)
{
final int bracketGrowth = 2 * sig.getSystem().getSheet().getInterline();
// Use a COPY of vertices, to reduce risks of concurrent modifications (but not all...)
Set<Inter> copy = new LinkedHashSet<>(sig.vertexSet());
for (Inter inter : copy) {
if (!inter.isRemoved()) {
Rectangle bounds = inter.getBounds();
if (bounds != null) {
// Dirty hack to make sure bracket serifs are fully painted
// (despite the fact that bracket serif is not included in their bounds)
if (inter.getShape() == Shape.BRACKET) {
bounds.grow(bracketGrowth, bracketGrowth);
}
if ((clip == null) || clip.intersects(bounds)) {
inter.accept(this);
}
}
}
}
}
private TableColumn getResizingColumn(Point p, int column) {
if (column == -1) {
return null;
}
int row = table.rowAtPoint(p);
Rectangle r = table.getCellRect(row, column, true);
r.grow(-3, 0);
if (r.contains(p)) {
return null;
}
int midPoint = r.x + r.width / 2;
int columnIndex;
if (table.getTableHeader().getComponentOrientation().isLeftToRight()) {
columnIndex = (p.x < midPoint) ? column - 1 : column;
} else {
columnIndex = (p.x < midPoint) ? column : column - 1;
}
if (columnIndex == -1) {
return null;
}
return table.getTableHeader().getColumnModel().getColumn(columnIndex);
}
/**
* Liga uma linha a um objeto manualmente (sem o uso do mouse).
*
* @param res
* @return
*/
public boolean LigarA(Elementar res) {
boolean sn = false;
if (res instanceof Forma) {
setEm((Forma) res);
if (getEm() != null) {
getEm().PosicionePonto(this);
getDono().OrganizeLinha();
sn = true;
}
}
getDono().reSetBounds();
ReenquadreLinha();
Rectangle rec = getBounds();
rec.grow(5, 5);
InvalidateArea(rec);
//ProcessaOverDraw(true);
return sn;
}
/**
* Detect any section which is too far from the other ones.
*
* @param seedSection the initial seed section
* @param collected the sections collected, including seed section
* @return the collection of isolated sections found
*/
private List<Section> detectIsolatedSections (Section seedSection,
List<Section> collected)
{
final List<Section> isolated = new ArrayList<>(collected);
final Rectangle slurBox = seedSection.getBounds();
boolean makingProgress;
do {
makingProgress = false;
for (Iterator<Section> it = isolated.iterator(); it.hasNext();) {
Section section = it.next();
Rectangle sectBox = section.getBounds();
sectBox.grow(params.slurBoxDx, params.slurBoxDy);
if (sectBox.intersects(slurBox)) {
slurBox.add(sectBox);
it.remove();
makingProgress = true;
}
}
} while (makingProgress);
return isolated;
}
private void paintRect(int x, int y, int w, int h, int t) {
if (w != 0 && h != 0) {
Rectangle rect = new Rectangle(x, y, w, h);
rect.grow(t, t);
paintImmediately(rect);
}
}
private void checkOutOfBounds(Point point) {
Rectangle bounds = map.getBounds();
bounds.grow(-shrinkViewPort, -shrinkViewPort);
outOfBounds = !bounds.contains(point);
if (outOfBounds)
outOfBoundsPoint = point;
}
private void grow (int h,
int v)
{
for (Rectangle rect : boxes) {
rect.grow(h, v);
}
}
/**
* Check that note heads do not appear on both stem head and tail.
* On tail we can have nothing or beams or flags, but no heads
*
* @param chord the chord to check
*/
private void checkHeadLocations (Chord chord)
{
// This test applies only to chords with stem
Glyph stem = chord.getStem();
if (stem == null) {
return;
}
Rectangle tailBox = new Rectangle(chord.getTailLocation());
int halfTailBoxSide = chord.getScale().toPixels(constants.halfTailBoxSide);
tailBox.grow(halfTailBoxSide, halfTailBoxSide);
for (TreeNode node : chord.getNotes()) {
Note note = (Note) node;
// If note is close to tail, it can't be a note
if (note.getBox().intersects(tailBox)) {
for (Glyph glyph : note.getGlyphs()) {
if (logger.isDebugEnabled() || glyph.isVip()) {
logger.info("Note {} too close to tail of stem {}",
note, stem);
}
glyph.setShape(null);
}
modified.set(true);
}
}
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e); //To change body of generated methods, choose Tools | Templates.
entrou = false;
Rectangle r = getBounds();
int x = r.width / 2;
int y = r.height / 2;
//r = new Rectangle(r.x - x, r.y - y, r.width * 2, r.height * 2);
r.grow(x + 2, y + 2);
InvalidateArea(r);
}
/**
* Find the first point of the current sequence which is close to the provided point
* (less than sticky distance).
*
* @param point the provided point
* @return the point found, or null if not found
*/
public Point findPoint (Point point)
{
Rectangle window = new Rectangle(point);
window.grow(getStickyDistance(), getStickyDistance());
for (Point pt : points) {
if (window.contains(pt)) {
return pt;
}
}
return null;
}
private List<Inter> buildStaffBarlineClosure (StaffBarlineInter oneBar)
{
final Rectangle oneBounds = oneBar.getBounds();
final Staff staff = oneBar.getStaff();
final SystemInfo system = staff.getSystem();
// Include a staffBarline per system staff, properly positioned in abscissa
final Skew skew = sheet.getSkew();
final Point center = GeoUtil.centerOf(oneBounds);
final double slope = skew.getSlope();
final List<Inter> closure = new ArrayList<>();
for (Staff st : system.getStaves()) {
if (st == staff) {
closure.add(oneBar);
} else {
double y1 = st.getFirstLine().yAt(center.getX());
double y2 = st.getLastLine().yAt(center.getX());
double y = (y1 + y2) / 2;
double x = center.x - ((y - center.y) * slope);
Rectangle box = new Rectangle((int) Math.rint(x), (int) Math.rint(y), 0, 0);
box.grow(oneBounds.width / 2, oneBounds.height / 2);
StaffBarlineInter g = new StaffBarlineInter(oneBar.getShape(), 1);
g.setManual(true);
g.setStaff(st);
g.setBounds(box);
closure.add(g);
}
}
// Display closure staff barlines to user
sheet.getInterIndex().getEntityService().publish(
new EntityListEvent<>(
this,
SelectionHint.ENTITY_INIT,
MouseMovement.PRESSING,
closure));
if (OMR.gui.displayConfirmation(
"Do you confirm whole system-height addition?",
"Insertion of " + closure.size() + " barline(s)")) {
return closure;
} else {
return Collections.EMPTY_LIST;
}
}
/**
* Last attempt to include discarded (and sloped) filaments to retrieved staff lines.
*/
private void includeDiscardedFilaments ()
{
List<StaffFilament> candidates = new ArrayList<>();
candidates.addAll(discardedFilaments);
candidates.addAll(slopedFilaments);
// Sort candidates filaments by top ordinate
Collections.sort(candidates, Filament.topComparator);
final int iMax = candidates.size() - 1;
for (SystemInfo system : sheet.getSystems()) {
// Systems may be side by side, so restart from top
int iMin = 0;
for (Staff staff : system.getStaves()) {
for (LineInfo line : staff.getLines()) {
final StaffFilament filament = (StaffFilament) line;
final Point2D startPt = filament.getStartPoint();
final Point2D stopPt = filament.getStopPoint();
final double minX = startPt.getX();
final double maxX = stopPt.getX();
final Rectangle lineBox = filament.getBounds();
lineBox.grow(0, scale.getFore());
final int minY = lineBox.y;
final int maxY = lineBox.y + lineBox.height;
boolean filamentModified = false;
// Browse discarded filaments
for (int i = iMin; i <= iMax; i++) {
Filament fil = candidates.get(i);
if (fil.getPartOf() != null) {
continue;
}
int firstPos = fil.getBounds().y;
if (firstPos < minY) {
iMin = i;
continue;
}
if (firstPos > maxY) {
break;
}
Point center = fil.getCentroid();
if ((center.x >= minX) && (center.x <= maxX)) {
if (canIncludeFilament(filament, fil)) {
filament.stealSections(fil);
filamentModified = true;
}
}
}
if (filamentModified) {
filament.setEndingPoints(startPt, stopPt); // Recompute line
}
}
}
}
}
@Override
public MouseEvent mouseMoved(MouseEvent mouseEvent)
{
if (!inOverlayManagingMode)
{
return mouseEvent;
}
final Point mousePoint = mouseEvent.getPoint();
mousePosition.setLocation(mousePoint);
if (!inOverlayResizingMode && !inOverlayDraggingMode)
{
currentManagedOverlay = null;
synchronized (overlayManager)
{
for (Overlay overlay : overlayManager.getOverlays())
{
final Rectangle bounds = overlay.getBounds();
if (bounds.contains(mousePoint))
{
currentManagedOverlay = overlay;
break;
}
}
}
}
if (currentManagedOverlay == null || !currentManagedOverlay.isResizable())
{
clientUI.setCursor(clientUI.getDefaultCursor());
return mouseEvent;
}
final Rectangle toleranceRect = new Rectangle(currentManagedOverlay.getBounds());
toleranceRect.grow(-OVERLAY_RESIZE_TOLERANCE, -OVERLAY_RESIZE_TOLERANCE);
final int outcode = toleranceRect.outcode(mouseEvent.getPoint());
switch (outcode)
{
case Rectangle.OUT_TOP:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
break;
case Rectangle.OUT_TOP | Rectangle.OUT_LEFT:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
break;
case Rectangle.OUT_LEFT:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
break;
case Rectangle.OUT_LEFT | Rectangle.OUT_BOTTOM:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
break;
case Rectangle.OUT_BOTTOM:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
break;
case Rectangle.OUT_BOTTOM | Rectangle.OUT_RIGHT:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
break;
case Rectangle.OUT_RIGHT:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
break;
case Rectangle.OUT_RIGHT | Rectangle.OUT_TOP:
clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
break;
default:
// center
clientUI.setCursor(clientUI.getDefaultCursor());
}
return mouseEvent;
}
/**
* Detect if the provided section is a thick one.
* (as seen in the context of the factory orientation)
*
* @param section the section to check
* @return true if fat
*/
public boolean isSectionFat (Section section)
{
if (section.isFat() == null) {
try {
if (section.getMeanThickness(orientation) <= 1) {
section.setFat(false);
return section.isFat();
}
// Check global slimness
if (section.getMeanAspect(orientation) < params.minSectionAspect) {
section.setFat(true);
return section.isFat();
}
// Check thickness
Rectangle bounds = orientation.oriented(section.getBounds());
Line line = orientation.switchRef(
section.getAbsoluteLine());
if (Math.abs(line.getSlope()) < (Math.PI / 4)) {
// Measure mean thickness on each half
int startCoord = bounds.x + (bounds.width / 4);
int startPos = line.yAtX(startCoord);
int stopCoord = bounds.x + ((3 * bounds.width) / 4);
int stopPos = line.yAtX(stopCoord);
// Start side
Rectangle oRoi = new Rectangle(startCoord, startPos, 0, 0);
final int halfWidth = Math.min(
params.probeWidth / 2,
bounds.width / 4);
oRoi.grow(halfWidth, params.maxSectionThickness);
PointsCollector collector = new PointsCollector(
orientation.absolute(oRoi));
section.cumulate(collector);
int startThickness = (int) Math.rint(
(double) collector.getSize() / oRoi.width);
// Stop side
oRoi.translate(stopCoord - startCoord, stopPos - startPos);
collector = new PointsCollector(orientation.absolute(oRoi));
section.cumulate(collector);
int stopThickness = (int) Math.rint(
(double) collector.getSize() / oRoi.width);
section.setFat(
(startThickness > params.maxSectionThickness)
|| (stopThickness > params.maxSectionThickness));
} else {
section.setFat(bounds.height > params.maxSectionThickness);
}
} catch (Exception ex) {
logger.warn("Error in checking fatness of " + section, ex);
section.setFat(true);
}
}
return section.isFat();
}
public void runTests() {
GraphicsConfiguration gc = getGraphicsConfiguration();
for (Image srcIm :
new Image[] {
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, true),
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, false),
// commented out due to 6593406
// getBMImage(gc, IMAGEW, IMAGEH),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, true),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, false),
getVImage(gc, IMAGEW, IMAGEH),
})
{
System.out.println("Testing source: " + srcIm);
// wiggle the source and dest rectangles
try {
for (int locationVar = -10; locationVar < 20; locationVar += 10)
{
for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
srcRect.translate(locationVar, locationVar);
srcRect.grow(sizeVar, sizeVar);
Rectangle dstRect =
new Rectangle(sizeVar, sizeVar,
srcRect.width, srcRect.height);
System.out.println("testing blit rect src: " + srcRect);
System.out.println(" dst: " + dstRect);
render(getGraphics(), srcIm, srcRect, dstRect);
test(srcRect, dstRect);
}
}
System.out.println("Test passed.");
} finally {
synchronized (lock) {
done = true;
lock.notifyAll();
}
}
}
}
public void runTests() {
GraphicsConfiguration gc = getGraphicsConfiguration();
for (Image srcIm :
new Image[] {
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, true),
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, false),
// commented out due to 6593406
// getBMImage(gc, IMAGEW, IMAGEH),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, true),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, false),
getVImage(gc, IMAGEW, IMAGEH),
})
{
System.out.println("Testing source: " + srcIm);
// wiggle the source and dest rectangles
try {
for (int locationVar = -10; locationVar < 20; locationVar += 10)
{
for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
srcRect.translate(locationVar, locationVar);
srcRect.grow(sizeVar, sizeVar);
Rectangle dstRect =
new Rectangle(sizeVar, sizeVar,
srcRect.width, srcRect.height);
System.out.println("testing blit rect src: " + srcRect);
System.out.println(" dst: " + dstRect);
render(getGraphics(), srcIm, srcRect, dstRect);
test(srcRect, dstRect);
}
}
System.out.println("Test passed.");
} finally {
synchronized (lock) {
done = true;
lock.notifyAll();
}
}
}
}
public void runTests() {
GraphicsConfiguration gc = getGraphicsConfiguration();
for (Image srcIm :
new Image[] {
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, true),
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, false),
// commented out due to 6593406
// getBMImage(gc, IMAGEW, IMAGEH),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, true),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, false),
getVImage(gc, IMAGEW, IMAGEH),
})
{
System.out.println("Testing source: " + srcIm);
// wiggle the source and dest rectangles
try {
for (int locationVar = -10; locationVar < 20; locationVar += 10)
{
for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
srcRect.translate(locationVar, locationVar);
srcRect.grow(sizeVar, sizeVar);
Rectangle dstRect =
new Rectangle(sizeVar, sizeVar,
srcRect.width, srcRect.height);
System.out.println("testing blit rect src: " + srcRect);
System.out.println(" dst: " + dstRect);
render(getGraphics(), srcIm, srcRect, dstRect);
test(srcRect, dstRect);
}
}
System.out.println("Test passed.");
} finally {
synchronized (lock) {
done = true;
lock.notifyAll();
}
}
}
}
/**
* Detect if the provided section is a thick one.
* (as seen in the context of the factory orientation)
*
* @param section the section to check
* @return true if fat
*/
public boolean isSectionFat (Section section)
{
final Boolean fat = fatSections.get(section);
if (fat != null) {
return fat;
}
try {
if (section.getMeanThickness(orientation) <= 1) {
return setFat(section, false);
}
// Check global slimness
if (section.getMeanAspect(orientation) < params.minSectionAspect) {
return setFat(section, true);
}
// Check thickness
Rectangle bounds = orientation.oriented(section.getBounds());
Line line = orientation.switchRef(section.getAbsoluteLine());
if (Math.abs(line.getSlope()) < (Math.PI / 4)) {
// Measure mean thickness on each half
int startCoord = bounds.x + (bounds.width / 4);
int startPos = line.yAtX(startCoord);
int stopCoord = bounds.x + ((3 * bounds.width) / 4);
int stopPos = line.yAtX(stopCoord);
// Start side
Rectangle oRoi = new Rectangle(startCoord, startPos, 0, 0);
final int halfWidth = Math.min(params.probeWidth / 2, bounds.width / 4);
oRoi.grow(halfWidth, params.maxThickness);
PointsCollector collector = new PointsCollector(orientation.absolute(oRoi));
section.cumulate(collector);
int startThickness = (int) Math.rint((double) collector.getSize() / oRoi.width);
// Stop side
oRoi.translate(stopCoord - startCoord, stopPos - startPos);
collector = new PointsCollector(orientation.absolute(oRoi));
section.cumulate(collector);
int stopThickness = (int) Math.rint((double) collector.getSize() / oRoi.width);
return setFat(
section,
(startThickness > params.maxThickness)
|| (stopThickness > params.maxThickness));
} else {
return setFat(section, bounds.height > params.maxThickness);
}
} catch (Exception ex) {
logger.warn("Error in checking fatness of " + section, ex);
return setFat(section, true);
}
}
@Override
protected Rectangle calculateClientArea() {
Rectangle result = new Rectangle(clientArea);
result.grow(10, 10);
return result;
}
public void runTests() {
GraphicsConfiguration gc = getGraphicsConfiguration();
for (Image srcIm :
new Image[] {
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, true),
getBufferedImage(gc, IMAGEW, IMAGEH,
BufferedImage.TYPE_INT_RGB, false),
// commented out due to 6593406
// getBMImage(gc, IMAGEW, IMAGEH),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, true),
// getBufferedImage(gc, IMAGEW, IMAGEH,
// BufferedImage.TYPE_INT_ARGB, false),
getVImage(gc, IMAGEW, IMAGEH),
})
{
System.out.println("Testing source: " + srcIm);
// wiggle the source and dest rectangles
try {
for (int locationVar = -10; locationVar < 20; locationVar += 10)
{
for (int sizeVar = -10; sizeVar < 20; sizeVar += 10) {
Rectangle srcRect = (Rectangle)IMAGE_BOUNDS.clone();
srcRect.translate(locationVar, locationVar);
srcRect.grow(sizeVar, sizeVar);
Rectangle dstRect =
new Rectangle(sizeVar, sizeVar,
srcRect.width, srcRect.height);
System.out.println("testing blit rect src: " + srcRect);
System.out.println(" dst: " + dstRect);
render(getGraphics(), srcIm, srcRect, dstRect);
test(srcRect, dstRect);
}
}
System.out.println("Test passed.");
} finally {
synchronized (lock) {
done = true;
lock.notifyAll();
}
}
}
}