Java Code Examples for java.awt.Rectangle.add()

The following are Jave code examples for showing how to use add() of the java.awt.Rectangle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Yass   File: YassLyrics.java   View Source Code Vote up 6 votes
/**
 * Main processing method for the Selector object
 */
public synchronized void run() {
	try {
		lyricsArea.getStyledDocument().setCharacterAttributes(0,
				lyricsArea.getStyledDocument().getLength(),
				notSelectStyle, false);
		lyricsArea.getStyledDocument().setCharacterAttributes(in,
				out - in, selectStyle, false);
		Rectangle r = lyricsArea.modelToView(in);
		r.add(lyricsArea.modelToView(out));
		lyricsArea.scrollRectToVisible(r);

		if (!lyricsArea.isEditable()) {
			preventFireUpdate = true;
			lyricsArea.getCaret().setDot(in);
			lyricsArea.getCaret().moveDot(out);
			preventFireUpdate = false;
		}
	} catch (Exception ignored) {
	}
}
 
Example 2
Project: VASSAL-src   File: Footprint.java   View Source Code Vote up 6 votes
private Rectangle getBB() {
  final Rectangle bb = piece.boundingBox();
  final Point pos = piece.getPosition();

  bb.x += pos.x;
  bb.y += pos.y;

  final int circleDiameter = 2*circleRadius;
  final Rectangle pr = new Rectangle();

  for (final Point p: pointList) {
    pr.setBounds(
      p.x - circleRadius, p.y - circleRadius, circleDiameter, circleDiameter
    );
    bb.add(pr);
  }

  bb.x -= pos.x;
  bb.y -= pos.y;

  return bb;
}
 
Example 3
Project: Tarski   File: mxGraphHandler.java   View Source Code Vote up 6 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 4
Project: VASSAL-src   File: RegionGrid.java   View Source Code Vote up 6 votes
public void mouseDragged(MouseEvent e) {
  if (!e.isMetaDown()) {
    scrollAtEdge(e.getPoint(), 15);
  }

  if (selectionRect != null) {
    // FIXME: inefficient, could be done with only one new Rectangle
    final Rectangle repaintRect =
      new Rectangle(selectionRect.x-1, selectionRect.y-1,
                    selectionRect.width+3, selectionRect.height+3);

    selectionRect.x = Math.min(e.getX(), anchor.x);
    selectionRect.y = Math.min(e.getY(), anchor.y);
    selectionRect.width = Math.abs(e.getX() - anchor.x);
    selectionRect.height = Math.abs(e.getY() - anchor.y);

    repaintRect.add(
      new Rectangle(selectionRect.x-1, selectionRect.y-1,
                    selectionRect.width+3, selectionRect.height+3));
    view.repaint(repaintRect);
  }
}
 
Example 5
Project: JavaGraph   File: JGraphUI.java   View Source Code Vote up 5 votes
/**
 * Calculates the dirty area and causes the canvas to be repainted.
 */
private void update(MouseEvent e) {
    if (this.dragOrigVertex != null) {
        Rectangle dirty =
            getScreenBounds(this.dragOrigVertex).getBounds();
        if (this.dragCurrPoint != null) {
            dirty.add(this.dragCurrPoint);
        }
        if (this.dragCurrVertex != null) {
            dirty.add(this.dragCurrVertex.getBounds());
        }
        if (e != null) {
            Point point = e.getPoint();
            this.dragCurrPoint = point;
            this.dragCurrVertex = vertexAt(point);
            dirty.add(point);
        }
        if (this.dragCurrVertex != null) {
            dirty.add(getScreenBounds(this.dragCurrVertex));
        }
        dirty.x -= 1;
        dirty.y -= 1;
        dirty.width += 2;
        dirty.height += 2;
        this.canvas.repaint(dirty);
    }
}
 
Example 6
Project: TrabalhoFinalEDA2   File: mxUtils.java   View Source Code Vote up 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 7
Project: GlitchKernel   File: SelectionShape.java   View Source Code Vote up 5 votes
public SelectionShape(Point startPoint, Point endPoint, SelectionTypes selectionType)
{
	this.startPoint = startPoint;
	this.endPoint = endPoint;
	this.freeHandSelectionPointList = new ArrayList<Point>();
	this.freeHandTranslatedSelectionPointList = new ArrayList<Point>();
	this.freeHandSelectionConnected = false;
	this.selectionType = selectionType;
	
	Rectangle selectionRectangle = new Rectangle(startPoint);
	selectionRectangle.add(endPoint);
	this.selectionRectangle = selectionRectangle;
}
 
Example 8
Project: geomapapp   File: ZoomOut.java   View Source Code Vote up 5 votes
public void mouseDragged(MouseEvent e) {
		if( !toggle.isSelected() )return;
		Rectangle shape = new Rectangle( start.x, start.y, 0, 0);
		shape.add(e.getPoint());
	//	if( shape.width<=10 || shape.height<=10 )return;
//System.out.println( shape.width +"\t"+ shape.height );
		sc.setShape( shape);
	}
 
Example 9
Project: VASSAL-src   File: MovementMarkable.java   View Source Code Vote up 5 votes
public Rectangle boundingBox() {
  final Rectangle r = piece.boundingBox();
  r.add(piece.boundingBox());
  final Dimension d = getImageSize();
  r.add(new Rectangle(xOffset, yOffset, d.width, d.height));
  return r;
}
 
Example 10
Project: Tarski   File: mxUtils.java   View Source Code Vote up 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 11
Project: geomapapp   File: Zoom.java   View Source Code Vote up 5 votes
public void mouseDragged(MouseEvent e) {
		if( !zoomIn.isSelected() && !zoomOut.isSelected() )return;
		Rectangle shape = new Rectangle( start.x, start.y, 0, 0);
		shape.add(e.getPoint());
	//	if( shape.width<=10 || shape.height<=10 )return;
//System.out.println( shape.width +"\t"+ shape.height );
		sc.setShape( shape);
	}
 
Example 12
Project: VASSAL-src   File: RegionGrid.java   View Source Code Vote up 5 votes
public Rectangle getSelectedBox() {
  Rectangle rect = null;
  for (Region r : selectedRegions) {
    final Rectangle sel = r.getSelectionRect();
    if (rect == null) {
      rect = sel;
    }
    else {
      rect.add(sel);
    }
  }
  return rect;
}
 
Example 13
Project: VASSAL-src   File: Map.java   View Source Code Vote up 5 votes
/**
   * @return the size of the map in pixels at 100% zoom,
   * including the edge buffer
   */
// FIXME: why synchronized?
  public synchronized Dimension mapSize() {
    final Rectangle r = new Rectangle(0,0);
    for (Board b : boards) r.add(b.bounds());
    r.width += edgeBuffer.width;
    r.height += edgeBuffer.height;
    return r.getSize();
  }
 
Example 14
Project: JavaGraph   File: LayoutMap.java   View Source Code Vote up 5 votes
/**
 * Converts a list of points to the minimal rectangle containing all of
 * them.
 */
static public Rectangle toBounds(List<Point2D> points) {
    Rectangle bounds = new Rectangle();
    for (Point2D point : points) {
        bounds.add(point);
    }
    return bounds;

}
 
Example 15
Project: TrabalhoFinalEDA2   File: mxConnectionHandler.java   View Source Code Vote up 5 votes
/**
 * 
 */
public void setBounds(Rectangle value)
{
	if ((bounds == null && value != null)
			|| (bounds != null && value == null)
			|| (bounds != null && value != null && !bounds.equals(value)))
	{
		Rectangle tmp = bounds;

		if (tmp != null)
		{
			if (value != null)
			{
				tmp.add(value);
			}
		}
		else
		{
			tmp = value;
		}

		bounds = value;

		if (tmp != null)
		{
			graphComponent.getGraphControl().repaint(tmp);
		}
	}
}
 
Example 16
Project: GlitchKernel   File: SelectionShape.java   View Source Code Vote up 4 votes
public void setEndPoint(Point endPoint) 
{
	this.endPoint = endPoint;
	selectionRectangle = new Rectangle(startPoint);
	selectionRectangle.add(endPoint);
}
 
Example 17
Project: Logisim   File: Print.java   View Source Code Vote up 4 votes
@Override
public int print(Graphics base, PageFormat format, int pageIndex) {
	if (pageIndex >= circuits.size())
		return Printable.NO_SUCH_PAGE;

	Circuit circ = circuits.get(pageIndex);
	CircuitState circState = proj.getCircuitState(circ);
	Graphics g = base.create();
	Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
	FontMetrics fm = g.getFontMetrics();
	String head = (header != null && !header.equals(""))
			? format(header, pageIndex + 1, circuits.size(), circ.getName())
			: null;
	int headHeight = (head == null ? 0 : fm.getHeight());

	// Compute image size
	double imWidth = format.getImageableWidth();
	double imHeight = format.getImageableHeight();

	// Correct coordinate system for page, including
	// translation and possible rotation.
	Bounds bds = circ.getBounds(g).expand(4);
	double scale = Math.min(imWidth / bds.getWidth(), (imHeight - headHeight) / bds.getHeight());
	if (g2 != null) {
		g2.translate(format.getImageableX(), format.getImageableY());
		if (rotateToFit && scale < 1.0 / 1.1) {
			double scale2 = Math.min(imHeight / bds.getWidth(), (imWidth - headHeight) / bds.getHeight());
			if (scale2 >= scale * 1.1) { // will rotate
				scale = scale2;
				if (imHeight > imWidth) { // portrait -> landscape
					g2.translate(0, imHeight);
					g2.rotate(-Math.PI / 2);
				} else { // landscape -> portrait
					g2.translate(imWidth, 0);
					g2.rotate(Math.PI / 2);
				}
				double t = imHeight;
				imHeight = imWidth;
				imWidth = t;
			}
		}
	}

	// Draw the header line if appropriate
	if (head != null) {
		g.drawString(head, (int) Math.round((imWidth - fm.stringWidth(head)) / 2), fm.getAscent());
		if (g2 != null) {
			imHeight -= headHeight;
			g2.translate(0, headHeight);
		}
	}

	// Now change coordinate system for circuit, including
	// translation and possible scaling
	if (g2 != null) {
		if (scale < 1.0) {
			g2.scale(scale, scale);
			imWidth /= scale;
			imHeight /= scale;
		}
		double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
		g2.translate(-bds.getX() + dx, -bds.getY());
	}

	// Ensure that the circuit is eligible to be drawn
	Rectangle clip = g.getClipBounds();
	clip.add(bds.getX(), bds.getY());
	clip.add(bds.getX() + bds.getWidth(), bds.getY() + bds.getHeight());
	g.setClip(clip);

	// And finally draw the circuit onto the page
	ComponentDrawContext context = new ComponentDrawContext(proj.getFrame().getCanvas(), circ, circState, base,
			g, printerView);
	Collection<Component> noComps = Collections.emptySet();
	circ.draw(context, noComps);
	g.dispose();
	return Printable.PAGE_EXISTS;
}
 
Example 18
Project: VASSAL-src   File: Embellishment0.java   View Source Code Vote up 4 votes
public Rectangle boundingBox() {
  final Rectangle r = piece.boundingBox();
  if (value > 0) r.add(getCurrentImageBounds());
  return r;
}
 
Example 19
Project: VASSAL-src   File: Embellishment.java   View Source Code Vote up 4 votes
public Rectangle boundingBox() {
  final Rectangle r = piece.boundingBox();
  if (value > 0) r.add(getCurrentImageBounds());
  return r;
}
 
Example 20
Project: Yass   File: YassLyrics.java   View Source Code Vote up 4 votes
/**
 * Description of the Method
 */
public void search() {
	int n = lyricsArea.getCaret().getDot();

	// if (ignoreCase) flags |= Pattern.CASE_INSENSITIVE;
	if (!findInput.getText().equals(findText) || pat == null) {
		findText = findInput.getText();
		pat = Pattern.compile(findText, Pattern.MULTILINE);
		m = pat.matcher(lyricsArea.getText());
	}
	if (!m.find(n)) {
		// rewind
		m = pat.matcher(lyricsArea.getText());
		if (!m.find(0)) {
			return;
		}
	}

	int in = m.start();

	int out = m.end();
	table.getSelectionModel().removeListSelectionListener(
			tableSelectionListener);
	lyricsArea.removeCaretListener(caretListener);
	lyricsArea.getCaret().setDot(in);
	lyricsArea.getCaret().moveDot(out);
	lyricsArea.getStyledDocument().setCharacterAttributes(0,
			lyricsArea.getStyledDocument().getLength(), notSelectStyle,
			false);
	lyricsArea.getStyledDocument().setCharacterAttributes(in, out - in,
			selectStyle, false);
	try {
		Rectangle r = lyricsArea.modelToView(in);
		r.add(lyricsArea.modelToView(out));
		lyricsArea.scrollRectToVisible(r);
	} catch (Exception ignored) {
	}

	selectSyllables(in, out);
	lyricsArea.addCaretListener(caretListener);
	table.getSelectionModel().addListSelectionListener(
			tableSelectionListener);
}