Java Code Examples for javax.swing.text.AbstractDocument#DefaultDocumentEvent
The following examples show how to use
javax.swing.text.AbstractDocument#DefaultDocumentEvent .
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: CompoundUndoManager.java From jeveassets with GNU General Public License v2.0 | 5 votes |
@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 2
Source File: SquirrelDefaultUndoManager.java From bigtable-sql with Apache License 2.0 | 5 votes |
/** * The same as super.editToBeUndone() just that we treat DocumentEvent.EventType.CHANGE * the same way as true == edit.isSignificant(). */ protected UndoableEdit editToBeUndone() { UndoableEdit ue = super.editToBeUndone(); if (ue == null) { return null; } int i = edits.indexOf(ue); while (i >= 0) { UndoableEdit edit = edits.elementAt(i--); if (edit.isSignificant()) { if (edit instanceof AbstractDocument.DefaultDocumentEvent) { if (DocumentEvent.EventType.CHANGE != ((AbstractDocument.DefaultDocumentEvent)edit).getType()) { return edit; } } else { return edit; } } } return null; }
Example 3
Source File: SquirrelDefaultUndoManager.java From bigtable-sql with Apache License 2.0 | 5 votes |
/** * The same as super.editToBeUndone() just that we treat DocumentEvent.EventType.CHANGE * the same way as true == edit.isSignificant(). * * The method of the super class already seems to be a bit buggy. * The DocumentEvent.EventType.CHANGE fix doesn't remove the bugs but makes it behave */ protected UndoableEdit editToBeRedone() { int count = edits.size(); UndoableEdit ue = super.editToBeRedone(); if (null == ue) { return null; } int i = edits.indexOf(ue); while (i < count) { UndoableEdit edit = edits.elementAt(i++); if (edit.isSignificant()) { if (edit instanceof AbstractDocument.DefaultDocumentEvent) { if (DocumentEvent.EventType.CHANGE != ((AbstractDocument.DefaultDocumentEvent)edit).getType()) { return edit; } } else { return edit; } } } return null; }
Example 4
Source File: ROCEditorListener.java From RipplePower with Apache License 2.0 | 5 votes |
@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 5
Source File: EditorUndoManager.java From SikuliX1 with MIT License | 4 votes |
@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 6
Source File: CompoundUndoMan.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
/** * 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(); }