001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Mikael MARCHE, Fayçal SOUGRATI, Vincent PAUTRET
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm.models;
025:
026: import java.awt.Component;
027:
028: import javax.swing.DefaultListCellRenderer;
029: import javax.swing.Icon;
030: import javax.swing.JList;
031: import javax.swing.ListCellRenderer;
032: import javax.swing.UIManager;
033:
034: import org.objectweb.salome_tmf.api.ApiConstants;
035: import org.objectweb.salome_tmf.data.AdminProjectData;
036: import org.objectweb.salome_tmf.data.User;
037: import org.objectweb.salome_tmf.ihm.IHMConstants;
038: import org.objectweb.salome_tmf.ihm.tools.Tools;
039:
040: /**
041: * Classe qui d?finit le renderer pour les listes d'utilisateurs
042: */
043: public class UserListRenderer extends DefaultListCellRenderer implements
044: ListCellRenderer, ApiConstants, IHMConstants {
045:
046: /**
047: * Le s?parateur de fichier
048: */
049: //private final String fileSeparator = "/" ;
050: /**
051: * M?thode qui red?finit le renderer des ?l?ments de la liste
052: * @param list la liste concern?e
053: * @param value l'objet dans la liste
054: * @param index indice dans la liste
055: * @param isSelected si l'objet est s?lectionn?
056: * @param cellHasFocus si le focus est sur la cellule
057: */
058: public Component getListCellRendererComponent(JList list,
059: Object value, int index, boolean isSelected,
060: boolean cellHasFocus) {
061: if (isSelected) {
062: setBackground(list.getSelectionBackground());
063: setForeground(list.getSelectionForeground());
064: } else {
065: setBackground(list.getBackground());
066: setForeground(list.getForeground());
067: }
068: Icon icon;
069:
070: if (value instanceof User
071: && !AdminProjectData.containsGroup((User) value,
072: ADMINNAME)) {
073: icon = Tools.createAppletImageIcon(PATH_TO_USER_ICON, "");
074: setIcon(icon);
075: setText(((User) value).getLogin() + " / "
076: + ((User) value).getLastName() + " "
077: + ((User) value).getFirstName());
078: } else if (value instanceof User
079: && AdminProjectData.containsGroup((User) value,
080: ADMINNAME)) {
081: icon = Tools.createAppletImageIcon(PATH_TO_ADMIN_ICON, "");
082: setIcon(icon);
083: setText(((User) value).getLogin() + " / "
084: + ((User) value).getLastName() + " "
085: + ((User) value).getFirstName());
086: } else if (value instanceof User) {
087: icon = Tools.createAppletImageIcon(PATH_TO_ADMIN_ICON, "");
088: setIcon(icon);
089: setText(((User) value).getLogin() + " / "
090: + ((User) value).getLastName() + " "
091: + ((User) value).getFirstName());
092: } else if (value instanceof Icon) {
093: setIcon((Icon) value);
094: setText("");
095: } else {
096: setIcon(null);
097: setText((value == null) ? "" : value.toString());
098: }
099:
100: setEnabled(list.isEnabled());
101: setFont(list.getFont());
102: setBorder((cellHasFocus) ? UIManager
103: .getBorder("List.focusCellHighlightBorder")
104: : noFocusBorder);
105:
106: return this ;
107:
108: } // Fin de la m?thode getListCellRendererComponent/5
109: } // Fin de la classe UserListRenderer
|