MCPcopy
hub / github.com/Col-E/Recaf / SearchBar

Method SearchBar

src/main/java/me/coley/recaf/ui/controls/SearchBar.java:40–84  ·  view source on GitHub ↗

@param text Supplier of searchable text.

(Supplier<String> text)

Source from the content-addressed store, hash-verified

38 * Supplier of searchable text.
39 */
40 public SearchBar(Supplier<String> text) {
41 setAlignment(Pos.CENTER_LEFT);
42 setHgap(7);
43 ColumnConstraints column1 = new ColumnConstraints();
44 column1.setPercentWidth(75);
45 ColumnConstraints column2 = new ColumnConstraints();
46 column2.setPercentWidth(25);
47 getColumnConstraints().addAll(column1, column2);
48 // TODO: Better search field:
49 // - Options
50 // - regex
51 this.text = text;
52 getStyleClass().add("context-menu");
53 txtSearch.getStyleClass().add("search-field");
54 txtSearch.setOnKeyPressed(e -> {
55 // Check if we've updated the search query
56 String searchText = e.getText();
57 if(!searchText.equals(lastSearchText)) {
58 dirty = true;
59 }
60 lastSearchText = searchText;
61 // Handle operations
62 if(e.getCode().getName().equals(KeyCode.ESCAPE.getName())) {
63 // Escape the search bar
64 if(onEscape != null)
65 onEscape.run();
66 } else if(e.getCode().getName().equals(KeyCode.ENTER.getName())) {
67 // Empty check
68 if (txtSearch.getText().isEmpty()) {
69 results = null;
70 return;
71 }
72 // Find next
73 // - Run search if necessary
74 if(dirty) {
75 results = search();
76 dirty = false;
77 }
78 if(onSearch != null && results != null)
79 onSearch.accept(results);
80 }
81 });
82 add(txtSearch, 0, 0);
83 add(lblResults, 1, 0);
84 }
85
86 /**
87 * @param onSearch

Callers

nothing calls this directly

Calls 9

searchMethod · 0.95
acceptMethod · 0.80
getNameMethod · 0.65
runMethod · 0.65
addMethod · 0.45
getTextMethod · 0.45
equalsMethod · 0.45
getCodeMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected