/*
 * Sidebar.java
 *
 * Copyright (c) 2003, Oracle Corporation. All rights reserved. Oracle grants
 * you ("Licensee") a non-exclusive, royalty-free, worldwide license to use,
 * modify and redistribute this software in source and binary code form, provided
 * that (i) this copyright notice and license appear on all copies of the
 * software; (ii) Licensee does not utilize the software in a manner disparaging
 * to Oracle; and (iii) Licensee does not utilize the software in a manner that
 * violates the terms of any Licensee agreement with Oracle.
 */

package samples.javaclient.analyzer;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import java.awt.GridLayout;
import javax.swing.BorderFactory;

/**
 * Sidebar, displays the Explorers in different tabs.
 * The Sidebar contains a {@link CatalogExplorer}, a {@link FavoritesExplorer}, 
 * and a {@link DimensionExplorer}.
 * Each Explorer is contained in a JTabbedPane in this Sidebar.
 * The Sidebar and the desktop are contained by a JSplitPane, so users can
 * change the size of the Sidebar and of the desktop.
 * <p>
 * The Sidebar is instantiated in the jbInit method of the Analyzer class.
 * @see Analyzer#jbInit
 */
public class Sidebar extends JPanel  {
  JTabbedPane m_explorerTab = new JTabbedPane();

  /**
   * Constructor.
   */
  public Sidebar() {
    try {
      
      jbInit();
      setMinimumSize(new Dimension(0,0));
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Sets up the user interface for this Sidebar.  
   * Each Explorer is in its own JTabbedPane.
   * @throws Exception 
   */
  private void jbInit() throws Exception {
    /*
     *  the Explorer panel will contain an Explorer Tabbed pane
     */
    this.setLayout(new GridLayout());
    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
    this.add(m_explorerTab);
    m_explorerTab.setMinimumSize(new Dimension(0,0));
  }

  /**
   * Adds an Explorer to the Sidebar.
   * The Explorer is added in a JTabbedPane.
   * 
   * @param explorer The Explorer to add.
   * @param title Title for the Explorer, such as "Saved Selections".
   * @return The number of Explorers that this Sidebar contains, including the 
   *         newly added Explorer.
   *         
   * @see CatalogExplorer        
   * @see DimensionExplorer
   * @see FavoritesExplorer
   * @see Analyzer#jbInit
   */
  public int addExplorer(JPanel explorer, String title) {
    // add new explorer to the end
    int count = m_explorerTab.getTabCount();
    explorer.setMinimumSize(new Dimension(0,0));
    m_explorerTab.add(title, explorer);
    return count;
  }

}