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