diff --git a/RSTAUI/src/main/java/org/fife/rsta/ui/AssistanceIconPanel.java b/RSTAUI/src/main/java/org/fife/rsta/ui/AssistanceIconPanel.java index afca1b1..b23febc 100644 --- a/RSTAUI/src/main/java/org/fife/rsta/ui/AssistanceIconPanel.java +++ b/RSTAUI/src/main/java/org/fife/rsta/ui/AssistanceIconPanel.java @@ -32,6 +32,9 @@ public class AssistanceIconPanel extends DecorativeIconPanel implements PropertyChangeListener { + private ComponentListener listener; + private JComponent listenedToComponent; + /** * The tool tip text for the light bulb icon. It is assumed that access * to this field is single-threaded (on the EDT). @@ -66,14 +69,16 @@ public AssistanceIconPanel(JComponent comp, int iconWidth) { private void init(JComponent comp) { + listenedToComponent = comp; + // null can be passed to make a "filler" icon panel for alignment // purposes. - if (comp!=null) { + if (listenedToComponent != null) { - ComponentListener listener = new ComponentListener(); + listener = new ComponentListener(); - if (comp instanceof JComboBox) { - JComboBox combo = (JComboBox)comp; + if (listenedToComponent instanceof JComboBox) { + JComboBox combo = (JComboBox)listenedToComponent; Component c = combo.getEditor().getEditorComponent(); if (c instanceof JTextComponent) { // Always true JTextComponent tc = (JTextComponent)c; @@ -81,10 +86,10 @@ private void init(JComponent comp) { } } else { // Usually a JTextComponent - comp.addFocusListener(listener); + listenedToComponent.addFocusListener(listener); } - comp.addPropertyChangeListener( + listenedToComponent.addPropertyChangeListener( ContentAssistable.ASSISTANCE_IMAGE, this); } @@ -139,6 +144,35 @@ public void setAssistanceEnabled(Image img) { } + @Override + public void updateUI() { + + // Since we actually listen to a child component of combo boxes, + // we must stop listening to the prior child component... + if (listenedToComponent instanceof JComboBox) { + JComboBox combo = (JComboBox)listenedToComponent; + Component c = combo.getEditor().getEditorComponent(); + if (c instanceof JTextComponent) { // Always true + JTextComponent tc = (JTextComponent)c; + tc.removeFocusListener(listener); + } + } + + super.updateUI(); + + // And start listening to the new one, since this might have + // changed because of the UI change. + if (listenedToComponent instanceof JComboBox) { + JComboBox combo = (JComboBox)listenedToComponent; + Component c = combo.getEditor().getEditorComponent(); + if (c instanceof JTextComponent) { // Always true + JTextComponent tc = (JTextComponent)c; + tc.addFocusListener(listener); + } + } + } + + /** * Listens for events in the text component we're annotating. */ diff --git a/RSTAUI/src/main/java/org/fife/rsta/ui/search/RegexAwareComboBox.java b/RSTAUI/src/main/java/org/fife/rsta/ui/search/RegexAwareComboBox.java index 96521d3..dc1d6c3 100644 --- a/RSTAUI/src/main/java/org/fife/rsta/ui/search/RegexAwareComboBox.java +++ b/RSTAUI/src/main/java/org/fife/rsta/ui/search/RegexAwareComboBox.java @@ -240,18 +240,22 @@ public void setAutoCompleteEnabled(boolean enabled) { } - /** - * Sets the image to display by this text field when content - * assistance is available. - * - * @param image The image. If this is {@code null}, a default image - * (a light bulb) is used). This should be kept small, around - * 8x8 for standard resolution monitors. - * @see #getContentAssistImage() - */ - public void setContentAssistImage(Image image) { - contentAssistImage = image; - } + /** + * Sets the image to display by this text field when content + * assistance is available. + * + * @param image The image. If this is {@code null}, a default image + * (a light bulb) is used). This should be kept small, around + * 8x8 for standard resolution monitors. + * @see #getContentAssistImage() + */ + public void setContentAssistImage(Image image) { + if (image != contentAssistImage) { + Image old = contentAssistImage; + contentAssistImage = image; + firePropertyChange(ContentAssistable.ASSISTANCE_IMAGE, old, image); + } + } /**