@Override public boolean isEnabled() { return textArea.isEditable(); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } Date today = new Date(); DateFormat timeDateStamp = DateFormat.getDateTimeInstance(); String dateString = timeDateStamp.format(today); textArea.replaceSelection(dateString); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } String content = e.getActionCommand(); if (content != null) { textArea.replaceSelection(content); } else { UIManager.getLookAndFeel().provideErrorFeedback(textArea); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } textArea.replaceSelection("\n"); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } textArea.replaceSelection("\t"); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } String selection = textArea.getSelectedText(); if (selection!=null) { StringBuilder buffer = new StringBuilder(selection); int length = buffer.length(); for (int i=0; i<length; i++) { char c = buffer.charAt(i); if (Character.isUpperCase(c)) { buffer.setCharAt(i, Character.toLowerCase(c)); } else if (Character.isLowerCase(c)) { buffer.setCharAt(i, Character.toUpperCase(c)); } } textArea.replaceSelection(buffer.toString()); } textArea.requestFocusInWindow(); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (textArea.isEnabled() && textArea.isEditable()) { textArea.undoLastAction(); textArea.requestFocusInWindow(); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } String selection = textArea.getSelectedText(); if (selection!=null) { textArea.replaceSelection(selection.toLowerCase()); } textArea.requestFocusInWindow(); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } String selection = textArea.getSelectedText(); if (selection!=null) { textArea.replaceSelection(selection.toUpperCase()); } textArea.requestFocusInWindow(); }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (textArea.isEnabled() && textArea.isEditable()) { textArea.redoLastAction(); textArea.requestFocusInWindow(); } }
/** * Configures the popup menu for this text area. This method is called * right before it is displayed, so a hosting application can do any * custom configuration (configuring actions, adding/removing items, etc.). * <p> * * The default implementation does nothing.<p> * * If you set the popup menu via {@link #setPopupMenu(JPopupMenu)}, you * will want to override this method, especially if you removed any of the * menu items in the default popup menu. * * @param popupMenu The popup menu. This will never be <code>null</code>. * @see #createPopupMenu() * @see #setPopupMenu(JPopupMenu) */ protected void configurePopupMenu(JPopupMenu popupMenu) { boolean canType = isEditable() && isEnabled(); // Since the user can customize the popup menu, these actions may not // have been created. if (undoMenuItem!=null) { undoMenuItem.setEnabled(undoAction.isEnabled() && canType); redoMenuItem.setEnabled(redoAction.isEnabled() && canType); cutMenuItem.setEnabled(cutAction.isEnabled() && canType); pasteMenuItem.setEnabled(pasteAction.isEnabled() && canType); deleteMenuItem.setEnabled(deleteAction.isEnabled() && canType); } }
if (textArea != null && textArea.isEditable()) { try { Document doc = textArea.getDocument();
if (textArea != null && textArea.isEditable()) { try { Document doc = textArea.getDocument();
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } try { int end = textArea.getSelectionStart(); int start = getPreviousWordStart(textArea, end); if (end>start) { textArea.getDocument().remove(start, end-start); } } catch (BadLocationException ex) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } RSyntaxTextArea sta = (RSyntaxTextArea)textArea; boolean noSelection= sta.getSelectionStart()==sta.getSelectionEnd(); // First, see if this language wants to handle inserting newlines // itself. boolean handled = false; if (noSelection) { RSyntaxDocument doc = (RSyntaxDocument)sta.getDocument(); handled = doc.insertBreakSpecialHandling(e); } // If not... if (!handled) { handleInsertBreak(sta, noSelection); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } RSyntaxTextArea rsta = (RSyntaxTextArea)getTextComponent(e); RSyntaxDocument doc = (RSyntaxDocument)rsta.getDocument(); int line = textArea.getCaretLineNumber(); int type = doc.getLastTokenTypeOnLine(line); if (type<0) { type = doc.getClosestStandardTokenTypeForInternalType(type); } // Only in MLC's should we try this if (type==Token.COMMENT_DOCUMENTATION || type==Token.COMMENT_MULTILINE) { insertBreakInMLC(e, rsta, line); } else { handleInsertBreak(rsta, true); } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { return;
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return;
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } int selStart = textArea.getSelectionStart(); int selEnd = textArea.getSelectionEnd(); try { int line1 = textArea.getLineOfOffset(selStart); int startOffs = textArea.getLineStartOffset(line1); int line2 = textArea.getLineOfOffset(selEnd); int endOffs = textArea.getLineEndOffset(line2); // Don't remove the last line if no actual chars are selected if (line2>line1) { if (selEnd==textArea.getLineStartOffset(line2)) { endOffs = selEnd; } } textArea.replaceRange(null, startOffs, endOffs); } catch (BadLocationException ble) { ble.printStackTrace(); // Never happens } }
@Override public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { if (!textArea.isEditable() || !textArea.isEnabled()) { UIManager.getLookAndFeel().provideErrorFeedback(textArea); return; } try { Caret c = textArea.getCaret(); int caretPos = c.getDot(); Document doc = textArea.getDocument(); Element map = doc.getDefaultRootElement(); int lineCount = map.getElementCount(); int line = map.getElementIndex(caretPos); if (line==lineCount-1) { UIManager.getLookAndFeel(). provideErrorFeedback(textArea); return; } Element lineElem = map.getElement(line); caretPos = lineElem.getEndOffset() - 1; c.setDot(caretPos); // Gets rid of any selection. doc.remove(caretPos, 1); // Should be '\n'. } catch (BadLocationException ble) { /* Shouldn't ever happen. */ ble.printStackTrace(); } textArea.requestFocusInWindow(); }