3853N/A/*
3853N/A * CDDL HEADER START
3853N/A *
3853N/A * The contents of this file are subject to the terms of the
3853N/A * Common Development and Distribution License, Version 1.0 only
3853N/A * (the "License"). You may not use this file except in compliance
3853N/A * with the License.
3853N/A *
3853N/A * You can obtain a copy of the license at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
3853N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
3853N/A * See the License for the specific language governing permissions
3853N/A * and limitations under the License.
3853N/A *
3853N/A * When distributing Covered Code, include this CDDL HEADER in each
3853N/A * file and include the License file at
3853N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
3853N/A * add the following below this CDDL HEADER, with the fields enclosed
3853N/A * by brackets "[]" replaced with your own identifying information:
3853N/A * Portions Copyright [yyyy] [name of copyright owner]
3853N/A *
3853N/A * CDDL HEADER END
3853N/A *
3853N/A *
3853N/A * Copyright 2008 Sun Microsystems, Inc.
3853N/A */
3853N/A
3853N/Apackage org.opends.guitools.controlpanel.ui.components;
3853N/A
3853N/Aimport java.awt.Color;
3853N/Aimport java.awt.Dimension;
3853N/Aimport java.awt.Graphics;
3853N/A
3853N/Aimport javax.swing.JCheckBox;
3853N/Aimport javax.swing.SwingConstants;
3853N/Aimport javax.swing.border.Border;
3853N/Aimport javax.swing.border.EmptyBorder;
3853N/Aimport javax.swing.event.ChangeEvent;
3853N/Aimport javax.swing.event.ChangeListener;
3853N/A
3853N/Aimport org.opends.guitools.controlpanel.browser.IconPool;
3853N/Aimport org.opends.guitools.controlpanel.datamodel.Category;
3853N/Aimport org.opends.guitools.controlpanel.ui.ColorAndFontConstants;
3853N/Aimport org.opends.guitools.controlpanel.ui.border.SelectedCategoryBorder;
3853N/Aimport org.opends.guitools.controlpanel.util.Utilities;
3853N/A
3853N/A
3853N/A/**
3853N/A * A component that acts as a checkbox but uses some customized buttons to
3853N/A * indicate the selected and unselected states. This component is used in the
3853N/A * 'Import LDIF' and 'Export LDIF' panels to hide parts of the dialog.
3853N/A *
3853N/A */
3853N/Aclass CategoryButton extends JCheckBox
3853N/A{
3853N/A private static final long serialVersionUID = 6191857253411571940L;
3853N/A private Border buttonSelectedBorder;
3853N/A private Border buttonUnselectedBorder;
3853N/A private final static Color backgroundColor =
3853N/A ColorAndFontConstants.greyBackground;
3853N/A
3853N/A /**
3853N/A * Constructor of the category button.
3853N/A * @param category the category associated with this button.
3853N/A */
3853N/A public CategoryButton(Category category)
3853N/A {
3853N/A super();
3853N/A setText(category.getName().toString());
3853N/A setHorizontalTextPosition(SwingConstants.TRAILING);
3853N/A setHorizontalAlignment(SwingConstants.LEADING);
3853N/A setFocusPainted(true);
3853N/A setRolloverEnabled(false);
3853N/A setContentAreaFilled(false);
3853N/A setOpaque(true);
3853N/A setBorderPainted(true);
3853N/A setSelectedIcon(Utilities.createImageIcon(
3853N/A IconPool.IMAGE_PATH+"/downarrow.png"));
3853N/A setIcon(Utilities.createImageIcon(IconPool.IMAGE_PATH+"/rightarrow.png"));
3853N/A setRolloverIcon(getIcon());
3853N/A setRolloverSelectedIcon(getSelectedIcon());
3853N/A setPressedIcon(getSelectedIcon());
3853N/A buttonSelectedBorder = new SelectedCategoryBorder();
3853N/A buttonUnselectedBorder = new EmptyBorder(5, 5, 5, 5);
3853N/A setBorder(isSelected() ? buttonSelectedBorder : buttonUnselectedBorder);
3853N/A addChangeListener(new ChangeListener()
3853N/A {
3853N/A public void stateChanged(ChangeEvent e)
3853N/A {
3853N/A setBorder(isSelected() ? buttonSelectedBorder : buttonUnselectedBorder);
3853N/A }
3853N/A });
3853N/A setBackground(backgroundColor);
3853N/A setForeground(ColorAndFontConstants.categoryForeground);
3853N/A setFont(ColorAndFontConstants.categoryFont);
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A public void updateUI()
3853N/A {
3853N/A super.updateUI();
3853N/A // some look and feels replace our border, so take it back
3853N/A setBorder(isSelected() ? buttonSelectedBorder : buttonUnselectedBorder);
3853N/A }
3853N/A
3853N/A /**
3853N/A * {@inheritDoc}
3853N/A */
3853N/A protected void paintComponent(Graphics g) {
3853N/A setBackground(backgroundColor);
3853N/A g.setColor(backgroundColor);
3853N/A g.setFont(ColorAndFontConstants.categoryFont);
3853N/A Dimension size = getSize();
3853N/A g.fillRect(0, 0, size.width, size.height);
3853N/A setBorder(isSelected() ? buttonSelectedBorder : buttonUnselectedBorder);
3853N/A super.paintComponent(g);
3853N/A }
3853N/A}