Refine search
private void process(MouseEvent e) { textComponent.requestFocus(); boolean enabled = textComponent.isEnabled(); boolean editable = textComponent.isEditable(); boolean nonempty = !(textComponent.getText() == null || textComponent.getText().equals("")); boolean marked = textComponent.getSelectedText() != null; boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard() .getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor); undoAction.setEnabled(enabled && editable && undoManager.canUndo()); redoAction.setEnabled(enabled && editable && undoManager.canRedo()); cutAction.setEnabled(enabled && editable && marked); copyAction.setEnabled(enabled && marked); pasteAction.setEnabled(enabled && editable && pasteAvailable); deleteAction.setEnabled(enabled && editable && marked); selectAllAction.setEnabled(enabled && nonempty); int nx = e.getX(); if (nx > 500) { nx = nx - popup.getSize().width; } popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height); } }
@Override public void undo() { editor.getDocument().addDocumentListener(this); super.undo(); editor.getDocument().removeDocumentListener(this); }
@Override public void redo() { editor.getDocument().addDocumentListener(this); super.redo(); editor.getDocument().removeDocumentListener(this); }
final UndoManager undo = new UndoManager(); Document doc = this.getProxy().getDocument(); doc.addUndoableEditListener(undoableEditEvent -> undo.addEdit(undoableEditEvent.getEdit()));
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) {
undoRedo.setLimit(500); notesEditor.getDocument().addUndoableEditListener(e -> undoRedo.addEdit(e.getEdit()));
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 redo() throws javax.swing.undo.CannotRedoException { compoundEdit.end(); if (firstModified == 0) { firstModified = ((StructuredEdit) editToBeRedone()).editedTime(); } boolean undoable = canUndo(); boolean changed = hasChanged(); super.redo(); firePropertyChangeEvent(UndoManager.UndoName, undoable, canUndo()); }
public void discardAllEdits() { boolean undoable = canUndo(); boolean redoable = canRedo(); boolean changed = hasChanged(); super.discardAllEdits(); modificationMarker = editToBeUndone(); firePropertyChangeEvent(UndoManager.UndoName, undoable, canUndo()); firePropertyChangeEvent(UndoManager.UndoName, redoable, canRedo()); }
public TextStandardActions(JTextComponent textComponent) { this.textComponent = textComponent; this.undoManager = new UndoManager(); initActions(); addPopupItems(); addKeyActions(); registerListeners(); }
/** * Constructs a SyntaxHighlightedStreamPane. * * @param controller the pdf reader controller * @param pluginMode the plugin mode */ public SyntaxHighlightedStreamPane(PdfReaderController controller, boolean pluginMode) { super(); initAttributes(); text = new ColorTextPane(); setViewportView(text); this.controller = controller; popupMenu = new StreamPanelContextMenu(text, this, pluginMode); text.setComponentPopupMenu(popupMenu); text.addMouseListener(new ContextMenuMouseListener(popupMenu, text)); manager = new UndoManager(); manager.setLimit(MAX_NUMBER_OF_EDITS); text.getDocument().addUndoableEditListener(manager); text.registerKeyboardAction(new UndoAction(manager), KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED); text.registerKeyboardAction(new RedoAction(manager), KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED); }
public void update() { Component c = getDocument().getFocusOwner(); if (undoManager != null && undoManager.canUndo()) { setEnabled(true); putValue(Action.NAME, undoManager.getUndoPresentationName()); } else { setEnabled(false); putValue(Action.NAME, undoText); } } }
public void update() { Component c = getDocument().getFocusOwner(); if (undoManager != null && undoManager.canRedo()) { setEnabled(true); putValue(Action.NAME, undoManager.getRedoPresentationName()); } else { setEnabled(false); putValue(Action.NAME, redoText); } } }
/** * Add an edit to the undo manager. * <p/> * Since we don't specify the edit type or name, further edits will not be staggered. * * @param command the command name. */ public void addEdit(String command) { if (!holdEdits) { markChanged(); undoManager.addEdit(new NodeLibraryUndoableEdit(this, command)); menuBar.updateUndoRedoState(); stopCombiningEdits(); } }