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 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014 ForgeRock AS.
016 */
017
018package org.opends.guitools.controlpanel.ui.components;
019
020import java.awt.GridBagConstraints;
021import java.awt.GridBagLayout;
022
023import javax.swing.JLabel;
024import javax.swing.JPanel;
025
026import org.opends.guitools.controlpanel.util.Utilities;
027import org.forgerock.i18n.LocalizableMessage;
028import org.forgerock.i18n.LocalizableMessageBuilder;
029
030/**
031 * This is a panel containing two labels with different fonts.  It is used
032 * for instance in the index panel.  The label on the left contains the type
033 * of object and the label on the right, details about the object.
034 *
035 */
036public class TitlePanel extends JPanel
037{
038  private static final long serialVersionUID = -5164867192115208627L;
039  private JLabel lTitle;
040  private JLabel lDetails;
041
042  private LocalizableMessage title;
043  private LocalizableMessage details;
044
045  /**
046   * Constructor of the panel.
047   * @param title the title of the panel.
048   * @param details the details of the panel.
049   */
050  public TitlePanel(LocalizableMessage title, LocalizableMessage details)
051  {
052    super(new GridBagLayout());
053    setOpaque(false);
054    GridBagConstraints gbc = new GridBagConstraints();
055    LocalizableMessageBuilder mb = new LocalizableMessageBuilder();
056    mb.append(title);
057    mb.append(" - ");
058    lTitle = Utilities.createTitleLabel(mb.toMessage());
059    lDetails = Utilities.createDefaultLabel(details);
060    gbc.fill = GridBagConstraints.NONE;
061    gbc.anchor = GridBagConstraints.SOUTHWEST;
062    gbc.gridx = 0;
063    gbc.gridy = 0;
064    add(lTitle, gbc);
065    gbc.gridx ++;
066    add(lDetails, gbc);
067    this.title = title;
068    this.details = details;
069  }
070
071  /**
072   * Sets the title of this panel.
073   * @param title the title of this panel.
074   */
075  public void setTitle(LocalizableMessage title)
076  {
077    lTitle.setText(title+" - ");
078    this.title = title;
079  }
080
081  /**
082   * Sets the details of this panel.
083   * @param details the details of this panel.
084   */
085  public void setDetails(LocalizableMessage details)
086  {
087    lDetails.setText(details.toString());
088    this.details = details;
089  }
090
091  /**
092   * Returns the title of this panel.
093   * @return the title of this panel.
094   */
095  public LocalizableMessage getTitle()
096  {
097    return title;
098  }
099
100  /**
101   * Returns the details of this panel.
102   * @return the details of this panel.
103   */
104  public LocalizableMessage getDetails()
105  {
106    return details;
107  }
108}