public CompoundEdit endCompoundEdit(boolean commit) { if (compoundEdit != null) { t("ending compound edit: "+commit); // NOI18N compoundEdit.end(); if (commit && undoRedoRecording && compoundEdit.isSignificant()) { if (!formModifiedLogged) { Logger logger = Logger.getLogger("org.netbeans.ui.metrics.form"); // NOI18N LogRecord rec = new LogRecord(Level.INFO, "USG_FORM_MODIFIED"); // NOI18N rec.setLoggerName(logger.getName()); logger.log(rec); formModifiedLogged = true; } getUndoRedoManager().undoableEditHappened( new UndoableEditEvent(this, compoundEdit)); } CompoundEdit edit = compoundEdit; compoundEdit = null; return edit; } return null; }
private void doUndoRedoTest(UndoRedo.Manager ur) { assertFalse("Nothing to undo", ur.canUndo()); ur.addChangeListener(this); MyEdit me = new MyEdit(); ur.undoableEditHappened(new UndoableEditEvent(this, me)); assertChange("One change"); assertTrue("Can undo now", ur.canUndo()); ur.undo(); assertFalse("Cannot undo", ur.canUndo()); assertChange("Snd change"); assertTrue("But redo", ur.canRedo()); ur.redo(); assertChange("Third change"); assertEquals("One undo", 1, me.undo); assertEquals("One redo", 1, me.redo); }
private void createTab() { jep=new JEditorPane(); jsp=new JScrollPane(jep); panes.add(jsp); jep.setContentType("text/plain"); typeOFileLabel.setText("Plain Text File"); editorPanes.add(jep); new CaretMonitor(jep, caretPosLabel); jep.addCaretListener(this); jep.getDocument().addUndoableEditListener((UndoableEditEvent uee) -> { undo.addEdit(uee.getEdit()); }); tabbedPane.addTab("*Tab "+(ct+1),jsp); tabbedPane.setSelectedIndex(ct); tabbedPane.setTabComponentAt(ct,new ButtonTabComponent(tabbedPane)); ct++; setToolbar(); }
public void undoableEditHappened(UndoableEditEvent e) { //Remember the edit and update the menus undo.addEdit(e.getEdit()); //undoAction.updateUndoState(); //redoAction.updateRedoState(); if (undo.canUndo()) { TEdit.setEnabled("Undo",true); TEdit.putValue("Undo", undo.getUndoPresentationName()); } else { TEdit.setEnabled("Undo",false); TEdit.putValue("Undo", "Undo"); } if (undo.canRedo()) { TEdit.setEnabled("Redo",true); TEdit.putValue("Redo",undo.getRedoPresentationName()); } else { TEdit.setEnabled("Redo",false); TEdit.putValue("Redo","Redo"); } }
@Override public void undoableEditHappened(UndoableEditEvent e) { boolean relevant = true; // only process edits that really changed anything if (GraphEditorTab.this.refreshing || getJGraph().isModelRefreshing()) { relevant = false; } else if (e.getEdit() instanceof GraphLayoutCacheChange) { GraphModelChange edit = (GraphModelChange) e.getEdit(); Object[] inserted = edit.getInserted(); Object[] removed = edit.getRemoved(); Object[] changed = edit.getChanged(); relevant = inserted != null && inserted.length > 0 || removed != null && removed.length > 0 || changed != null && changed.length > 0; } if (relevant) { super.undoableEditHappened(e); setDirty(isMinor(e.getEdit())); updateHistoryButtons(); } }
@Override public void undoableEditHappened(UndoableEditEvent e) { if (e.getEdit() instanceof GraphModelEdit) { try { getJModel().syncGraph(); AspectGraph graph = getJModel().getGraph(); // we need to clone the graph to properly freeze the next layout change AspectGraph graphClone = graph.clone(); graphClone.setFixed(); getSimulatorModel().doAddGraph(getResourceKind(), graphClone, true); getPropertiesPanel().setProperties(getJModel().getProperties()); } catch (IOException e1) { // do nothing } } }
public void undoableEditHappened(UndoableEditEvent e) { // Remember the edit and update the menus undo.addEdit(e.getEdit()); if (undo.canUndo()) { ((BrowserMDIFrame)internalFrame.getParentFrame()).actionUndo.setEnabled(true); } else { ((BrowserMDIFrame)internalFrame.getParentFrame()).actionUndo.setEnabled(false); } if (undo.canRedo()) { ((BrowserMDIFrame)internalFrame.getParentFrame()).actionRedo.setEnabled(true); } else { ((BrowserMDIFrame)internalFrame.getParentFrame()).actionRedo.setEnabled(false); } /* * internalFrame.getParentFrame(). undoAction.updateUndoState(); * redoAction.updateRedoState(); */ }
/** 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 new form SemanticAnnotation */ public SemanticAnnotation(String inputFile) { this.inputFile = inputFile; initComponents(); readInputFile(); spinner.setValue(0); selectButton.doClick(); splitPane.setDividerLocation(0.5); outText.getDocument().addUndoableEditListener( new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); } }); }
/** * Updates the frame that is represented by the specified element to * refer to the specified URL. * * @param el the element * @param url the new url */ private void updateFrame(Element el, URL url) { try { writeLock(); DefaultDocumentEvent ev = new DefaultDocumentEvent(el.getStartOffset(), 1, DocumentEvent.EventType.CHANGE); AttributeSet elAtts = el.getAttributes(); AttributeSet copy = elAtts.copyAttributes(); MutableAttributeSet matts = (MutableAttributeSet) elAtts; ev.addEdit(new AttributeUndoableEdit(el, copy, false)); matts.removeAttribute(HTML.Attribute.SRC); matts.addAttribute(HTML.Attribute.SRC, url.toString()); ev.end(); fireChangedUpdate(ev); fireUndoableEditUpdate(new UndoableEditEvent(this, ev)); } finally { writeUnlock(); } }
/** * Modifies the value of the named property, firing a change event if the * new value differs from the pre-existing one. * * @param javaPropName * The name of the JavaBeans property you are modifying. If the * change does not correspond with a bean property, or you want * to suppress the property change event, this parameter should * be null. * @param plPropName * The name of PL.INI the property to set/update (this is also * the key in the in-memory properties map) * @param propValue * The new value for the property */ private void putPropertyImpl(String javaPropName, String plPropName, String propValue) { String oldValue = properties.get(plPropName); properties.put(plPropName, propValue); classLoader = getClassLoaderFromCache(); // in case this changes the classpath if (javaPropName != null) { firePropertyChange(javaPropName, oldValue, propValue); } if ((oldValue == null && propValue != null) || (oldValue != null && !oldValue.equals(propValue))) { UndoableEdit edit = new UndoablePropertyEdit(plPropName, oldValue, propValue, this); for (int i = undoableEditListeners.size() -1; i >= 0; i--) { undoableEditListeners.get(i).undoableEditHappened(new UndoableEditEvent(this, edit)); } } }
/** * The setters on the DSType uses a different method to set properties than the * one used in testUndoAndRedo. This confirms that the setters do create undo and * redo edits. */ public void testUndoOnSetters() throws Exception { final JDBCDataSourceType dsType = new JDBCDataSourceType(); class TestUndoableEditListener implements UndoableEditListener { private int editCount = 0; public void undoableEditHappened(UndoableEditEvent e) { editCount++; } public int getEditCount() { return editCount; } } TestUndoableEditListener undoableEditListener = new TestUndoableEditListener(); dsType.addUndoableEditListener(undoableEditListener); dsType.setComment("comment"); dsType.setDDLGeneratorClass("class"); dsType.setName("name"); assertEquals(3, undoableEditListener.getEditCount()); }
public void undoableEditHappened(UndoableEditEvent e) { IApplication app = getSession().getApplication(); SquirrelPreferences prefs = app.getSquirrelPreferences(); if (fileOpened || fileSaved) { if (prefs.getWarnForUnsavedFileEdits()) { unsavedEdits = true; } getActiveSessionTabWidget().setUnsavedEdits(true); ActionCollection actions = getSession().getApplication().getActionCollection(); actions.enableAction(FileSaveAction.class, true); } else if (prefs.getWarnForUnsavedBufferEdits()) { unsavedEdits = true; } }
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()); } }
/** * * @param widget */ @Override public void movementFinished(Widget widget) { if (widget instanceof TitleWidget) { widget = ((TitleWidget) widget).parent; } String n = (String) findObject(widget); WorkspaceObject obj = ws.getActiveLayer().getObjectById(n); if (obj != null) { obj.setLoc(new org.vap.core.model.micro.Point(widget.getLocation())); } MyAbstractUndoableEdit myAbstractUndoableEdit = new MyAbstractUndoableEdit(widget); manager.undoableEditHappened(new UndoableEditEvent(widget, myAbstractUndoableEdit)); //XXX: Savable support file.makeDirty(); }
@Override public void undoableEditHappened(UndoableEditEvent evt) { if (compoundEdit == null) { compoundEdit = createCompoundEdit(evt.getEdit()); return; } // group ended? if (!groupEnd) { compoundEdit.addEdit(evt.getEdit()); return; } // new group groupEnd = false; compoundEdit.end(); compoundEdit = createCompoundEdit(evt.getEdit()); }
@Override public void handleZoomEvent(ZoomEvent e) { if (isReactingToUndoRedo()) { return; // if it's just the undo/redo caused zoom event, we don't want to react to it } if (e.isStart()) { undoZoomEvent = new Map2DUndoZoom(mapComponent.getMap2DPanel(), this); undoZoomEvent.setLocOld(e.getZoomLevel().getAxes().getMapDimensions()); } else { if (undoZoomEvent == null) { // Exceptions.printStackTrace(new IllegalStateException( // "undoZoomEvent was null when adding an evenet to UndoRedo manager.")); return; } if (undoZoomEvent.getLocOld() == null) { // Exceptions.printStackTrace(new IllegalStateException( // "undoZoomEvent.getLocOld() was null when adding an evenet to UndoRedo manager.")); return; } undoZoomEvent.setLocNew(e.getZoomLevel().getAxes().getMapDimensions()); undo.undoableEditHappened(new UndoableEditEvent(this, undoZoomEvent)); undoZoomEvent = null; } }
public void selectFile() { JFileChooser chooser = new JFileChooser(); if(filters.size()==0) return; // @TODO: fail! if(filters.size()==1) chooser.setFileFilter(filters.get(0)); else { Iterator<FileFilter> i = filters.iterator(); while(i.hasNext()) { chooser.addChoosableFileFilter( i.next()); } } if(lastPath!=null) chooser.setCurrentDirectory(new File(lastPath)); int returnVal = chooser.showOpenDialog(ro.getMainFrame()); if(returnVal == JFileChooser.APPROVE_OPTION) { String newFilename = chooser.getSelectedFile().getAbsolutePath(); System.out.println("You chose to open this file: " + newFilename); lastPath = chooser.getSelectedFile().getParent(); ro.getUndoHelper().undoableEditHappened(new UndoableEditEvent(this,new UndoableActionSelectFile(this, label, newFilename) ) ); } }
@Override public void changedUpdate(DocumentEvent arg0) { if(allowSetText==false) return; float newNumber; try { newNumber = Float.parseFloat(textField.getText()); } catch(NumberFormatException e) { return; } if(newNumber != value) { allowSetText=false; ro.getUndoHelper().undoableEditHappened(new UndoableEditEvent(this,new UndoableActionSelectNumber(this, label, newNumber) ) ); allowSetText=true; } }
void doInsert(final int offset, final String text, final AttributeSet attrs) throws BadLocationException { final DefaultDocumentEvent event = new DefaultDocumentEvent(offset, text.length(), EventType.INSERT); final UndoableEdit contentEdit = content.insertString(offset, text); if (contentEdit != null) { event.addEdit(contentEdit); } insertUpdate(event, attrs); event.end(); fireInsertUpdate(event); if (contentEdit != null) { fireUndoableEditUpdate(new UndoableEditEvent(this, event)); } }
public synchronized final void atomicUnlockImpl(boolean inUndoOrRedo) { extWriteUnlock(); if (atomicDepth == 0) { throw new IllegalStateException("atomicUnlock() without atomicLock()"); } if (--atomicDepth == 0) { // lock really ended fireAtomicUnlock(atomicLockEventInstance); if (!inUndoOrRedo && atomicEdits != null && atomicEdits.size() > 0) { atomicEdits.end(); fireUndoableEditUpdate(new UndoableEditEvent(this, atomicEdits)); atomicEdits = null; } } }
/** * 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()); } } }); }
private void init() { basusSyntaxDocument = new BasusSyntaxDocument(); setStyledDocument(basusSyntaxDocument); undoManager = new UndoManager(); getDocument().addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(final UndoableEditEvent e) { if (!basusSyntaxDocument.isHighlighting()) { undoManager.addEdit(e.getEdit()); notifyProvider(); } } }); getDocument().addDocumentListener(this); addKeyListener(this); final ActionMap am = getActionMap(); am.put(DefaultEditorKit.insertBreakAction, new AutoIndentAction()); }
public SyntaxDocument(Lexer lexer) { super(); putProperty(PlainDocument.tabSizeAttribute, 4); // outside ?! this.lexer = lexer; // Listen for undo and redo events addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent event) { if (event.getEdit().isSignificant()) { undo.addEdit(event.getEdit()); } } }); }
/** * Loops through each PlaceablePetriNetComponents start and ending coordinates (i.e. before and after translation) * and creates a {@link pipe.historyActions.component.MovePetriNetObject} undoEdit for each event * * It then creates an {@link pipe.historyActions.MultipleEdit} with all these undoEdits in and * registers this with the undoListener. * @param startingCoordinates of selected items before translation * @param translatedCoordinates of selected items after translation */ private void createMovedUndoItem(Map<String, Point2D> startingCoordinates, Map<PlaceablePetriNetComponent, Point2D> translatedCoordinates) { List<UndoableEdit> undoableEdits = new LinkedList<>(); for (Map.Entry<PlaceablePetriNetComponent, Point2D> entry : translatedCoordinates.entrySet()) { PlaceablePetriNetComponent component = entry.getKey(); Point2D starting = startingCoordinates.get(component.getId()); Point2D translated = entry.getValue(); if (!starting.equals(translated)) { undoableEdits.add(new MovePetriNetObject(component, starting, translated)); } } if (!undoableEdits.isEmpty()) { petriNetController.getUndoListener().undoableEditHappened(new UndoableEditEvent(this, new MultipleEdit(undoableEdits))); } }
public void undoableEditHappened(UndoableEditEvent e) { // Remember the edit and update the menus undo.addEdit(e.getEdit()); if (undo.canUndo()) { internalFrame.getParentFrame().actionUndo.setEnabled(true); } else { internalFrame.getParentFrame().actionUndo.setEnabled(false); } if (undo.canRedo()) { internalFrame.getParentFrame().actionRedo.setEnabled(true); } else { internalFrame.getParentFrame().actionRedo.setEnabled(false); } /* * internalFrame.getParentFrame(). undoAction.updateUndoState(); * redoAction.updateRedoState(); */ }
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); } }
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); } }
@Override public void undoableEditHappened(UndoableEditEvent e) { assert component != null; if (edit == null) { startNewEdit(component, e.getEdit()); processDocumentChange(component); return; } //AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) e.getEdit(); UndoableEdit event = e.getEdit(); if (event instanceof DocumentEvent) { if (((DocumentEvent)event).getType().equals(DocumentEvent.EventType.CHANGE)) { edit.addEdit(e.getEdit()); return; } } int offsetChange = component.getCaretPosition() - lastOffset; int lengthChange = component.getDocument().getLength() - lastLength; if (Math.abs(offsetChange) == 1 && Math.abs(lengthChange) == 1) { lastOffset = component.getCaretPosition(); lastLength = component.getDocument().getLength(); super.undoableEditHappened(e); processDocumentChange(component); } else { // last change consists of multiple chars, start new compound edit startNewEdit(component, e.getEdit()); } }
private void startNewEdit (JTextComponent component, UndoableEdit atomicEdit) { if (edit != null) { // finish the last edit edit.end(); } edit = new MyCompoundEdit(); edit.addEdit(atomicEdit); super.undoableEditHappened(new UndoableEditEvent(component, edit)); lastOffset = component.getCaretPosition(); lastLength = component.getDocument().getLength(); }
private boolean checkAndFireAtomicEdits() { if (atomicEdits != null && atomicEdits.size() > 0) { // Some edits performed atomicEdits.end(); AtomicCompoundEdit nonEmptyAtomicEdits = atomicEdits; atomicEdits = null; // Clear the var to allow doc.runAtomic() in undoableEditHappened() fireUndoableEditUpdate(new UndoableEditEvent(this, nonEmptyAtomicEdits)); return true; } else { return false; } }