Package swingtree

Class RenderAs<C extends JComponent,E,T extends E>

java.lang.Object
swingtree.RenderAs<C,E,T>
Type Parameters:
C - The type of the component which is used to render the cell.
E - The type of the value of the cell.
T - The type of the value of the cell.

public final class RenderAs<C extends JComponent,E,T extends E> extends Object
This class models the API of the RenderBuilder which allows you to specify how a cell should be rendered. Most likely you will want to call asText(Function) on this as most cells are rendered as simple texts. An example would be a combo box containing enum values, which you don't want to render as the enum name (all capital letters), but rather as a more human-readable string.
  • Method Details

    • as

      public RenderBuilder<C,E> as(Configurator<CellDelegate<C,T>> valueInterpreter)
      Specify a lambda which receives a CellDelegate instance for you to customize its renderer. This is the most generic way to customize the rendering of a cell, as you can choose between vastly different ways of rendering:
      
       		.when( MyEnum.class )
       		.as( cell -> {
       			// do component based rendering:
       			cell.setRenderer( new JLabel( "Hello World" ) );
       			// or do graphics rendering directly:
       			cell.setRenderer( g -> {
       				// draw something
       				g.drawString( "Hello World", 0, 0 );
       			});
       		})
          
      Parameters:
      valueInterpreter - A lambda which customizes the provided cell.
      Returns:
      The builder API allowing method chaining.
    • asComponent

      public RenderBuilder<C,E> asComponent(Function<CellDelegate<C,T>,Component> renderer)
      Specify a lambda which receives a CellDelegate instance and return a Component which is then used to render the cell.
      
       		.when( MyEnum.class )
       		.asComponent( cell -> new JLabel( "Hello World" ) )
          
      Parameters:
      renderer - A function which returns a Component which is then used to render the cell.
      Returns:
      The builder API allowing method chaining.
    • asText

      public RenderBuilder<C,E> asText(Function<CellDelegate<C,T>,String> renderer)
      Specify a lambda which receives a CellDelegate instance and return a String which is then used to render the cell.
      
       		.when( MyEnum.class )
       		.asText( cell -> "Hello World" )
          
      Parameters:
      renderer - A function which returns a String which is then used to render the cell.
      Returns:
      The builder API allowing method chaining.
    • render

      public RenderBuilder<C,E> render(BiConsumer<CellDelegate<C,T>,Graphics2D> renderer)
      Specify a lambda which receives a CellDelegate instance as well as a Graphics instance and then renders the cell.
      
        	.when( MyEnum.class )
        	.render( (cell, g) -> {
        		// draw something
        		g.drawString( "Hello World", 0, 0 );
          })
       
      Parameters:
      renderer - A function which receives a CellDelegate instance as well as a Graphics instance and then renders the cell.
      Returns:
      The builder API allowing method chaining.