Example #1
0
  @Override
  public void mousePressed(MouseEvent event, StateRenderer2D source) {

    if (event.getButton() != MouseEvent.BUTTON1) {

      if (element != null) {
        MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_CHANGED);
        changeEvent.setChangedObject(element);
        changeEvent.setSourceMap(pivot);
        AddObjectEdit edit = new AddObjectEdit(element);
        element.setFinished(true);

        undoManager.addEdit(edit);
        pivot.warnChangeListeners(changeEvent);
        element = null;

        if (associatedSwitch != null) associatedSwitch.doClick();
      }

      super.mousePressed(event, source);
      return;
    }

    LocationType lt = source.getRealWorldLocation(event.getPoint());

    if (element == null) {
      element = new PathElement(pivot.getMapGroup(), pivot, lt);
      element.setFill(fill);
      element.setShape(fill);
      pivot.addObject(element);
      element.addPoint(0, 0, 0, false);
      MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_ADDED);
      changeEvent.setChangedObject(element);
      changeEvent.setSourceMap(pivot);
      pivot.warnChangeListeners(changeEvent);
    } else {
      double[] offsets =
          element.getCenterLocation().getOffsetFrom(source.getRealWorldLocation(event.getPoint()));
      element.addPoint(-offsets[1], -offsets[0], 0, false);

      MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_CHANGED);
      changeEvent.setChangedObject(element);
      changeEvent.setSourceMap(pivot);
      pivot.warnChangeListeners(changeEvent);
    }
  }
Example #2
0
 @Override
 public void setActive(boolean mode, StateRenderer2D source) {
   if (!mode && element != null) {
     MapChangeEvent changeEvent = new MapChangeEvent(MapChangeEvent.OBJECT_CHANGED);
     changeEvent.setChangedObject(element);
     changeEvent.setSourceMap(pivot);
     AddObjectEdit edit = new AddObjectEdit(element);
     undoManager.addEdit(edit);
     element.setFinished(true);
     pivot.warnChangeListeners(changeEvent);
   }
 }