当前位置: 首页>>代码示例>>Java>>正文


Java JTextComponent.isEditable方法代码示例

本文整理汇总了Java中javax.swing.text.JTextComponent.isEditable方法的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent.isEditable方法的具体用法?Java JTextComponent.isEditable怎么用?Java JTextComponent.isEditable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.JTextComponent的用法示例。


在下文中一共展示了JTextComponent.isEditable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replaceText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
static void replaceText(JTextComponent textComponent, final int offset, final int length, final String text) {
    if (!textComponent.isEditable()) {
        return;
    }
    final Document document = textComponent.getDocument();
    Runnable r = new Runnable() {
        public @Override void run() {
            try {
                if (length > 0) {
                    document.remove(offset, length);
                }
                document.insertString(offset, text, null);
            } catch (BadLocationException ble) {
                ErrorManager.getDefault().notify(ble);
            }
        }
    };
    if (document instanceof BaseDocument) {
        ((BaseDocument)document).runAtomic(r);
    } else {
        r.run();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CamelCaseOperations.java

示例2: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
	JTextComponent target = getTextComponent(e);
	boolean beep = true;
	if ((target != null) && (target.isEditable())) {
		try {
			Document doc = target.getDocument();
			int ss = target.getSelectionStart();
			int se = target.getSelectionEnd();

			if (ss != se) {
				doc.remove(ss, se - ss);
				beep = false;
			}
		} catch (BadLocationException bl) {
		}
	}
	if (beep) {
		UIManager.getLookAndFeel().provideErrorFeedback(target);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:22,代码来源:TextActions.java

示例3: mouseClicked

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
        if (!(e.getSource() instanceof JTextComponent)) {
            return;
        }

        textComponent = (JTextComponent) e.getSource();
        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 && (lastActionSelected == Actions.CUT || lastActionSelected == Actions.PASTE));
        cutAction.setEnabled(enabled && editable && marked);
        copyAction.setEnabled(enabled && marked);
        pasteAction.setEnabled(enabled && editable && pasteAvailable);
        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);
    }
}
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:33,代码来源:ContextMenuMouseListener.java

示例4: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if ((target != null) && (evt != null)) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }

        String content = evt.getActionCommand();
        if (content != null) {
            target.replaceSelection(content);
        } else {
            target.getToolkit().beep();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:BaseKit.java

示例5: show

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void show(Component invoker, int x, int y) {
	JTextComponent tc = (JTextComponent) invoker;
	String sel = tc.getSelectedText();

	boolean selected = sel != null && !sel.equals("");
	boolean enableAndEditable = tc.isEnabled() && tc.isEditable();

	cutItem.setEnabled(selected && enableAndEditable);
	copyItem.setEnabled(selected && tc.isEnabled());
	deleteItem.setEnabled(selected && enableAndEditable);
	pasteItem.setEnabled(enableAndEditable);
	selectAllItem.setEnabled(tc.isEnabled());

	super.show(invoker, x, y);
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:16,代码来源:TextComponentPopupMenu.java

示例6: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed (final ActionEvent evt, final JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }

        final Caret caret = target.getCaret();
        final BaseDocument doc = (BaseDocument)target.getDocument();
        doc.runAtomicAsUser (new Runnable () {
            public void run () {
                DocumentUtilities.setTypingModification(doc, true);
                try {
                    int dotPos = caret.getDot();
                    int eolPos = Utilities.getRowEnd(doc, dotPos);
                    int wsPos = Utilities.getNextWord(target, dotPos);
                    wsPos = (dotPos == eolPos) ? wsPos : Math.min(eolPos, wsPos);
                    doc.remove(dotPos , wsPos - dotPos);
                } catch (BadLocationException e) {
                    target.getToolkit().beep();
                } finally {
                    DocumentUtilities.setTypingModification(doc, false);
                }
            }
        });
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:ActionFactory.java

示例7: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    if (!target.isEditable() || !target.isEnabled()) {
        target.getToolkit().beep();
        return;
    }
    final BaseDocument doc = (BaseDocument) target.getDocument();
    final Indent indenter = Indent.get(doc);
    final class R implements Runnable {
        public @Override void run() {
            try {
                Caret caret = target.getCaret();
                int dotpos = caret.getDot();
                int eoloffset = Utilities.getRowEnd(target, dotpos);
                doc.insertString(eoloffset, "" + what, null); //NOI18N
                if (withNewline) {
                    //This is code from the editor module, but it is
                    //a pretty strange way to do this:
                    doc.insertString(dotpos, "-", null); //NOI18N
                    doc.remove(dotpos, 1);
                    int eolDot = Utilities.getRowEnd(target, caret.getDot());
                    int newDotPos = indenter.indentNewLine(eolDot);
                    caret.setDot(newDotPos);
                }
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    indenter.lock();
    try {
        doc.runAtomicAsUser(new R());
    } finally {
        indenter.unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:InsertSemicolonAction.java

示例8: getStateFor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
protected static State getStateFor(final JTextComponent jc) {
    if (!AquaFocusHandler.isActive(jc)) {
        return State.INACTIVE;
    }

    if (!jc.isEnabled()) {
        return State.DISABLED;
    }

    if (!jc.isEditable()) {
        return State.DISABLED;
    }

    return State.ACTIVE;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:AquaTextFieldBorder.java

示例9: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null && target.isEditable()) {
        CompletionLayoutPopup.CompletionPopup completionPopup = CompletionLayoutPopup.CompletionPopup.getInstance();
        completionPopup.show(target, -1);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ClipboardHistoryAction.java

示例10: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target == null) return;
    if (!target.isEditable() || !target.isEnabled()) {
        problem(null);
        return;
    }
    Caret caret = target.getCaret();
    BaseDocument doc = (BaseDocument)target.getDocument();
    try {
        if (caret.isSelectionVisible()) {
            int startPos = Utilities.getRowStart(doc, target.getSelectionStart());
            int endPos = target.getSelectionEnd();
            doc.atomicLock();
            try {

                if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
                    endPos--;
                }

                int pos = startPos;
                int lineCnt = Utilities.getRowCount(doc, startPos, endPos);                            

                for (;lineCnt > 0; lineCnt--) {
                    doc.insertString(pos, commentStartString, null); 
                    doc.insertString(Utilities.getRowEnd(doc,pos), commentEndString, null);
                    pos = Utilities.getRowStart(doc, pos, +1);
                }

            } finally {
                doc.atomicUnlock();
            }
        } else { // selection not visible
            doc.insertString(Utilities.getRowStart(doc, target.getSelectionStart()),
                commentStartString, null);
            doc.insertString(Utilities.getRowEnd(doc, target.getSelectionStart()),
                commentEndString, null);
        }
    } catch (BadLocationException e) {
        problem(null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:XMLKit.java

示例11: show

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void show(Component invoker, int x, int y) {
	JTextComponent target = getTextComponent(invoker);
	if (target == null) {
		return;
	}
	if (target instanceof JPasswordField) {
		boolean enabled = false;
		Object copyClientProp = target.getClientProperty("JPasswordField.cutCopyAllowed");
		if (copyClientProp != null && copyClientProp instanceof Boolean && (Boolean) copyClientProp == true) {
			enabled = true;
		}
		this.copyMenuItem.setEnabled(enabled);
		this.cutMenuItem.setEnabled(enabled);
	} else {
		if (target.getSelectionStart() != target.getSelectionEnd()) {
			this.copyMenuItem.setEnabled(true);
		} else {
			this.copyMenuItem.setEnabled(false);
		}
		if (target.getSelectionStart() != target.getSelectionEnd() && target.isEditable()) {
			this.cutMenuItem.setEnabled(true);
		} else {
			this.cutMenuItem.setEnabled(false);
		}
	}

	if (target.isEditable()) {
		this.pasteMenuItem.setEnabled(true);
	} else {
		this.pasteMenuItem.setEnabled(false);
	}
	if (target.isEditable() && target.getSelectionStart() != target.getSelectionEnd()) {
		this.deleteMenuItem.setEnabled(true);
	} else {
		this.deleteMenuItem.setEnabled(false);
	}
	if (getTextLength(target) > 0) {
		this.selectAllMenuItem.setEnabled(true);
	} else {
		this.selectAllMenuItem.setEnabled(false);
	}
	// if ((getTextLength(target) > 0) && target.isEditable()) {
	// this.clearMenuItem.setEnabled(true);
	// } else {
	// this.clearMenuItem.setEnabled(false);
	// }
	super.show(invoker, x, y);
	this.parent.requestFocus();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:51,代码来源:ClipboardActionsPopup.java

示例12: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }

        BaseDocument doc = (BaseDocument)target.getDocument();
        int dotPos = target.getCaret().getDot();
        try {
            // look for identifier around caret
            int[] block = org.netbeans.editor.Utilities.getIdentifierBlock(doc, dotPos);

            // If there is no identifier around, warn user
            if (block == null) {
                target.getToolkit().beep();
                return;
            }

            // Get the identifier to operate on
            CharSequence identifier = DocumentUtilities.getText(doc, block[0], block[1] - block[0]);

            // Handle the case we already have the work done - e.g. if we got called over 'getValue'
            if (CharSequenceUtilities.startsWith(identifier, prefix) && 
                    Character.isUpperCase(identifier.charAt(prefix.length()))) return;

            // Handle the case we have other type of known xEr: eg isRunning -> getRunning
            for (int i=0; i<prefixGroup.length; i++) {
                String actPref = prefixGroup[i];
                if (CharSequenceUtilities.startsWith(identifier, actPref)
                        && identifier.length() > actPref.length()
                        && Character.isUpperCase(identifier.charAt(actPref.length()))
                   ) {
                    doc.remove(block[0], actPref.length());
                    doc.insertString(block[0], prefix, null);
                    return;
                }
            }

            // Upcase the first letter
            Utilities.changeCase(doc, block[0], 1, Utilities.CASE_UPPER);
            // Prepend the prefix before it
            doc.insertString(block[0], prefix, null);
        } catch (BadLocationException e) {
            target.getToolkit().beep();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:ExtKit.java

示例13: replaceChar

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
static void replaceChar(JTextComponent textComponent, int offset, char c) {
    if (!textComponent.isEditable()) {
        return;
    }
    replaceText(textComponent, offset, 1, String.valueOf(c));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:CamelCaseOperations.java

示例14: isEnabled

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public boolean isEnabled() {
	JTextComponent tc = getTextComponent(null);
	return (tc==null || tc.isEditable()) ? super.isEnabled() : false;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:6,代码来源:RTextAreaEditorKit.java

示例15: canImport

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * 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.
 * @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);
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:19,代码来源:RTATextTransferHandler.java


注:本文中的javax.swing.text.JTextComponent.isEditable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。