KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > matuschek > jobo > RegExpRuleTableModel


1 package net.matuschek.jobo;
2
3 import java.util.Vector JavaDoc;
4 import javax.swing.table.AbstractTableModel JavaDoc;
5 import net.matuschek.spider.RegExpRule;
6 /*********************************************
7     Copyright (c) 2001 by Daniel Matuschek
8  *********************************************/

9
10
11
12 /**
13  * Table model to view RegExpRules
14  *
15  * @author Daniel Matuschek
16  * @version $ID$
17  */

18 public class RegExpRuleTableModel
19 extends AbstractTableModel JavaDoc
20 {
21
22     private static final long serialVersionUID = -2211969715108211170L;
23
24     final static String JavaDoc[] columns = { "Allow","Pattern" };
25
26     /**
27      * create a new RegExpRuleTableModel associated with the given
28      * RegExpURLCheck
29      */

30     public RegExpRuleTableModel(Vector JavaDoc rules) {
31         super();
32         this.rules = rules;
33     }
34
35     public int getColumnCount() {
36         return columns.length;
37     }
38
39     public int getRowCount() {
40         return rules.size();
41     }
42
43     public String JavaDoc getColumnName(int col) {
44         return columns[col];
45     }
46
47     public Object JavaDoc getValueAt(int row, int col) {
48         RegExpRule rule = (RegExpRule)rules.elementAt(row);
49         if (col == 0) {
50             return new Boolean JavaDoc(rule.getAllow());
51         } else if (col == 1) {
52             return rule.getPattern();
53         } else {
54             return null;
55         }
56     }
57
58     public Class JavaDoc<?> getColumnClass(int col) {
59         if (col == 0) {
60             return Boolean JavaDoc.class;
61         } else if (col == 1) {
62             return String JavaDoc.class;
63         } else {
64             return null;
65         }
66     }
67
68     /**
69      * every cell is editable
70      */

71      public boolean isCellEditable(int row, int column) {
72          return true;
73      }
74
75
76      /**
77       **/

78      public void setValueAt(Object JavaDoc value, int row, int col) {
79          RegExpRule rule = (RegExpRule)rules.elementAt(row);
80
81          if (col == 0) {
82              // allow/deny
83
rule.setAllow(((Boolean JavaDoc)value).booleanValue());
84          } else if (col == 1) {
85              try {
86                  rule.setPattern((String JavaDoc)value);
87              } catch (org.apache.regexp.RESyntaxException e) {
88                  // TO DO !
89
}
90          } else {
91              // this should never happen
92
return;
93          }
94
95      }
96
97
98      // private variables
99

100      Vector JavaDoc rules = null;
101
102 } // RegExpRuleTableModel
103
Popular Tags