KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > administrator > gui > ConceptTable


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.administrator.gui;
20
21 import java.util.ArrayList JavaDoc;
22
23 import javax.swing.*;
24 import javax.swing.table.*;
25
26 import org.lucane.client.Plugin;
27 import org.lucane.client.Client;
28 import org.lucane.common.concepts.*;
29
30 public class ConceptTable extends JTable
31 {
32     public ConceptTable(Plugin plugin, String JavaDoc name, ArrayList JavaDoc concepts)
33     {
34         super(new ConceptTableModel(plugin, concepts));
35         getColumnModel().getColumn(0).setMinWidth(16);
36         getColumnModel().getColumn(0).setMaxWidth(20);
37         getTableHeader().getColumnModel().getColumn(0).setHeaderValue("");
38         getTableHeader().getColumnModel().getColumn(1).setHeaderValue(name);
39         setRowSelectionAllowed(true);
40         setShowVerticalLines(false);
41     }
42
43     public ConceptTable(Plugin plugin, String JavaDoc name)
44     {
45         this(plugin, name, new ArrayList JavaDoc());
46     }
47     
48     public void setConcepts(ArrayList JavaDoc list)
49     {
50         ConceptTableModel model = (ConceptTableModel)this.getModel();
51         model.setConcepts(list);
52     }
53     
54     public void addConcept(Concept concept)
55     {
56         ConceptTableModel model = (ConceptTableModel)this.getModel();
57         model.addConcept(concept);
58     }
59     
60     public Concept getConceptAt(int row)
61     {
62         return ((ConceptTableModel)this.getModel()).getConceptAt(row);
63     }
64 }
65
66 class ConceptTableModel extends AbstractTableModel
67 {
68     private ArrayList JavaDoc concepts;
69
70     private ImageIcon groupIcon;
71     private ImageIcon userIcon;
72     private ImageIcon pluginIcon;
73     private ImageIcon serviceIcon;
74     
75     public ConceptTableModel(Plugin plugin, ArrayList JavaDoc concepts)
76     {
77         this.concepts = concepts;
78         
79         this.groupIcon = Client.getImageIcon("group.png");
80         this.userIcon = Client.getImageIcon("user.png");
81         this.pluginIcon = plugin.getImageIcon("plugin.jpg");
82         this.serviceIcon = plugin.getImageIcon("service.jpg");
83     }
84
85     public void setConcepts(ArrayList JavaDoc concepts)
86     {
87         this.concepts = concepts;
88         this.fireTableDataChanged();
89     }
90
91     public void addConcept(Concept concept)
92     {
93         this.concepts.add(concept);
94         this.fireTableDataChanged();
95     }
96     
97     public Concept getConceptAt(int row)
98     {
99         return (Concept)concepts.get(row);
100     }
101     
102     public void removeAt(int row)
103     {
104         if(row < 0)
105             return;
106         
107         concepts.remove(row);
108         this.fireTableDataChanged();
109     }
110     
111     public ArrayList JavaDoc getConceptList()
112     {
113         return concepts;
114     }
115     
116     public Object JavaDoc getValueAt(int x, int y)
117     {
118         Concept c = (Concept)concepts.get(x);
119         
120         if(y == 1)
121             return c.getName();
122         
123         if(c instanceof PluginConcept)
124             return pluginIcon;
125         if(c instanceof GroupConcept)
126             return groupIcon;
127         if(c instanceof UserConcept)
128             return userIcon;
129         if(c instanceof ServiceConcept)
130             return serviceIcon;
131         
132         return "";
133     }
134     
135     public Class JavaDoc getColumnClass(int c)
136     {
137         return (c==0 ? ImageIcon.class : String JavaDoc.class);
138     }
139
140     public int getColumnCount()
141     {
142         return 2;
143     }
144
145     public int getRowCount()
146     {
147         return concepts.size();
148     }
149 }
150
Popular Tags