本文整理匯總了Java中javax.swing.undo.UndoManager.undo方法的典型用法代碼示例。如果您正苦於以下問題:Java UndoManager.undo方法的具體用法?Java UndoManager.undo怎麽用?Java UndoManager.undo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.undo.UndoManager
的用法示例。
在下文中一共展示了UndoManager.undo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
示例2: 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));
}
示例3: 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));
}
示例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: 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());
}
示例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: testUndoRemoveDSType
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void testUndoRemoveDSType() {
UndoManager manager = new UndoManager();
JDBCDataSourceType type = new JDBCDataSourceType();
pld.addDataSourceType(type);
pld.addUndoableEditListener(manager);
assertFalse(manager.canUndo());
assertEquals(1, pld.getDataSourceTypes().size());
pld.removeDataSourceType(type);
assertTrue(manager.canUndo());
assertTrue(pld.getDataSourceTypes().isEmpty());
manager.undo();
assertEquals(1, pld.getDataSourceTypes().size());
assertTrue(manager.canRedo());
assertEquals(type, pld.getDataSourceTypes().get(0));
}
示例8: onUndo
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void onUndo() {
if(undoManager.canUndo() && hasChanges) {
undoManager.undo();
} else {
// HACK need to call parent frames undo if we have no changes
CommonModuleFrame cmf = CommonModuleFrame.getCurrentFrame();
if(cmf == null) return;
final UndoManager cmfUndoManager = cmf.getExtension(UndoManager.class);
if(cmfUndoManager != null && cmfUndoManager.canUndo()) {
cmfUndoManager.undo();
// reset this flag - otherwise the group undo manager
// will attempt to undo with 'nothing' as last value
hasChanges = false;
}
}
}
示例9: actionPerformed
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent e)
{
Document doc = getTextComponent(e).getDocument();
UndoManager um = getUndoManagerForDocument(doc);
if(um != null)
{
try
{
um.undo();
}
catch (CannotUndoException ex)
{
System.out.println("Unable to undo: " + ex);
ex.printStackTrace();
}
updateUndo(doc);
}
}
示例10: testSimpleUndoRedo
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void testSimpleUndoRedo() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc);
doc.insertString(0, "abc\ndef\nghi\n", null);
ViewUpdatesTesting.setViewBounds(pane, 4, 8);
pane.modelToView(0);
doc.insertString(4, "o", null);
doc.remove(3, 3);
doc.insertString(4, "ab", null);
doc.remove(7, 2);
pane.modelToView(0);
undoManager.undo(); // insert(7,2)
undoManager.undo(); // remove(4,2)
undoManager.undo(); // insert(3,3)
undoManager.undo();
undoManager.redo();
undoManager.redo();
undoManager.redo();
undoManager.redo();
}
示例11: testLongLineUndo
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void testLongLineUndo() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc);
int lineLen = 4000;
StringBuilder sb = new StringBuilder(lineLen + 10);
for (int i = 0; i < lineLen; i++) {
sb.append('a');
}
sb.append('\n');
doc.insertString(0, sb.toString(), null);
pane.modelToView(0);
doc.remove(0, lineLen);
pane.modelToView(0);
undoManager.undo();
undoManager.redo();
}
示例12: testBehaviour
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void testBehaviour() throws Exception {
Document doc = new PlainDocument();
doc.insertString(0, "test hello world", null);
UndoManager undo = new UndoManager();
doc.addUndoableEditListener(undo);
Position pos = doc.createPosition(2);
doc.remove(0, 3);
assert (pos.getOffset() == 0);
undo.undo();
assert (pos.getOffset() == 2);
Position pos2 = doc.createPosition(5);
doc.remove(4, 2);
Position pos3 = doc.createPosition(4);
assertSame(pos2, pos3);
undo.undo();
assert (pos3.getOffset() == 5);
}
示例13: testUndoXsdImportChange
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void testUndoXsdImportChange() throws Exception {
WSDLModel model = Util.loadWSDLModel("resources/HotelReservationService2.wsdl");
UndoManager um = new UndoManager();
model.addUndoableEditListener(um);
WSDLSchema schema = model.getDefinitions().getTypes().getExtensibilityElements(WSDLSchema.class).get(0);
org.netbeans.modules.xml.schema.model.Import xsdImport =
schema.getSchemaModel().getSchema().getImports().iterator().next();
model.startTransaction();
xsdImport.setSchemaLocation("OTA_TravelItinerary.xsd");
model.endTransaction();
um.undo();
assertEquals("OTA_TravelItinerary2.xsd", xsdImport.getSchemaLocation());
}
示例14: testRollback
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void testRollback() throws Exception {
UndoManager um = new UndoManager();
schema.getModel().addUndoableEditListener(um);
GlobalElement stick = schema.getModel().getFactory().createGlobalElement();
stick.setName("stickAfterRollbackElement");
model.startTransaction();
schema.addElement(stick);
model.endTransaction();
GlobalElement ge = schema.getModel().getFactory().createGlobalElement();
ge.setName("newElement");
int initialCount = schema.getElements().size();
model.startTransaction();
schema.addElement(ge);
assertEquals(initialCount+1, schema.getElements().size());
String text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("newElement") > 0);
( (AbstractModel)model).rollbackTransaction();
text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("newElement") == -1);
assertEquals(initialCount, schema.getElements().size());
assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
um.undo();
text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("stickAfterRollbackElement") == -1);
um.redo();
text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
}
示例15: testDeleteRollback
import javax.swing.undo.UndoManager; //導入方法依賴的package包/類
public void testDeleteRollback() throws Exception {
UndoManager um = new UndoManager();
schema.getModel().addUndoableEditListener(um);
GlobalElement stick = schema.getModel().getFactory().createGlobalElement();
stick.setName("stickAfterRollbackElement");
model.startTransaction();
schema.addElement(stick);
model.endTransaction();
model.startTransaction();
ArrayList<GlobalComplexType> types = new ArrayList(schema.getComplexTypes());
ArrayList<GlobalElement> elements = new ArrayList(schema.getElements());
GlobalElement element = elements.get(0);
if(element.getName().equals("purchaseOrder")) {
schema.removeElement(element);
String text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("purchaseOrder")== -1);
( (AbstractModel)model).rollbackTransaction();
text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("purchaseOrder") > 0);
assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
um.undo();
text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("stickAfterRollbackElement") == -1);
um.redo();
text = (( AbstractDocumentModel)model).getAccess().getCurrentDocumentText();
assertTrue(text.indexOf("stickAfterRollbackElement") > 0);
}
}