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(); }
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(); }
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); }
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(); } }}); }
public void testSetTypes() throws Exception { UndoManager um = new UndoManager(); WSDLModel model = TestCatalogModel.getDefault().getWSDLModel(NamespaceLocation.ECHOCONCAT); model.addUndoableEditListener(um); TestComponentListener cl = new TestComponentListener(); PropertyListener pl = new PropertyListener(); model.addComponentListener(cl); model.addPropertyChangeListener(pl); Definitions d = model.getDefinitions(); int childCount = d.getChildren().size(); Types types = d.getTypes(); assertNotNull(types); model.startTransaction(); d.setTypes(null); model.endTransaction(); cl.assertEvent(ComponentEvent.EventType.CHILD_REMOVED, d); pl.assertEvent(Definitions.TYPES_PROPERTY, types, null); um.undo(); assertEquals(childCount, d.getChildren().size()); um.redo(); assertEquals(childCount-1, d.getChildren().size()); }
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); }
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); }
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()); }
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)); }
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()); }
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()); }
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)); }
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()); }
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()); }
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()); }
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)); }
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)); }
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(); } }
/** * 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()); } }); }
public void run() { Display display = Display.getDefault(); Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT); Shell shell = getParentShell(); shell.setCursor(waitCursor); try { ProjectExplorerView explorerView = getProjectExplorerView(); if (explorerView != null) { UndoManager undoManager = explorerView.getUndoManager(); undoManager.redo(); } } catch (Throwable e) { ConvertigoPlugin.logException(e, "Unable to redo the last action."); } finally { shell.setCursor(null); waitCursor.dispose(); } }
public void run() { Display display = Display.getDefault(); Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT); Shell shell = getParentShell(); shell.setCursor(waitCursor); try { ProjectExplorerView explorerView = getProjectExplorerView(); if (explorerView != null) { UndoManager undoManager = explorerView.getUndoManager(); undoManager.undo(); } } catch (Throwable e) { ConvertigoPlugin.logException(e, "Unable to undo the last action."); } finally { shell.setCursor(null); waitCursor.dispose(); } }
public XMap(Object app, Projection proj, BufferedImage image) { this.app = app; this.proj = proj; this.image = image; width = image.getWidth(); height = image.getHeight(); overlays = new Vector(); overlayAlphas = new HashMap<Overlay, Float>(); mapInsets = null; zoom = 1d; rotation = 0; try { CylindricalProjection p = (CylindricalProjection) proj; wrap = Math.rint(360.*(p.getX(10.)-p.getX(9.))); } catch (ClassCastException ex) { wrap = -1.; } // GMA 1.6.4: Add mouse motion listener to perform pan, mouse listener to perform center addMouseMotionListener(this); addMouseListener(this); undoManager = new UndoManager(); undoManager.setLimit(8); zoomActionTrack.getDocument().addUndoableEditListener(undoManager); }
public XMap(Object app, Projection proj, int width, int height) { this.app = app; this.proj = proj; this.width = width; this.height = height; overlays = new Vector(); overlayAlphas = new HashMap<Overlay, Float>(); mapInsets = null; zoom = 1d; setLayout( null ); // addMapInset( new haxby.image.Logo(this) ); try { CylindricalProjection p = (CylindricalProjection) proj; wrap = Math.rint(360.*(p.getX(10.)-p.getX(9.))); } catch (ClassCastException ex) { wrap = -1.; } // GMA 1.6.4: Add mouse motion listener to perform pan, mouse listener to perform center addMouseMotionListener(this); addMouseListener(this); addKeyListener(this); undoManager = new UndoManager(); undoManager.setLimit(8); zoomActionTrack.getDocument().addUndoableEditListener(undoManager); }
/** Creates a new instance of XMLEditorPane */ public XMLTextEditor() { super(); XMLEditorKit kit = new XMLEditorKit(); setEditorKitForContentType(XMLEditorKit.XML_MIME_TYPE, kit); setContentType(XMLEditorKit.XML_MIME_TYPE); setBackground(Color.white); //setFont(new Font("Monospaced", Font.PLAIN, 12)); // add undoable edit undoManager = new UndoManager(); UndoableEditListener undoableEditHandler = new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); } }; getDocument().addUndoableEditListener(undoableEditHandler); }
/** Creates a new instance of GUIPepaModelEditor */ public GUIPepaModelEditor(GUIMultiModelHandler handler) { editor = new JEditorPane(); PepaEditorKit kit = new PepaEditorKit(); editor.setEditorKitForContentType("text/pepa", kit); editor.setContentType("text/pepa"); undoManager = new UndoManager(); undoManager.setLimit(200); //editor.setForeground(FOREGROUND_COLOR); this.handler = handler; d = (PlainDocument)editor.getDocument(); editor.getDocument().addDocumentListener(this); initComponents(); }
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)); }
private void formWindowOpened(java.awt.event.WindowEvent evt) { // TODO add your handling code here: //_mapView.setLockViewUpdate(true); //_mapDocument.setIsLayoutView(false); //_mapView.setIsLayoutMap(false); this._mapLayout.setLockViewUpdate(true); _mapView.zoomToExtent(_mapView.getViewExtent()); //_mapView.setLockViewUpdate(false); this.zoomUndoManager = new UndoManager(); //Open MeteoData form _frmMeteoData = new FrmMeteoData(this, false); //_frmMeteoData.setSize(500, 280); _frmMeteoData.setLocation(this.getX() + 10, this.getY() + this.getHeight() - _frmMeteoData.getHeight() - 40); _frmMeteoData.setVisible(this._options.isShowStartMeteoDataDlg()); // if (this._options.isShowStartMeteoDataDlg()) { // _frmMeteoData = new FrmMeteoData(this, false); // //_frmMeteoData.setSize(500, 280); // _frmMeteoData.setLocation(this.getX() + 10, this.getY() + this.getHeight() - _frmMeteoData.getHeight() - 40); // _frmMeteoData.setVisible(this._options.isShowStartMeteoDataDlg()); // } }
public void undo() throws javax.swing.undo.CannotUndoException { compoundEdit.end(); UndoableEdit edit = editToBeUndone(); if (((StructuredEdit) editToBeUndone()).editedTime() == firstModified) { firstModified = 0; } else if (firstModified == 0) { firstModified = ((StructuredEdit) editToBeUndone()).editedTime(); } boolean redoable = canRedo(); boolean changed = hasChanged(); super.undo(); firePropertyChangeEvent(UndoManager.RedoName, redoable, canRedo()); }
public void undoableEditHappened(UndoableEditEvent uee) { UndoableEdit edit = uee.getEdit(); boolean undoable = canUndo(); long editTime = System.currentTimeMillis(); if (firstModified == 0 || editTime - compoundEdit.editedTime() > 700) { compoundEdit.end(); compoundEdit = new StructuredEdit(); } compoundEdit.addEdit(edit); firstModified = firstModified == 0 ? compoundEdit.editedTime() : firstModified; if (lastEdit() != compoundEdit) { boolean changed = hasChanged(); addEdit(compoundEdit); firePropertyChangeEvent(UndoManager.UndoName, undoable, canUndo()); } }
private SourceCodeEditor createSourceEditor() { SourceCodeEditor ed = new SourceCodeEditor(); SyntaxDocument doc = new SyntaxDocument(); doc.setSyntax(SyntaxFactory.getSyntax("html")); CompoundUndoManager cuh = new CompoundUndoManager(doc, new UndoManager()); doc.addUndoableEditListener(cuh); doc.setDocumentFilter(new IndentationFilter()); doc.addDocumentListener(textChangedHandler); ed.setDocument(doc); ed.addFocusListener(focusHandler); ed.addCaretListener(caretHandler); ed.addMouseListener(popupHandler); return ed; }
private JEditorPane createWysiwygEditor() { JEditorPane ed = new JEditorPane(); ed.setEditorKitForContentType("text/html", new WysiwygHTMLEditorKit()); ed.setContentType("text/html"); insertHTML(ed, "<p></p>", 0); ed.addCaretListener(caretHandler); ed.addFocusListener(focusHandler); // spell checker, must be before the popup handler Preference pref = PrefUtil.get(PreferenceKey.SPELLING, Spelling.none.toString()); Spelling spelling = Spelling.valueOf(pref.getStringValue()); if (Spelling.none != spelling) SpellChecker.register(ed); ed.addMouseListener(popupHandler); HTMLDocument document = (HTMLDocument) ed.getDocument(); CompoundUndoManager cuh = new CompoundUndoManager(document, new UndoManager()); document.addUndoableEditListener(cuh); document.addDocumentListener(textChangedHandler); return ed; }
private void addEditorPane(JEditorPane pane, Icon icon, File file, boolean created) { 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()); tabPane.setSelectedComponent(c); pane.requestFocus(); }
/** * This method is called from within the constructor to initialise the undo * manager for the text pane. */ private void initUndoManager() { undoF = new UndoManager(); undoF.setLimit(5000); doc.addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent evt) { undoF.addEdit(evt.getEdit()); // adding a "*" to the file name, when the file has changed but not saved if (jframe.getFileTabCount() != 0 && jframe.getSelectedPath().indexOf("*") == -1) { jframe.setSelectedTitle(subPath + "*"); jframe.setTitle(jframe.getJifVersion() + " - " + jframe.getSelectedPath()); } } }); }
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; } } }