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 */
017package org.opends.guitools.controlpanel.ui.renderer;
018
019import java.awt.Component;
020
021import javax.swing.JComboBox;
022import javax.swing.JLabel;
023import javax.swing.JList;
024
025import org.opends.guitools.controlpanel.datamodel.CategorizedComboBoxElement;
026/**
027 *  This class is used simply to avoid an inset on the left for the
028 *  elements of the combo box.
029 *  Since this item is a CategorizedComboBoxElement of type
030 *  CategorizedComboBoxElement.Type.REGULAR, it has by default an inset on
031 *  the left.
032 */
033public class NoLeftInsetCategoryComboBoxRenderer extends CustomListCellRenderer
034{
035  /**
036   * The constructor.
037   * @param combo the combo box to be rendered.
038   */
039  public NoLeftInsetCategoryComboBoxRenderer(JComboBox combo)
040  {
041    super(combo);
042  }
043
044  @Override
045  public Component getListCellRendererComponent(JList list, Object value,
046      int index, boolean isSelected, boolean cellHasFocus)
047  {
048    Component comp = super.getListCellRendererComponent(list, value, index,
049        isSelected, cellHasFocus);
050    if (value instanceof CategorizedComboBoxElement)
051    {
052      CategorizedComboBoxElement element = (CategorizedComboBoxElement)value;
053      String name = getStringValue(element);
054      ((JLabel)comp).setText(name);
055    }
056    comp.setFont(defaultFont);
057    return comp;
058  }
059}