public static void main(String[] args) {
   // TODO Auto-generated method stub
   ShapeFactory sf = new ShapeFactory();
   Shape circle = sf.getShape("CIRCLE");
   Shape rect = sf.getShape("RECTANGLE");
   circle.draw();
   rect.draw();
 }
示例#2
0
  public void paint(Graphics g) {
    super.paint(g);

    Dimension size = getSize();

    // Position of new piece on board
    int boardTop = (int) size.getHeight() - BoardHeight * squareHeight();

    for (int i = 0; i < BoardHeight; ++i) {
      for (int j = 0; j < BoardWidth; ++j) {
        Tetrominoes shape = shapeAt(j, BoardHeight - i - 1);
        if (shape != Tetrominoes.NoShape)
          drawSquare(g, 0 + j * squareWidth(), boardTop + i * squareHeight(), shape);
      }
    }

    if (curPiece.getShape() != Tetrominoes.NoShape) {
      for (int i = 0; i < 4; ++i) {
        int x = curX + curPiece.x(i);
        int y = curY - curPiece.y(i);
        drawSquare(
            g,
            0 + x * squareWidth(),
            boardTop + (BoardHeight - y - 1) * squareHeight(),
            curPiece.getShape());
      }
    }
  }
示例#3
0
  static Drawing drawTest() {
    Drawing d = new Drawing();
    d.setFaceColor(Color.YELLOW);
    //		d.setTransparency(0.9);
    d.moveTo(0, 0, 0);
    d.line(2, 0, 0);
    d.line(0, 0, 2);
    d.line(-2, 0, 0);
    Shape rect = d.close();

    d.moveTo(0.2, 0, 0.2);
    d.line(1.6, 0, 0);
    d.line(0, 0, 1.6);
    d.line(-1.6, 0, 0);
    Shape intern = d.close();
    d.delete(intern);

    Shape fig = d.extrude(rect, 2);
    d.save("test.brep");

    d.setMeshSize(fig, 0.1);
    d.setMeshSize(fig, 2, 0, 0, 0.01);
    fig.setMeshSize(0, 0.5, 0, 50);

    return d;
  }
示例#4
0
  /** @return the shapes contained in this group container */
  public Shape[] getShapes() {
    // Out escher container record should contain serveral
    //  SpContainers, the first of which is the group shape itself
    List lst = _escherContainer.getChildRecords();

    ArrayList shapeList = new ArrayList();
    // Don't include the first SpContainer, it is always NotPrimitive
    for (int i = 1; i < lst.size(); i++) {
      EscherRecord r = (EscherRecord) lst.get(i);
      if (r instanceof EscherContainerRecord) {
        // Create the Shape for it
        EscherContainerRecord container = (EscherContainerRecord) r;
        Shape shape = ShapeFactory.createShape(container, this);
        shape.setSheet(getSheet());
        shapeList.add(shape);
      } else {
        // Should we do anything special with these non
        //  Container records?
        logger.log(
            POILogger.ERROR,
            "Shape contained non container escher record, was " + r.getClass().getName());
      }
    }

    // Put the shapes into an array, and return
    Shape[] shapes = (Shape[]) shapeList.toArray(new Shape[shapeList.size()]);
    return shapes;
  }
示例#5
0
  /**
   * Computes the standard packed array strides for a given shape.
   *
   * @param shape the shape of a matrix:
   * @param startValue the startValue for the strides
   * @return the strides for a matrix of n dimensions
   */
  public static int[] calcStrides(int[] shape, int startValue) {
    if (Shape.isColumnVectorShape(shape)) {
      int[] ret = new int[2];
      Arrays.fill(ret, startValue);
      return ret;
    }

    if (Shape.isRowVectorShape(shape)) {
      int[] ret = new int[2];
      ret[0] = 1;
      ret[1] = shape[0];
      return ret;
    }

    int dimensions = shape.length;
    int[] stride = new int[dimensions];

    int st = startValue;
    for (int j = dimensions - 1; j >= 0; j--) {
      stride[j] = st;
      st *= shape[j];
    }

    if (dimensions > 2 && shape[0] == 1) {
      stride = ArrayUtil.reverseCopy(stride);
    }

    return stride;
  }
  public IReason updateNeeded(IUpdateContext context) {
    // retrieve name from pictogram model
    String pictogramName = null;
    PictogramElement pictogramElement = context.getPictogramElement();
    if (pictogramElement instanceof ContainerShape) {
      ContainerShape cs = (ContainerShape) pictogramElement;
      for (Shape shape : cs.getChildren()) {
        if (shape.getGraphicsAlgorithm() instanceof Text) {
          Text text = (Text) shape.getGraphicsAlgorithm();
          pictogramName = text.getValue();
        }
      }
    }

    // retrieve name from business model
    String businessName = null;
    Object bo = getBusinessObjectForPictogramElement(pictogramElement);
    if (bo instanceof EClass) {
      EClass eClass = (EClass) bo;
      businessName = eClass.getName();
    }

    // update needed, if names are different
    boolean updateNameNeeded =
        ((pictogramName == null && businessName != null)
            || (pictogramName != null && !pictogramName.equals(businessName)));
    if (updateNameNeeded) {
      return Reason.createTrueReason("Name is out of date");
    } else {
      return Reason.createFalseReason();
    }
  }
示例#7
0
 @Override
 protected boolean intersectsOnOwnAxes(Shape s) {
   // return getHorizontalProjection().intersects(s.getHorizontalProjection()) &&
   //        getVerticalProjection().intersects(s.getVerticalProjection());
   return s.getHorizontalProjection().intersects(v00.x(), v11.x())
       && s.getVerticalProjection().intersects(v00.y(), v11.y());
 }
示例#8
0
文件: Shape.java 项目: thu/DemoJavaSE
  public static void main(String[] args) {
    // square
    Square square = new Square(5.6);
    System.out.println("area: " + square.getArea());
    System.out.println("perimeter: " + square.getPerimeter());

    // rectangle
    Rectangle rectangle = new Rectangle(1.2, 3.4);
    System.out.println("area: " + rectangle.getArea());
    System.out.println("perimeter: " + rectangle.getPerimeter());

    // circle
    Circle circle = new Circle(1.2);
    System.out.println("area: " + circle.getArea());
    System.out.println("perimeter: " + circle.getPerimeter());

    // triangle
    Triangle triangle = new Triangle(1.2, 1.2, 1.2);
    System.out.println("area: " + triangle.getArea());
    System.out.println("perimeter: " + triangle.getPerimeter());

    // shape
    Shape shape = new Circle(1);
    System.out.println("area: " + shape.getArea());
    System.out.println("perimeter: " + shape.getPerimeter());
  }
  @Test
  public void twentyFor4x5RectangleFromSquare() throws Exception {
    final Rectangle rectangle = new Rectangle();
    rectangle.setWidth(5);
    rectangle.setHeight(4);

    final Square square = new Square();
    square.setSideLength(3);

    List<Shape> shapes =
        new ArrayList<Shape>() {
          {
            add(rectangle);
            add(square);
          }
        };

    List<Integer> areas = new ArrayList<Integer>();
    for (Shape shape : shapes) {
      areas.add(shape.area());
    }

    assertEquals(20, areas.get(0).intValue());
    assertEquals(9, areas.get(1).intValue());
  }
示例#10
0
 public double totalPerimeter() {
   double tot = 0;
   for (Shape s : shape) {
     tot += s.perimeter();
   }
   return tot;
 }
示例#11
0
  /**
   * Build a shape for the entire subtree by joining together the shapes for each of its edges.
   * Vertices included since needed for FullTextPanel.
   */
  public Shape constructInternalShape(DiagramBase diagram, boolean includeVertices) {
    GeneralPath shape = new GeneralPath();
    Enumeration edges = m_edgeList.elements();
    while (edges.hasMoreElements()) {
      TreeEdge edge = (TreeEdge) edges.nextElement();
      Shape edgeShape = edge.getSchemeShape(diagram);
      PathIterator path = edgeShape.getPathIterator(null);
      shape.append(path, false);

      if (includeVertices) {
        Shape vertexShape;
        if (!edge.getSourceVertex().isVirtual()) {
          vertexShape = edge.getSourceVertex().getShape(diagram);
          path = vertexShape.getPathIterator(null);
          shape.append(path, false);
        }
        if (!edge.getDestVertex().isVirtual()) {
          vertexShape = edge.getDestVertex().getShape(diagram);
          path = vertexShape.getPathIterator(null);
          shape.append(path, false);
        }
      }
    }
    BasicStroke stroke =
        new BasicStroke(
            diagram.getSubtreeLineWidth() - DiagramBase.EDGE_OUTLINE_WIDTH + 1,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_MITER);
    internalShapeTable.put(diagram, stroke.createStrokedShape(shape));
    return (Shape) internalShapeTable.get(diagram);
  }
示例#12
0
 @Override
 protected void reset() {
   for (Shape shape : shapes) {
     shape.free();
   }
   shapes.clear();
 }
示例#13
0
 public double totalArea() {
   double tot = 0;
   for (Shape s : shape) {
     tot += s.area();
   }
   return tot;
 }
示例#14
0
 @Override
 public void drawWireFrame(GL gl) {
   Util.drawPoint(gl, center);
   for (Shape shape : parts) {
     shape.drawWireFrame(gl);
   }
 }
  /**
   * Draw the outline of the given shape. Only the vertices are set. The colour has to be set
   * independently of this method.
   *
   * @param shape The shape to draw.
   * @param fill The fill to apply
   */
  public static final void draw(Shape shape, ShapeFill fill) {
    float points[] = shape.getPoints();

    Texture t = TextureImpl.getLastBind();
    TextureImpl.bindNone();

    float center[] = shape.getCenter();
    GL.glBegin(SGL.GL_LINE_STRIP);
    for (int i = 0; i < points.length; i += 2) {
      fill.colorAt(shape, points[i], points[i + 1]).bind();
      Vector2f offset = fill.getOffsetAt(shape, points[i], points[i + 1]);
      GL.glVertex2f(points[i] + offset.x, points[i + 1] + offset.y);
    }

    if (shape.closed()) {
      fill.colorAt(shape, points[0], points[1]).bind();
      Vector2f offset = fill.getOffsetAt(shape, points[0], points[1]);
      GL.glVertex2f(points[0] + offset.x, points[1] + offset.y);
    }
    GL.glEnd();

    if (t == null) {
      TextureImpl.bindNone();
    } else {
      t.bind();
    }
  }
示例#16
0
  /**
   * This implementation calls <code>super.hitTest</code> and returns the result if non-null (this
   * should be a HitInfo.Point), then returns a HitInfo.Interior if the mouse-click occured inside
   * the text bound (as defined by text layout)
   *
   * @return a HitInfo corresponding to the given mouse-event
   */
  public HitInfo hitTest(PEMouseEvent e) {

    // from Bitmap:
    if (image != null) {
      if (getBounds().contains(e.getPicPoint())) {
        return new HitInfo.Interior((PicText) element, e);
      }
      return null;
    }

    // from TextLayout:
    if (!getBounds().contains(e.getPicPoint())) return null;

    PicText te = (PicText) element;
    // recompute textlayout b-box, but store it in a temporary field !
    Rectangle2D tb = textLayout.getBounds();
    Shape text_bounds = text2ModelTr.createTransformedShape(tb);
    if (text_bounds.contains(e.getPicPoint())) {
      // [SR:pending] for the hitInfo to be reliable, getPicPoint() should first be transformed by
      //              inverse text2ModelTr ! (especially when rotationAngle != 0)
      TextHitInfo thi =
          textLayout.hitTestChar(
              (float) (e.getPicPoint().x - strx),
              (float) (e.getPicPoint().y - stry)); // guaranteed to return a non-null thi
      return new HitInfo.Text((PicText) element, thi, e);
    }
    // test hit on textlayout's bounding rectangle :
    // else if (bounds.contains(e.getPicPoint())) return new HitInfo.Interior(element,e);
    return null;
  }
示例#17
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public IPickable getPickableShapeAt(int x, int y, Class type) {
    IPickable res = null;
    int bestDist = Integer.MAX_VALUE;
    synchronized (shapes) {
      for (int i = shapes.size() - 1; i >= 0; i--) {
        Shape shape = shapes.get(i);
        if (shape.screenCoordinates != null
            && ((type == null && shape instanceof IPickable)
                || (type != null && type.isAssignableFrom(shape.getClass())))) {

          int distSq =
              (shape.screenCoordinates.x - x) * (shape.screenCoordinates.x - x)
                  + (shape.screenCoordinates.y - y) * (shape.screenCoordinates.y - y);
          if (distSq > shape.diameter * shape.diameter / 4 + 7 * 7) continue;
          distSq += shape.screenCoordinates.z;
          if (distSq < bestDist) {
            bestDist = distSq;
            res = (IPickable) shape;
          }
        }
      }
    }
    return res;
  }
示例#18
0
  /**
   * this method is implemented directly in basic shapes in complex shapes this method is
   * implemented using delegation
   */
  public void renderShapeToScreen() {
    System.out.println("Rectangle: renderShapeToScreen");
    for (Shape s : rectangleEdges) {

      // delegate to child objects
      s.renderShapeToScreen();
    }
  }
示例#19
0
 public boolean contains(Shape target) {
   for (Shape o : elementData) {
     if (o != null && o.equals(target)) {
       return true;
     }
   }
   return false;
 }
 public boolean contains(int x, int y) {
   // If the button has changed size,
   // make a new shape object.
   if (shape == null || !shape.getBounds().equals(getBounds())) {
     shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
   }
   return shape.contains(x, y);
 }
示例#21
0
 public static void main(String[] args) {
   Shape triangle = new Triangle(new RedColor());
   triangle.getShape();
   triangle = new Triangle(new BlueColor());
   triangle.getShape();
   Shape circle = new Circle(new RedColor());
   circle.getShape();
 }
示例#22
0
  /**
   * Add a shape to this group.
   *
   * @param shape - the Shape to add
   */
  public void addShape(Shape shape) {
    _escherContainer.addChildRecord(shape.getSpContainer());

    Sheet sheet = getSheet();
    shape.setSheet(sheet);
    shape.setShapeId(sheet.allocateShapeId());
    shape.afterInsert(sheet);
  }
示例#23
0
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   Shape s = getShape();
   System.out.println(s.toString());
   s.readShapeData();
   System.out.println(s.computeArea());
   System.out.println(s.computePerimeter());
 }
示例#24
0
 @Override
 public boolean hasArea() {
   for (Shape geom : shapes) {
     if (geom.hasArea()) {
       return true;
     }
   }
   return false;
 }
 void addShape(Shape shape) {
   // Add the shape to the canvas, and set its size/position and color.
   // The shape is added at the top-left corner, with size 80-by-50.
   // Then redraw the canvas to show the newly added shape.
   shape.setColor(currentColor);
   shape.reshape(3, 3, 80, 50);
   shapes.add(shape);
   repaint();
 }
示例#26
0
 protected Point randomPointIn(Shape shape) {
   if (!shape.hasArea()) // or try the center?
   throw new UnsupportedOperationException("Need area to define shape!");
   Rectangle bbox = shape.getBoundingBox();
   Point p;
   do {
     p = randomPointIn(bbox);
   } while (!bbox.relate(p).intersects());
   return p;
 }
示例#27
0
 /**
  * Constructs a ShapeIcon.
  *
  * @param shape the shape to draw
  * @param decoration a decorating shape to draw
  * @param width width of the icon
  * @param height height of the icon
  */
 public ShapeIcon(Shape shape, Shape decoration, int width, int height) {
   w = width;
   h = height;
   this.shape = shape;
   this.decoration = decoration;
   Rectangle rect = shape == null ? new Rectangle() : shape.getBounds();
   if (decoration != null) rect = rect.union(decoration.getBounds());
   offsetX = w / 2 - rect.width / 2 - rect.x;
   offsetY = h / 2 - rect.height / 2 - rect.y;
 }
示例#28
0
 @Override
 public void colorButtonHit(Color c) {
   col = c;
   if (selectedIndex > -1) {
     Shape s = model.getShape(selectedIndex);
     s.setColor(col);
     model.setShape(selectedIndex, s);
   }
   GUIFunctions.changeSelectedColor(c);
 }
示例#29
0
 private static Point[] projectPoints(
     Shape<? extends Coordinates> shape, Calibration calibration, int width, int height) {
   Point[] points = new Point[shape.count()];
   CoordProjector projector = new CoordProjector(calibration, width, height);
   for (int i = 0; i < shape.count(); ++i) {
     Coordinates c = shape.get(i);
     points[i] = projector.project(c);
   }
   return points;
 }
示例#30
0
  public static void main(String[] args) {
    Shape[] shapes = {
      new Circle(5, 10, 10, new LargeCircleDrawer()),
      new Circle(20, 30, 100, new SmallCircleDrawer())
    };

    for (Shape next : shapes) {
      next.draw();
    }
  }