Java Code Examples for javax.swing.event.UndoableEditEvent

The following examples show how to use javax.swing.event.UndoableEditEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: openAGV   Source File: BezierLinerEditHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent evt) {
  if (!(evt.getEdit() instanceof BezierLinerEdit)) {
    return;
  }
  BezierFigure owner = ((BezierLinerEdit) evt.getEdit()).getOwner();
  if (!(owner instanceof PathConnection)) {
    return;
  }

  PathConnection path = (PathConnection) owner;
  path.updateControlPoints();
  PathModel pathModel = path.getModel();
  pathModel.getPropertyPathControlPoints().markChanged();
  pathModel.propertiesChanged(path);
}
 
Example 2
Source Project: netbeans   Source File: FormModel.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source Project: netbeans   Source File: UndoRedoTest.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source Project: ApkToolPlus   Source File: CodeEditArea.java    License: Apache License 2.0 6 votes vote down vote up
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();
	 */

}
 
Example 5
Source Project: groovy   Source File: TextUndoManager.java    License: Apache License 2.0 6 votes vote down vote up
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());
    }

}
 
Example 6
Source Project: bigtable-sql   Source File: SQLPanelAPI.java    License: Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 7
/**
 * Panel action, update entity
 */
@Override
public void actionPerformed(ActionEvent arg0) {
	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.showDialog(ro.getMainFrame(), Translator.get("Select"));
	if(returnVal == JFileChooser.APPROVE_OPTION) {
		String newFilename = chooser.getSelectedFile().getAbsolutePath();
		lastPath = chooser.getSelectedFile().getParent();

		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeString(e, newFilename) ) );
	}
}
 
Example 8
protected void conditionalChange() {
	int newNumber;
	
	try {
		newNumber = Integer.valueOf(field.getText());
		field.setForeground(UIManager.getColor("Textfield.foreground"));
	} catch(NumberFormatException e1) {
		field.setForeground(Color.RED);
		newNumber = e.get();
	}
	
	if(lock.isLocked()) return;
	lock.lock();

	if(newNumber != e.get()) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeInt(e, newNumber) ) );
	}
	lock.unlock();
}
 
Example 9
Source Project: nextreports-designer   Source File: SyntaxDocument.java    License: Apache License 2.0 6 votes vote down vote up
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());
            }
        }
        
    });
}
 
Example 10
Source Project: PIPE   Source File: DragManager.java    License: MIT License 6 votes vote down vote up
/**
 * 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)));
    }
}
 
Example 11
Source Project: netbeans   Source File: InstantRenamePerformer.java    License: Apache License 2.0 5 votes vote down vote up
private static void sendUndoableEdit(Document d, UndoableEdit ue) {
    if(d instanceof AbstractDocument) {
        UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners();
        UndoableEditEvent ev = new UndoableEditEvent(d, ue);
        for(UndoableEditListener uel : uels) {
            uel.undoableEditHappened(ev);
        }
    }
}
 
Example 12
Source Project: netbeans   Source File: UndoRedoWrappingCooperationTest.java    License: Apache License 2.0 5 votes vote down vote up
void sendUndoableEdit(Document d, UndoableEdit ue) {
    if(d instanceof AbstractDocument) {
        UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners();
        UndoableEditEvent ev = new UndoableEditEvent(d, ue);
        for(UndoableEditListener uel : uels) {
            uel.undoableEditHappened(ev);
        }
    }
}
 
Example 13
Source Project: netbeans   Source File: UndoRedoTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testUndoDeliversChangesWithTooManyEdits() {
    UndoRedo.Manager ur = new UndoRedo.Manager() {
        @Override
        public boolean canUndo() {
            if (super.canUndo()) {
                undoableEditHappened(new UndoableEditEvent(this, new MyEdit(true)));
            }
            return super.canUndo();
        }
    };
    doUndoRedoTest(ur);
}
 
Example 14
Source Project: netbeans   Source File: UndoRedoActionTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testUndoDeliversChangesWithTooManyEdits() {
    UndoRedo.Manager man = new UndoRedo.Manager() {
        @Override
        public boolean canUndo() {
            if (super.canUndo()) {
                undoableEditHappened(new UndoableEditEvent(UndoRedoActionTest.this, new MyEdit(true)));
            }
            return super.canUndo();
        }
    };
    doUndoRedoTest(man, false);
}
 
Example 15
Source Project: netbeans   Source File: UndoRedoActionTest.java    License: Apache License 2.0 5 votes vote down vote up
private void doUndoRedoTest(UndoRedo.Manager man, boolean testCounts) {
    me = new MyEdit();
    man.undoableEditHappened(new UndoableEditEvent(this, me));
    assertTrue("Can undo", man.canUndo());
    this.ur = man;
    
    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action u = undoAction(lkp);
    Action r = redoAction(lkp);

    assertFalse("Not enabled", u.isEnabled());
    assertFalse("Not enabledR", r.isEnabled());
    MyEdit lu = new MyEdit();
    MyEdit lr = new MyEdit();
    u.addPropertyChangeListener(lu);
    r.addPropertyChangeListener(lr);

    ic.add(this);

    assertTrue("Action is enabled", u.isEnabled());
    assertEquals("One change", 1, lu.cnt);
    assertEquals("No redo change", 0, lr.cnt);
    assertEquals("Undo presentation", "&Undo My Undo", u.getValue(Action.NAME));

    u.actionPerformed(new ActionEvent(this, 0, ""));
    if (testCounts) {
        assertEquals("my edit undone", 1, me.undo);

        assertFalse("No more undo", man.canUndo());
        assertTrue("But redo", man.canRedo());
        assertEquals("Another undo change", 2, lu.cnt);
        assertEquals("New redo change", 1, lr.cnt);
        assertTrue("Redo action enabled", r.isEnabled());
        assertEquals("Redo presentation correct", "&Redo My Redo", r.getValue(Action.NAME));
    }

    r.actionPerformed(new ActionEvent(this, 0, ""));
    assertFalse("Redo action no longer enabled", r.isEnabled());
}
 
Example 16
Source Project: netbeans   Source File: UndoRedoSupport.java    License: Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example 17
Source Project: netbeans   Source File: UndoRedoSupport.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 18
Source Project: netbeans   Source File: BaseDocument.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 19
Source Project: netbeans   Source File: BaseDocumentTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testRecursiveUndoableEdits() throws Exception {
    final BaseDocument doc = new BaseDocument(false, "text/plain");
    class UEL implements UndoableEditListener, Runnable {
        boolean undo;
        @Override
        public void undoableEditHappened(UndoableEditEvent e) {
            //doc.runAtomic(this);
            doc.render(this);
            undo = e.getEdit().canUndo();
        }

        @Override
        public void run() {
        }
    }
    UEL uel = new UEL();
    doc.addUndoableEditListener(uel);

    class Atom implements Runnable {
        @Override
        public void run() {
            try {
                doc.insertString(0, "Ahoj", null);
            } catch (BadLocationException ex) {
                throw new IllegalStateException(ex);
            }
        }
    }
    doc.runAtomicAsUser(new Atom());

    assertTrue("Can undo now", uel.undo);
}
 
Example 20
Source Project: netbeans   Source File: UndoRedoSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
    if (edit == null) {
        startNewEdit(e.getEdit());
        processDocumentChange();
        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();
        addEdit(e.getEdit());
        processDocumentChange();
    } else {
        // last change consists of multiple chars, start new compound edit
        startNewEdit(e.getEdit());
    }
}
 
Example 21
Source Project: netbeans   Source File: CompletionImpl.java    License: Apache License 2.0 5 votes vote down vote up
static void sendUndoableEdit(Document d, UndoableEdit ue) {
    if(d instanceof AbstractDocument) {
        UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners();
        UndoableEditEvent ev = new UndoableEditEvent(d, ue);
        for(UndoableEditListener uel : uels) {
            uel.undoableEditHappened(ev);
        }
    }
}
 
Example 22
Source Project: netbeans   Source File: DocumentContentTesting.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void undoableEditHappened(UndoableEditEvent e) {
    if (e.getSource() == getValidExpectedDocument(container)) {
        assert undoEditPair == null;
        undoEditPair = new UndoEditPair();
        undoEditPair.expectedUndoEdit = e.getEdit();
    } else if (e.getSource() == getValidDocument(container)) {
        assert (undoEditPair != null);
        undoEditPair.testUndoEdit = e.getEdit();
        addEdit(undoEditPair);
        undoEditPair = null;
    } else {
        throw new IllegalStateException("Unexpected source of undo event: " + e);
    }
}
 
Example 23
Source Project: netbeans   Source File: MacroDialogSupport.java    License: Apache License 2.0 5 votes vote down vote up
private static void sendUndoableEdit(Document d, UndoableEdit ue) {
    if(d instanceof AbstractDocument) {
        UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners();
        UndoableEditEvent ev = new UndoableEditEvent(d, ue);
        for(UndoableEditListener uel : uels) {
            uel.undoableEditHappened(ev);
        }
    }
}
 
Example 24
Source Project: netbeans   Source File: AbbrevDetection.java    License: Apache License 2.0 5 votes vote down vote up
private static void sendUndoableEdit(Document d, UndoableEdit ue) {
    if(d instanceof AbstractDocument) {
        UndoableEditListener[] uels = ((AbstractDocument)d).getUndoableEditListeners();
        UndoableEditEvent ev = new UndoableEditEvent(d, ue);
        for(UndoableEditListener uel : uels) {
            uel.undoableEditHappened(ev);
        }
    }
}
 
Example 25
Source Project: visualvm   Source File: SyntaxDocument.java    License: GNU General Public License v2.0 5 votes vote down vote up
public SyntaxDocument(Lexer lexer) {
    super();
    putProperty(PlainDocument.tabSizeAttribute, 4);
    this.lexer = lexer;
    // Listen for undo and redo events
    addUndoableEditListener(new UndoableEditListener() {

        @Override
        public void undoableEditHappened(UndoableEditEvent evt) {
            if (evt.getEdit().isSignificant()) {
                undo.addEdit(evt.getEdit());
            }
        }
    });
}
 
Example 26
@Override
public void undoableEditHappened(UndoableEditEvent e) {
	//  Start a new compound edit

	if (compoundEdit == null) {
		compoundEdit = startCompoundEdit(e.getEdit());
		return;
	}

	int offsetChange = textComponent.getCaretPosition() - lastOffset;
	int lengthChange = textComponent.getDocument().getLength() - lastLength;

	//  Check for an attribute change
	UndoableEdit edit = e.getEdit();
	if (edit instanceof AbstractDocument.DefaultDocumentEvent) {
		AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) e.getEdit();
		if (event.getType().equals(DocumentEvent.EventType.CHANGE)) {
			if (offsetChange == 0) {
				compoundEdit.addEdit(e.getEdit());
				return;
			}
		}
	}

	//  Check for an incremental edit or backspace.
	//  The Change in Caret position and Document length should both be
	//  either 1 or -1.
	if (offsetChange == lengthChange
			&& Math.abs(offsetChange) == 1) {
		compoundEdit.addEdit(e.getEdit());
		lastOffset = textComponent.getCaretPosition();
		lastLength = textComponent.getDocument().getLength();
		return;
	}

	//  Not incremental edit, end previous edit and start a new one
	compoundEdit.end();
	compoundEdit = startCompoundEdit(e.getEdit());
}
 
Example 27
public void actionPerformed(ActionEvent e) {
	Entity entity = ro.getPickedEntity();
	if(entity==null) {
		Log.error("RemoveEntity with no entity selected.");
		return;
	}
	ro.undoableEditHappened(new UndoableEditEvent(this,new ActionEntityRemove(ro,entity) ) );
}
 
Example 28
Source Project: PIPE   Source File: Contains.java    License: MIT License 5 votes vote down vote up
@Override
public boolean matches(Object argument) {
    UndoableEditEvent event = (UndoableEditEvent) argument;
    UndoableEdit edit = event.getEdit();

    return edit.equals(expectedEdit);
}
 
Example 29
/**
 * the panel element has changed.  poke the entity.
 */
@Override
public void itemStateChanged(ItemEvent arg0) {
	boolean newValue = field.isSelected();
	if(e.get()!=newValue) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeBoolean(e, newValue) ) );
	}
}
 
Example 30
@Override
public void stateChanged(ChangeEvent arg0) {
	int oldValue = e.get();
	int newValue = field.getValue();
	
	if(newValue!=oldValue) {
		ro.undoableEditHappened(new UndoableEditEvent(this,new ActionChangeInt(e,newValue) ) );
	}
}