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.Color;
027: import java.awt.Component;
028: import java.io.Serializable;
029: import java.util.ArrayList;
030:
031: import javax.swing.Icon;
032: import javax.swing.JLabel;
033: import javax.swing.JTable;
034: import javax.swing.UIManager;
035: import javax.swing.border.EmptyBorder;
036: import javax.swing.table.TableCellRenderer;
037:
038: import org.objectweb.salome_tmf.ihm.IHMConstants;
039: import org.objectweb.salome_tmf.ihm.tools.*;
040:
041: /**
042: * Classe qui d?finit le renderer pour la table du projet
043: * @author teaml039
044: * @version : 0.1
045: */
046: public class ProjectTableCellRenderer extends JLabel implements
047: IHMConstants, TableCellRenderer, Serializable {
048:
049: /**
050: * Liste des couleurs pour chaque ligne
051: */
052: static ArrayList rowColors;
053:
054: /******************************************************************************/
055: /** CONSTRUCTEUR ***/
056: /******************************************************************************/
057:
058: /**
059: * Construit un nouveau renderer
060: */
061: public ProjectTableCellRenderer() {
062: super ();
063: setOpaque(true);
064: rowColors = new ArrayList();
065: } // Fin du constructeur ProjectTableCellRenderer/0
066:
067: /******************************************************************************/
068: /** METHODES PUBLIQUES ***/
069: /******************************************************************************/
070:
071: /**
072: * Retourne le composant utilis? pour dessiner la cellule.
073: * @param table la table sur laquelle on utilise le renderer
074: * @param value valeur de l'objet dans la cellule
075: * @param isSelected vrai si la cellule est s?lectionn?e
076: * @param hasFocus vrai si la cellule a le focus
077: * @param row le num?ro de ligne
078: * @param column le num?ro de colonne
079: */
080: public Component getTableCellRendererComponent(JTable table,
081: Object value, boolean isSelected, boolean hasFocus,
082: int row, int column) {
083:
084: if (isSelected) {
085: setForeground(table.getSelectionForeground());
086: setBackground(table.getSelectionBackground());
087:
088: } else if (rowColors.size() > 0) {
089:
090: setBackground((Color) rowColors.get(row));
091: if (rowColors.get(row).equals(Color.BLUE)) {
092: setForeground(Color.WHITE);
093: } else {
094: setForeground(Color.BLACK);
095: }
096: }
097:
098: setFont(table.getFont());
099: if (value == null) {
100: setText("");
101: } else if (value instanceof Icon) {
102: setIcon((Icon) value);
103: setText("");
104: } else {
105: setText(value.toString());
106: }
107: setValue(value);
108: if (hasFocus) {
109: setBorder(UIManager
110: .getBorder("Table.focusCellHighlightBorder"));
111: if (table.isCellEditable(row, column)) {
112: super .setForeground(UIManager
113: .getColor("Table.focusCellForeground"));
114: super .setBackground(UIManager
115: .getColor("Table.focusCellBackground"));
116: }
117: } else {
118: setBorder(new EmptyBorder(1, 2, 1, 2));
119: }
120: if (table.getValueAt(row, column) instanceof String) {
121: setToolTipText(Tools.createHtmlString((String) table
122: .getValueAt(row, column), 60));
123: }
124:
125: return this ;
126: } // Fin de la m?thode getTableCellRendererComponent/6
127:
128: /**
129: * Modifie le contenu de la cellule
130: * @param value valeur de la cellule
131: */
132: protected void setValue(Object value) {
133: setText((value == null) ? "" : value.toString());
134: } // Fin de la m?thode setValue/1
135:
136: /**
137: * Ajoute une couleur dans la liste des couleurs
138: * @param color une couleur
139: */
140: public static void setColor(Color color) {
141: rowColors.add(color);
142: } // Fin de la m?thode setColor/1
143:
144: /**
145: * Modifie la couleur de la ligne pass?e en param?tre
146: * @param row un num?ro de ligne
147: * @param color une couleur
148: */
149: public static void setColor(int row, Color color) {
150: rowColors.remove(row);
151: rowColors.add(row, color);
152: } // Fin de la m?thode setColor/2
153:
154: } // Fin de la classe ProjectTableRenderer
|