mirror of
https://github.com/NationalSecurityAgency/ghidra
synced 2024-08-28 13:30:21 +00:00
Merge remote-tracking branch
'origin/GP-2616-dragonmacher-patch-window-npe' (Closes #4604)
This commit is contained in:
commit
7641a386a1
|
@ -336,6 +336,11 @@ public class TextFieldAutocompleter<T> {
|
|||
* Build the completion window, parented to the attached field that last had focus.
|
||||
*/
|
||||
protected void buildCompletionWindow() {
|
||||
if (focus == null) {
|
||||
// shouldn't happen; likely some off focus issue
|
||||
return;
|
||||
}
|
||||
|
||||
completionWindow = new JWindow(WindowUtilities.windowForComponent(focus));
|
||||
completionWindow.add(content);
|
||||
content.setVisible(true);
|
||||
|
@ -388,7 +393,9 @@ public class TextFieldAutocompleter<T> {
|
|||
*/
|
||||
private void doUpdateDisplayLocation() {
|
||||
Point p = getCompletionWindowPosition();
|
||||
completionWindow.setLocation(p);
|
||||
if (p != null) {
|
||||
completionWindow.setLocation(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -431,6 +438,9 @@ public class TextFieldAutocompleter<T> {
|
|||
* preference.
|
||||
*/
|
||||
protected Dimension getDefaultCompletionWindowDimension() {
|
||||
if (focus == null) {
|
||||
return new Dimension(-1, -1);
|
||||
}
|
||||
return new Dimension(focus.getWidth(), -1);
|
||||
}
|
||||
|
||||
|
@ -438,9 +448,13 @@ public class TextFieldAutocompleter<T> {
|
|||
* A convenience function that returns the bottom on-screen position of the given field's caret.
|
||||
*
|
||||
* @param field the field, typically the one having focus
|
||||
* @return the on-screen position of the caret's bottom.
|
||||
* @return the on-screen position of the caret's bottom; null if the given field is null
|
||||
*/
|
||||
protected Point getCaretPositionOnScreen(JTextField field) {
|
||||
if (focus == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FontMetrics metrics = field.getFontMetrics(field.getFont());
|
||||
Caret c = field.getCaret();
|
||||
Point p = c.getMagicCaretPosition(); // returns a shared reference
|
||||
|
@ -555,14 +569,18 @@ public class TextFieldAutocompleter<T> {
|
|||
}
|
||||
|
||||
private void completionActivated(T sel) {
|
||||
if (focus == null) {
|
||||
// shouldn't happen; likely some off focus issue
|
||||
return;
|
||||
}
|
||||
|
||||
AutocompletionEvent<T> ev = new AutocompletionEvent<>(sel, focus);
|
||||
if (!fireAutocompletionListeners(ev)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
focus.getDocument()
|
||||
.insertString(focus.getCaretPosition(), getCompletionText(sel),
|
||||
null);
|
||||
.insertString(focus.getCaretPosition(), getCompletionText(sel), null);
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
throw new AssertionError("INTERNAL: Should not be here", e);
|
||||
|
|
Loading…
Reference in a new issue