01: /* Copyright 2004 Inderjeet Singh. All rights reserved. You may not modify,
02: * use, reproduce or distribute this software except in compliance with the
03: * terms of the license at http://tcpmon.dev.java.net/
04: * $Id: RequestsTableModel.java,v 1.2 2004/11/09 20:32:15 inder Exp $ */
05:
06: package tcpmon;
07:
08: import java.util.*;
09: import javax.swing.table.*;
10:
11: /**
12: *
13: * @author Inderjeet Singh
14: */
15: public class RequestsTableModel extends AbstractTableModel {
16: public int getColumnCount() {
17: return columnNames.length;
18: }
19:
20: public int getRowCount() {
21: return entries.size();
22: }
23:
24: private String[] columnNames = { "State", "Time", "Request Host",
25: "Target Host", "Request" };
26:
27: public String getColumnName(int col) {
28: return columnNames[col].toString();
29: }
30:
31: public boolean isCellEditable(int row, int col) {
32: return false;
33: }
34:
35: public Object getValueAt(int row, int col) {
36: String[] data = (String[]) entries.get(row);
37: return data[col];
38: }
39:
40: public String getForwardData(int row) {
41: String[] data = (String[]) entries.get(row);
42: return data[5];
43: }
44:
45: public String getReverseData(int row) {
46: String[] data = (String[]) entries.get(row);
47: return data[6];
48: }
49:
50: public void addEntry(String state, long time, String requestHost,
51: String targetHost, String request, String forwardData,
52: String reverseData) {
53: String[] entry = new String[7];
54: entry[0] = state;
55: entry[1] = (new Date(time)).toString();
56: entry[2] = requestHost;
57: entry[3] = targetHost;
58: entry[4] = request;
59: entry[5] = forwardData;
60: entry[6] = reverseData;
61: entries.add(0, entry);
62: fireTableDataChanged();
63: }
64:
65: public void deleteRow(int i) {
66: entries.remove(i);
67: fireTableDataChanged();
68: }
69:
70: public void deleteAllRows() {
71: entries.clear();
72: fireTableDataChanged();
73: }
74:
75: private List entries = new LinkedList();
76: };
|