Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.webcheats.format;
- import br.com.webcheats.enums.ECode;
- import br.com.webcheats.enums.EForum;
- import br.com.webcheats.enums.EIcons;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class Format {
- // os navegadores exibem as listas de forma diferente.
- // essa variável é para tratar para que ambos exibam a lista do mesmo modo.
- private final String ITEM = "▪";
- private final Sintax sintax;
- public Format() {
- this.sintax = new Sintax();
- }
- public String bold(String content){
- String code = ECode.bold.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- public String italic(String content){
- String code = ECode.italic.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- public String underline(String content){
- String code = ECode.underline.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- public String center(String content){
- String code = ECode.center.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- public String left(String content){
- String code = ECode.left.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- public String right(String content){
- String code = ECode.right.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- public String color(String color, String content){
- String code = ECode.color.code();
- return sintax.initQuote(code, color) + content + sintax.end(code);
- }
- public String size(String size, String content){
- String code = ECode.size.code();
- return sintax.initValue(code, size) + content + sintax.end(code);
- }
- public String font(String font, String content){
- String code = ECode.font.code();
- return sintax.initValue(code, font) + content + sintax.end(code);
- }
- public String spoiler(String content){
- String code = ECode.spoiler.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- public String quote(String content){
- String code = ECode.quote.code();
- return sintax.init(code) + content + sintax.end(code);
- }
- d
- public String image(String url){
- String code = ECode.image.code();
- return sintax.init(code) + url + sintax.end(code);
- }
- public String video(String url){
- String code = ECode.video.code();
- return sintax.init(code) + url + sintax.end(code);
- }
- public String link(String url, String text){
- String code = ECode.link.code();
- return sintax.initQuote(code, url) + text + sintax.end(code);
- }
- public String list(ArrayList<String>list, boolean center){
- String content = "";
- content = list.stream().map((s) -> ITEM + " " + s).reduce(content, String::concat);
- return center ? center(content) : content;
- }
- public final int ALIGN_LEFT = 0;
- public final int ALIGN_CENTER = 1;
- public final int ALIGN_RIGHT = 2;
- public String list(ArrayList<String>list, int alignType){
- String content = list(list, false);
- switch(alignType){
- case ALIGN_CENTER: return center(content);
- case ALIGN_LEFT: return left(content);
- case ALIGN_RIGHT: return right(content);
- default: return null;
- }
- }
- public String listEnum(ArrayList<String>list){
- String code = ECode.list.code();
- String item = ECode.item.code();
- String content = sintax.init(code + "=1");
- content = list.stream().map((s) -> "["+item+"] " + s).reduce(content, String::concat);
- return content += sintax.end(code);
- }
- public final int MEDIA_IMAGE = 0;
- public final int MEDIA_VIDEO = 1;
- public String listMedia(ArrayList<String>urls, int mediaType, boolean center){
- String list = "";
- for(String url:urls)
- list = (mediaType == MEDIA_IMAGE ? image(url) : video(url)) + jump();
- return center ? center(list) : list;
- }
- public String listURL(ArrayList<String>urls, String replace){
- String content = "";
- for(String url : urls)
- content = link(url, replace) + jump();
- return content;
- }
- public String listURL(ArrayList<String>urls, ArrayList<String>replaces){
- if(urls.size() == replaces.size() && urls.size() > 0){
- int size = urls.size();
- String content = "";
- for(int i = 0; i < size; i++)
- content += link(urls.get(i), replaces.get(i)) + jump();
- return content;
- }
- return null;
- }
- public String logo(String url){
- return image(url.isEmpty() ? EForum.logo.image() : url);
- }
- public String separator(String url){
- return center(image(url.isEmpty() ? EForum.separator.image() : url));
- }
- public String text(String font, String size, String content){
- return font(font, size(size, content));
- }
- public String text(String font, String size, String color, String content){
- return font(font, size(size, color(color, content)));
- }
- public String text(String icon, String font, String size, String color, String content){
- String tempicon = image(icon);
- return font(font, size(size, color(color, tempicon + " " + content)));
- }
- // manter em private, deixar o usuário usar os atributos de inteiro.
- private final String TABLE_OUTER = "class:outer_border,width:800";
- private final String TABLE_FULL = "class:grid, width:800";
- public final int TABLE_BORDER_OUTER = 0;
- public final int TABLE_BORDER_FULL = 1;
- // contrói a linha da tabela -- MANTER PRIVADO --
- public String line(ArrayList<String>lines){
- String code = ECode.line.code();
- String content = "";
- content = lines.stream().map((line) -> sintax.init(code) + line + sintax.end(code)).reduce(content, String::concat);
- return content;
- }
- // constrói a coluna da tabela -- MANTER PRIVADO --
- private String column(ArrayList<String>lines){
- String code = ECode.column.code();
- return sintax.init(code) + line(lines) + sintax.end(code);
- }
- // contrói a coluna da tabela -- MANTER PRIVADO --
- private String tableContent(ArrayList<String>columns, ArrayList<String>lines){
- String code = ECode.column.code();
- String content = "";
- content = columns.stream().map((_item) -> sintax.init(code) + line(lines) + sintax.end(code)).reduce(content, String::concat);
- return content;
- }
- public String table(ArrayList<String>columns, ArrayList<String>rows){
- String code = ECode.table.code();
- String content = sintax.init(code);
- content += tableContent(columns, rows);
- return content += sintax.end(code);
- }
- public String table(ArrayList<String>columns, ArrayList<String>lines, int alignType){
- String content = table(columns, lines);
- switch(alignType){
- case ALIGN_CENTER: return center(content);
- case ALIGN_LEFT: return left(content);
- case ALIGN_RIGHT: return right(content);
- }
- return null;
- }
- public String table(ArrayList<String>columns, ArrayList<String>lines, int border, boolean center){
- String code = ECode.table.code();
- String content = sintax.initQuote(code, border == TABLE_BORDER_FULL ? TABLE_FULL : TABLE_OUTER);
- content += tableContent(columns, lines);
- content += sintax.end(code);
- return center ? center(content) : content;
- }
- public String table(ArrayList<String>columns, ArrayList<String>lines, int border, int alignType){
- String content = table(columns, lines, border, false);
- switch(alignType){
- case ALIGN_CENTER: return center(content);
- case ALIGN_LEFT: return left(content);
- case ALIGN_RIGHT: return right(content);
- }
- return null;
- }
- // valores vindos da view.
- private final String TABLE_YES = "y";
- private final String TABLE_NO = "n";
- private ArrayList<String> arrayToArrayList(String array[]){
- ArrayList<String>temp = new ArrayList<>();
- temp.addAll(Arrays.asList(array));
- return temp;
- }
- // troca o valor da string pelo ícone correspondente
- // usado somente na tabela -- MANTER PRIVADO --
- private String setTableIcon(String identifier){
- String icon;
- switch(identifier.toLowerCase()){
- case TABLE_NO: icon = EIcons.no.icon(); break;
- case TABLE_YES: icon = EIcons.yes.icon(); break;
- default: icon = EIcons.none.icon(); break;
- }
- return image(icon);
- }
- // much better and faster than uformatter version :D
- public String tableCompatibility(ArrayList<String>system32, ArrayList<String>system64){
- if(system32.size() != system64.size()) return null;
- CompatibilityTableConstants comp = new CompatibilityTableConstants();
- String header = column(arrayToArrayList(comp.getHeader()));
- ArrayList<String>systemName = arrayToArrayList(comp.getSystem());
- ArrayList<String>tempArray;
- String body = "";
- for(int i = 0; i < systemName.size(); i++){
- tempArray = new ArrayList<>();
- tempArray.add(systemName.get(i));
- tempArray.add(setTableIcon(system32.get(i)));
- tempArray.add(setTableIcon(system64.get(i)));
- body += column(tempArray);
- }
- String code = ECode.table.code();
- return sintax.initQuote(code, TABLE_OUTER) + (header + body) + sintax.end(code);
- }
- public String tableCompability(ArrayList<String>system32, ArrayList<String>system64, int alignType){
- String content = tableCompatibility(system32, system64);
- switch(alignType){
- case ALIGN_CENTER: return center(content);
- case ALIGN_LEFT: return left(content);
- case ALIGN_RIGHT: return right(content);
- default: return null;
- }
- }
- // para pular uma linha.
- public String jump(){
- return System.lineSeparator();
- }
- // para pular 'n' linhas.
- public String jump(int times){
- if(times <= 1) return jump();
- String content = "";
- for(int i = 0; i < times; i++)
- content += System.lineSeparator();
- return content;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement