Esempio n. 1
0
 /** Treat the current stroke as a lasso selection if it is mostly closed. */
 public void actionPerformed(ActionEvent evt) {
   _interp.removeCurrentSymbol();
   TimedStroke stroke = _interp.getCurrentStroke();
   int num = stroke.getVertexCount();
   /*
   double length = PathLengthFE.pathLength(stroke);
   double dist = FEUtilities.distance(stroke.getX(0), stroke.getY(0),
           stroke.getX(num-1), stroke.getY(num-1));
   double ratio = dist/length;
   if(ratio <= CLOSE_PROPORTION){
   */
   Polygon2D poly = new Polygon2D.Float();
   poly.moveTo(stroke.getX(0), stroke.getY(0));
   for (int i = 1; i < num; i++) {
     poly.lineTo(stroke.getX(i), stroke.getY(i));
   }
   poly.closePath();
   Iterator iter = _interp.getController().containedSketchFigures(poly);
   ArrayList hitFigures = new ArrayList();
   while (iter.hasNext()) {
     Figure f = (Figure) iter.next();
     if (f instanceof FigureDecorator) {
       f = ((FigureDecorator) f).getDecoratedFigure();
     }
     hitFigures.add(f);
   }
   //        }
   toggleSelection(hitFigures);
 }
Esempio n. 2
0
 /**
  * Toggle the selection state of the given figures. Implemented as a template method so that
  * subclasses can override the behavior.
  */
 protected void toggleSelection(List hitFigures) {
   SelectionModel m = _interp.getController().getSelectionModel();
   for (Iterator i = hitFigures.iterator(); i.hasNext(); ) {
     Figure f = (Figure) i.next();
     if (!(m.containsSelection(f))) {
       m.addSelection(f);
     } else {
       m.removeSelection(f);
     }
   }
 }