Java Code Examples for javax.swing.event.UndoableEditEvent#getEdit()

The following examples show how to use javax.swing.event.UndoableEditEvent#getEdit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BezierLinerEditHandler.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent evt) {
  if (!(evt.getEdit() instanceof BezierLinerEdit)) {
    return;
  }
  BezierFigure owner = ((BezierLinerEdit) evt.getEdit()).getOwner();
  if (!(owner instanceof PathConnection)) {
    return;
  }

  PathConnection path = (PathConnection) owner;
  path.updateControlPoints();
  PathModel pathModel = path.getModel();
  pathModel.getPropertyPathControlPoints().markChanged();
  pathModel.propertiesChanged(path);
}
 
Example 2
Source File: TextUndoManager.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void undoableEditHappened(UndoableEditEvent uee) {
    UndoableEdit edit = uee.getEdit();
    boolean undoable = canUndo();

    long editTime = System.currentTimeMillis();

    if (firstModified == 0 ||
            editTime - compoundEdit.editedTime() > 700) {
        compoundEdit.end();
        compoundEdit = new StructuredEdit();
    }
    compoundEdit.addEdit(edit);

    firstModified = firstModified == 0 ?
            compoundEdit.editedTime() : firstModified;

    if (lastEdit() != compoundEdit) {
        boolean changed = hasChanged();
        addEdit(compoundEdit);
        firePropertyChangeEvent(UndoManager.UndoName, undoable, canUndo());
    }

}
 
Example 3
Source File: UndoRedoSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
    if (edit == null) {
        startNewEdit(e.getEdit());
        processDocumentChange();
        return;
    }
    //AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) e.getEdit();
    UndoableEdit event = e.getEdit();
    if (event instanceof DocumentEvent) {
        if (((DocumentEvent)event).getType().equals(DocumentEvent.EventType.CHANGE)) {
            edit.addEdit(e.getEdit());
            return;
        }
    }
    int offsetChange = component.getCaretPosition() - lastOffset;
    int lengthChange = component.getDocument().getLength() - lastLength;

    if (Math.abs(offsetChange) == 1 && Math.abs(lengthChange) == 1) {
        lastOffset = component.getCaretPosition();
        lastLength = component.getDocument().getLength();
        addEdit(e.getEdit());
        processDocumentChange();
    } else {
        // last change consists of multiple chars, start new compound edit
        startNewEdit(e.getEdit());
    }
}
 
Example 4
Source File: CompoundUndoManager.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
	//  Start a new compound edit

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

	int offsetChange = textComponent.getCaretPosition() - lastOffset;
	int lengthChange = textComponent.getDocument().getLength() - lastLength;

	//  Check for an attribute change
	UndoableEdit edit = e.getEdit();
	if (edit instanceof AbstractDocument.DefaultDocumentEvent) {
		AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) e.getEdit();
		if (event.getType().equals(DocumentEvent.EventType.CHANGE)) {
			if (offsetChange == 0) {
				compoundEdit.addEdit(e.getEdit());
				return;
			}
		}
	}

	//  Check for an incremental edit or backspace.
	//  The Change in Caret position and Document length should both be
	//  either 1 or -1.
	if (offsetChange == lengthChange
			&& Math.abs(offsetChange) == 1) {
		compoundEdit.addEdit(e.getEdit());
		lastOffset = textComponent.getCaretPosition();
		lastLength = textComponent.getDocument().getLength();
		return;
	}

	//  Not incremental edit, end previous edit and start a new one
	compoundEdit.end();
	compoundEdit = startCompoundEdit(e.getEdit());
}
 
Example 5
Source File: ROCEditorListener.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent ev) {
	UndoableEdit edit = ev.getEdit();
	if (edit instanceof AbstractDocument.DefaultDocumentEvent && ((AbstractDocument.DefaultDocumentEvent) edit)
			.getType() == AbstractDocument.DefaultDocumentEvent.EventType.CHANGE) {
		return;
	}
	manager.addEdit(edit);
}
 
Example 6
Source File: RepeatMenuItem.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
    PixelitorEdit edit = (PixelitorEdit) e.getEdit();

    if (edit == null) { // happens when all images are closed
        setEnabled(false);
        getAction().putValue(Action.NAME, "Repeat");
        return;
    }

    setEnabled(edit.canRepeat());
    getAction().putValue(Action.NAME, "Repeat " + edit.getPresentationName());
}
 
Example 7
Source File: Contains.java    From PIPE with MIT License 5 votes vote down vote up
@Override
public boolean matches(Object argument) {
    UndoableEditEvent event = (UndoableEditEvent) argument;
    UndoableEdit edit = event.getEdit();

    return edit.equals(expectedEdit);
}
 
Example 8
Source File: EditorUndoManager.java    From SikuliX1 with MIT License 4 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
   UndoableEdit edit=e.getEdit();
   if (edit instanceof AbstractDocument.DefaultDocumentEvent) {
      AbstractDocument.DefaultDocumentEvent event=(AbstractDocument.DefaultDocumentEvent)edit;
      int start=event.getOffset();
      int len=event.getLength();
      Debug.log(9, "undoableEditHappened " + start + "," + len);
      boolean isNeedStart=false;
      if(event.getType().equals(DocumentEvent.EventType.CHANGE) ||
         event.getType().equals(DocumentEvent.EventType.INSERT) ){
         try {
            String text=event.getDocument().getText(start, len);
            if (text.contains("\n"))
               isNeedStart=true;
         } catch (BadLocationException e1) {
           Debug.error(me + "undoableEditHappened: Problem getting text\n%s", e1.getMessage());
         }
      }

      if (current==null) {
         isNeedStart=true;
      }
      else if (lastEditName==null || !lastEditName.equals(edit.getPresentationName())) {
         isNeedStart=true;
      }

      while (pointer<edits.size()-1) {
         edits.remove(edits.size()-1);
         isNeedStart=true;
      }
      if (isNeedStart) {
         createCompoundEdit();
      }

      current.addEdit(edit);
      lastEditName=edit.getPresentationName();

      refreshControls();
   }
}
 
Example 9
Source File: CompoundUndoMan.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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

    if (compoundEdit == null) {
        compoundEdit = startCompoundEdit(e.getEdit());
        startCombine = false;
        updateDirty();
        return;
    }
    if (e.getEdit() instanceof DefaultDocumentEvent) {
        // Java 6 to 8
        AbstractDocument.DefaultDocumentEvent docEvt = (DefaultDocumentEvent) e.getEdit();

        int editLine = doc.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;

    } else // Java 9: It seems that all the edits are wrapped and we cannot get line number!
    // See https://github.com/netroby/jdk9-dev/blob/master/jdk/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java#L279
    // AbstractDocument.DefaultDocumentEventUndoableWrapper docEvt = e.getEdit();
    {
        if (startCombine && !e.getEdit().isSignificant()) {
            compoundEdit.addEdit(e.getEdit());
            startCombine = false;
            updateDirty();
            return;
        }
    }

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

    updateDirty();
}