Class SelectionLayerPainter

All Implemented Interfaces:
ILayerPainter
Direct Known Subclasses:
CopySelectionLayerPainter, FillHandleLayerPainter

public class SelectionLayerPainter extends GridLineCellLayerPainter
Specialised GridLineCellLayerPainter that renders an additional border around selected cells. By default the additional selection anchor border style is black dotted one pixel sized line. This style can be configured via ConfigRegistry.
See Also:
  • Constructor Details

    • SelectionLayerPainter

      public SelectionLayerPainter(org.eclipse.swt.graphics.Color gridColor)
      Create a SelectionLayerPainter that renders grid lines in the specified color and uses the default clipping behaviour.
      Parameters:
      gridColor - The color that should be used to render the grid lines.
    • SelectionLayerPainter

      public SelectionLayerPainter()
      Create a SelectionLayerPainter that renders gray grid lines and uses the default clipping behaviour.
    • SelectionLayerPainter

      public SelectionLayerPainter(org.eclipse.swt.graphics.Color gridColor, boolean clipLeft, boolean clipTop)
      Create a SelectionLayerPainter that renders grid lines in the specified color and uses the specified clipping behaviour.
      Parameters:
      gridColor - The color that should be used to render the grid lines.
      clipLeft - Configure the rendering behaviour when cells overlap. If set to true the left cell will be clipped, if set to false the right cell will be clipped. The default value is false.
      clipTop - Configure the rendering behaviour when cells overlap. If set to true the top cell will be clipped, if set to false the bottom cell will be clipped. The default value is false.
    • SelectionLayerPainter

      public SelectionLayerPainter(boolean clipLeft, boolean clipTop)
      Create a SelectionLayerPainter that renders gray grid lines and uses the specified clipping behaviour.
      Parameters:
      clipLeft - Configure the rendering behaviour when cells overlap. If set to true the left cell will be clipped, if set to false the right cell will be clipped. The default value is false.
      clipTop - Configure the rendering behaviour when cells overlap. If set to true the top cell will be clipped, if set to false the bottom cell will be clipped. The default value is false.
  • Method Details

    • paintLayer

      public void paintLayer(ILayer natLayer, org.eclipse.swt.graphics.GC gc, int xOffset, int yOffset, org.eclipse.swt.graphics.Rectangle pixelRectangle, IConfigRegistry configRegistry)
      Specified by:
      paintLayer in interface ILayerPainter
      Overrides:
      paintLayer in class GridLineCellLayerPainter
      Parameters:
      natLayer - The layer to paint.
      gc - GC used for painting
      xOffset - x offset of the layer from the origin of the table
      yOffset - y offset of the layer from the origin of the table
      pixelRectangle - area the layer can paint in
      configRegistry - IConfigRegistry in use by NatTable. Useful for looking up associated painters.
    • getBorderCells

      protected BorderPainter.BorderCell[][] getBorderCells(ILayer natLayer, int xOffset, int yOffset, org.eclipse.swt.graphics.Rectangle positionRectangle, Function<ILayerCell,Boolean> function)
      Calculate the cells around which borders should be painted.
      Parameters:
      natLayer - The layer that is painted.
      xOffset - of the layer from the origin of the table
      yOffset - of the layer from the origin of the table
      positionRectangle - The calculated position rectangle for the pixel rectangle that should be painted.
      function - The function that is used to determine if a border should be applied to a cell or not.
      Returns:
      The BorderPainter.BorderCells around which the border should be painted or null if no border rendering is necessary.
      Since:
      2.0
    • fixBoundsInGridLines

      protected org.eclipse.swt.graphics.Rectangle fixBoundsInGridLines(org.eclipse.swt.graphics.Rectangle cellBounds, int xOffset, int yOffset)
      Returns a rectangle that will cover the left and top grid lines, if they are present.
      Parameters:
      cellBounds - the rectangle that needs to be considered
      xOffset - the starting x coordinate of the area we can draw on. The fix will not be applied if the cellBounds are placed on this limit.
      yOffset - the starting y coordinate of the area we can draw on. The fix will not be applied if the cellBounds are placed on this limit.
      Returns:
      Updated rectangle.
      Since:
      1.5
    • isInCurrentLayer

      protected boolean isInCurrentLayer(int ix, int iy, int xOffset, int yOffset, org.eclipse.swt.graphics.Rectangle cellBounds, BorderPainter.BorderCell[][] borderCells)
      Tries to detect if the cell is part of the current layer. It does so using xOffset/yOffset (which are not affected by single cell updates) and detecting overlapping of cells, which should not be possible in the same layer. It's not perfect, there might be false positives.
      Parameters:
      ix - column position
      iy - row position
      xOffset - column offset
      yOffset - row offset
      cellBounds - cell bounds
      borderCells - available border cells
      Returns:
      true if the cell is part of the current layer.
      Since:
      1.5
    • getBorderStyle

      protected BorderStyle getBorderStyle(IConfigRegistry configRegistry)
      Get the border style that should be used to render the border for cells that are currently selected. Checks the IConfigRegistry for a registered IStyle for the SelectionConfigAttributes.SELECTION_GRID_LINE_STYLE label or the SelectionStyleLabels.SELECTION_ANCHOR_GRID_LINE_STYLE label. If none is registered, a default line style will be returned.
      Parameters:
      configRegistry - The IConfigRegistry to retrieve the style information from.
      Returns:
      The border style that should be used
      Since:
      1.5