Java Code Examples for java.awt.Rectangle#add()
The following examples show how to use
java.awt.Rectangle#add() .
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: BowTieExpandVerticesJob.java From ghidra with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: Chord.java From libreveris with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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); }
Example 3
Source File: Selection.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
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(); } }
Example 4
Source File: CurvesBuilder.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * 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; }
Example 5
Source File: GhostGlassPane.java From audiveris with GNU Affero General Public License v3.0 | 6 votes |
/** * 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; } }
Example 6
Source File: ElementBoxView.java From SwingBox with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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()); }
Example 7
Source File: SxCallout.java From SikuliX1 with MIT License | 6 votes |
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); }
Example 8
Source File: Demo_RandomUVCoordsConstrained.java From haxademic with MIT License | 5 votes |
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; }
Example 9
Source File: ScreenMarkerPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
void resizeMarker(Point point) { drawingScreenMarker = true; Rectangle bounds = new Rectangle(startLocation); bounds.add(point); overlay.setPreferredLocation(bounds.getLocation()); overlay.setPreferredSize(bounds.getSize()); }
Example 10
Source File: ScreenMarkerPlugin.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
void resizeMarker(Point point) { drawingScreenMarker = true; Rectangle bounds = new Rectangle(startLocation); bounds.add(point); overlay.setPreferredLocation(bounds.getLocation()); overlay.setPreferredSize(bounds.getSize()); }
Example 11
Source File: BaseMappedPolygon.java From haxademic with MIT License | 5 votes |
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; }
Example 12
Source File: AreaWrapper.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
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); } }
Example 13
Source File: Tree.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
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; }
Example 14
Source File: Animator.java From SikuliX1 with MIT License | 5 votes |
@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++; }
Example 15
Source File: Displayable.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
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; }
Example 16
Source File: mxGraphHandler.java From blog-codes with Apache License 2.0 | 5 votes |
/** * */ 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); } } }
Example 17
Source File: mxUtils.java From blog-codes with Apache License 2.0 | 5 votes |
/** * 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; }
Example 18
Source File: WedgesBuilder.java From audiveris with GNU Affero General Public License v3.0 | 4 votes |
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; }
Example 19
Source File: AreaWrapper.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
/** 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; } }
Example 20
Source File: SpotlightPanel.java From pumpernickel with MIT License | 4 votes |
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)); } }