List of usage examples for javax.swing.text AbstractDocument.DefaultDocumentEvent getLength
public int getLength()
From source file:net.pandoragames.far.ui.swing.component.UndoHistory.java
private String stringValue(UndoableEdit edit) { if (edit instanceof AbstractDocument.DefaultDocumentEvent) { AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) edit; String change = null;/*from ww w.j a v a 2 s. co m*/ if (event.getType() == DocumentEvent.EventType.REMOVE) { change = "DEL"; } else { try { change = event.getDocument().getText(event.getOffset(), event.getLength()); if (event.getType() == DocumentEvent.EventType.CHANGE) change = change + " (c)"; } catch (BadLocationException blx) { change = "EXC: " + blx.getMessage(); } } return change; } else { return edit.getPresentationName(); } }
From source file:org.executequery.gui.text.TextUndoManager.java
public void undoableEditHappened(UndoableEditEvent undoableEditEvent) { UndoableEdit edit = undoableEditEvent.getEdit(); AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) edit; EventType eventType = event.getType(); if (eventType == EventType.INSERT) { try {//from w w w . j a v a2 s. com if (addNextInsert) { add(); } compoundEdit.addEdit(edit); int start = event.getOffset(); int length = event.getLength(); String text = event.getDocument().getText(start, length); if (StringUtils.endsWithAny(text, WHITESPACE)) { addNextInsert = true; } } catch (BadLocationException e) { Log.debug(e); } } else if (eventType == EventType.REMOVE) { add(); compoundEdit.addEdit(edit); add(); } else if (eventType == EventType.CHANGE) { compoundEdit.addEdit(edit); } redoCommand.setEnabled(false); undoCommand.setEnabled(true); }