1 6 7 package com.quikj.application.web.talk.client.monitoring; 8 9 import java.awt.*; 10 11 15 public class MonitorDisplayFormatter 16 { 17 private static final int MAX_COLUMN_LENGTH = 255; 18 private TextArea textArea; 19 20 21 public MonitorDisplayFormatter(TextArea text_area) 22 { 23 textArea = text_area; 24 25 textArea.setFont(new Font("Courier", Font.PLAIN, 12)); 28 } 29 30 public void clear() 31 { 32 textArea.setText(""); 33 } 34 35 public void appendText(String text) 36 { 37 textArea.append(text); 38 } 39 40 public TextArea getTextArea() 41 { 42 return textArea; 43 } 44 45 public void appendTable(String [] table_header, String [][] data) 46 { 47 int cols = table_header.length; 49 int width = 0; 50 StringBuffer buffer = new StringBuffer (); 51 StringBuffer bar = new StringBuffer (); 52 int i; 53 54 for (i = 0; i < cols; i++) 56 { 57 int col_width = table_header[i].length(); 58 if (col_width > MAX_COLUMN_LENGTH) 59 { 60 col_width = MAX_COLUMN_LENGTH; 61 } 62 width += col_width; 63 } 64 width += 1 + cols; 65 66 for (i = 0; i < width; i++) 67 { 68 bar.append('-'); 69 } 70 bar.append('\n'); 71 buffer.append(bar + "|"); 72 73 for (i = 0; i < cols; i++) 75 { 76 StringBuffer filler = new StringBuffer (); 77 String label = table_header[i]; 78 int size = table_header[i].length(); 79 if (size > MAX_COLUMN_LENGTH) 80 { 81 size = MAX_COLUMN_LENGTH; 82 } 83 84 int x; 85 if (label.length() > size) 86 { 87 label = label.substring(0, size); 88 } 89 90 if (label.length() < size) 91 { 92 x = size - label.length(); 93 int j; 94 for (j = 0; j < x; j++) 95 { 96 filler.append(' '); 97 } 98 99 label = label + filler; 100 } 101 102 buffer.append(label + "|"); 103 } 104 105 buffer.append("\n" + bar); 107 108 for (i = 0; i < data.length; i++) 110 { 111 buffer.append("|"); 112 113 for (int j = 0; j < cols; j++) 115 { 116 String value = data[i][j]; 117 118 int size = table_header[j].length(); 119 if (size > MAX_COLUMN_LENGTH) 120 { 121 size = MAX_COLUMN_LENGTH; 122 } 123 124 String str; 125 if (value == null) 126 { 127 str = ""; 128 } 129 else 130 { 131 str = value; 132 } 133 134 if (str.length() > size) 135 { 136 str = str.substring(0, size); 137 } 138 else if (str.length() < size) 139 { 140 int x = size - str.length(); 141 StringBuffer filler = new StringBuffer (); 142 for (int k = 0; k < x; k++) 143 { 144 filler.append(' '); 145 } 146 str += filler; } 148 149 str = str.replace('\n', ' '); 151 152 buffer.append(str + "|"); 153 } 154 buffer.append("\n"); 155 } 156 157 buffer.append(bar.toString() + "\n"); 158 textArea.append(buffer.toString()); 159 } 160 161 } 162 | Popular Tags |