01: package net.matuschek.jobo;
02:
03: import java.util.Vector;
04: import javax.swing.table.AbstractTableModel;
05: import net.matuschek.spider.RegExpRule;
06:
07: /*********************************************
08: Copyright (c) 2001 by Daniel Matuschek
09: *********************************************/
10:
11: /**
12: * Table model to view RegExpRules
13: *
14: * @author Daniel Matuschek
15: * @version $ID$
16: */
17: public class RegExpRuleTableModel extends AbstractTableModel {
18:
19: private static final long serialVersionUID = -2211969715108211170L;
20:
21: final static String[] columns = { "Allow", "Pattern" };
22:
23: /**
24: * create a new RegExpRuleTableModel associated with the given
25: * RegExpURLCheck
26: */
27: public RegExpRuleTableModel(Vector rules) {
28: super ();
29: this .rules = rules;
30: }
31:
32: public int getColumnCount() {
33: return columns.length;
34: }
35:
36: public int getRowCount() {
37: return rules.size();
38: }
39:
40: public String getColumnName(int col) {
41: return columns[col];
42: }
43:
44: public Object getValueAt(int row, int col) {
45: RegExpRule rule = (RegExpRule) rules.elementAt(row);
46: if (col == 0) {
47: return new Boolean(rule.getAllow());
48: } else if (col == 1) {
49: return rule.getPattern();
50: } else {
51: return null;
52: }
53: }
54:
55: public Class<?> getColumnClass(int col) {
56: if (col == 0) {
57: return Boolean.class;
58: } else if (col == 1) {
59: return String.class;
60: } else {
61: return null;
62: }
63: }
64:
65: /**
66: * every cell is editable
67: */
68: public boolean isCellEditable(int row, int column) {
69: return true;
70: }
71:
72: /**
73: **/
74: public void setValueAt(Object value, int row, int col) {
75: RegExpRule rule = (RegExpRule) rules.elementAt(row);
76:
77: if (col == 0) {
78: // allow/deny
79: rule.setAllow(((Boolean) value).booleanValue());
80: } else if (col == 1) {
81: try {
82: rule.setPattern((String) value);
83: } catch (org.apache.regexp.RESyntaxException e) {
84: // TO DO !
85: }
86: } else {
87: // this should never happen
88: return;
89: }
90:
91: }
92:
93: // private variables
94:
95: Vector rules = null;
96:
97: } // RegExpRuleTableModel
|