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


Java UndoableEdit类代码示例

本文整理汇总了Java中javax.swing.undo.UndoableEdit的典型用法代码示例。如果您正苦于以下问题:Java UndoableEdit类的具体用法?Java UndoableEdit怎么用?Java UndoableEdit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UndoableEdit类属于javax.swing.undo包,在下文中一共展示了UndoableEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addEdit

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Override
public boolean addEdit(UndoableEdit anEdit) {
    if (super.addEdit(anEdit)) {
        if (mergeEditIndex >= MERGE_INDEX_NOT_INITIALIZED) { // Valid or not inited
            if (anEdit instanceof BaseDocumentEvent) {
                mergeEditIndex = size() - 1;
            } else if (anEdit.getClass() != BaseDocument.AtomicCompoundEdit.class &&
                !CaretUndo.isCaretUndoEdit(anEdit)
            ) {
                mergeEditIndex = MERGE_PROHIBITED; // Do not allow merging if there are unknown undoable edits
            }
        }
        return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:BaseDocument.java

示例2: replaceEdit

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
/** Try to determine whether this event can replace the old one.
* This is used to batch the one-letter modifications into larger
* parts (words) and undoing/redoing them at once.
* This method returns true whether 
*/
public @Override boolean replaceEdit(UndoableEdit anEdit) {
    BaseDocument doc = (BaseDocument)getDocument();
    if (anEdit instanceof BaseDocument.AtomicCompoundEdit) {
        BaseDocument.AtomicCompoundEdit compEdit
                = (BaseDocument.AtomicCompoundEdit)anEdit;

        BaseDocumentEvent aMergeEdit = compEdit.getMergeEdit();
        if (!doc.undoMergeReset && aMergeEdit != null) {
            if (canMerge(aMergeEdit)) {
                previous = anEdit;
                return true;
            }
        }
    } else if (anEdit instanceof BaseDocumentEvent) {
        BaseDocumentEvent evt = (BaseDocumentEvent)anEdit;

        if (!doc.undoMergeReset && canMerge(evt)) {
            previous = anEdit;
            return true;
        }
    }
    doc.undoMergeReset = false;
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:BaseDocumentEvent.java

示例3: die

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
public @Override void die() {
       // Super of die()
int size = edits.size();
for (int i = size-1; i >= 0; i--)
{
    UndoableEdit e = (UndoableEdit)edits.elementAt(i);
    e.die();
}

       alive2 = false;
       // End super of die()
       
       if (previous != null) {
           previous.die();
           previous = null;
       }
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:BaseDocumentEvent.java

示例4: testWrapping

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
public void testWrapping() throws Exception {
        MimePath mimePath = MimePath.EMPTY;
        MockMimeLookup.setInstances(mimePath, new TestingUndoableEditWrapper(), new TestingUndoableEditWrapper2());
        CESEnv env = new CESEnv();
        Document doc = env.support.openDocument();
//        doc.addUndoableEditListener(new UndoableEditListener() {
//            @Override
//            public void undoableEditHappened(UndoableEditEvent e) {
//                UndoableEdit edit = e.getEdit();
//            }
//        });
        doc.insertString(0, "Test", null);
        Class wrapEditClass = TestingUndoableEditWrapper.WrapCompoundEdit.class;
        assertNotNull(NbDocument.getEditToBeUndoneOfType(env.support, wrapEditClass));
        Class wrapEditClass2 = TestingUndoableEditWrapper2.WrapCompoundEdit2.class;
        assertNotNull(NbDocument.getEditToBeUndoneOfType(env.support, wrapEditClass2));
        
        // A trick to get whole edit
        UndoableEdit wholeEdit = NbDocument.getEditToBeUndoneOfType(env.support, UndoableEdit.class);
        assertTrue(wholeEdit instanceof List);
        @SuppressWarnings("unchecked")
        List<? extends UndoableEdit> listEdit = (List<? extends UndoableEdit>) wholeEdit;
        assertEquals(3, listEdit.size());
        assertEquals(wrapEditClass, listEdit.get(1).getClass());
        assertEquals(wrapEditClass2, listEdit.get(2).getClass());
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:UndoableEditWrapperTest.java

示例5: testAddCaretUndoableEdit

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Test
public void testAddCaretUndoableEdit() throws Exception {
    final JEditorPane pane = new JEditorPane("text/plain", "Haf");
    //final CompoundEdit compoundEdit = new CompoundEdit();
    final boolean[] editAdded = { false };
    final Document doc = pane.getDocument();
    doc.putProperty(CustomUndoDocument.class, new CustomUndoDocument() {
        @Override
        public void addUndoableEdit(UndoableEdit edit) {
            editAdded[0] = true;
        }
    });
    final EditorCaret editorCaret = new EditorCaret();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            pane.setCaret(editorCaret);
            EditorUtilities.addCaretUndoableEdit(doc, editorCaret);
        }
    });
    
    assertTrue(editAdded[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:EditorUtilitiesTest.java

示例6: getUndoPresentationName

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Override
   public String getUndoPresentationName() {
UndoableEdit last = lastEdit();
if (last != null) {
    return last.getUndoPresentationName();
} else {
           String name = getPresentationName();
           if (!"".equals(name)) {
               name = UIManager.getString("AbstractUndoableEdit.undoText")
                       + " " + name;
           } else {
               name = UIManager.getString("AbstractUndoableEdit.undoText");
           }

           return name;
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:StableCompoundEdit.java

示例7: getRedoPresentationName

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Override
   public String getRedoPresentationName() {
UndoableEdit last = lastEdit();
if (last != null) {
    return last.getRedoPresentationName();
} else {
           String name = getPresentationName();
           if (!"".equals(name)) {
               name = UIManager.getString("AbstractUndoableEdit.redoText")
                       + " " + name;
           } else {
               name = UIManager.getString("AbstractUndoableEdit.redoText");
           }

           return name;
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:StableCompoundEdit.java

示例8: getEditToBeUndoneRedoneOfType

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
private static <T extends UndoableEdit> T getEditToBeUndoneRedoneOfType(EditorCookie ec, Class<T> type, boolean redone) {
    UndoRedo ur;
    if (ec instanceof CloneableEditorSupport &&
            ((ur = ((CloneableEditorSupport)ec).getUndoRedo()) instanceof UndoRedoManager))
    {
        UndoRedoManager urManager = (UndoRedoManager) ur;
        UndoableEdit edit = urManager.editToBeUndoneRedone(redone);
        if (type.isInstance(edit)) {
            return type.cast(edit);
        } else if (edit instanceof List) {
            @SuppressWarnings("unchecked")
            List<UndoableEdit> listEdit = (List<UndoableEdit>) edit;
            for (int i = listEdit.size() -1; i >= 0; i--) { // Go from most wrapped back
                edit = listEdit.get(i);
                if (type.isInstance(edit)) {
                    @SuppressWarnings("unchecked") T inst = (T) edit;
                    return inst;
                }
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:NbDocument.java

示例9: wrap

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Override
public UndoableEdit wrap(UndoableEdit ed, Document doc) {
    if (!active.get()) {
        return ed;
    }
    if (doc.getProperty(BaseDocument.StreamDescriptionProperty) == null) {
        //no dataobject
        return ed;
    }
    UndoableEditDelegate current = new UndoableEditDelegate(ed, (BaseDocument) doc, performer);
    UndoableEditDelegate first = docToFirst.get(doc);
    if (first == null) {
        docToFirst.put((BaseDocument) doc, current);
    }
    return current;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:InstantRefactoringPerformer.java

示例10: 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

示例11: getUndoPresentationName

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Override
   public String getUndoPresentationName() {
UndoableEdit last = lastEdit();
if (last != null) {
    return last.getUndoPresentationName();
} else {
           String name = getPresentationName();
           if (!"".equals(name)) {
               name = NbBundle.getMessage(ContentEdit.class, "AbstractUndoableEdit.undoText.param", name); // NOI18N
           } else {
               name = NbBundle.getMessage(ContentEdit.class, "AbstractUndoableEdit.undoText"); // NOI18N
           }

           return name;
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:StableCompoundEdit.java

示例12: getRedoPresentationName

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Override
   public String getRedoPresentationName() {
UndoableEdit last = lastEdit();
if (last != null) {
    return last.getRedoPresentationName();
} else {
           String name = getPresentationName();
           if (!"".equals(name)) {
               name = NbBundle.getMessage(ContentEdit.class, "AbstractUndoableEdit.redoText.param", name); // NOI18N
           } else {
               name = NbBundle.getMessage(ContentEdit.class, "AbstractUndoableEdit.redoText"); // NOI18N
           }

           return name;
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:StableCompoundEdit.java

示例13: addEdit

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
@Override
public boolean addEdit(UndoableEdit edit) {
	if ((lastEdit() != null) && lastEdit().equals(edit)) {
		return false;
	} else {
		return super.addEdit(edit);
	}
}
 
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:9,代码来源:PdfJumbler.java

示例14: addEdit

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
private void addEdit(UndoableEdit edit) {
	if (compoundEdits.isEmpty()) {
		UndoableEditEvent editEvent = new UndoableEditEvent(getMainList(), edit);
		for (UndoableEditListener l : editListeners) {
			l.undoableEditHappened(editEvent);
		}
	} else {
		compoundEdits.peek().addEdit(edit);
	}
}
 
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:11,代码来源:UndoableList.java

示例15: main

import javax.swing.undo.UndoableEdit; //导入依赖的package包/类
public static void main(String[] args) {
	final LinkedList<UndoableEdit> edits = new LinkedList<UndoableEdit>();
	UndoableEditListener editListener = new UndoableEditListener() {
		@Override
		public void undoableEditHappened(UndoableEditEvent e) {
			System.out.println(e.getEdit());
			edits.addFirst(e.getEdit());
		}
	};
	
	UndoableList<Integer> list = new UndoableList<Integer>(new LinkedList<Integer>());
	list.addUndoableEditListener(editListener);
	for (int i = 1; i < 10; i++) {
		list.add(2*i);
	}
	System.out.println(list);
	list.add(6, 13);
	System.out.println(list);
	list.set(3, 7);
	System.out.println(list);
	
	List<Integer> subList = list.subList(3, 6);
	System.out.println(subList);
	subList.set(0, 8);
	System.out.println(list);
	System.out.println(subList);
	subList.remove(1);
	
	System.out.println("----------------------------------");
	for (UndoableEdit edit : edits) {
		System.out.println("Undo " + edit);
		edit.undo();
		System.out.println(list);
	}
}
 
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:36,代码来源:UndoableList.java


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