本文整理汇总了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();
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
}
示例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);
}
示例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);
}
}
});
}
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}
}
}
示例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));
}
示例14: isEnabled
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public boolean isEnabled() {
JTextComponent tc = getTextComponent(null);
return (tc==null || tc.isEditable()) ? super.isEnabled() : false;
}
示例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);
}