01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.modules.session;
19:
20: import javax.swing.JLabel;
21: import javax.swing.JTable;
22: import javax.swing.table.DefaultTableModel;
23: import javax.swing.table.TableCellRenderer;
24:
25: import de.finix.contelligent.client.i18n.Resources;
26: import de.finix.contelligent.client.security.Role;
27:
28: public class RoleTable extends JTable {
29:
30: private final static int ROW_HEIGHT = 25;
31:
32: public RoleTable(DefaultTableModel dtm) {
33: super (dtm);
34: setDefaultRenderer(Role.class, new RoleRenderer());
35: setRowHeight(ROW_HEIGHT);
36: }
37:
38: class RoleRenderer implements TableCellRenderer {
39: public java.awt.Component getTableCellRendererComponent(
40: JTable table, Object object, boolean isSelected,
41: boolean hasFocus, int row, int column) {
42: JLabel cellRenderer = new JLabel();
43: cellRenderer.setFont(table.getFont());
44: if (object instanceof Role) {
45: Role role = (Role) object;
46: if (column == 0) {
47: cellRenderer.setText(role.getName());
48: cellRenderer.setIcon(Resources.roleIcon);
49: } else if (column == 1) {
50: cellRenderer.setText(role.getPrincipal()
51: .getDisplayName());
52: }
53: } else {
54: String privilege = (String) object;
55: if (column == 0) {
56: cellRenderer.setText(Resources
57: .getLocalString("privilege_" + privilege));
58: cellRenderer.setIcon(Resources.privilegeIcon);
59: } else if (column == 1) {
60: cellRenderer.setText("");
61: }
62: }
63: return cellRenderer;
64: }
65: }
66: }
|