/** * 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); } }
@Override public boolean isEnabled() { JTextComponent tc = getTextComponent(null); return (tc==null || tc.isEditable()) ? super.isEnabled() : false; }
/** * Notifies all listeners that a caret change has occurred. * * @param e The caret event. */ @Override protected void fireCaretUpdate(CaretEvent e) { // Decide whether we need to repaint the current line background. possiblyUpdateCurrentLineHighlightLocation(); // Now, if there is a highlighted region of text, allow them to cut // and copy. if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) { cutAction.setEnabled(true); copyAction.setEnabled(true); } // Otherwise, if there is no highlighted region, don't let them cut // or copy. The condition here should speed things up, because this // way, we will only enable the actions the first time the selection // becomes nothing. else if (cutAction.isEnabled()) { cutAction.setEnabled(false); copyAction.setEnabled(false); } super.fireCaretUpdate(e); }
/** * 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); } }
@Override public boolean isEnabled() { JTextComponent tc = getTextComponent(null); return (tc==null || tc.isEditable()) ? super.isEnabled() : false; }
public boolean isEnabled() { JTextComponent tc = getTextComponent(null); return (tc==null || tc.isEditable()) ? super.isEnabled() : false; }
public boolean isEnabled() { JTextComponent tc = getTextComponent(null); return (tc==null || tc.isEditable()) ? super.isEnabled() : false; }
/** * Notifies all listeners that a caret change has occurred. * * @param e The caret event. */ protected void fireCaretUpdate(CaretEvent e) { // Decide whether we need to repaint the current line background. possiblyUpdateCurrentLineHighlightLocation(); // Now, if there is a highlighted region of text, allow them to cut // and copy. if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) { cutAction.setEnabled(true); copyAction.setEnabled(true); } // Otherwise, if there is no highlighted region, don't let them cut // or copy. The condition here should speed things up, because this // way, we will only enable the actions the first time the selection // becomes nothing. else if (cutAction.isEnabled()) { cutAction.setEnabled(false); copyAction.setEnabled(false); } super.fireCaretUpdate(e); }
/** * Notifies all listeners that a caret change has occurred. * * @param e The caret event. */ protected void fireCaretUpdate(CaretEvent e) { // Decide whether we need to repaint the current line background. possiblyUpdateCurrentLineHighlightLocation(); // Now, if there is a highlighted region of text, allow them to cut // and copy. if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) { cutAction.setEnabled(true); copyAction.setEnabled(true); } // Otherwise, if there is no highlighted region, don't let them cut // or copy. The condition here should speed things up, because this // way, we will only enable the actions the first time the selection // becomes nothing. else if (cutAction.isEnabled()==true) { cutAction.setEnabled(false); copyAction.setEnabled(false); } super.fireCaretUpdate(e); }
/** * Notifies all listeners that a caret change has occurred. * * @param e The caret event. */ @Override protected void fireCaretUpdate(CaretEvent e) { // Decide whether we need to repaint the current line background. possiblyUpdateCurrentLineHighlightLocation(); // Now, if there is a highlighted region of text, allow them to cut // and copy. if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) { cutAction.setEnabled(true); copyAction.setEnabled(true); } // Otherwise, if there is no highlighted region, don't let them cut // or copy. The condition here should speed things up, because this // way, we will only enable the actions the first time the selection // becomes nothing. else if (cutAction.isEnabled()) { cutAction.setEnabled(false); copyAction.setEnabled(false); } super.fireCaretUpdate(e); }