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-2016 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/** Class used to have components that provide a valid accessible name. */
027public class AccessibleTableHeaderRenderer implements TableCellRenderer
028{
029  private TableCellRenderer renderer;
030
031  /**
032   * Constructor of the renderer.
033   * @param renderer the renderer to be used as base.
034   */
035  public AccessibleTableHeaderRenderer(TableCellRenderer renderer)
036  {
037    this.renderer = renderer;
038  }
039
040  @Override
041  public Component getTableCellRendererComponent(JTable table, Object value,
042      boolean isSelected, boolean hasFocus, int row, int column)
043  {
044    Component comp = renderer.getTableCellRendererComponent(table, value,
045        isSelected, hasFocus, row, column);
046    comp.getAccessibleContext().setAccessibleName(
047        Utilities.stripHtmlToSingleLine(String.valueOf(value)));
048    return comp;
049  }
050}