GP-5769 - Updated dialogs with combo boxes to have consistent behavior

when the Enter key is pressed
This commit is contained in:
dragonmacher 2025-08-27 19:47:35 -04:00
parent dc09c94c81
commit dc72238178
20 changed files with 46 additions and 137 deletions

View file

@ -16,7 +16,7 @@
package docking.options.editor;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.beans.PropertyEditorSupport;
import java.util.*;
import java.util.List;
@ -65,7 +65,7 @@ public class FontPropertyEditor extends PropertyEditorSupport {
private GComboBox<FontWrapper> fontCombo;
private GComboBox<Integer> sizeCombo;
private GComboBox<String> styleCombo;
private ActionListener actionListener = e -> fontChanged();
private ItemListener itemListener = e -> fontChanged();
private List<FontWrapper> systemFontNames;
public FontChooserPanel() {
@ -78,9 +78,9 @@ public class FontPropertyEditor extends PropertyEditorSupport {
}
updatePreviewLabel(font);
fontCombo.removeActionListener(actionListener);
sizeCombo.removeActionListener(actionListener);
styleCombo.removeActionListener(actionListener);
fontCombo.removeItemListener(itemListener);
sizeCombo.removeItemListener(itemListener);
styleCombo.removeItemListener(itemListener);
FontWrapper fontWrapper = new FontWrapper(font.getName());
updateComboBoxModeIfNeeded(fontWrapper);
@ -91,10 +91,9 @@ public class FontPropertyEditor extends PropertyEditorSupport {
sizeCombo.setSelectedItem(size);
styleCombo.setSelectedIndex(styleChoice);
fontCombo.addActionListener(actionListener);
sizeCombo.addActionListener(actionListener);
styleCombo.addActionListener(actionListener);
fontCombo.addItemListener(itemListener);
sizeCombo.addItemListener(itemListener);
styleCombo.addItemListener(itemListener);
}
private void updateComboBoxModeIfNeeded(FontWrapper fontWrapper) {
@ -144,7 +143,7 @@ public class FontPropertyEditor extends PropertyEditorSupport {
styleCombo =
new GComboBox<>(new String[] { "PLAIN", "BOLD", "ITALIC", "BOLD & ITALIC" });
styleCombo.setMaximumRowCount(9);
styleCombo.addActionListener(actionListener);
styleCombo.addItemListener(itemListener);
styleCombo.getAccessibleContext().setAccessibleName("Style");
panel.add(styleCombo);
panel.getAccessibleContext().setAccessibleName("Style");
@ -163,7 +162,7 @@ public class FontPropertyEditor extends PropertyEditorSupport {
sizeCombo =
new GComboBox<>(IntStream.rangeClosed(1, 72).boxed().toArray(Integer[]::new));
sizeCombo.setMaximumRowCount(9);
sizeCombo.addActionListener(actionListener);
sizeCombo.addItemListener(itemListener);
sizeCombo.getAccessibleContext().setAccessibleName("Size");
panel.add(sizeCombo);
panel.getAccessibleContext().setAccessibleName("Size");
@ -182,7 +181,7 @@ public class FontPropertyEditor extends PropertyEditorSupport {
systemFontNames = getSystemFontNames();
fontCombo = new GComboBox<>(systemFontNames.toArray(new FontWrapper[0]));
fontCombo.setMaximumRowCount(9);
fontCombo.addActionListener(actionListener);
fontCombo.addItemListener(itemListener);
fontCombo.getAccessibleContext().setAccessibleName("Font");
panel.add(fontCombo);
panel.getAccessibleContext().setAccessibleName("Font");

View file

@ -15,6 +15,7 @@
*/
package docking.widgets.combobox;
import java.util.Collection;
import java.util.Vector;
import javax.swing.*;
@ -71,8 +72,8 @@ public class GComboBox<E> extends JComboBox<E> implements GComponent {
*
* @param items a vector containing objects of generic type {@code E} to insert into the combo box
*/
public GComboBox(Vector<E> items) {
super(items);
public GComboBox(Collection<E> items) {
super(new Vector<>(items));
init();
}

View file

@ -64,8 +64,6 @@ public class GhidraComboBox<E> extends JComboBox<E> implements GComponent {
private List<KeyListener> keyListeners = new ArrayList<>();
private boolean setSelectedFlag = false;
private boolean forwardEnter;
private Action defaultSystemEnterForwardingAction;
private Document document;
private PassThroughActionListener passThroughActionListener;
private PassThroughKeyListener passThroughKeyListener;
@ -125,20 +123,6 @@ public class GhidraComboBox<E> extends JComboBox<E> implements GComponent {
setDocument(document);
}
// HACK ALERT: see setEnterKeyForwarding(boolean)
ActionMap am = getActionMap();
if (am != null) {
defaultSystemEnterForwardingAction = am.get("enterPressed");
am.put("enterPressed", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (forwardEnter) {
defaultSystemEnterForwardingAction.actionPerformed(e);
}
}
});
}
// As mentioned above, the default editor gets replaced. In that case, restore the columns
// if the client has set the value.
if (oldColumns > 0) {
@ -147,23 +131,6 @@ public class GhidraComboBox<E> extends JComboBox<E> implements GComponent {
}
}
/**
* HACK ALERT: By default, the JComboBoxUI forwards the &lt;Enter&gt; key actions to the root
* pane of the JComboBox's container (which is used primarily by any installed 'default
* button'). The problem is that the forwarding does not happen always. In the case that the
* &lt;Enter&gt; key will trigger a selection in the combo box, the action is NOT forwarded.
* <p>
* By default Ghidra disables the forwarding altogether, since most users of
* {@link GhidraComboBox} will add an action listener to handle &lt;Enter&gt; actions.
* <p>
* To re-enable the default behavior, set the <code>forwardEnter</code> value to true.
*
* @param forwardEnter true to enable default &lt;Enter&gt; key handling.
*/
public void setEnterKeyForwarding(boolean forwardEnter) {
this.forwardEnter = forwardEnter;
}
/**
* Returns the text in combobox's editor text component
* @return the text in combobox's editor text component

View file

@ -97,7 +97,7 @@ public interface SettingsDefinition {
public String getDescription();
/**
* Removes any values in the given settings object assocated with this settings definition
* Removes any values in the given settings object associated with this settings definition
* @param settings the settings object to be cleared.
*/
public void clear(Settings settings);