Java Code Examples for javax.swing.event.UndoableEditListener

The following examples show how to use javax.swing.event.UndoableEditListener. 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: PIPE   Source File: PipeApplicationController.java    License: MIT License 6 votes vote down vote up
/**
 * Register the tab to the Petri net
 * @param net Petri net
 * @param tab tab which houses the graphical petri net components
 * @param historyObserver listener for stepback/forward events in animation
 * @param undoListener listener for undo/redo events
 * @param zoomListener listener for zoom events
 */
//TODO: THIS IS RATHER UGLY, too many params but better than what was here before
public void registerTab(PetriNet net, PetriNetTab tab, Observer historyObserver, UndoableEditListener undoListener,
                        PropertyChangeListener zoomListener) {
    AnimationHistoryImpl animationHistory = new AnimationHistoryImpl();
    animationHistory.addObserver(historyObserver);
    GUIAnimator animator = new GUIAnimator(new PetriNetAnimator(net), animationHistory, this);

    CopyPasteManager copyPasteManager = new CopyPasteManager(undoListener, tab, net, this);

    ZoomController zoomController = new ZoomController(100);
    tab.addZoomListener(zoomController);
    PetriNetController petriNetController =
            new PetriNetController(net, undoListener, animator, copyPasteManager, zoomController, tab);
    netControllers.put(tab, petriNetController);
    tab.updatePreferredSize();

    PropertyChangeListener changeListener =
            new PetriNetChangeListener(applicationModel, tab, petriNetController);
    net.addPropertyChangeListener(changeListener);

    setActiveTab(tab);
    initialiseNet(net, changeListener);
}
 
Example 2
Source Project: jeveassets   Source File: TextManager.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void installTextComponent(final JTextComponent component) {
	//Make sure this component does not already have a UndoManager
	Document document = component.getDocument();
	boolean found = false;
	if (document instanceof AbstractDocument) {
		AbstractDocument abstractDocument = (AbstractDocument) document;
		for (UndoableEditListener editListener : abstractDocument.getUndoableEditListeners()) {
			if (editListener.getClass().equals(CompoundUndoManager.class)) {
				CompoundUndoManager undoManager = (CompoundUndoManager) editListener;
				undoManager.reset();
				return;
			}
		}
	}
	if (!found) {
		new TextManager(component);
	}
}
 
Example 3
Source Project: PIPE   Source File: ComponentEditorManager.java    License: MIT License 6 votes vote down vote up
/**
 * Creates actions for editing the petri net
 *
 * @param controller PIPE application controller
 */
public ComponentEditorManager(PipeApplicationController controller) {
    copyAction = new CopyAction(controller);
    pasteAction = new PasteAction(controller);
    cutAction = new CutAction(controller);
    deleteAction = new DeleteAction(controller);
    undoAction = new UndoAction(controller);
    redoAction = new RedoAction(controller, undoAction);
    undoAction.registerRedoAction(redoAction);
    undoAction.setEnabled(false);
    redoAction.setEnabled(false);

    UndoableEditListener listener = new SimpleUndoListener(redoAction, undoAction, controller);
    deleteAction.addUndoableEditListener(listener);
    copyAction.addUndoableEditListener(listener);
    cutAction.addUndoableEditListener(listener);
    pasteAction.addUndoableEditListener(listener);

    storeEnabledStatus();
}
 
Example 4
Source Project: PIPE   Source File: TokenActionManager.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor
 * @param undoListener undo listener
 * @param applicationModel PIPE application model
 * @param applicationController PIPE application controller
 * @param applicationView PIPE application view
 */
public TokenActionManager(UndoableEditListener undoListener, PipeApplicationModel applicationModel,
                          PipeApplicationController applicationController, PipeApplicationView applicationView) {
    tokenAction = new AddTokenAction(applicationModel);
    deleteTokenAction = new DeleteTokenAction(applicationModel);
    specifyTokenClasses = new SpecifyTokenAction(applicationController, applicationView);
    tokenAction.addUndoableEditListener(undoListener);
    deleteTokenAction.addUndoableEditListener(undoListener);
    specifyTokenClasses.addUndoableEditListener(undoListener);
}
 
Example 5
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 6
Source Project: netbeans   Source File: BaseDocument.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addUndoableEditListener(UndoableEditListener listener) {
    super.addUndoableEditListener(listener);
    if (LOG.isLoggable(Level.FINE)) {
        UndoableEditListener[] listeners = getUndoableEditListeners();
        if (listeners.length > 1) {
            // Having two UE listeners may be dangerous - for example
            // having two undo managers attached at once will lead to strange errors
            // since only one of the UMs will work normally while processing
            // in the other one will be (typically silently) failing.
            LOG.log(Level.INFO, "Two or more UndoableEditListeners attached", new Exception()); // NOI18N
        }
    }
}
 
Example 7
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 8
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 9
Source Project: netbeans   Source File: AbstractModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void addUndoableRefactorListener(UndoableEditListener uel) {
    //
    savedUndoableEditListeners = ues.getUndoableEditListeners();
    if (savedUndoableEditListeners != null) {
        for (UndoableEditListener saved : savedUndoableEditListeners) {
            if (saved instanceof UndoManager) {
                ((UndoManager)saved).discardAllEdits();
            }
        }
    }
    ues = new ModelUndoableEditSupport();
    ues.addUndoableEditListener(uel);
}
 
Example 10
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 11
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 12
Source Project: PIPE   Source File: ComponentCreatorManager.java    License: MIT License 5 votes vote down vote up
public ComponentCreatorManager(UndoableEditListener undoListener, PipeApplicationModel applicationModel,
                               PipeApplicationController applicationController) {
    placeAction = new PlaceAction(applicationModel);

    transAction = new ImmediateTransitionAction(applicationModel);

    timedtransAction = new TimedTransitionAction(applicationModel);

    annotationAction = new AnnotationAction(applicationModel);

    inhibarcAction =
            new ArcAction("Inhibitor Arc", "Add an inhibitor arc (alt-h)", KeyEvent.VK_H, InputEvent.ALT_DOWN_MASK,
                    new InhibitorSourceVisitor(), new InhibitorCreator(), applicationModel,
                    applicationController, new InhibitorArcHead());
    arcAction = new ArcAction("Arc", "Add an arc (alt-a)", KeyEvent.VK_A, InputEvent.ALT_DOWN_MASK,
            new NormalArcSourceVisitor(), new NormalCreator(applicationController), applicationModel,
            applicationController,
            new NormalHead());

    rateParameterAction = new SpecifyRateParameterAction(applicationController);

    placeAction.addUndoableEditListener(undoListener);
    transAction.addUndoableEditListener(undoListener);
    timedtransAction.addUndoableEditListener(undoListener);
    arcAction.addUndoableEditListener(undoListener);
    inhibarcAction.addUndoableEditListener(undoListener);
    annotationAction.addUndoableEditListener(undoListener);
    rateParameterAction.addUndoableEditListener(undoListener);
}
 
Example 13
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 14
Source Project: PIPE   Source File: CopyPasteManager.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor
 *
 * @param listener              undoable event listener, used to register undo events to
 * @param petriNetTab           current Petri net tab
 * @param net                   underlying Petri net displayed on the Petri net tab
 * @param applicationController main application controller
 */
public CopyPasteManager(UndoableEditListener listener, PetriNetTab petriNetTab, PetriNet net,
                        PipeApplicationController applicationController) {
    this.petriNetTab = petriNetTab;
    petriNet = net;
    this.applicationController = applicationController;
    addMouseListener(this);
    addMouseMotionListener(this);
    addKeyListener(this);
    this.listener = listener;

}
 
Example 15
Source Project: dragonwell8_jdk   Source File: Test6968363.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addUndoableEditListener(UndoableEditListener listener) {
    this.document.addUndoableEditListener(listener);
}
 
Example 16
Source Project: dragonwell8_jdk   Source File: Test6968363.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void removeUndoableEditListener(UndoableEditListener listener) {
    this.document.removeUndoableEditListener(listener);
}
 
Example 17
Source Project: TencentKona-8   Source File: Test6968363.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addUndoableEditListener(UndoableEditListener listener) {
    this.document.addUndoableEditListener(listener);
}
 
Example 18
Source Project: TencentKona-8   Source File: Test6968363.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void removeUndoableEditListener(UndoableEditListener listener) {
    this.document.removeUndoableEditListener(listener);
}
 
Example 19
Source Project: jdk8u60   Source File: Test6968363.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addUndoableEditListener(UndoableEditListener listener) {
    this.document.addUndoableEditListener(listener);
}
 
Example 20
Source Project: consulo   Source File: EditorComponentImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void removeUndoableEditListener(UndoableEditListener undoableEditListener) {
}
 
Example 21
Source Project: openjdk-jdk8u   Source File: Test6968363.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addUndoableEditListener(UndoableEditListener listener) {
    this.document.addUndoableEditListener(listener);
}
 
Example 22
Source Project: openjdk-jdk8u   Source File: Test6968363.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void removeUndoableEditListener(UndoableEditListener listener) {
    this.document.removeUndoableEditListener(listener);
}
 
Example 23
Source Project: netbeans   Source File: InstantRefactoringPerformer.java    License: Apache License 2.0 4 votes vote down vote up
public InstantRefactoringPerformer(final JTextComponent target, int caretOffset, InstantRefactoringUI ui) {
    releaseAll();
    this.target = target;
    this.ui = ui;
    doc = target.getDocument();

    MutablePositionRegion mainRegion = null;
    List<MutablePositionRegion> regions = new ArrayList<>(ui.getRegions().size());

    for (MutablePositionRegion current : ui.getRegions()) {
        // TODO: type parameter name is represented as ident -> ignore surrounding <> in rename
        if (isIn(current, caretOffset)) {
            mainRegion = current;
        } else {
            regions.add(current);
        }
    }

    if (mainRegion == null) {
        throw new IllegalArgumentException("No highlight contains the caret.");
    }

    regions.add(0, mainRegion);

    region = new SyncDocumentRegion(doc, regions);

    if (doc instanceof BaseDocument) {
        BaseDocument bdoc = ((BaseDocument) doc);
        bdoc.addPostModificationDocumentListener(this);
        
        UndoableWrapper wrapper = MimeLookup.getLookup("text/x-java").lookup(UndoableWrapper.class);
        if(wrapper != null) {
            wrapper.setActive(true, this);
        }

        UndoableEdit undo = new CancelInstantRenameUndoableEdit(this);
        for (UndoableEditListener l : bdoc.getUndoableEditListeners()) {
            l.undoableEditHappened(new UndoableEditEvent(doc, undo));
        }
    }

    target.addKeyListener(this);

    target.putClientProperty(InstantRefactoringPerformer.class, this);
    target.putClientProperty("NetBeansEditor.navigateBoundaries", mainRegion); // NOI18N
	
    requestRepaint();
    
    target.select(mainRegion.getStartOffset(), mainRegion.getEndOffset());
    
    span = region.getFirstRegionLength();
    compl = new CompletionLayout(this);
    compl.setEditorComponent(target);
    final KeyStroke OKKS = ui.getKeyStroke();
    target.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(OKKS, OKActionKey);
    Action OKAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if(registry.contains(InstantRefactoringPerformer.this)) {
                doFullRefactoring();
                target.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(OKKS);
                target.getActionMap().remove(OKActionKey);
            } else {
                target.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(OKKS);
                target.getActionMap().remove(OKActionKey);
            }
        }
    };
    target.getActionMap().put(OKActionKey, OKAction);
    final KeyStroke keyStroke = ui.getKeyStroke();
    compl.showCompletion(ui.getOptions(), caretOffset, Bundle.INFO_PressAgain(getKeyStrokeAsText(keyStroke)));
    
    registry.add(this);
}
 
Example 24
Source Project: netbeans   Source File: InstantRenamePerformer.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates a new instance of InstantRenamePerformer */
private InstantRenamePerformer(JTextComponent target, Set<Token> highlights, int caretOffset) throws BadLocationException {
    this.target = target;
    doc = target.getDocument();

    MutablePositionRegion mainRegion = null;
    List<MutablePositionRegion> regions = new ArrayList<MutablePositionRegion>();

    for (Token h : highlights) {
        // type parameter name is represented as ident -> ignore surrounding <> in rename
        int delta = h.id() == JavadocTokenId.IDENT && h.text().charAt(0) == '<' && h.text().charAt(h.length() - 1) == '>' ? 1 : 0;
        Position start = NbDocument.createPosition(doc, h.offset(null) + delta, Bias.Backward);
        Position end = NbDocument.createPosition(doc, h.offset(null) + h.length() - delta, Bias.Forward);
        MutablePositionRegion current = new MutablePositionRegion(start, end);
        
        if (isIn(current, caretOffset)) {
            mainRegion = current;
        } else {
            regions.add(current);
        }
    }

    if (mainRegion == null) {
        throw new IllegalArgumentException("No highlight contains the caret.");
    }

    regions.add(0, mainRegion);

    region = new SyncDocumentRegion(doc, regions);

    if (doc instanceof BaseDocument) {
        BaseDocument bdoc = ((BaseDocument) doc);
        bdoc.setPostModificationDocumentListener(this);

        UndoableEdit undo = new CancelInstantRenameUndoableEdit(this);
        for (UndoableEditListener l : bdoc.getUndoableEditListeners()) {
            l.undoableEditHappened(new UndoableEditEvent(doc, undo));
        }
    }

    target.addKeyListener(this);

    target.putClientProperty(InstantRenamePerformer.class, this);
    target.putClientProperty("NetBeansEditor.navigateBoundaries", mainRegion); // NOI18N
	
    requestRepaint();
    
    target.select(mainRegion.getStartOffset(), mainRegion.getEndOffset());
    
    span = region.getFirstRegionLength();
    
    registry.add(this);
    sendUndoableEdit(doc, CloneableEditorSupport.BEGIN_COMMIT_GROUP);
}
 
Example 25
Source Project: PIPE   Source File: PipeApplicationView.java    License: MIT License 4 votes vote down vote up
public void setUndoListener(UndoableEditListener listener) {
    undoListener = listener;
}
 
Example 26
Source Project: PIPE   Source File: GuiAction.java    License: MIT License 4 votes vote down vote up
/**
 * Adds a listener to this action that is interested in undoable actions
 * @param l listener
 */
public void addUndoableEditListener(UndoableEditListener l) {
    //TODO: Should ideally throw an exception if listener != null
    listener = l;
}
 
Example 27
Source Project: netbeans   Source File: OutputDocument.java    License: Apache License 2.0 4 votes vote down vote up
public void addUndoableEditListener(UndoableEditListener listener) {
    //no-op
}
 
Example 28
Source Project: netbeans   Source File: OutputDocument.java    License: Apache License 2.0 4 votes vote down vote up
public void removeUndoableEditListener(UndoableEditListener listener) {
    //no-op
}
 
Example 29
Source Project: PIPE   Source File: AbstractPetriNetComponentControllerTest.java    License: MIT License 4 votes vote down vote up
protected DummyController(Place component, UndoableEditListener listener) {
    super(component, listener);
}
 
Example 30
Source Project: netbeans   Source File: AbstractModel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void removeUndoableEditListener(UndoableEditListener uel) {
    ues.removeUndoableEditListener(uel);
}