Package ghidra.app.util
Class AddressInput
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ghidra.app.util.AddressInput
- All Implemented Interfaces:
FocusableEditor
,ImageObserver
,MenuContainer
,Serializable
,Accessible
Input field for entering address or address expression. Handles multiple address
spaces and supports both hex and decimal number modes for evaluating numbers.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Predicate
<AddressSpace> static final Predicate
<AddressSpace> Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an AddressInput field with no specified program or address.AddressInput
(AddressFactory factory) Constructs an AddressInput field and initialized with an address factory.AddressInput
(AddressFactory factory, Consumer<Address> addressChangedConsumer) Constructs an AddressInput field with a consumer to be notified when the address field changes and initialized with an address factory.AddressInput
(Program program) Constructs an AddressInput field and initialized with a program.AddressInput
(Program program, Consumer<Address> addressChangedConsumer) Constructs an AddressInput field with a consumer to be notified when the address field changes and initialized with a program.AddressInput
(Consumer<Address> addressChangedConsumer) Constructs an AddressInput field with a consumer to be called when the address field's value changes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addActionListener
(ActionListener listener) Add an action listener that will be notified anytime the user presses the return key while in the text field.void
clear()
Clear the offset part of the address field.boolean
void
Called with the editor should take focus.Gets the current address the field evaluates to or null if the text does not evaluate to a valid, unique address.Returns the address space selected in the combobox the default address space if the comboBox is not being shown.Returns the address in the field or null if the address can't be parsed.getText()
Returns the text in this field.boolean
hasInput()
Returns true if the Address input field contains text.boolean
Returns true if the address input field is editable.boolean
void
removeActionListener
(ActionListener listener) Removes the action listener from the list to be notified.void
void
select()
Select the text field that is the offset.void
setAccessibleName
(String name) Sets the accessible name for this address input field.void
setAddress
(Address address) Set the field to display the given addressvoid
setAddressErrorConsumer
(Consumer<String> addressErrorConsumer) Sets a consumer to be notified when the address input field changes, but can't be parsed into a valid address.void
setAddressFactory
(AddressFactory factory) Legacy method for setting the address factory to be used to parse address.void
setAddressSpace
(AddressSpace addressSpace) Sets the selected AddressSpace to the given space.void
setAddressSpaceEditable
(boolean state) Set the address space (if it is shown) such that it is not editable.void
setAddressSpaceFilter
(Predicate<AddressSpace> spaceFilter) Sets a filter predicate to determine which address spaces should be selectable by the user.void
setAssumeHex
(boolean hexMode) Sets the hex/decimal mode for this field.void
setComponentBorders
(Border border) Used to set the internal borders for use in specialized use cases such as a table field editor.void
setEditable
(boolean b) Set the text field to be editable or not.void
setEnabled
(boolean enabled) void
setProgram
(Program program) Set the program to be used to parse addresses and expressions and also to determine the list of valid address spaces.void
setProgram
(Program program, Predicate<AddressSpace> addessSpaceFilter) Sets the program and the address space filter at the same time.void
Sets the text in the expression input textfield.void
Set the address space and offset.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
ALL_MEMORY_SPACES
-
LOADED_MEMORY_SPACES
-
-
Constructor Details
-
AddressInput
public AddressInput()Constructs an AddressInput field with no specified program or address. -
AddressInput
Constructs an AddressInput field with a consumer to be called when the address field's value changes.- Parameters:
addressChangedConsumer
- the consumer to be called when the value in the address field changes
-
AddressInput
Constructs an AddressInput field and initialized with a program.- Parameters:
program
- the program used to evaluate the entered address expression.
-
AddressInput
Constructs an AddressInput field and initialized with an address factory.- Parameters:
factory
- the address factory used to evaluate the entered address expression.
-
AddressInput
Constructs an AddressInput field with a consumer to be notified when the address field changes and initialized with a program.- Parameters:
program
- the program used to evaluate the entered address expression.addressChangedConsumer
- the consumer to be called when the value in the address field changes
-
AddressInput
Constructs an AddressInput field with a consumer to be notified when the address field changes and initialized with an address factory.- Parameters:
factory
- the address factory used to evaluate the entered address expression.addressChangedConsumer
- the consumer to be called when the value in the address field changes
-
-
Method Details
-
setAddressSpaceFilter
Sets a filter predicate to determine which address spaces should be selectable by the user. If after filtering only one space is remaining, the address space portion of the address input field will not be shown.- Parameters:
spaceFilter
- the predicate for filtering selectable address spaces.
-
setText
Sets the text in the expression input textfield.- Parameters:
text
- the text to initialize the input textfield
-
setComponentBorders
Used to set the internal borders for use in specialized use cases such as a table field editor.- Parameters:
border
- the border to use for the internal components that make up this input field
-
setAssumeHex
public void setAssumeHex(boolean hexMode) Sets the hex/decimal mode for this field. When in hex mode, all numbers are assumed to be hexadecimal values. When in decimal mode, all numbers are assumed to be decimal numbers unless prefixed with "0x".- Parameters:
hexMode
- true to assume numbers are hexadecimal.
-
setAddress
Set the field to display the given address- Parameters:
address
- the new address to display
-
setAddressSpace
Sets the selected AddressSpace to the given space.- Parameters:
addressSpace
- the address space to set selected
-
getAddressWithExceptions
Returns the address in the field or null if the address can't be parsed.- Returns:
- The address for the current value in the text field
- Throws:
ExpressionException
- if expression can not be evaluated to a valid address.NullPointerException
- if AddressFactory has not been set.
-
getAddress
Gets the current address the field evaluates to or null if the text does not evaluate to a valid, unique address.- Returns:
- the current address the field evalutes to or null if the text does not evalute to a valid unique address.
-
getAddressSpace
Returns the address space selected in the combobox the default address space if the comboBox is not being shown.- Returns:
- the selected address space, or the default address space if no combo added, or null if no program is set.
-
hasInput
public boolean hasInput()Returns true if the Address input field contains text. The getAddress() method will return null if text is not a valid address.- Returns:
- true if the address field is not blank
-
getText
Returns the text in this field.- Returns:
- the text in this field
-
setProgram
Set the program to be used to parse addresses and expressions and also to determine the list of valid address spaces. Only loaded memory spaces will be allowed (seeAddressSpace.isLoadedMemorySpace()
).- Parameters:
program
- the program to use to resolve address expressions
-
setProgram
Sets the program and the address space filter at the same time. This avoid some weird intermediate results if the are set separately.- Parameters:
program
- the program to use to parse addresses and expressions.addessSpaceFilter
- the predicate to determine which address spaces are user selectable
-
setAddressFactory
Legacy method for setting the address factory to be used to parse address. Should only be used when a program is not readily available.- Parameters:
factory
- the address factory to be used to parse addresses.
-
setAddressErrorConsumer
Sets a consumer to be notified when the address input field changes, but can't be parsed into a valid address.- Parameters:
addressErrorConsumer
- the consumer to be notified for bad address input
-
clear
public void clear()Clear the offset part of the address field. -
select
public void select()Select the text field that is the offset. -
simulateAddressChanged
Set the address space and offset. NOTE: UnlikesetAddress(Address)
this method is intended for test use only and mimics user input with address changed notification- Parameters:
addr
- the address value
-
isEnabled
public boolean isEnabled() -
containsAddressSpaces
public boolean containsAddressSpaces() -
setAddressSpaceEditable
public void setAddressSpaceEditable(boolean state) Set the address space (if it is shown) such that it is not editable. If the combo box is shown for multiple address spaces, then the combo box is replaced with a fixed uneditable text field that shows the currently selected address space.- Parameters:
state
- false means that the combo box should not be editable
-
addActionListener
Add an action listener that will be notified anytime the user presses the return key while in the text field.- Parameters:
listener
- the action listener to be notified.
-
removeActionListener
Removes the action listener from the list to be notified.- Parameters:
listener
- the listener to be removed
-
setEnabled
public void setEnabled(boolean enabled) - Overrides:
setEnabled
in classJComponent
-
setAccessibleName
Sets the accessible name for this address input field.- Parameters:
name
- the accessible name for this address field
-
setEditable
public void setEditable(boolean b) Set the text field to be editable or not.- Parameters:
b
- true if the address input field can be edited
-
isEditable
public boolean isEditable()Returns true if the address input field is editable.- Returns:
- true if the address input field is editable.
-
focusEditor
public void focusEditor()Description copied from interface:FocusableEditor
Called with the editor should take focus.- Specified by:
focusEditor
in interfaceFocusableEditor
-
requestFocus
public void requestFocus()- Overrides:
requestFocus
in classJComponent
-