Example usage for javax.swing.text JTextComponent isEditable

List of usage examples for javax.swing.text JTextComponent isEditable

Introduction

In this page you can find the example usage for javax.swing.text JTextComponent isEditable.

Prototype

public boolean isEditable() 

Source Link

Document

Returns the boolean indicating whether this TextComponent is editable or not.

Usage

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions.
 *///from   w ww  .j  a  v a 2 s .  c o m
protected void addCopyMenu(final JTextComponent component) {
    Preconditions.checkNotNull(component);

    if (!component.isEditable()) {
        component.setCursor(new Cursor(Cursor.TEXT_CURSOR));
    }

    final JPopupMenu contextMenu = new JPopupMenu();
    JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction));
    copy.setText(i18n.getString(I18n.TEXT_COPY_ID));
    contextMenu.add(copy);
    contextMenu.addSeparator();

    JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction));
    selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID));
    contextMenu.add(selectAll);

    component.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                contextMenu.show(component, e.getX(), e.getY());
            }
        }
    });
}

From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java

/**
 * creates CAP for Actions Replace Text/*from  w  w w  .  ja  v a  2 s  . c  om*/
 * @param source Component
 */
protected void replaceText(Component source) {
    Component src = source;
    Component parent = getComponentParent() != null ? getComponentParent() : src.getParent();
    if (parent instanceof JComboBox) {
        src = parent;
    }
    String text = null;
    boolean isEditable = false;
    boolean isCbxItem = false;
    boolean isSupported = true;
    if (src instanceof JTextComponent) {
        JTextComponent jtf = (JTextComponent) src;
        text = jtf.getText();
        isEditable = jtf.isEditable();
        if ((source instanceof JTextArea || source instanceof JTextPane || source instanceof JEditorPane)
                && (text.indexOf(CharacterConstants.LINEFEED) != -1
                        || text.indexOf(CharacterConstants.RETURN) != -1)) {
            isSupported = false;
            sendInfoMessage(Constants.REC_MULTILINE_MSG);
        }
        if (parent instanceof JTable) {
            JTable tbl = (JTable) parent;
            replaceTableText(src, tbl, text);
            return;
        }
    }
    if (src instanceof JComboBox) {
        JComboBox cbx = (JComboBox) src;
        isEditable = cbx.isEditable();
        if (isEditable) {
            ComboBoxEditor cbxEditor = cbx.getEditor();
            text = cbxEditor.getItem().toString();
            String[] cbxItems = m_recordHelper.getRenderedComboItems(cbx);
            for (int i = 0; i < cbxItems.length; i++) {
                String item = cbxItems[i];
                if (item.equals(text)) {
                    isCbxItem = true;
                }
            }
        } else {
            return;
        }
    }
    if (text.length() > Constants.REC_MAX_STRING_LENGTH) {
        ShowObservInfoMessage infoMsg = new ShowObservInfoMessage(Constants.REC_MAX_STRING_MSG);
        try {
            AUTServer.getInstance().getServerCommunicator().send(infoMsg);
        } catch (CommunicationException e) {
            // no log available here
        }
        return;
    }
    if (m_map.get(source) != null && !(text.equals(m_map.get(source).toString())) && isSupported && isEditable
            && !isCbxItem) {
        m_map.put(src, text);
        IComponentIdentifier id = null;
        try {
            id = ComponentHandler.getIdentifier(src);
            Action a = new Action();
            a = m_recordHelper.compSysToAction(id, "CompSystem.InputText"); //$NON-NLS-1$        
            List parameterValues = new LinkedList();
            text = StringParsing.singleQuoteText(text);
            parameterValues.add(text);
            String logName = createLogicalName(src, id);
            createCAP(a, id, parameterValues, logName);
        } catch (NoIdentifierForComponentException nifce) {
            // no identifier for the component, log this as an error
            log.error("no identifier for '" + src); //$NON-NLS-1$
        }
    }
}

From source file:org.fife.ui.rtextarea.RTATextTransferHandler.java

/**
 * This method indicates if a component would accept an import of the
 * given set of data flavors prior to actually attempting to import it. 
 *
 * @param comp The component to receive the transfer.  This argument is
 *        provided to enable sharing of TransferHandlers by multiple
 *        components.//from ww w  . j  a v  a2s. com
 * @param flavors The data formats available.
 * @return <code>true</code> iff the data can be inserted.
 */
@Override
public boolean canImport(JComponent comp, DataFlavor[] flavors) {
    JTextComponent c = (JTextComponent) comp;
    if (!(c.isEditable() && c.isEnabled()))
        return false;
    return (getImportFlavor(flavors, c) != null);
}