MCPcopy Create free account
hub / github.com/HumbleUI/JWM / accept

Method accept

examples/dashboard/java/PanelTextInput.java:34–112  ·  view source on GitHub ↗
(Event e)

Source from the content-addressed store, hash-verified

32 }
33
34 @Override
35 public void accept(Event e) {
36 if (e instanceof EventTextInput ee) {
37 int start = ee.getReplacementStart() == -1 ? text.length() : ee.getReplacementStart();
38 int end = start + ee.getReplacementEnd() - ee.getReplacementStart();
39 text = text.substring(0, start) + ee.getText() + text.substring(end);
40 lastMarked = null;
41 window.requestFrame();
42 } else if (e instanceof EventTextInputMarked ee) {
43 int start = ee.getReplacementStart() == -1 ? text.length() : ee.getReplacementStart();
44 int end = start + ee.getReplacementEnd() - ee.getReplacementStart();
45 text = text.substring(0, start) + text.substring(end);
46 lastMarked = ee;
47 window.requestFrame();
48 } else if (e instanceof EventMouseButton ee) {
49 window.unmarkText();
50 window.requestFrame();
51 } else if (e instanceof EventMouseMove ee) {
52 boolean isInside = contains(ee.getX(), ee.getY());
53 if (!_wasInside && isInside)
54 window.setMouseCursor(MouseCursor.IBEAM);
55 if (_wasInside && !isInside)
56 window.setMouseCursor(MouseCursor.ARROW);
57 _wasInside = isInside;
58 } else if (e instanceof EventKey ee) {
59 Key key = ee.getKey();
60 KeyLocation loc = ee.getLocation();
61
62 var keyText = loc == KeyLocation.DEFAULT ? key.getName() : capitalize(loc.toString()) + " " + key.getName();
63 if (ee.isPressed() && !keys.contains(keyText))
64 keys.add(keyText);
65 else if (!ee.isPressed())
66 keys.remove(keyText);
67
68 if (ee.isPressed()) {
69 switch (key) {
70 case ENTER -> text += "\n";
71
72 case BACKSPACE -> {
73 if (lastMarked == null && text.length() > 0) {
74 try (var iter = BreakIterator.makeCharacterInstance();) {
75 iter.setText(text);
76 text = text.substring(0, iter.preceding(text.length()));
77 }
78 }
79 }
80
81 case SPACE -> {
82 if (Platform.CURRENT == Platform.MACOS
83 && ee.isModifierDown(KeyModifier.CONTROL)
84 && ee.isModifierDown(KeyModifier.MAC_COMMAND))
85 {
86 App.openSymbolsPalette();
87 }
88 }
89 }
90
91 if (ee.isModifierDown(Example.MODIFIER)) {

Callers

nothing calls this directly

Calls 13

openSymbolsPaletteMethod · 0.95
setMethod · 0.95
makePlainTextMethod · 0.95
getMethod · 0.95
getStringMethod · 0.95
getFormatsMethod · 0.95
containsMethod · 0.80
capitalizeMethod · 0.80
requestFrameMethod · 0.45
unmarkTextMethod · 0.45
setMouseCursorMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected