1 package sample.blocks.scalable.webmonitor; 2 3 52 import javax.swing.table.*; 53 54 55 56 import java.util.ArrayList ; 57 import java.util.HashMap ; 58 65 public class ResultTable extends AbstractTableModel { 66 69 private static final long serialVersionUID = 6951728232313370721L; 70 private String [] columnNames = {"URL","STATUS"}; 71 protected static int NUM_COLUMNS = 2; 72 protected static int START_NUM_ROWS = 0; 73 protected int nextEmptyRow = 0; 74 protected int numRows = 0; 75 76 private ArrayList urls; 78 private HashMap urlsToStatus; 80 81 public ResultTable() { 82 urls = new ArrayList (); 84 urlsToStatus = new HashMap (); 85 } 86 87 90 public String getColumnName(int column) { 91 return columnNames[column]; 92 } 93 94 97 public synchronized int getColumnCount() { 98 return NUM_COLUMNS; 99 } 100 101 104 public synchronized int getRowCount() { 105 if (numRows < START_NUM_ROWS) { 106 return START_NUM_ROWS; 107 } else { 108 return numRows; 109 } 110 } 111 112 115 public synchronized Object getValueAt(int row, int column) { 116 try { 117 System.out.println("Getting row "+row+" by column "+column ); 118 switch (column) { 119 case 0: 121 return urls.get(row); 122 case 1: 124 return urlsToStatus.get(urls.get(row)); 125 } 126 } catch (Exception e) { 127 } 128 return "N/A"; 129 } 131 136 public synchronized void updateURLStatus(String url, String status) { 137 boolean addedRow = !urls.contains(url) ; 139 urlsToStatus.put(url, status); 140 if (addedRow) { 142 numRows++; 143 urls.add(url); 144 fireTableRowsInserted(urls.size(), urls.size()); 145 System.out.println("init"); 146 } else { 147 int row = urls.indexOf(url); 148 System.out.println("Updated row "+row); 149 fireTableRowsUpdated(row, row); 150 151 } 152 } 154 155 156 } | Popular Tags |