001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2009 Sun Microsystems, Inc.
015 * Portions Copyright 2015-2016 ForgeRock AS.
016 */
017
018package org.opends.guitools.controlpanel.ui.renderer;
019
020import java.awt.Component;
021
022import javax.swing.BorderFactory;
023import javax.swing.JTable;
024import javax.swing.border.Border;
025import javax.swing.table.DefaultTableCellRenderer;
026
027import org.opends.guitools.controlpanel.ui.ColorAndFontConstants;
028
029/** Class used to render the task tables. */
030public class TaskCellRenderer extends DefaultTableCellRenderer
031{
032  private static final long serialVersionUID = -84332267021523835L;
033  /** The border of the first column. TODO: modify CustomCellRenderer to make this public. */
034  private static final Border column0Border =
035    BorderFactory.createCompoundBorder(
036      BorderFactory.createMatteBorder(0, 1, 0, 0,
037          ColorAndFontConstants.gridColor),
038          BorderFactory.createEmptyBorder(4, 4, 4, 4));
039  /** The default border. */
040  private static final Border defaultBorder = CustomCellRenderer.defaultBorder;
041
042  /** Default constructor. */
043  public TaskCellRenderer()
044  {
045    setFont(ColorAndFontConstants.tableFont);
046    setOpaque(true);
047    setBackground(ColorAndFontConstants.treeBackground);
048    setForeground(ColorAndFontConstants.treeForeground);
049  }
050
051  @Override
052  public Component getTableCellRendererComponent(JTable table, Object value,
053      boolean isSelected, boolean hasFocus, int row, int column) {
054    super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
055        row, column);
056
057    if (hasFocus)
058    {
059      setBorder(
060          CustomCellRenderer.getDefaultFocusBorder(table, value, isSelected,
061              row, column));
062    }
063    else if (column == 0)
064    {
065      setBorder(column0Border);
066    }
067    else
068    {
069      setBorder(defaultBorder);
070    }
071    return this;
072  }
073}
074