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 2010 Sun Microsystems, Inc.
015 * Portions Copyright 2015 ForgeRock AS.
016 */
017package org.opends.guitools.controlpanel.ui.renderer;
018
019import java.awt.Component;
020
021import javax.swing.JTable;
022import javax.swing.table.TableCellRenderer;
023
024import org.opends.guitools.controlpanel.util.Utilities;
025
026/**
027 * Class used to have components that provide a valid accessible name.
028 */
029public class AccessibleTableHeaderRenderer implements TableCellRenderer
030{
031  private TableCellRenderer renderer;
032
033  /**
034   * Constructor of the renderer.
035   * @param renderer the renderer to be used as base.
036   */
037  public AccessibleTableHeaderRenderer(TableCellRenderer renderer)
038  {
039    this.renderer = renderer;
040  }
041
042  /** {@inheritDoc} */
043  public Component getTableCellRendererComponent(JTable table, Object value,
044      boolean isSelected, boolean hasFocus, int row, int column)
045  {
046    Component comp = renderer.getTableCellRendererComponent(table, value,
047        isSelected, hasFocus, row, column);
048    comp.getAccessibleContext().setAccessibleName(
049        Utilities.stripHtmlToSingleLine(String.valueOf(value)));
050    return comp;
051  }
052}