/**
   * Whenever an UndoableEdit happens the edit will either be absorbed by the current compound edit
   * or a new compound edit will be started
   */
  @Override
  public void undoableEditHappened(UndoableEditEvent e) {
    //  Start a new compound edit

    AbstractDocument.DefaultDocumentEvent docEvt = (DefaultDocumentEvent) e.getEdit();

    if (compoundEdit == null) {
      compoundEdit = startCompoundEdit(e.getEdit());
      startCombine = false;
      updateDirty();
      return;
    }

    int editLine = ((SyntaxDocument) docEvt.getDocument()).getLineNumberAt(docEvt.getOffset());

    //  Check for an incremental edit or backspace.
    //  The Change in Caret position and Document length should both be
    //  either 1 or -1.
    if ((startCombine || Math.abs(docEvt.getLength()) == 1) && editLine == lastLine) {
      compoundEdit.addEdit(e.getEdit());
      startCombine = false;
      updateDirty();
      return;
    }

    //  Not incremental edit, end previous edit and start a new one
    lastLine = editLine;

    compoundEdit.end();
    compoundEdit = startCompoundEdit(e.getEdit());

    updateDirty();
  }
 /** Efface le noeud DOM, et son parent s'il devient vide. */
 private void effacerNoeud(final boolean annulation, final CompoundEdit cedit1) {
   CompoundEdit cedit = null;
   if (!annulation) {
     final FormUndoableEdit fedit =
         new FormUndoableEdit(FormUndoableEdit.TypeEdition.SUPPRIMER, this);
     if (cedit1 != null) cedit1.addEdit(fedit);
     else {
       cedit = new CompoundEdit();
       cedit.addEdit(fedit);
     }
   }
   final Element elparent = (Element) affParent.getNoeud();
   if (attribut) {
     final String nom = cfg.nomAttribut(refNoeud);
     final String espace = cfg.espaceAttribut(refNoeud);
     elparent.removeAttributeNS(espace, nom);
   } else {
     final Node textNode = noeud.getNextSibling();
     elparent.removeChild(noeud);
     if (textNode.getNodeType() == Node.TEXT_NODE) elparent.removeChild(textNode);
   }
   noeud = null;
   if (!annulation) affParent.testEffacementParent(cedit1 != null ? cedit1 : cedit);
   else lireEnfants();
   doc.textPane.miseAJourArbre();
   if (cedit1 == null && cedit != null) {
     cedit.end();
     doc.textPane.addEdit(cedit);
   }
 }
  @Override
  public void process() {

    // put all the edits together
    CompoundEdit edit = new CompoundEdit();

    boolean removeAnnotation = removeMatched.isSelected();

    Pattern pattern =
        caseInsensitive.isSelected()
            ? Pattern.compile(patternField.getText(), Pattern.CASE_INSENSITIVE)
            : Pattern.compile(patternField.getText());

    BasicPatternMatcher<Note> matcher = new BasicPatternMatcher<Note>(Note.class, pattern);

    Annotation target = (Annotation) annotationComboBox.getSelectedItem();

    List<Annotation> createdAnnotations = new ArrayList<Annotation>();
    List<Annotation> removedAnnotations = new ArrayList<Annotation>();

    for (AnnotatedEntity entity : getSelectionController().getSelection().getEntities()) {

      for (Annotation annotation : entity.getAnnotations()) {

        String matched = annotation.accept(matcher);

        if (!matched.isEmpty()) {
          if (target instanceof StringAnnotation) {
            createdAnnotations.add(((StringAnnotation) target).getInstance(matched));
            if (removeAnnotation) {
              removedAnnotations.add(annotation);
            }
          } else if (target.getClass().equals(Charge.class)) {
            Charge charge = (Charge) target.newInstance();
            charge.setValue(Double.parseDouble(matched));
            createdAnnotations.add(charge);
            if (removeAnnotation) {
              removedAnnotations.add(annotation);
            }
          }
        }
      }

      edit.addEdit(new AddAnnotationEdit(entity, createdAnnotations));
      for (Annotation a : removedAnnotations) {
        edit.addEdit(new RemoveAnnotationEdit(entity, a));
        entity.removeAnnotation(a);
      }
      entity.addAnnotations(createdAnnotations);
      createdAnnotations.clear();
      removedAnnotations.clear();
    }

    // inform the compound edit that we've finished editing
    edit.end();

    addEdit(edit);
  }
Example #4
0
 /** Die Methode schliest den dummy Compound falls es ein "Space oder Enter" gedrueckt wird */
 public void keyTyped(KeyEvent e) {
   char keyChar = e.getKeyChar();
   if (keyChar == ' ' || keyChar == '\n') {
     // Falls Req Req Compound schliessen und an
     // Req Manager uebergeben
     if (ReqOROpt) {
       if (myReqCompound.isInProgress()) {
         myReqCompound.end();
         myReqField.addEdit(myReqCompound);
       }
       // sonst Opt Compound schliessen und an
       // Opt Manager uebergeben
     } else {
       if (myOptCompound.isInProgress()) {
         myOptCompound.end();
         myOptField.addEdit(myOptCompound);
       }
     }
   }
 }
Example #5
0
 @Override
 public UndoableEdit updateTransform(JEnvironment env) {
   JDocumentViewer viewer = getDocument().getViewer();
   JRequest req = viewer.getCurrentRequest();
   CompoundEdit cEdit = new CompoundEdit();
   if (req.isAltDown
       && req.getSelectionMode() == req.GROUP_MODE
       && addingTransform.getType() == AffineTransform.TYPE_TRANSLATION) {
     cEdit.addEdit(new JDuplicateObjectEdit(viewer, this));
   }
   cEdit.addEdit(new JTransformImageObjectEdit(viewer, this, addingTransform));
   addingTransform = null;
   cEdit.end();
   return cEdit;
 }
Example #6
0
  public void endCompound() {
    if (DEBUG) System.out.println("ChangeManager.endCompound()");

    compoundEdit.end();

    if ((editToBeUndone() instanceof UndoableDesignerEdit) && compoundEdit.isSignificant()) {
      super.discardAllEdits();
    } else if ((editToBeUndone() instanceof UndoablePluginEditAbstact)
        && compoundEdit.isSignificant()) {
      super.discardAllEdits();
    }

    super.addEdit(compoundEdit);

    compoundEdit = null;

    fireStateChanged(new ChangeEvent(this));
  }
 @SuppressWarnings("unchecked")
 private static CompoundEdit reset(
     final ComputedTrajectorySet cts, final BroomPromptModel broom, final boolean outPosition) {
   final RockSet<Pos> ipos = cts.getInitialPos();
   final RockSet<Vel> ivel = cts.getInitialVel();
   // store the initial state:
   final PosMemento[] pm = new PosMemento[RockSet.ROCKS_PER_SET];
   for (int i16 = RockSet.ROCKS_PER_SET - 1; i16 >= 0; i16--)
     pm[i16] = new PosMemento(ipos, i16, ipos.getRock(i16).p());
   final IndexMemento bi = new IndexMemento(broom, broom.getIdx16());
   final HandleMemento bh = new HandleMemento(broom, broom.getOutTurn());
   final XYMemento bxy = new XYMemento(broom, broom.getBroom());
   final SplitMemento bs = new SplitMemento(broom, broom.getSplitTimeMillis().getValue());
   final boolean preS = cts.getSuspended();
   cts.setSuspended(true);
   try {
     // reset:
     RockSet.allZero(ivel);
     broom.setIdx16(-1);
     if (outPosition) RockSetUtils.allOut(ipos);
     else RockSetUtils.allHome(ipos);
     broom.setIdx16(1);
     broom.setBroom(new Point2D.Double(0, 0));
     broom.getSplitTimeMillis().setValue(3300);
   } finally {
     cts.setSuspended(preS);
   }
   // create a compound edit
   final CompoundEdit ce = new CompoundEdit();
   ce.addEdit(new UndoableMemento(new SuspendMemento(cts, preS), new SuspendMemento(cts, true)));
   for (int i16 = RockSet.ROCKS_PER_SET - 1; i16 >= 0; i16--)
     ce.addEdit(new UndoableMemento(pm[i16], new PosMemento(ipos, i16, ipos.getRock(i16).p())));
   ce.addEdit(new UndoableMemento(bi, new IndexMemento(broom, broom.getIdx16())));
   ce.addEdit(new UndoableMemento(bh, new HandleMemento(broom, broom.getOutTurn())));
   ce.addEdit(new UndoableMemento(bxy, new XYMemento(broom, broom.getBroom())));
   ce.addEdit(
       new UndoableMemento(bs, new SplitMemento(broom, broom.getSplitTimeMillis().getValue())));
   ce.addEdit(new UndoableMemento(new SuspendMemento(cts, true), new SuspendMemento(cts, preS)));
   ce.end();
   return ce;
 }