当前位置: 首页>>代码示例>>Java>>正文


Java UndoableEdit.addEdit方法代码示例

本文整理汇总了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;
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:StableCompoundEdit.java

示例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;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:AbstractModel.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ModRootElement.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ModRootElement.java

示例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());
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:60,代码来源:LineRootElement.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:LineRootElement.java


注:本文中的javax.swing.undo.UndoableEdit.addEdit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。