use of javax.swing.text.Caret in project blue by kunstmusik.
the class AddSemiColonLineCommentAction 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 (org.netbeans.editor.Utilities.isSelectionShowing(caret)) {
startPos = org.netbeans.editor.Utilities.getRowStart(doc, target.getSelectionStart());
endPos = target.getSelectionEnd();
if (endPos > 0 && org.netbeans.editor.Utilities.getRowStart(doc, endPos) == endPos) {
endPos--;
}
endPos = org.netbeans.editor.Utilities.getRowEnd(doc, endPos);
} else {
// selection not visible
startPos = org.netbeans.editor.Utilities.getRowStart(doc, caret.getDot());
endPos = org.netbeans.editor.Utilities.getRowEnd(doc, caret.getDot());
}
int lineCount = org.netbeans.editor.Utilities.getRowCount(doc, startPos, endPos);
comment(doc, startPos, lineCount);
} catch (BadLocationException e) {
target.getToolkit().beep();
}
});
}
}
use of javax.swing.text.Caret in project jsql-injection by ron190.
the class DeletePrevCharAction method actionPerformed.
/**
* The operation to perform when this action is triggered.
*
* @param e the action event
*/
@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 > 0) {
int delChars = 1;
if (dot > 1) {
String dotChars = doc.getText(dot - 2, 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, delChars);
}
} catch (BadLocationException ble) {
LOGGER.error(ble, ble);
}
}
}
use of javax.swing.text.Caret in project omegat by omegat-org.
the class GlossaryTextArea method processKeyEvent.
@Override
protected void processKeyEvent(KeyEvent e) {
KeyStroke s = KeyStroke.getKeyStrokeForEvent(e);
if (s.equals(PropertiesShortcuts.getEditorShortcuts().getKeyStroke("editorContextMenu"))) {
JPopupMenu popup = new JPopupMenu();
populateContextMenu(popup);
Caret caret = getCaret();
Point p = caret == null ? getMousePosition() : caret.getMagicCaretPosition();
popup.show(this, (int) p.getX(), (int) p.getY());
e.consume();
}
super.processKeyEvent(e);
}
use of javax.swing.text.Caret in project omegat by omegat-org.
the class MultipleTransPane method processKeyEvent.
@Override
protected void processKeyEvent(KeyEvent e) {
KeyStroke s = KeyStroke.getKeyStrokeForEvent(e);
if (s.equals(PropertiesShortcuts.getEditorShortcuts().getKeyStroke("editorContextMenu"))) {
JPopupMenu popup = new JPopupMenu();
Caret caret = getCaret();
Point p = caret == null ? getMousePosition() : caret.getMagicCaretPosition();
populateContextMenu(popup, Java8Compat.viewToModel(MultipleTransPane.this, p));
popup.show(this, (int) p.getX(), (int) p.getY());
e.consume();
}
super.processKeyEvent(e);
}
use of javax.swing.text.Caret in project java-swing-tips by aterai.
the class FocusOwnerCaret method makeTextArea.
private static Component makeTextArea(boolean flg) {
JTextArea textArea = new JTextArea() {
@Override
public void updateUI() {
setCaret(null);
super.updateUI();
if (flg) {
Caret oldCaret = getCaret();
int blinkRate = oldCaret.getBlinkRate();
Caret caret = new FocusOwnerCaret();
caret.setBlinkRate(blinkRate);
setCaret(caret);
caret.setSelectionVisible(true);
}
}
};
textArea.setText("FocusOwnerCaret: " + flg + "\n111\n22222\n33333333\n");
textArea.selectAll();
return new JScrollPane(textArea);
}
Aggregations