Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ta funcionando cara, mas ta muito 'pesado', fiz muito na preguiça
- ta sendo configurado pro string, dependendo de quanta info for inserida o tópico vai ficar gigante e tem fórum que limita o numero de carateres...
- já fiz um outro algoritmo que reduz isso, formatando por completo usando stringbuilder, depois te passo.
- Mas esse aqui pode ser usado pra ir desenvolvendo ai, o nome dos métodos na outro classe são os mesmos,vlw? */
- package formatter.model;import java.util.ArrayList;public class TopicFormatter{private StringBuilder str=null;private Topic topic=null;private EditConfig conf=null;public TopicFormatter(Topic topic,EditConfig conf){this.TEXT_SIZE=conf.getFONT_SIZE();this.MAIN_TEXT_SIZE=conf.getMAIN_FONT_SIZE();this.SEPARATOR=conf.getSeparator();this.MAIN_FONT_NAME=conf.getMainFontName();this.FONT_NAME=conf.getFontName();this.MAIN_TEXT_COLOR=conf.getMainFontColor();this.TEXT_COLOR=conf.getFontColor();this.topic=topic;this.conf=conf;}
- private final int TEXT_SIZE;private final int MAIN_TEXT_SIZE;private final String TEXT_COLOR;private final String MAIN_TEXT_COLOR;private final String FONT_NAME;private final String MAIN_FONT_NAME;private final String SEPARATOR;private final String DOWNLOAD_IMAGE="imagem - download";private final String SCAN_IMAGE="~~~~ ALGUMA IMAGEM DE DOWNLOAD P/ SUBSTITUIR ~~~~~";private final String LN=System.getProperty("line.separator");private final String FORUM_LOGO;private final String DEF_CLOSE="]";private final String DEF_AUT_CLOSE="\"]";private final String INIT_FONT="[FONT=";private final String END_FONT="[/FONT]";private final String INIT_COLOR="[COLOR=\"";private final String END_COLOR="[/COLOR]";private final String INIT_SIZE="[SIZE=";private final String END_SIZE="[/SIZE]";private final String INIT_CENTER="[CENTER]";private final String END_CENTER="[/CENTER]";private final String INIT_LEFT="[LEFT]";private final String END_LEFT="[/LEFT]";private final String INIT_RIGHT="[RIGHT]";private final String END_RIGHT="[/RIGHT]";private final String INIT_IMAGE="[IMG]";private final String END_IMAGE="[/IMG]";private final String INIT_VIDEO="[VIDEO]";private final String END_VIDEO="[/VIDEO]";private final String INIT_LIST="[LIST]";private final String LIST_MARK="[*]";private final String END_LIST="[/LIST]";private final String INIT_INDENT="[INDENT]";private final String END_INDENT="[/INDENT]";private final String INIT_TABLE_W_BORDER="[TABLE=\"class: outer_border, width: 700, align: center\"]";private final String INIT_TABLE_WO_BORDER="[TABLE=\"width: 700, align: center\"]";private final String END_TABLE="[/TABLE]";private final String FIRST_ROW_INIT="[TR][TD=\"align: center, bgcolor: #3F3F3F\"][FONT=impact][COLOR=#696969][SIZE=5]";private final String FIRST_ROW_END="[/SIZE][/COLOR][/FONT][/TD]";private final String TABLE_ROW_INIT="[TR][TD=\"align: center\"]";private final String TABLE_ROW_END="[/TD][/TR]";private final String MOVIE_LIST_ICON="[IMG]http://i.imgur.com/YNyxHPj.png[/IMG]";private final String IMAGE_LIST_ICON="[IMG]http://i.imgur.com/7l0717V.png[/IMG]";private final String STEP_LIST_ICON="[IMG]http://i.imgur.com/w7AuT7s.png[/IMG]";private final String SCAN_LIST_ICON="[IMG]http://i.imgur.com/vmueg95.png[/IMG]";private final String FUNCTION_LIST_ICON="[IMG]http://i.imgur.com/NirSkip.png[/IMG]";private final String DOWNLOAD_LIST_ICON="[IMG]http://i.imgur.com/9Ma0JdM.png[/IMG]";public synchronized String createHeader(boolean upperCase){str=new StringBuilder();str.append(INIT_CENTER).append(FORUM_LOGO).append(LN).append(INIT_FONT).append(MAIN_FONT_NAME).append(DEF_CLOSE).append(INIT_COLOR).append(MAIN_TEXT_COLOR).append(DEF_AUT_CLOSE).append(INIT_SIZE).append(MAIN_TEXT_SIZE).append(DEF_CLOSE).append(topic.getTitle().toUpperCase()).append(END_SIZE).append(END_COLOR).append(END_FONT).append(LN).append(INIT_FONT).append(FONT_NAME).append(DEF_CLOSE).append(INIT_COLOR).append(TEXT_COLOR).append(DEF_AUT_CLOSE).append(INIT_SIZE).append(TEXT_SIZE).append(DEF_CLOSE).append("[I]Escrito por :[/I] ").append(upperCase?topic.getAuthor().toUpperCase():topic.getAuthor()).append(LN).append(LN).append(upperCase?topic.getIntro().toUpperCase():topic.getIntro()).append(LN).append(LN).append(SEPARATOR).append(LN).append(LN).append(END_SIZE).append(END_COLOR).append(END_FONT).append(END_CENTER);return str.toString();}
- public synchronized String createStepList(){str=new StringBuilder("");if(!topic.getStepsList().isEmpty()){str.append(LN).append(INIT_CENTER).append(INIT_FONT).append(MAIN_FONT_NAME).append(DEF_CLOSE).append(INIT_SIZE).append(MAIN_TEXT_SIZE).append(DEF_CLOSE).append(INIT_COLOR).append(MAIN_TEXT_COLOR).append(DEF_AUT_CLOSE).append(STEP_LIST_ICON).append(LN).append("TUTORIAL").append(END_COLOR).append(END_SIZE).append(END_FONT).append(LN).append(LN).append(INIT_LEFT).append(INIT_FONT).append(FONT_NAME).append(DEF_CLOSE).append(INIT_COLOR).append(TEXT_COLOR).append(DEF_AUT_CLOSE).append(INIT_SIZE).append(TEXT_SIZE).append(DEF_CLOSE).append(INIT_INDENT).append(INIT_LIST).append(LN);for(String item:topic.getStepsList())
- str.append(LIST_MARK).append(item).append(LN);str.append(END_LIST).append(END_INDENT).append(END_SIZE).append(END_COLOR).append(END_FONT).append(END_LEFT).append(LN).append(LN).append(SEPARATOR).append(END_CENTER).append(LN);}
- return str.toString();}
- public synchronized String createImageList(){str=new StringBuilder("");if(!topic.getImagesList().isEmpty()){str.append(INIT_CENTER).append(INIT_FONT).append(MAIN_FONT_NAME).append(DEF_CLOSE).append(INIT_SIZE).append(MAIN_TEXT_SIZE).append(DEF_CLOSE).append(INIT_COLOR).append(MAIN_TEXT_COLOR).append(DEF_AUT_CLOSE).append(IMAGE_LIST_ICON).append(LN).append("IMAGENS").append(END_COLOR).append(END_SIZE).append(END_FONT).append(LN).append(LN);for(String item:topic.getImagesList())
- str.append(INIT_IMAGE).append(item).append(END_IMAGE).append(LN);str.append(SEPARATOR).append(END_CENTER).append(LN);}
- return str.toString();}
- public synchronized String createVideoList(){str=new StringBuilder("");if(!topic.getVideoList().isEmpty()){str.append(INIT_CENTER).append(INIT_FONT).append(MAIN_FONT_NAME).append(DEF_CLOSE).append(INIT_SIZE).append(MAIN_TEXT_SIZE).append(DEF_CLOSE).append(INIT_COLOR).append(MAIN_TEXT_COLOR).append(DEF_AUT_CLOSE).append(MOVIE_LIST_ICON).append(LN).append("VÍDEOS").append(END_COLOR).append(END_SIZE).append(END_FONT).append(LN).append(LN);for(String item:topic.getVideoList())
- str.append(INIT_VIDEO).append(item).append(END_VIDEO).append(LN);str.append(LN).append(SEPARATOR).append(END_CENTER);}
- return str.toString();}
- public synchronized String createFunctionList(ArrayList<String>list,boolean useBorder){str=new StringBuilder("");if(!topic.getFunctionList().isEmpty()){str.append(LN).append(INIT_CENTER).append(INIT_FONT).append(MAIN_FONT_NAME).append(DEF_CLOSE).append(INIT_SIZE).append(MAIN_TEXT_SIZE).append(DEF_CLOSE).append(INIT_COLOR).append(MAIN_TEXT_COLOR).append(DEF_AUT_CLOSE).append(FUNCTION_LIST_ICON).append(LN).append("FUNCIONALIDADES").append(END_COLOR).append(END_SIZE).append(END_FONT).append(LN).append(LN).append(useBorder?INIT_TABLE_W_BORDER:INIT_TABLE_WO_BORDER).append(LN);for(String item:topic.getFunctionList())
- str.append(TABLE_ROW_INIT).append(item).append(TABLE_ROW_END).append(LN);str.append(END_TABLE);str.append(LN).append(LN).append(SEPARATOR).append(END_CENTER);}
- return str.toString();}
- public synchronized String createListLink(boolean isDownload,boolean useImage){ArrayList<String>list=null;if(isDownload)
- list=topic.getDownloadList();else list=topic.getScanList();str=new StringBuilder("");if(!list.isEmpty()){str.append(INIT_CENTER).append(INIT_FONT).append(MAIN_FONT_NAME).append(DEF_CLOSE).append(INIT_COLOR).append(MAIN_TEXT_COLOR).append(DEF_AUT_CLOSE).append(INIT_SIZE).append(MAIN_TEXT_SIZE).append(DEF_CLOSE).append(LN);if(isDownload){str.append(DOWNLOAD_LIST_ICON).append(LN).append("DOWNLOAD");}else{str.append(SCAN_LIST_ICON).append(LN).append("SCAN");}
- str.append(END_SIZE).append(END_COLOR).append(END_FONT).append(LN).append(INIT_FONT).append(FONT_NAME).append(DEF_CLOSE).append(INIT_COLOR).append(TEXT_COLOR).append(DEF_AUT_CLOSE).append(INIT_SIZE).append(TEXT_SIZE).append(DEF_CLOSE).append(LN);for(String item:list){str.append("[URL=\"").append(item).append(DEF_AUT_CLOSE);if(useImage){if(isDownload)
- str.append(DOWNLOAD_IMAGE);else
- str.append(SCAN_IMAGE);}else{if(isDownload)
- str.append("Clique Aqui para Baixar o Arquivo");else
- str.append("CLique Aqui para visualizar o Scan");}
- str.append("[/URL]").append(LN);}
- str.append(END_SIZE).append(END_COLOR).append(END_FONT).append(LN).append(SEPARATOR).append(END_CENTER).append(LN);}
- return str.toString();}
- public synchronized String createFooter(){str=new StringBuilder();str.append(LN);if(!topic.getOutro().isEmpty()){str.append(INIT_CENTER).append(INIT_COLOR).append(TEXT_COLOR).append(DEF_AUT_CLOSE).append(INIT_SIZE).append(TEXT_SIZE).append(DEF_CLOSE).append(INIT_FONT).append(FONT_NAME).append(DEF_CLOSE).append(LN).append(topic.getOutro()).append(LN).append(END_COLOR).append(END_CENTER);}
- str.append(LN).append(LN);if(!topic.getThanksList().isEmpty()){str.append(INIT_RIGHT).append(INIT_COLOR).append(MAIN_TEXT_COLOR).append(DEF_AUT_CLOSE).append(" [B]AGRADECIMENTOS[/B] ").append(END_COLOR).append(LN).append(INIT_COLOR).append(TEXT_COLOR).append(DEF_AUT_CLOSE);for(String item:topic.getThanksList()){str.append(item).append(LN);}
- str.append(END_COLOR).append(LN).append(LN).append("[I][COLOR=\"000000\"][SIZE=1]Tópico formatado utilizando 'nome do negocio lá'.[/SIZE][/COLOR]").append(LN).append("[B]ALGUMA COISA[/B]CHEATS[/I]").append(END_RIGHT);}
- str.append(END_FONT).append(END_SIZE);return str.toString();}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement