Package ghidra.app.decompiler.component.margin

# Interface DecompilerMarginProvider

All Known Implementing Classes:
  `LineNumberDecompilerMarginProvider`

public interface DecompilerMarginProvider
A provider of a margin Swing component

To add a margin to the decompiler, a client must implement this interface to provide the component that is actually added to the UI. For a reference implementation, see `LineNumberDecompilerMarginProvider`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Component`
  `getComponent()`
  Get the Swing component implementing the actual margin, often `this`
  `default void`
  `setOptions(DecompileOptions options)`
  Set the options for the margin
  `void`
  `setProgram(Program program, LayoutModel model, LayoutPixelIndexMap pixmap)`
  Called whenever the program, function, or layout changes

- ## Method Details

  - ### setProgram

    void setProgram(Program program, LayoutModel model, LayoutPixelIndexMap pixmap)
    Called whenever the program, function, or layout changes

    The implementation should keep a reference at least to the `model` and the `pixmap` for later use during painting. The model provides access to the lines of decompiler C code. Each layout corresponds to a single line of C code. For example, the first line of code is rendered by the layout at index 0. The tenth is rendered by the layout at index 9. Rarely, a line may be wrapped by the renderer, leading to a non-uniform layout. The `pixmap` can map from a pixel's vertical position to the layout index at the same position in the main panel. It accounts for scrolling an non-uniformity. It is safe to assume the layouts render contiguous lines of C code. The recommended strategy for painting is thus:

    1. Compute the visible part of the margin needing repainting. See `JComponent.getVisibleRect()`
    2. Compute the layout indices for the vertical bounds of that part. See `LayoutPixelIndexMap.getIndex(int)`
    3. Iterate over the layouts within those bounds, inclusively.
    4. Compute the vertical position of each layout and paint something appropriate for its corresponding line. See `LayoutPixelIndexMap.getPixel(BigInteger)`

    A call to this method should cause the component to be repainted.

    Parameters:
      `program` - the program for the current function
      `model` - the line/token model
      `pixmap` - a map from pixels' y coordinates to layout index, i.e, line number

  - ### getComponent

    Component getComponent()
    Get the Swing component implementing the actual margin, often `this`
    Returns:
      the component

  - ### setOptions

    default void setOptions(DecompileOptions options)
    Set the options for the margin

    This is called at least once when the provider is added to the margin service. See `DecompilerMarginService.addMarginProvider(DecompilerMarginProvider)`. It subsequently called whenever a decompiler option changes. To receive other options, the provider will need to listen using its own mechanism.

    A call to this method should cause the component to be repainted. Implementors may choose to repaint only when certain options change.