Android Open Source - gti350-lab2-android-demo Shape Container






From Project

Back to project page gti350-lab2-android-demo.

License

The source code is released under:

MIT License

If you think the Android project gti350-lab2-android-demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package log350.example.example6;
/*  w  w w.  j a v a  2  s .  co m*/
import java.util.ArrayList;

class ShapeContainer {
  public ArrayList< Shape > shapes = new ArrayList< Shape >();

  public Shape getShape( int index ) { return shapes.get(index); }

  public void addShape( ArrayList< Point2D > points /* in world space */ ) {
    Shape s = new Shape( points );
    shapes.add( s );
  }

  // returns -1 if no shape contains the given point
  public int indexOfShapeContainingGivenPoint( Point2D p /* in world space */ ) {
    for ( int i = 0; i < shapes.size(); ++i ) {
      Shape s = shapes.get(i);
      if ( s.contains(p) )
        return i;
    }
    return -1;
  }

  public void draw( GraphicsWrapper gw, int indexOfShapeToHighlight /* -1 for none */ ) {
    for ( int i = 0; i < shapes.size(); ++i ) {
      Shape s = shapes.get(i);
      s.draw(gw, i==indexOfShapeToHighlight );
    }
  }

  public AlignedRectangle2D getBoundingRectangle() {
    AlignedRectangle2D rect = new AlignedRectangle2D();
    for ( Shape s : shapes )
      rect.bound( s.getBoundingRectangle() );
    return rect;
  }
}




Java Source Code List

log350.example.example6.AlignedRectangle2D.java
log350.example.example6.DrawingView.java
log350.example.example6.GraphicsWrapper.java
log350.example.example6.Log350Example6Activity.java
log350.example.example6.MyButton.java
log350.example.example6.Point2DUtil.java
log350.example.example6.Point2D.java
log350.example.example6.ShapeContainer.java
log350.example.example6.Shape.java
log350.example.example6.Vector2D.java