1 | package com.jsql.view.swing.text.action; | |
2 | ||
3 | import com.jsql.util.LogLevelUtil; | |
4 | import org.apache.logging.log4j.LogManager; | |
5 | import org.apache.logging.log4j.Logger; | |
6 | ||
7 | import javax.swing.text.BadLocationException; | |
8 | import javax.swing.text.Document; | |
9 | import javax.swing.text.JTextComponent; | |
10 | import javax.swing.text.TextAction; | |
11 | import java.awt.event.ActionEvent; | |
12 | ||
13 | /** | |
14 | * Action to cancel Beep sound when deleting last character. | |
15 | * Used on TextPane and TextArea. | |
16 | */ | |
17 | public abstract class AbstractCharAction extends TextAction { | |
18 | | |
19 | /** | |
20 | * Log4j logger sent to view. | |
21 | */ | |
22 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
23 | ||
24 | /** | |
25 | * Create this object with the appropriate identifier. | |
26 | */ | |
27 | protected AbstractCharAction(String deleteAction) { | |
28 | super(deleteAction); | |
29 | } | |
30 | ||
31 | protected abstract void delete(Document doc, int dot) throws BadLocationException; | |
32 | ||
33 | /** | |
34 | * The operation to perform when this action is triggered. | |
35 | */ | |
36 | @Override | |
37 | public void actionPerformed(ActionEvent event) { | |
38 | | |
39 | JTextComponent target = this.getTextComponent(event); | |
40 | ||
41 |
2
1. actionPerformed : negated conditional → NO_COVERAGE 2. actionPerformed : negated conditional → NO_COVERAGE |
if (target == null || !target.isEditable()) { |
42 | return; | |
43 | } | |
44 | | |
45 | try { | |
46 | var doc = target.getDocument(); | |
47 | var caret = target.getCaret(); | |
48 | int dot = caret.getDot(); | |
49 | int mark = caret.getMark(); | |
50 | | |
51 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (dot != mark) { |
52 |
2
1. actionPerformed : removed call to javax/swing/text/Document::remove → NO_COVERAGE 2. actionPerformed : Replaced integer subtraction with addition → NO_COVERAGE |
doc.remove(Math.min(dot, mark), Math.abs(dot - mark)); |
53 | } else { | |
54 |
1
1. actionPerformed : removed call to com/jsql/view/swing/text/action/AbstractCharAction::delete → NO_COVERAGE |
this.delete(doc, dot); |
55 | } | |
56 | } catch (BadLocationException e) { | |
57 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
58 | } | |
59 | } | |
60 | } | |
Mutations | ||
41 |
1.1 2.2 |
|
51 |
1.1 |
|
52 |
1.1 2.2 |
|
54 |
1.1 |