java.awt.Rectangle#add ( )源码实例Demo

下面列出了java.awt.Rectangle#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: BowTieExpandVerticesJob.java
private Rectangle getBounds(List<FcgVertex> vertices) {
	RenderContext<FcgVertex, FcgEdge> renderContext = viewer.getRenderContext();
	Function<? super FcgVertex, Shape> shaper = renderContext.getVertexShapeTransformer();

	Layout<FcgVertex, FcgEdge> layout = viewer.getGraphLayout();

	Rectangle area = null;
	for (FcgVertex v : vertices) {
		Rectangle bounds = shaper.apply(v).getBounds();
		Point2D loc = layout.apply(v);
		int x = (int) loc.getX();
		int y = (int) loc.getY();
		// do we need to compensate for vertex centering (like is done in the default layout)?		
		//	x -= (bounds.width / 2);
		//	y -= (bounds.height / 2);
		bounds.setLocation(x, y);
		if (area == null) {
			area = bounds; // initialize
		}
		area.add(bounds);
	}

	return area;
}
 
源代码2 项目: libreveris   文件: Chord.java
/**
 * Compute the chord bounding box, including its stem (if any) as
 * well as all the notes of the chord.
 */
@Override
protected void computeBox ()
{
    // Stem or similar info
    Rectangle newBox = new Rectangle(getTailLocation());
    newBox.add(getHeadLocation());

    // Each and every note
    for (TreeNode n : getNotes()) {
        Note note = (Note) n;

        newBox.add(note.getBox());
    }

    setBox(newBox);
}
 
源代码3 项目: audiveris   文件: CurvesBuilder.java
/**
 * Compute the bounding box of all extension lines from curve end to reachable arcs.
 * (making sure that interior of rectangle is not empty)
 *
 * @param curve         the curve being extended (on 'reverse' side)
 * @param reachableArcs the arcs nearby
 * @return the global bounding box
 */
private Rectangle getExtensionBox (Curve curve,
                                   Set<ArcView> reachableArcs)
{
    Point ce = curve.getEnd(reverse);
    Rectangle extBox = new Rectangle(ce.x, ce.y, 1, 1);

    for (ArcView arcView : reachableArcs) {
        Point arcEnd = arcView.getEnd(!reverse);

        if (arcEnd != null) {
            extBox.add(arcEnd);
        } else {
            Point arcPt = arcView.getJunction(!reverse);

            if (arcPt != null) {
                extBox.add(arcPt);
            }
        }
    }

    return extBox;
}
 
源代码4 项目: SwingBox   文件: ElementBoxView.java
/**
 * Obtains the allocation of a box together with all its child boxes.
 * @param b the box
 * @return the smallest rectangle containing the box and all its child boxes
 */
private Rectangle getCompleteBoxAllocation(Box b)
{
    Rectangle ret = b.getAbsoluteBounds();
    if (b instanceof ElementBox)
    {
        ElementBox eb = (ElementBox) b;
        for (int i = eb.getStartChild(); i < eb.getEndChild(); i++)
        {
            Box child = eb.getSubBox(i);
            if (child.isVisible())
            {
                Rectangle r = getCompleteBoxAllocation(child);
                ret.add(r);
            }
        }
    }
    return ret.intersection(b.getClipBlock().getClippedContentBounds());
}
 
源代码5 项目: SikuliX1   文件: SxCallout.java
private void makeComponent() {
  if (layout == Layout.TOP) {
    triangle.rotate(0);
    dx = 0; dy = 0;
    triangle.setLocationRelativeToComponent(rbox, Layout.BOTTOM);
  } else if (layout == Layout.BOTTOM) {
    dx = 0; dy = TRIANGLE_SIZE;
    triangle.rotate(Math.PI);
    triangle.setLocationRelativeToComponent(rbox, Layout.TOP);
  } else if (layout == Layout.LEFT) {
    dx = 0; dy = 0;
    triangle.rotate(-Math.PI / 2);
    triangle.setLocationRelativeToComponent(rbox, Layout.RIGHT);
  } else if (layout == Layout.RIGHT) {
    dx = TRIANGLE_SIZE; dy = 0;
    triangle.rotate(Math.PI / 2);
    triangle.setLocationRelativeToComponent(rbox, Layout.LEFT);
  }
  Rectangle bounds = rbox.getBounds();
  bounds.add(triangle.getBounds());
  setActualBounds(bounds);
}
 
源代码6 项目: audiveris   文件: GhostGlassPane.java
/**
 * Assign the current point, where the dragged image is to be displayed,
 * and repaint as few as possible of the glass pane.
 *
 * @param localPoint the current location (glasspane-based)
 */
private void setLocalPoint (Point localPoint)
{
    // Anything to repaint since last time the point was set?
    if (draggedImage != null) {
        Rectangle rect = getSceneBounds(localPoint);
        Rectangle dirty = new Rectangle(rect);

        if (prevRectangle != null) {
            dirty.add(prevRectangle);
        }

        dirty.grow(1, 1); // To cope with rounding errors

        // Set new values now, to avoid race condition with repaint
        this.localPoint = localPoint;
        prevRectangle = rect;

        repaint(dirty.x, dirty.y, dirty.width, dirty.height);
    } else {
        this.localPoint = localPoint;
        prevRectangle = null;
    }
}
 
源代码7 项目: TrakEM2   文件: Selection.java
protected void apply(final int what, final double[] params) {
	if (null == active) return;
	final LayerSet ls = active.getLayerSet();
	final Collection<Displayable> affected = getAffected();
	try {
		ls.addTransformStep(affected);
		final Rectangle sel_box = getLinkedBox();
		switch (what) {
			case 0: translate(params[0], params[1]); break;
			case 1: rotate(params[0], box.x + box.width/2, box.y + box.height/2); break;
			case 2: scale(params[0], params[1], box.x + box.width/2, box.y + box.height/2); break;
		}
		sel_box.add(getLinkedBox());
		ls.addTransformStep(affected);
		Display.repaint(display.getLayer(), sel_box, Selection.PADDING);
	} catch (Exception e) {
		IJError.print(e);
		ls.undoOneStep();
	}
}
 
源代码8 项目: plugins   文件: ScreenMarkerPlugin.java
void resizeMarker(Point point)
{
	drawingScreenMarker = true;
	Rectangle bounds = new Rectangle(startLocation);
	bounds.add(point);
	overlay.setPreferredLocation(bounds.getLocation());
	overlay.setPreferredSize(bounds.getSize());
}
 
源代码9 项目: blog-codes   文件: mxUtils.java
/**
 * Returns the bounding box for the rotated rectangle.
 */
public static mxRectangle getBoundingBox(mxRectangle rect, double rotation)
{
	mxRectangle result = null;

	if (rect != null && rotation != 0)
	{
		double rad = Math.toRadians(rotation);
		double cos = Math.cos(rad);
		double sin = Math.sin(rad);

		mxPoint cx = new mxPoint(rect.getX() + rect.getWidth() / 2,
				rect.getY() + rect.getHeight() / 2);

		mxPoint p1 = new mxPoint(rect.getX(), rect.getY());
		mxPoint p2 = new mxPoint(rect.getX() + rect.getWidth(), rect.getY());
		mxPoint p3 = new mxPoint(p2.getX(), rect.getY() + rect.getHeight());
		mxPoint p4 = new mxPoint(rect.getX(), p3.getY());

		p1 = getRotatedPoint(p1, cos, sin, cx);
		p2 = getRotatedPoint(p2, cos, sin, cx);
		p3 = getRotatedPoint(p3, cos, sin, cx);
		p4 = getRotatedPoint(p4, cos, sin, cx);

		Rectangle tmp = new Rectangle((int) p1.getX(), (int) p1.getY(), 0,
				0);
		tmp.add(p2.getPoint());
		tmp.add(p3.getPoint());
		tmp.add(p4.getPoint());

		result = new mxRectangle(tmp);
	}
	else if (rect != null)
	{
		result = (mxRectangle) rect.clone();
	}

	return result;
}
 
源代码10 项目: blog-codes   文件: mxGraphHandler.java
/**
 * 
 */
public void setPreviewBounds(Rectangle bounds)
{
	if ((bounds == null && previewBounds != null)
			|| (bounds != null && previewBounds == null)
			|| (bounds != null && previewBounds != null && !bounds
					.equals(previewBounds)))
	{
		Rectangle dirty = null;

		if (isVisible())
		{
			dirty = previewBounds;

			if (dirty != null)
			{
				dirty.add(bounds);
			}
			else
			{
				dirty = bounds;
			}
		}

		previewBounds = bounds;

		if (dirty != null)
		{
			graphComponent.getGraphControl().repaint(dirty.x - 1,
					dirty.y - 1, dirty.width + 2, dirty.height + 2);
		}
	}
}
 
源代码11 项目: TrakEM2   文件: Displayable.java
static public Rectangle getMinimalBoundingBox(Displayable[] d) {
	final Rectangle box = d[0].getBoundingBox();
	final Rectangle tmp = new Rectangle();
	for (int i=1; i<d.length; i++) {
		box.add(d[i].getBoundingBox(tmp));
	}
	return box;
}
 
源代码12 项目: SikuliX1   文件: Animator.java
@Override
public void actionPerformed(ActionEvent e) {

  float r = funcr.getValue(count);

  int x = (int) (origin.x + (int) radius * Math.sin(r));
  int y=  (int) (origin.y + (int) radius * Math.cos(r));

  Point p = new Point(x,y);

  Rectangle r1 = comp.getBounds();

  comp.setLocation(p);

  // r1 stores the union of the bounds before/after the animated step
  Rectangle r2 = comp.getBounds();
  r1.add(r2);

  comp.getParent().getParent().repaint(r1.x,r1.y,r1.width,r1.height);
  //repaint(r1);
  //      comp.getParent().invalidate();
  //      comp.repaint();

  if (count == repeatCount)
    count = 0;
  else
    count++;

}
 
源代码13 项目: TrakEM2   文件: Tree.java
protected Rectangle getPaintingBounds() {
	Rectangle box = null;
	synchronized (node_layer_map) {
		for (final Collection<Node<T>> nodes : node_layer_map.values()) {
			final Rectangle b = getBounds(nodes);
			if (null == box) box = b;
			else if (null != b) box.add(b);
		}
	}
	return box;
}
 
源代码14 项目: TrakEM2   文件: AreaWrapper.java
public void mouseDragged(MouseEvent me, Layer la, int x_p, int y_p, int x_d, int y_d, int x_d_old, int y_d_old) {
	// nothing, the BrushThread handles it
	if (null != AreaWrapper.controller_key && KeyEvent.VK_M == AreaWrapper.controller_key.intValue() && ProjectToolbar.getToolId() == ProjectToolbar.BRUSH) {
		// "move" the area
		Rectangle r = area.getBounds();
		area.transform(new AffineTransform(1, 0, 0, 1, x_d - x_d_old, y_d - y_d_old));
		r.add(new Rectangle(r.x + (x_d_old - x_d), r.y + (y_d_old - y_d), r.width, r.height));
		Display.getFront().getCanvas().repaint(source.at.createTransformedShape(r).getBounds(), 1);
		return;
	}
	if (null != blowcommander) {
		blowcommander.mouseDragged(me, la, x_p, y_p, x_d, y_d, x_d_old, y_d_old);
	}
}
 
源代码15 项目: haxademic   文件: BaseMappedPolygon.java
protected Rectangle createBoundingBox(PVector[] points) {
	Rectangle rect = new Rectangle(new Point((int)points[0].x, (int)points[0].y));
	for (int i = 1; i < points.length; i++) {
		rect.add(points[i].x, points[i].y);
	}
	return rect;
}
 
源代码16 项目: runelite   文件: ScreenMarkerPlugin.java
void resizeMarker(Point point)
{
	drawingScreenMarker = true;
	Rectangle bounds = new Rectangle(startLocation);
	bounds.add(point);
	overlay.setPreferredLocation(bounds.getLocation());
	overlay.setPreferredSize(bounds.getSize());
}
 
源代码17 项目: haxademic   文件: Demo_RandomUVCoordsConstrained.java
protected Rectangle createBoundingBox(PVector[] points) {
	Rectangle rect = new Rectangle(new Point((int)points[0].x, (int)points[0].y));
	for (int i = 1; i < points.length; i++) {
		rect.add(points[i].x, points[i].y);
	}
	return rect;
}
 
源代码18 项目: TrakEM2   文件: AreaWrapper.java
/** For best smoothness, each mouse dragged event should be captured!*/
public void run() {
	final AffineTransform at_inv;
	try {
		 at_inv = source.getAffineTransform().createInverse();
	} catch (NoninvertibleTransformException nite) {
		IJError.print(nite);
		return;
	}
	// create brush
	while (!isInterrupted()) {
		// detect mouse up (don't use 'flags': was recorded on starting up)
		if (0 == (dc.getModifiers() & leftClick)) {
			//Utils.log2("--------->>  Quit brushing from inside loop");
			quit();
			return;
		}
		final Point p = dc.getCursorLoc(); // as offscreen coords
		if (p.equals(previous_p) /*|| (null != previous_p && p.distance(previous_p) < brush_size/5) */) {
			try { Thread.sleep(3); } catch (InterruptedException ie) {}
			continue;
		}
		if (!dc.getSrcRect().contains(p.x, p.y)) {
			// Ignoring point off srcRect
			continue;
		}
		final Runnable task = new Runnable() {
			public void run() {
				final AffineTransform aff = new AffineTransform(1, 0, 0, 1, p.x, p.y);
				aff.preConcatenate(at_inv);
				final Area slash = slashInInts(brush.createTransformedArea(aff));
				synchronized (arealock) {
					if (0 == (flags & alt)) {
						// no modifiers, just add
						area.add(slash);
					} else {
						// with alt down, subtract
						area.subtract(slash);
					}
				}
				synchronized (pointslock) {
					points.add(p);
				}
				final Rectangle copy = new Rectangle(p.x - brush_size/2, p.y - brush_size/2, brush_size, brush_size);
				// repaint only the last added slash
				Display.repaint(la, 3, copy, false, false); 
				// accumulate rectangle for repainting out the brush circle
				synchronized (arealock) {
					if (null != r_old) copy.add(r_old);
					r_old = copy;
				}
			}
		};
		
		try {
			accumulator.submit(task);
		} catch (Throwable t) {
			// will happen when quit() calls accumulator.shutdown(),
			// which will then refuse to run any task.
			// Only the jobs completed up to this time point
			// will be finished, so the trace may finish earlier
			// than the mouse release point in slow computers.
			return;
		}

		previous_p = p;
	}
}
 
源代码19 项目: audiveris   文件: WedgesBuilder.java
private WedgeInter createWedgeInter (SegmentInter s1,
                                     SegmentInter s2,
                                     boolean rev,
                                     GradeImpacts impacts)
{
    Shape shape = rev ? Shape.CRESCENDO : Shape.DIMINUENDO;

    Rectangle box = new Rectangle(s1.getBounds());
    box.add(s2.getBounds());

    // Determine precise closed ends
    Line2D l1 = new Line2D.Double(s1.getInfo().getEnd(true), s1.getInfo().getEnd(false));
    Line2D l2 = new Line2D.Double(s2.getInfo().getEnd(true), s2.getInfo().getEnd(false));

    // Beware s1 and s2 are in no particular order
    final boolean swap;

    if (shape == Shape.CRESCENDO) {
        swap = l2.getY2() < l1.getY2();
    } else {
        swap = l2.getY1() < l1.getY1();
    }

    if (swap) {
        Line2D temp = l1;
        l1 = l2;
        l2 = temp;
    }

    WedgeInter inter = new WedgeInter(l1, l2, box, shape, impacts);

    /* For a wedge, we can restrict the containing systems as just the closest one. */
    Point2D refPoint = (shape == Shape.CRESCENDO) ? l1.getP1() : l1.getP2();
    Staff staff = sheet.getStaffManager().getClosestStaff(refPoint);
    staff.getSystem().getSig().addVertex(inter);

    // Build the underlying glyph as the compound of the two segments glyphs
    inter.setGlyph(
            sheet.getGlyphIndex().registerOriginal(
                    GlyphFactory.buildGlyph(Arrays.asList(s1.getGlyph(), s2.getGlyph()))));

    return inter;
}
 
源代码20 项目: pumpernickel   文件: SpotlightPanel.java
protected void recalculateHighlight(boolean forceImmediateUpdate) {
	Rectangle highlightSum = null;
	for (JComponent h : highlightedComponents) {
		if (h.isShowing() && h.getParent() != null) {
			Rectangle r = h.getBounds();
			r = SwingUtilities.convertRectangle(h.getParent(), r, this);
			if (highlightSum == null) {
				highlightSum = r;
			} else {
				highlightSum.add(r);
			}
		}
	}

	if (highlightSum == null) {
		putClientProperty(TARGET_ALPHA, 0f);
	} else {
		putClientProperty(TARGET_ALPHA, 1f);
		putClientProperty(TARGET_X, (float) highlightSum.getX());
		putClientProperty(TARGET_Y, (float) highlightSum.getY());
		putClientProperty(TARGET_WIDTH, (float) highlightSum.getWidth());
		putClientProperty(TARGET_HEIGHT, (float) highlightSum.getHeight());
	}

	if (getClientProperty(REAL_X) == null) {
		putClientProperty(REAL_ALPHA, 0);
		putClientProperty(REAL_X, getClientProperty(TARGET_X));
		putClientProperty(REAL_Y, getClientProperty(TARGET_Y));
		putClientProperty(REAL_WIDTH, getClientProperty(TARGET_WIDTH));
		putClientProperty(REAL_HEIGHT, getClientProperty(TARGET_HEIGHT));
	}

	if (forceImmediateUpdate) {
		putClientProperty(REAL_ALPHA, getClientProperty(TARGET_ALPHA));
		putClientProperty(REAL_X, getClientProperty(TARGET_X));
		putClientProperty(REAL_Y, getClientProperty(TARGET_Y));
		putClientProperty(REAL_WIDTH, getClientProperty(TARGET_WIDTH));
		putClientProperty(REAL_HEIGHT, getClientProperty(TARGET_HEIGHT));
	}

}