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