Exemplo n.º 1
0
 @Override
 public Sketch clone() {
   Sketch newSketch = new Sketch();
   for (int i = 0; i < this.noOfStrokes + 1; i++) {
     newSketch.points.add(new ArrayList<SketchPoint>());
     for (int j = 0; j < this.points.get(i).size(); j++) {
       newSketch.points.get(i).add(this.points.get(i).get(j));
     }
   }
   newSketch.noOfStrokes = this.noOfStrokes;
   return newSketch;
 }
Exemplo n.º 2
0
  public void drawSketch(Graphics2D g2d, Sketch sketch, Symbol symbol) {

    List<List<SketchPoint>> allPoints = sketch.getAllPoints();
    Point2D.Float loc = new Float();
    Point2D.Float prevLoc = new Float();
    BasicStroke stroke;
    Color strokeColor = null;
    if (symbol.getClassName().equalsIgnoreCase("box")) {
      strokeColor = new Color(255, 0, 0, 255);
    } else if (symbol.getClassName().contains("arrow")) {
      strokeColor = new Color(0, 255, 0, 255);
    } else if (Character.isDigit(symbol.getClassName().charAt(0))) {
      strokeColor = new Color(0, 0, 255, 255);
    } else {
      strokeColor = new Color(255, 128, 0, 255);
    }
    for (int i = 0; i < allPoints.size(); i++) {
      List<SketchPoint> currentStroke = allPoints.get(i);
      loc.x = currentStroke.get(0).x;
      loc.y = currentStroke.get(0).y;
      for (int j = 1; j < currentStroke.size(); j++) {
        prevLoc.x = loc.x;
        prevLoc.y = loc.y;

        loc.x = currentStroke.get(j).x;
        loc.y = currentStroke.get(j).y;

        g2d.setColor(strokeColor);
        stroke = new BasicStroke(0.5f * 5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
        g2d.setStroke(stroke);
        g2d.draw(new Line2D.Float(prevLoc, loc));
      }
    }
  }