Class LineNumberDecompilerMarginProvider

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ghidra.app.decompiler.component.margin.LineNumberDecompilerMarginProvider
All Implemented Interfaces:
LayoutModelListener, DecompilerMarginProvider, ImageObserver, MenuContainer, Serializable, Accessible

public class LineNumberDecompilerMarginProvider extends JPanel implements DecompilerMarginProvider, LayoutModelListener
The built-in provider for the Decompiler's line number margin
See Also:
  • Constructor Details

    • LineNumberDecompilerMarginProvider

      public LineNumberDecompilerMarginProvider()
  • Method Details

    • setProgram

      public void setProgram(Program program, LayoutModel model, LayoutPixelIndexMap pixmap)
      Description copied from interface: DecompilerMarginProvider
      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.

      Specified by:
      setProgram in interface DecompilerMarginProvider
      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
    • setOptions

      public void setOptions(DecompileOptions options)
      Description copied from interface: DecompilerMarginProvider
      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.

      Specified by:
      setOptions in interface DecompilerMarginProvider
    • getComponent

      public Component getComponent()
      Description copied from interface: DecompilerMarginProvider
      Get the Swing component implementing the actual margin, often this
      Specified by:
      getComponent in interface DecompilerMarginProvider
      Returns:
      the component
    • modelSizeChanged

      public void modelSizeChanged(IndexMapper indexMapper)
      Description copied from interface: LayoutModelListener
      Called whenever the number of indexes changed
      Specified by:
      modelSizeChanged in interface LayoutModelListener
      Parameters:
      indexMapper - Maps indexes from before the model size change to indexes after the model size changed.
    • dataChanged

      public void dataChanged(BigInteger start, BigInteger end)
      Description copied from interface: LayoutModelListener
      Called when the data at an index or range of indexes changes.
      Specified by:
      dataChanged in interface LayoutModelListener
      Parameters:
      start - the starting index for the region of data changes.
      end - the ending index (inclusive) for the region of data changes.
    • paint

      public void paint(Graphics g)
      Overrides:
      paint in class JComponent