mirror of
https://github.com/NationalSecurityAgency/ghidra
synced 2024-09-13 21:56:19 +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.
|
* Build the completion window, parented to the attached field that last had focus.
|
||||||
*/
|
*/
|
||||||
protected void buildCompletionWindow() {
|
protected void buildCompletionWindow() {
|
||||||
|
if (focus == null) {
|
||||||
|
// shouldn't happen; likely some off focus issue
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
completionWindow = new JWindow(WindowUtilities.windowForComponent(focus));
|
completionWindow = new JWindow(WindowUtilities.windowForComponent(focus));
|
||||||
completionWindow.add(content);
|
completionWindow.add(content);
|
||||||
content.setVisible(true);
|
content.setVisible(true);
|
||||||
|
@ -388,8 +393,10 @@ public class TextFieldAutocompleter<T> {
|
||||||
*/
|
*/
|
||||||
private void doUpdateDisplayLocation() {
|
private void doUpdateDisplayLocation() {
|
||||||
Point p = getCompletionWindowPosition();
|
Point p = getCompletionWindowPosition();
|
||||||
|
if (p != null) {
|
||||||
completionWindow.setLocation(p);
|
completionWindow.setLocation(p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the prefix from the given text field, used to query the model.
|
* Gets the prefix from the given text field, used to query the model.
|
||||||
|
@ -431,6 +438,9 @@ public class TextFieldAutocompleter<T> {
|
||||||
* preference.
|
* preference.
|
||||||
*/
|
*/
|
||||||
protected Dimension getDefaultCompletionWindowDimension() {
|
protected Dimension getDefaultCompletionWindowDimension() {
|
||||||
|
if (focus == null) {
|
||||||
|
return new Dimension(-1, -1);
|
||||||
|
}
|
||||||
return new Dimension(focus.getWidth(), -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.
|
* 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
|
* @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) {
|
protected Point getCaretPositionOnScreen(JTextField field) {
|
||||||
|
if (focus == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
FontMetrics metrics = field.getFontMetrics(field.getFont());
|
FontMetrics metrics = field.getFontMetrics(field.getFont());
|
||||||
Caret c = field.getCaret();
|
Caret c = field.getCaret();
|
||||||
Point p = c.getMagicCaretPosition(); // returns a shared reference
|
Point p = c.getMagicCaretPosition(); // returns a shared reference
|
||||||
|
@ -555,14 +569,18 @@ public class TextFieldAutocompleter<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void completionActivated(T sel) {
|
private void completionActivated(T sel) {
|
||||||
|
if (focus == null) {
|
||||||
|
// shouldn't happen; likely some off focus issue
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AutocompletionEvent<T> ev = new AutocompletionEvent<>(sel, focus);
|
AutocompletionEvent<T> ev = new AutocompletionEvent<>(sel, focus);
|
||||||
if (!fireAutocompletionListeners(ev)) {
|
if (!fireAutocompletionListeners(ev)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
focus.getDocument()
|
focus.getDocument()
|
||||||
.insertString(focus.getCaretPosition(), getCompletionText(sel),
|
.insertString(focus.getCaretPosition(), getCompletionText(sel), null);
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
catch (BadLocationException e) {
|
catch (BadLocationException e) {
|
||||||
throw new AssertionError("INTERNAL: Should not be here", e);
|
throw new AssertionError("INTERNAL: Should not be here", e);
|
||||||
|
|
Loading…
Reference in a new issue