本文整理汇总了Java中javax.swing.undo.UndoableEdit.addEdit方法的典型用法代码示例。如果您正苦于以下问题:Java UndoableEdit.addEdit方法的具体用法?Java UndoableEdit.addEdit怎么用?Java UndoableEdit.addEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.undo.UndoableEdit
的用法示例。
在下文中一共展示了UndoableEdit.addEdit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addEdit
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
@Override
public boolean addEdit(UndoableEdit anEdit) {
if (!isInProgress()) {
return false;
} else {
UndoableEdit last = lastEdit();
// If this is the first subedit received, just add it.
// Otherwise, give the last one a chance to absorb the new
// one. If it won't, give the new one a chance to absorb
// the last one.
if (last == null) {
edits.add(anEdit);
}
else if (!last.addEdit(anEdit)) {
if (anEdit.replaceEdit(last)) {
edits.remove(edits.size()-1);
}
edits.add(anEdit);
}
return true;
}
}
示例2: addEdit
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
@Override
public boolean addEdit(UndoableEdit anEdit) {
if (! isInProgress()) return false;
UndoableEdit last = lastEdit();
if (last == null) {
return super.addEdit(anEdit);
} else {
if (! last.addEdit(anEdit)) {
return super.addEdit(anEdit);
} else {
return true;
}
}
}
示例3: resetMods
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
/**
* Reset modifications and start new accounting.
* @param compoundEdit compound edit to add the resulting edit to. When null no adding is done.
*/
public void resetMods(UndoableEdit compoundEdit) {
ResetModsEdit edit = new ResetModsEdit();
if (compoundEdit != null) {
compoundEdit.addEdit(edit);
}
edit.run();
}
示例4: addModElement
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
private ModElement addModElement(UndoableEdit compoundEdit, int startOffset, int endOffset) {
ModElement modElement = new ModElement(this, startOffset, endOffset);
lastModElementIndex = findModElementIndex(startOffset, true);
AddModElementEdit edit = new AddModElementEdit(lastModElementIndex, modElement);
edit.run();
compoundEdit.addEdit(edit);
return modElement;
}
示例5: insertUpdate
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
public void insertUpdate(DocumentEvent evt, UndoableEdit edit, AttributeSet attr) {
int insertOffset = evt.getOffset();
int insertEndOffset = insertOffset + evt.getLength();
CharSequence text = DocumentUtilities.getText(doc);
if (insertOffset > 0) { // [Swing] marks (and elements) at offset zero do not move up
insertOffset--;
}
try {
int index = -1; // Index of the elements modification - computed lazily
List<LineElement> addedLines = null; // Collected added lines
LineElement removedLine = null; // Removed line element
Position lastAddedLineEndPos = null;
for (int offset = insertOffset; offset < insertEndOffset; offset++) {
if (text.charAt(offset) == '\n') {
if (index == -1) { // Not computed yet
index = getElementIndex(offset);
removedLine = (LineElement)getElement(index);
lastAddedLineEndPos = removedLine.getStartPosition();
addedLines = new ArrayList<LineElement>(2);
}
Position lineEndPos = doc.createPosition(offset + 1);
addedLines.add(new LineElement(this, lastAddedLineEndPos, lineEndPos));
lastAddedLineEndPos = lineEndPos;
}
}
if (index != -1) { // Some lines were added
// If the text was inserted at the line boundary i.e. right after existing '\n'
// and the ending char of the inserted text was not '\n' (otherwise
// it would be a "clean" line insert) then there must be two line elements
// removed.
Position removedLineEndPos = removedLine.getEndPosition();
int removedLineEndOffset = removedLineEndPos.getOffset();
Element[] removed; // removed line elements
int lastAddedLineEndOffset = lastAddedLineEndPos.getOffset();
if (insertEndOffset == removedLineEndOffset
&& lastAddedLineEndOffset != removedLineEndOffset
// && index + 1 < getElementCount()
) {
LineElement removedLine2 = (LineElement)getElement(index + 1);
removed = new Element[] { removedLine, removedLine2 };
removedLineEndPos = removedLine2.getEndPosition();
removedLineEndOffset = removedLineEndPos.getOffset();
} else { // just one line removed
removed = new Element[] { removedLine };
}
if (lastAddedLineEndOffset < removedLineEndOffset) {
addedLines.add(new LineElement(this, lastAddedLineEndPos, removedLineEndPos));
}
Element[] added = new Element[addedLines.size()];
addedLines.toArray(added);
edit.addEdit(new Edit(index, removed, added));
replace(index, removed.length, added);
}
} catch (BadLocationException e) {
throw new IllegalStateException(e.toString());
}
}
示例6: removeUpdate
import javax.swing.undo.UndoableEdit; //导入方法依赖的package包/类
public void removeUpdate(DocumentEvent evt, UndoableEdit edit2) {
UndoableEdit edit = legacyRemoveUpdate(evt);
if (edit != null) {
edit2.addEdit(edit);
}
}