Tuesday, 13 July 2021

AsciiTable: Create custom grid theme

'TA_Grid' class provides 'addCharacterMap' method to define custom TA_Grid.

 

Signature

TA_Grid addCharacterMap(int ruleset, char none, char horizontal, char vertical, char topleft, char topright, char bottomleft, char bottomright, char midleft, char midright, char midboth, char middown, char midup)

 

Adds a new character map for a given rule set.

a.   ruleset required rule type (e.g. normal or light)

b.   none the none character (usually blank)

c.    horizontal the horizontal border character

d.   vertical the vertical border character

e.   topleft the top-left corner character

f.     topright the top-right corner character

g.   bottomleft the bottom-left corner character

h.   bottomright the bottom-right corner character

i.     midleft the mid-left corner character

j.     midright the mid-right corner character

k.    midboth the mid-both connector character

l.     middown the mid-down connector character

m. midup the mid-up connector character

 

Find the below working application.

 

CustomGridTheme.java

package com.sample.app;

import de.vandermeer.asciitable.AsciiTable;
import de.vandermeer.asciithemes.TA_Grid;
import de.vandermeer.asciithemes.TA_GridConfig;
import de.vandermeer.skb.interfaces.transformers.textformat.TextAlignment;

public class CustomGridTheme {

	public static void main(String args[]) {

		AsciiTable asciiTable = new AsciiTable();

		asciiTable.addRule();
		asciiTable.addRow("Row 1 col 1", "Row 1 col 2");

		asciiTable.addRule();
		asciiTable.addRow("Row 2 col 1", "Row 2 col 2");

		asciiTable.addRule();
		asciiTable.addRow("Row 3 col 1", "Row 3 col 2");
		asciiTable.addRule();

		asciiTable.setTextAlignment(TextAlignment.CENTER);

		TA_Grid myGrid = TA_Grid.create("grid using UTF-8 light border characters");

		myGrid.addCharacterMap(TA_GridConfig.RULESET_NORMAL, ' ', '^', '&', '#', '#', '%', '%', '+', '+', '+', '#',
				'%');

		asciiTable.getContext().setGrid(myGrid);

		String rend = asciiTable.render(35);
		System.out.println(rend);

	}

}

 


 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment