private void registerListeners() { textComponent.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == 3 && e.getSource() == textComponent) { process(e); } } }); textComponent.getDocument().addUndoableEditListener(event -> undoManager.addEdit(event.getEdit())); }
private static void makeTextComponentUndoable(JTextComponent textConponent) { final UndoManager undoManager = new UndoManager(); textConponent.getDocument().addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent evt) {
notesEditor.getDocument().addUndoableEditListener(e -> undoRedo.addEdit(e.getEdit()));
/** * De-serializes a text area. * * @param s The stream to read from. * @throws ClassNotFoundException * @throws IOException */ private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { s.defaultReadObject(); // UndoManagers cannot be serialized without Exceptions. See // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4275892 undoManager = createUndoManager(); getDocument().addUndoableEditListener(undoManager); lineHighlightManager = null; // Keep FindBugs happy. }
/** * Serializes this text area. * * @param s The stream to write to. * @throws IOException If an IO error occurs. */ private void writeObject(ObjectOutputStream s) throws IOException { // UndoManagers cannot be serialized without Exceptions. See // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4275892 getDocument().removeUndoableEditListener(undoManager); s.defaultWriteObject(); getDocument().addUndoableEditListener(undoManager); }
/** * Sets the document used by this text area. * * @param document The new document to use. * @throws IllegalArgumentException If the document is not an instance of * {@link RDocument}. */ @Override public void setDocument(Document document) { if (!(document instanceof RDocument)) { throw new IllegalArgumentException("RTextArea requires " + "instances of RDocument for its document"); } if (undoManager!=null) { // First time through, undoManager==null Document old = getDocument(); if (old!=null) { old.removeUndoableEditListener(undoManager); } } super.setDocument(document); if (undoManager!=null) { document.addUndoableEditListener(undoManager); discardAllEdits(); } }
/** * Removes all undoable edits from this document's undo manager. This * method also makes the undo/redo actions disabled. */ /* * NOTE: For some reason, it appears I have to create an entirely new * <code>undoManager</code> for undo/redo to continue functioning * properly; if I don't, it only ever lets you do one undo. Not * too sure why this is... */ public void discardAllEdits() { undoManager.discardAllEdits(); getDocument().removeUndoableEditListener(undoManager); undoManager = createUndoManager(); getDocument().addUndoableEditListener(undoManager); undoManager.updateActions(); }
doc.addUndoableEditListener(undoableEditEvent -> undo.addEdit(undoableEditEvent.getEdit()));
@Override protected void init() { super.init(); // NOTE: Our actions are created here instead of in a static block // so they are only created when the first RTextArea is instantiated, // not before. There have been reports of users calling static getters // (e.g. RSyntaxTextArea.getDefaultBracketMatchBGColor()) which would // cause these actions to be created and (possibly) incorrectly // localized, if they were in a static block. if (cutAction==null) { createPopupMenuActions(); } // Install the undo manager. undoManager = createUndoManager(); getDocument().addUndoableEditListener(undoManager); // Set the defaults for various stuff. Color markAllHighlightColor = getDefaultMarkAllHighlightColor(); markAllHighlightPainter = new SmartHighlightPainter( markAllHighlightColor); setMarkAllHighlightColor(markAllHighlightColor); carets = new CaretStyle[2]; setCaretStyle(INSERT_MODE, CaretStyle.THICK_VERTICAL_LINE_STYLE); setCaretStyle(OVERWRITE_MODE, CaretStyle.BLOCK_STYLE); setDragEnabled(true); // Enable drag-and-drop. setTextMode(INSERT_MODE); // Carets array must be created first! setMarkAllOnOccurrenceSearches(true); // Fix the odd "Ctrl+H <=> Backspace" Java behavior. fixCtrlH(); }
public JTextFieldUndoable() { super(); this.undoListener = new JTextFieldUndoListener(this); this.getDocument().addUndoableEditListener(this.undoListener); }
@Override public void setText(String t) { this.getDocument().removeUndoableEditListener(this.undoListener); try { super.setText(t); } finally { this.getDocument().addUndoableEditListener(this.undoListener); } } }
public JUndoableCayenneTextPane(SyntaxConstant syntaxConstant) { super(syntaxConstant); this.undoListener = new JTextFieldUndoListener(this.getPane()); getDocument().addUndoableEditListener(this.undoListener); }
@Override public void setText(String t) { getDocument().removeUndoableEditListener(this.undoListener); try { super.setText(t); } finally { getDocument().addUndoableEditListener(this.undoListener); } } }
public static void registerNewUndoManager(JComponent jtc, Document d) { UndoManager undoManager = new UndoManager(); d.addUndoableEditListener(undoManager); FormUtils.registerUndoRedoActions(jtc, FormUtils.createUndoAction(undoManager, "undo"), FormUtils.createRedoAction(undoManager, "redo")); }
/** * Method for setting a document as the current document for the text pane and re-registering the controls and * settings for it */ public void registerDocument(ExtendedHTMLDocument htmlDoc) { jtpMain.setDocument(htmlDoc); jtpMain.getDocument().addUndoableEditListener(new CustomUndoableEditListener()); jtpMain.getDocument().addDocumentListener(this); jtpMain.setCaretPosition(0); purgeUndos(); registerDocumentStyles(); }
void registerListeners() { unregisterListeners(); _editor.getEditor().addKeyListener( _editorKeyListener ); _editor.getEditor().addCaretListener( _editorCaretListener ); _editor.getEditor().getDocument().addUndoableEditListener( _docListener ); }
void registerListeners() { unregisterListeners(); getEditor().getEditor().addKeyListener( _editorKeyListener ); getEditor().getEditor().getDocument().addUndoableEditListener( _docListener ); }
private void init() { putClientProperty(HONOR_DISPLAY_PROPERTIES, true); setEditorKitForContentType("text/html", new SloppyHTMLEditorKit()); addPropertyChangeListener(new PropertyHandler()); getDocument().addUndoableEditListener(getUndoableEditListener()); initActions(); }
private void init() { putClientProperty(HONOR_DISPLAY_PROPERTIES, true); setEditorKitForContentType("text/html", new SloppyHTMLEditorKit()); addPropertyChangeListener(new PropertyHandler()); getDocument().addUndoableEditListener(getUndoableEditListener()); initActions(); }
private void init() { putClientProperty(HONOR_DISPLAY_PROPERTIES, true); setEditorKitForContentType("text/html", new SloppyHTMLEditorKit()); addPropertyChangeListener(new PropertyHandler()); getDocument().addUndoableEditListener(getUndoableEditListener()); initActions(); }