protected void addPoint(
          SplineCADToolContext context, double pointX, double pointY, InputEvent event) {
        SplineCADTool ctxt = context.getOwner();

        (context.getState()).Exit(context);
        context.clearState();
        try {
          ctxt.setQuestion(
              PluginServices.getText(this, "insert_next_point")
                  + ", "
                  + PluginServices.getText(this, "close")
                  + " "
                  + "["
                  + PluginServices.getText(this, "SplineCADTool.close")
                  + "] "
                  + PluginServices.getText(this, "cad.or")
                  + " "
                  + PluginServices.getText(this, "end")
                  + " "
                  + "["
                  + PluginServices.getText(this, "SplineCADTool.end")
                  + "]");
          ctxt.setDescription(new String[] {"close", "terminate", "cancel"});
          ctxt.addPoint(pointX, pointY, event);
        } finally {
          context.setState(Spline.NextPoint);
          (context.getState()).Entry(context);
        }
        return;
      }
    protected void addOption(SplineCADToolContext context, String s) {
      SplineCADTool ctxt = context.getOwner();

      if (s.equals(PluginServices.getText(this, "cancel"))) {
        boolean loopbackFlag = context.getState().getName().equals(Spline.FirstPoint.getName());

        if (loopbackFlag == false) {
          (context.getState()).Exit(context);
        }

        context.clearState();
        try {
          ctxt.cancel();
        } finally {
          context.setState(Spline.FirstPoint);

          if (loopbackFlag == false) {
            (context.getState()).Entry(context);
          }
        }
      } else if (s.equals("")) {
        boolean loopbackFlag = context.getState().getName().equals(Spline.FirstPoint.getName());

        if (loopbackFlag == false) {
          (context.getState()).Exit(context);
        }

        context.clearState();
        try {
          ctxt.endGeometry();
        } finally {
          context.setState(Spline.FirstPoint);

          if (loopbackFlag == false) {
            (context.getState()).Entry(context);
          }
        }
      } else {
        boolean loopbackFlag = context.getState().getName().equals(Spline.FirstPoint.getName());

        if (loopbackFlag == false) {
          (context.getState()).Exit(context);
        }

        context.clearState();
        try {
          ctxt.throwOptionException(PluginServices.getText(this, "incorrect_option"), s);
        } finally {
          context.setState(Spline.FirstPoint);

          if (loopbackFlag == false) {
            (context.getState()).Entry(context);
          }
        }
      }

      return;
    }
    protected void addValue(SplineCADToolContext context, double d) {
      SplineCADTool ctxt = context.getOwner();

      boolean loopbackFlag = context.getState().getName().equals(Spline.FirstPoint.getName());

      if (loopbackFlag == false) {
        (context.getState()).Exit(context);
      }

      context.clearState();
      try {
        ctxt.throwValueException(PluginServices.getText(this, "incorrect_value"), d);
      } finally {
        context.setState(Spline.FirstPoint);

        if (loopbackFlag == false) {
          (context.getState()).Entry(context);
        }
      }
      return;
    }
    protected void endPoint(
        SplineCADToolContext context, double pointX, double pointY, InputEvent event) {
      SplineCADTool ctxt = context.getOwner();

      boolean loopbackFlag = context.getState().getName().equals(Spline.FirstPoint.getName());

      if (loopbackFlag == false) {
        (context.getState()).Exit(context);
      }

      context.clearState();
      try {
        ctxt.addPoint(pointX, pointY, event);
        ctxt.endGeometry();
      } finally {
        context.setState(Spline.FirstPoint);

        if (loopbackFlag == false) {
          (context.getState()).Entry(context);
        }
      }
      return;
    }
      protected void addOption(SplineCADToolContext context, String s) {
        SplineCADTool ctxt = context.getOwner();

        if (s.equalsIgnoreCase(PluginServices.getText(this, "SplineCADTool.close"))
            || s.equals(PluginServices.getText(this, "close"))) {

          (context.getState()).Exit(context);
          context.clearState();
          try {
            ctxt.addOption(s);
            ctxt.closeGeometry();
            ctxt.endGeometry();
            ctxt.end();
          } finally {
            context.setState(Spline.FirstPoint);
            (context.getState()).Entry(context);
          }
        } else if (s.equalsIgnoreCase(PluginServices.getText(this, "SplineCADTool.end"))
            || s.equals(PluginServices.getText(this, "terminate"))) {

          (context.getState()).Exit(context);
          context.clearState();
          try {
            ctxt.addOption(s);
            ctxt.endGeometry();
            ctxt.end();
          } finally {
            context.setState(Spline.FirstPoint);
            (context.getState()).Entry(context);
          }
        } else {
          super.addOption(context, s);
        }

        return;
      }
Esempio n. 6
0
  /**
   * Método para dibujar lo necesario para el estado en el que nos encontremos.
   *
   * @param g Graphics sobre el que dibujar.
   * @param selectedGeometries BitSet con las geometrías seleccionadas.
   * @param x parámetro x del punto que se pase para dibujar.
   * @param y parámetro x del punto que se pase para dibujar.
   */
  public void drawOperation(Graphics g, double x, double y) {
    SplineCADToolState actualState = _fsm.getState();
    String status = actualState.getName();
    if (status.equals("Spline.NextPoint") || status.equals("Spline.FirstPoint")) {
      //        	ArrayList points=new ArrayList();
      Point2D[] points = new Point2D[list.size() + 1];
      Point2D[] auxPoints = (Point2D[]) list.toArray(new Point2D[0]);
      for (int i = 0; i < auxPoints.length; i++) {
        points[i] = (Point2D) auxPoints[i].clone();
      }

      //        	points.addAll(list);
      points[points.length - 1] = new Point2D.Double(x, y);
      Geometry spline = createSpline(points);
      ViewPort vp = getCadToolAdapter().getMapControl().getViewPort();
      DrawOperationContext doc = new DrawOperationContext();
      doc.setGraphics((Graphics2D) g);
      doc.setViewPort(vp);
      doc.setSymbol(DefaultCADTool.selectionSymbol);
      try {
        spline.invokeOperation(Draw.CODE, doc);
      } catch (GeometryOperationNotSupportedException e) {
        e.printStackTrace();
      } catch (GeometryOperationException e) {
        e.printStackTrace();
      }

      //        	spline.draw((Graphics2D)g,vp,DefaultCADTool.selectionSymbol);
    }
    VectorialLayerEdited vle = getVLE();
    if (!vle.getLayer().isVisible()) return;
    try {
      Image imgSel = vle.getSelectionImage();
      if (imgSel != null) g.drawImage(imgSel, 0, 0, null);
      Image imgHand = vle.getHandlersImage();
      if (imgHand != null) g.drawImage(imgHand, 0, 0, null);
    } catch (Exception e) {
    }
  }
 protected void Default(SplineCADToolContext context) {
   throw (new statemap.TransitionUndefinedException(
       "State: " + context.getState().getName() + ", Transition: " + context.getTransition()));
 }