Java Console / Console Print Form

Function: print console tables, supports dynamic length of the field, left-aligned, right-aligned, centered, set the maximum length of the column, set the column break character, setting a maximum number of lines to print.

Class Download: http: //download.csdn.net/download/j506825719/10211082

Simple to use: the new time, a given column names, and column values ​​List, after calling printTable get a table string.

Advanced use: see all public methods, you will be able to know what the function.

The effect is as follows:


Interface is as follows:


   
   
  1. package com.benjamin.debug.extendclass;
  2. import java.awt.Font;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util. List;
  6. import java.util.Map;
  7. /**
  8. *
  9. * @author Benjamin su
  10. * QQ:506825719
  11. * Email:jiang506825719@qq.com
  12. *
  13. */
  14. public class TextTable {
  15. //这个变量只是用来获取字符串的标准长度,修改无意义
  16. private static Font font = new Font( "宋体", Font.PLAIN, 16);
  17. private String columnInterval= "|"; //列之间的间隔符号
  18. private AlignType at=AlignType.Left;
  19. private Integer MaxValueLenth= 40;
  20. private Map<String,Integer> maxFieldValueLengthMap= null;
  21. List<String> columnNameList= null;
  22. List< List<String>> columnValueList= null;
  23. private boolean isException= false;
  24. private Integer pringtTableRow= 30;
  25. /**
  26. * 初始化时不给定列长度Map
  27. * @param columnNameListTmp
  28. * @param columnValueListTmp
  29. */
  30. public TextTable( List<String> columnNameListTmp, List< List<String>> columnValueListTmp){
  31. }
  32. /**
  33. * 初始化时给定列长度Map
  34. * @param columnNameListTmp
  35. * @param columnValueListTmp
  36. * @param maxFieldValueLengthMapTmp
  37. */
  38. public TextTable( List<String> columnNameListTmp, List< List<String>> columnValueListTmp,Map<String,Integer> maxFieldValueLengthMapTmp){
  39. }
  40. /**
  41. * 获得处理后的表格字符串
  42. * @return
  43. */
  44. public String printTable(){
  45. }
  46. /**
  47. * 获取一个字符串的标准长度是多少
  48. * A2*. 这样是四个标准长度
  49. * 系统系统 这样是8个标准长度
  50. * @param str
  51. * @return
  52. */
  53. public static Integer getStrPixelsLenth(String str){
  54. }
  55. /**
  56. * 让列值居中
  57. * @param columnValue
  58. * @param ColumnPixelsLenth
  59. * @return
  60. */
  61. private String makeValueCenter(String columnValue,Integer repaireStrLength){
  62. }
  63. /**
  64. * 让列值左对齐
  65. * @param columnValue
  66. * @param ColumnPixelsLenth
  67. * @return
  68. */
  69. private String makeValueLeft(String columnValue,Integer repaireStrLength){
  70. }
  71. /**
  72. * 让列值右对齐
  73. * @param columnValue
  74. * @param ColumnPixelsLenth
  75. * @return
  76. */
  77. private String makeValueRight(String columnValue,Integer repaireStrLength){
  78. }
  79. /**
  80. * 获取用于填充的字符串
  81. * @param str
  82. * @param PixelsLenth
  83. * @return
  84. */
  85. private static String getRepairStr(char str,Integer PixelsLenth){
  86. }
  87. /**
  88. * 根据像素长度来切割字符串
  89. * @param str
  90. * @param PixelsLenth
  91. * @return
  92. */
  93. private static String subStrByPixels(String str,Integer PixelsLenth){
  94. }
  95. /**
  96. * 让列值对齐(左对齐OR居中OR右对齐)
  97. * @param columnValue
  98. * @param ColumnPixelsLenth
  99. * @return
  100. */
  101. private String makeValueAlign(String columnValue,Integer ColumnPixelsLenth){
  102. }
  103. /**
  104. * 设置列与列之间用什么间隔,默认是|
  105. * @param columnInterval
  106. */
  107. public void setColumnInterval(String columnInterval) {
  108. }
  109. /**
  110. * 设置列值最大长度,超过则用省略号代替
  111. * @param maxValueLenth
  112. */
  113. public void setMaxValueLenth(Integer maxValueLenth) {
  114. }
  115. /**
  116. * 如果不指定列长度Map,这里将自动计算
  117. * @param columnNameListTmp
  118. * @param columnValueListTmp
  119. * @param maxFieldValueLengthMapTmp
  120. */
  121. private void setMaxFieldValueLengthMap( List<String> columnNameListTmp, List< List<String>> columnValueListTmp,Map<String, Integer> maxFieldValueLengthMapTmp) {
  122. }
  123. /**
  124. * 设置最多打印多少行
  125. * @param pringtTableRow
  126. */
  127. public void setPringtTableRow(Integer pringtTableRow) {
  128. }
  129. /**
  130. * 设置对齐方式
  131. * @param at
  132. */
  133. public void setAt(AlignType at) {
  134. }
  135. public enum AlignType {
  136. Left,
  137. Center,
  138. Rigth
  139. }
  140. }



Original Address: https: //blog.csdn.net/j506825719/article/details/78996659

Guess you like

Origin www.cnblogs.com/jpfss/p/11496440.html