use of javax.swing.text.Caret in project enclojure by EricThorsen.
the class ClojureCodeCompletion_Provider method getAllHippieMatches.
public static ArrayList<String> getAllHippieMatches(JTextComponent target) {
ArrayList<String> ret = new ArrayList<String>();
EditorUI editorUI = Utilities.getEditorUI(target);
Caret caret = target.getCaret();
int dotPos = caret.getDot();
WordMatch m = editorUI.getWordMatch();
if (m != null) {
String s = null;
String searchWord = "";
int c = 0;
do {
c += 1;
s = m.getMatchWord(dotPos, false);
if (s != null && !ret.contains(s)) {
ret.add(s);
if (c == 1)
searchWord = m.getPreviousWord();
}
} while (s != null && m.isFound());
if (searchWord == null)
searchWord = "";
do {
s = m.getMatchWord(dotPos + searchWord.length() + 2, true);
if (s != null && !ret.contains(s))
if (!s.equalsIgnoreCase(searchWord) && !ret.contains(s))
ret.add(s);
} while (s != null && m.isFound());
}
return ret;
}
use of javax.swing.text.Caret in project omegat by omegat-org.
the class StaticUIUtils method makeCaretAlwaysVisible.
/**
* Make caret visible even when the {@link JTextComponent} is not editable.
*/
public static FocusListener makeCaretAlwaysVisible(final JTextComponent comp) {
FocusListener listener = new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
Caret caret = comp.getCaret();
caret.setVisible(true);
caret.setSelectionVisible(true);
}
};
comp.addFocusListener(listener);
return listener;
}
use of javax.swing.text.Caret in project blue by kunstmusik.
the class RemoveSemiColonLineCommentAction method actionPerformed.
@Override
public void actionPerformed(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(() -> {
try {
int startPos;
int endPos;
if (Utilities.isSelectionShowing(caret)) {
startPos = Utilities.getRowStart(doc, target.getSelectionStart());
endPos = target.getSelectionEnd();
if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
endPos--;
}
endPos = Utilities.getRowEnd(doc, endPos);
} else {
// selection not visible
startPos = Utilities.getRowStart(doc, caret.getDot());
endPos = Utilities.getRowEnd(doc, caret.getDot());
}
int lineCount = Utilities.getRowCount(doc, startPos, endPos);
uncomment(doc, startPos, lineCount);
} catch (BadLocationException e) {
target.getToolkit().beep();
}
});
}
}
use of javax.swing.text.Caret in project jsql-injection by ron190.
the class DeleteNextCharAction method actionPerformed.
/**
* The operation to perform when this action is triggered.
*/
@Override
public void actionPerformed(ActionEvent e) {
JTextComponent target = this.getTextComponent(e);
if ((target != null) && (target.isEditable())) {
try {
Document doc = target.getDocument();
Caret caret = target.getCaret();
int dot = caret.getDot();
int mark = caret.getMark();
if (dot != mark) {
doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
} else if (dot < doc.getLength()) {
int delChars = 1;
if (dot < doc.getLength() - 1) {
String dotChars = doc.getText(dot, 2);
char c0 = dotChars.charAt(0);
char c1 = dotChars.charAt(1);
if (c0 >= '\uD800' && c0 <= '\uDBFF' && c1 >= '\uDC00' && c1 <= '\uDFFF') {
delChars = 2;
}
}
doc.remove(dot, delChars);
}
} catch (BadLocationException ble) {
LOGGER.error(ble, ble);
}
}
}
use of javax.swing.text.Caret in project jsql-injection by ron190.
the class SilentDeleteTextAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JTextComponent target = this.getTextComponent(e);
if (Objects.nonNull(target) && target.isEditable()) {
Caret caret = target.getCaret();
int dot = caret.getDot();
int mark = caret.getMark();
if (DefaultEditorKit.deletePrevCharAction.equals(this.getValue(Action.NAME))) {
// @see javax/swing/text/DefaultEditorKit.java DeletePrevCharAction
if (dot == 0 && mark == 0) {
return;
}
} else {
// @see javax/swing/text/DefaultEditorKit.java DeleteNextCharAction
Document doc = target.getDocument();
if (dot == mark && doc.getLength() == dot) {
return;
}
}
}
this.deleteAction.actionPerformed(e);
}
Aggregations