本文整理汇总了Java中org.netbeans.editor.Utilities.changeCase方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.changeCase方法的具体用法?Java Utilities.changeCase怎么用?Java Utilities.changeCase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.editor.Utilities
的用法示例。
在下文中一共展示了Utilities.changeCase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import org.netbeans.editor.Utilities; //导入方法依赖的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();
}
}
}