本文整理汇总了Java中javax.swing.undo.UndoManager类的典型用法代码示例。如果您正苦于以下问题:Java UndoManager类的具体用法?Java UndoManager怎么用?Java UndoManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UndoManager类属于javax.swing.undo包,在下文中一共展示了UndoManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: flushUndoQueue
import javax.swing.undo.UndoManager; //导入依赖的package包/类
static void flushUndoQueue(Document d) {
SwingUtilities.invokeLater(() -> {
if (d == null) {
return;
}
for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
if (!(tc instanceof ConsoleEditor)) {
continue;
}
ConsoleEditor cake = (ConsoleEditor)tc;
if (cake.getEditorPane() == null) {
continue;
}
Document check = cake.getEditorPane().getDocument();
if (check != d) {
continue;
}
UndoRedo ur = tc.getUndoRedo();
if (ur instanceof UndoManager) {
((UndoManager)ur).discardAllEdits();
}
}});
}
示例2: undo
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public static void undo(Context context, final int count) throws Exception {
final Document doc = getDocument(context);
final UndoManager undoManager = (UndoManager) doc.getProperty(UndoManager.class);
logUndoRedoOp(context, "UNDO", count);
invoke(context, new Runnable() {
@Override
public void run() {
try {
int cnt = count;
while (undoManager.canUndo() && --cnt >= 0) {
undoManager.undo();
}
} catch (CannotUndoException e) {
throw new IllegalStateException(e);
}
}
});
logPostUndoRedoOp(context, count);
}
示例3: redo
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public static void redo(Context context, final int count) throws Exception {
final Document doc = getDocument(context);
final UndoManager undoManager = (UndoManager) doc.getProperty(UndoManager.class);
logUndoRedoOp(context, "REDO", count);
invoke(context, new Runnable() {
@Override
public void run() {
try {
int cnt = count;
while (undoManager.canRedo() && --cnt >= 0) {
undoManager.redo();
}
} catch (CannotRedoException e) {
throw new IllegalStateException(e);
}
}
});
logPostUndoRedoOp(context, count);
}
示例4: testCreateGlobalElementUndoRedo
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testCreateGlobalElementUndoRedo() throws Exception {
SchemaModel model = Util.loadSchemaModel("resources/Empty.xsd");
UndoManager ur = new UndoManager();
model.addUndoableEditListener(ur);
SchemaComponentFactory fact = model.getFactory();
GlobalElement ge = fact.createGlobalElement();
model.startTransaction();
model.getSchema().addElement(ge);
ge.setName("Foo"); // edit #1
LocalComplexType lct = fact.createLocalComplexType();
Sequence seq = fact.createSequence();
lct.setDefinition(seq);
ge.setInlineType(lct);
model.endTransaction();
assertEquals(1, model.getSchema().getElements().size());
ur.undo();
assertEquals(0, model.getSchema().getElements().size());
ur.redo();
ge = model.getSchema().getElements().iterator().next();
assertEquals("Foo", ge.getName());
assertNotNull(ge.getInlineType());
assertNotNull(((LocalComplexType)ge.getInlineType()).getDefinition());
}
示例5: testSetAttributeOnGlobalComplexTypeUndoRedo
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testSetAttributeOnGlobalComplexTypeUndoRedo() throws Exception {
SchemaModel model = Util.loadSchemaModel("resources/PurchaseOrder.xsd");
UndoManager ur = new UndoManager();
model.addUndoableEditListener(ur);
GlobalComplexType potype = model.getSchema().getComplexTypes().iterator().next();
assertEquals("PurchaseOrderType", potype.getName());
model.startTransaction();
potype.setAbstract(Boolean.TRUE);
model.endTransaction();
ur.undo();
assertNull(potype.getAttribute(SchemaAttributes.ABSTRACT));
ur.redo();
assertNotNull(potype.getAttribute(SchemaAttributes.ABSTRACT));
}
示例6: testSyncUndo
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testSyncUndo() throws Exception {
SchemaModel model = Util.loadSchemaModel(TEST_XSD);
UndoManager um = new UndoManager();
model.addUndoableEditListener(um);
GlobalComplexType gct = (GlobalComplexType)Util.findComponent(
model.getSchema(), "/schema/complexType[@name='PurchaseOrderType']");
assertEquals(3, gct.getDefinition().getChildren().size());
Util.setDocumentContentTo(model, "resources/PurchaseOrder_SyncUndo.xsd");
model.sync();
um.undo();
assertEquals(3, gct.getDefinition().getChildren().size());
um.redo();
assertEquals(2, gct.getDefinition().getChildren().size());
}
示例7: testSyncUndoRename
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testSyncUndoRename() throws Exception {
SchemaModel model = Util.loadSchemaModel(TEST_XSD);
UndoManager um = new UndoManager();
model.addUndoableEditListener(um);
assertEquals(2, model.getSchema().getElements().size());
Util.setDocumentContentTo(model, "resources/PurchaseOrder_SyncUndoRename.xsd");
model.sync();
assertEquals(2, model.getSchema().getElements().size());
assertEquals("purchaseOrder2", model.getSchema().getElements().iterator().next().getName());
um.undo();
assertEquals(2, model.getSchema().getElements().size());
assertEquals("purchaseOrder", model.getSchema().getElements().iterator().next().getName());
um.redo();
assertEquals(2, model.getSchema().getElements().size());
assertEquals("purchaseOrder2", model.getSchema().getElements().iterator().next().getName());
}
示例8: testMultipleMutationUndoRedo
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testMultipleMutationUndoRedo() throws Exception {
mModel = Util.loadModel("resources/Empty.xml");
UndoManager urListener = new UndoManager();
mModel.addUndoableEditListener(urListener);
//setup
mModel.startTransaction();
B b2 = new B(mModel, 2);
mModel.getRootComponent().addAfter(b2.getName(), b2, TestComponent3._A);
String v = "testComponentListener.b2";
b2.setValue(v);
mModel.endTransaction();
b2 = mModel.getRootComponent().getChild(B.class);
assertEquals(v, b2.getAttribute(TestAttribute3.VALUE));
urListener.undo();
b2 = mModel.getRootComponent().getChild(B.class);
assertNull(b2);
urListener.redo();
b2 = mModel.getRootComponent().getChild(B.class);
assertEquals(v, b2.getAttribute(TestAttribute3.VALUE));
}
示例9: testSyncUndoRedo
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testSyncUndoRedo() throws Exception {
defaultSetup();
UndoManager urListener = new UndoManager();
mModel.addUndoableEditListener(urListener);
assertEquals("setup: initial", 1, mModel.getRootComponent().getChildren(C.class).size());
Util.setDocumentContentTo(mDoc, "resources/test2.xml");
mModel.sync();
assertEquals("setup: sync", 0, mModel.getRootComponent().getChildren(C.class).size());
urListener.undo();
assertEquals("undo sync", 1, mModel.getRootComponent().getChildren(C.class).size());
urListener.redo();
assertEquals("undo sync", 0, mModel.getRootComponent().getChildren(C.class).size());
}
示例10: testUndoRedoWithIdentity
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testUndoRedoWithIdentity() throws Exception {
mModel = Util.loadModel("resources/test1_name.xml");
UndoManager ur = new UndoManager();
mModel.addUndoableEditListener(ur);
E e1 = mModel.getRootComponent().getChild(E.class);
assertNull(e1.getValue());
mModel.startTransaction();
String v = "new test value";
e1.setValue(v);
mModel.endTransaction();
assertEquals(v, e1.getValue());
ur.undo();
assertNull("expect null, get "+e1.getValue(), e1.getValue());
ur.redo();
assertEquals(v, e1.getValue());
}
示例11: testUndoRedoWithoutIdentity
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testUndoRedoWithoutIdentity() throws Exception {
mModel = Util.loadModel("resources/test1_noname.xml");
UndoManager ur = new UndoManager();
mModel.addUndoableEditListener(ur);
E e1 = mModel.getRootComponent().getChild(E.class);
assertNull(e1.getValue());
mModel.startTransaction();
String v = "new test value";
e1.setValue(v);
mModel.endTransaction();
assertEquals(v, e1.getValue());
ur.undo();
assertNull("expect null, get "+e1.getValue(), e1.getValue());
ur.redo();
assertEquals(v, e1.getValue());
}
示例12: testUndoRedoOnMutationFromEvent
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testUndoRedoOnMutationFromEvent() throws Exception {
defaultSetup();
mModel.addComponentListener(new Handler());
UndoManager um = new UndoManager();
mModel.addUndoableEditListener(um);
mModel.startTransaction();
mModel.getRootComponent().appendChild("test", new D(mModel, 2));
mModel.endTransaction();
um.undo();
D d = mModel.getRootComponent().getChild(D.class);
assertNull(d);
um.redo();
d = mModel.getRootComponent().getChild(D.class);
assertNotNull(d.getChild(B.class));
}
示例13: testUndoOnMutationFromSyncEvent
import javax.swing.undo.UndoManager; //导入依赖的package包/类
public void testUndoOnMutationFromSyncEvent() throws Exception {
defaultSetup();
mModel.addComponentListener(new Handler());
UndoManager um = new UndoManager();
mModel.addUndoableEditListener(um);
Util.setDocumentContentTo(mDoc, "resources/test1_2.xml");
mModel.sync();
D d = mModel.getRootComponent().getChild(D.class);
assertNotNull(d.getChild(B.class));
um.undo();
mModel.getAccess().flush(); // after fix for 83963 need manual flush after undo/redo
assertNull(mModel.getRootComponent().getChild(D.class));
mModel = Util.dumpAndReloadModel(mModel);
assertNull(mModel.getRootComponent().getChild(D.class));
}
示例14: addEditorPane
import javax.swing.undo.UndoManager; //导入依赖的package包/类
private void addEditorPane( JEditorPane pane, Icon icon, File file, boolean created, boolean focus ) {
final JComponent c = (pane.getUI() instanceof BaseTextUI) ?
Utilities.getEditorUI(pane).getExtComponent() : new JScrollPane( pane );
Document doc = pane.getDocument();
doc.addDocumentListener( new MarkingDocumentListener( c ) );
doc.putProperty( FILE, file );
doc.putProperty( CREATED, created ? Boolean.TRUE : Boolean.FALSE );
UndoManager um = new UndoManager();
doc.addUndoableEditListener( um );
doc.putProperty( BaseDocument.UNDO_MANAGER_PROP, um );
com2text.put( c, pane );
tabPane.addTab( file.getName(), icon, c, file.getAbsolutePath() );
if (focus) {
tabPane.setSelectedComponent( c );
pane.requestFocus();
}
}
示例15: setUndoRedoButtonsEnabled
import javax.swing.undo.UndoManager; //导入依赖的package包/类
/**
* Sets the undo and redo buttons enabled or not.
* Additionally the ToolTipText will be set.
*/
private void setUndoRedoButtonsEnabled() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
UndoManager undoManager = graphController.getNetworkModelAdapter().getUndoManager();
getJButtonUndo().setEnabled(undoManager.canUndo());
getJButtonUndo().setToolTipText(undoManager.getUndoPresentationName());
getJButtonRedo().setEnabled(undoManager.canRedo());
getJButtonRedo().setToolTipText(undoManager.getRedoPresentationName());
}
});
}