KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > console > lib > gui > GraphTableModel


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 France Telecom R&D
4 * Copyright (C) 2003 INRIA
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 *
24 * @authors: Julien Buret
25 * @authors: Nicolas Droze
26 */

27 package org.objectweb.clif.console.lib.gui;
28
29 import java.util.Vector JavaDoc;
30
31 import javax.swing.table.DefaultTableModel JavaDoc;
32
33 public class GraphTableModel extends DefaultTableModel JavaDoc {
34
35     public int rows;
36     private int id;
37     private Vector JavaDoc injectors = new Vector JavaDoc();
38     private Boolean JavaDoc value;
39
40     public GraphTableModel(String JavaDoc[] cname) {
41         super(cname, 0);
42     }
43
44     /**
45      * Sets an ID for this table model. (Used in the panel that represents two
46      * graphics in the same panel)
47      * @param id
48      */

49     public void setId(int id) {
50         this.id = id;
51     }
52
53     /**
54      * @return the identifier of this table model
55      */

56     public int getId() {
57         return id;
58     }
59
60     /**
61      * Adds an injector to this table model list.
62      * @param injectorName The name of the injector to add
63      */

64     public void addInjector(String JavaDoc injectorName) {
65         Object JavaDoc[] arg = new Object JavaDoc[3];
66         arg[0] = new Boolean JavaDoc(false);
67         arg[1] = new Boolean JavaDoc(true);
68         arg[2] = injectorName;
69         addRow(arg);
70     }
71
72     /**
73      * Necessary to display boolean value as a checkbox in the table.
74      * @see javax.swing.table.TableModel#getColumnClass(int)
75      */

76     public Class JavaDoc getColumnClass(int c) {
77         return getValueAt(0, c).getClass();
78     }
79
80     /**
81      * @return the names of every host in this table model.
82      */

83     public Object JavaDoc[] getAllInjectors() {
84         injectors.removeAllElements();
85         rows = getRowCount();
86
87         for (int i = 0; i < rows; i++) {
88             injectors.add(getValueAt(i, 2));
89         }
90
91         return injectors.toArray();
92     }
93
94     /**
95      * @return the host names whose display checkbox is checked
96      */

97     public Object JavaDoc[] getInjectorsToDisplay() {
98         injectors.removeAllElements();
99         rows = getRowCount();
100
101         for (int i = 0; i < rows; i++) {
102             value = (Boolean JavaDoc) getValueAt(i, 0);
103             if (value.booleanValue())
104                 injectors.add(getValueAt(i, 2));
105         }
106
107         return injectors.toArray();
108     }
109
110     /**
111      * @return the host names whose collect checkbox is checked
112      */

113     public Object JavaDoc[] getInjectorsToCollect() {
114         injectors.removeAllElements();
115         rows = getRowCount();
116
117         for (int i = 0; i < rows; i++) {
118             value = (Boolean JavaDoc) getValueAt(i, 1);
119             if (value.booleanValue())
120                 injectors.add(getValueAt(i, 2));
121         }
122
123         return injectors.toArray();
124     }
125
126     /**
127      * Information about the editable cell of the table.
128      * @see javax.swing.table.TableModel#isCellEditable(int, int)
129      */

130     public boolean isCellEditable(int rowIndex, int columnIndex) {
131         if (columnIndex == 2)
132             return false;
133         else
134             return true;
135     }
136
137 }
Popular Tags